fix issued cert
This commit is contained in:
@@ -23,7 +23,8 @@ MESSAGE = """
|
|||||||
Oi {first_name}, tudo bem?<br/><br/>
|
Oi {first_name}, tudo bem?<br/><br/>
|
||||||
|
|
||||||
O certificado do curso <b>{course}</b> vai expirar em breve.<br/>
|
O certificado do curso <b>{course}</b> vai expirar em breve.<br/>
|
||||||
Para manter sua certificação válida, é recomendável refazer o curso 30 dias antes da expiração.<br/><br/>
|
Para manter sua certificação válida, é recomendável refazer o curso 30 dias
|
||||||
|
antes da expiração.<br/><br/>
|
||||||
|
|
||||||
<a href="https://saladeaula.digital">👉 Acesse o curso e renove sua certificação</a>
|
<a href="https://saladeaula.digital">👉 Acesse o curso e renove sua certificação</a>
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ MESSAGE = """
|
|||||||
Oi {first_name}, tudo bem?<br/><br/>
|
Oi {first_name}, tudo bem?<br/><br/>
|
||||||
|
|
||||||
Há 3 dias você foi matriculado no curso <b>{course}</b>.<br/>
|
Há 3 dias você foi matriculado no curso <b>{course}</b>.<br/>
|
||||||
Ainda não começou? Não perca a oportunidade de aprender e aproveitar ao máximo seu curso!<br/><br/>
|
Ainda não começou? Não perca a oportunidade de aprender e aproveitar
|
||||||
|
ao máximo seu curso!<br/><br/>
|
||||||
|
|
||||||
<a href="https://saladeaula.digital">👉 Acesse seu curso agora</a>
|
<a href="https://saladeaula.digital">👉 Acesse seu curso agora</a>
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
|||||||
course = enrollment_layer.collection.get_items(
|
course = enrollment_layer.collection.get_items(
|
||||||
TransactKey(new_image['id'])
|
TransactKey(new_image['id'])
|
||||||
+ SortKey('METADATA#COURSE', path_spec='cert', rename_key='cert')
|
+ SortKey('METADATA#COURSE', path_spec='cert', rename_key='cert')
|
||||||
|
# Post-migration: remove the following lines
|
||||||
+ SortKey('STARTED', path_spec='started_at', rename_key='started_at')
|
+ SortKey('STARTED', path_spec='started_at', rename_key='started_at')
|
||||||
+ SortKey('COMPLETED', path_spec='completed_at', rename_key='completed_at'),
|
+ SortKey('COMPLETED', path_spec='completed_at', rename_key='completed_at'),
|
||||||
flatten_top=False,
|
flatten_top=False,
|
||||||
@@ -42,7 +43,11 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
|||||||
completed_at: datetime = fromisoformat(course['completed_at']) # type: ignore
|
completed_at: datetime = fromisoformat(course['completed_at']) # type: ignore
|
||||||
cert_expires_at = now_ + timedelta(days=int(cert['exp_interval']))
|
cert_expires_at = now_ + timedelta(days=int(cert['exp_interval']))
|
||||||
|
|
||||||
data = json.dumps(
|
try:
|
||||||
|
# Send template URI and data to Paperforge API to generate a PDF
|
||||||
|
r = requests.post(
|
||||||
|
PAPERFORGE_API,
|
||||||
|
data=json.dumps(
|
||||||
{
|
{
|
||||||
'template_s3_uri': cert['s3_uri'],
|
'template_s3_uri': cert['s3_uri'],
|
||||||
'template_vars': {
|
'template_vars': {
|
||||||
@@ -55,26 +60,28 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
|||||||
'year': now_.strftime('%Y'),
|
'year': now_.strftime('%Y'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
# Send template URI and data to Paperforge API to generate a PDF
|
|
||||||
r = requests.post(PAPERFORGE_API, data=data)
|
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
object_key = f'issuedcerts/{enrollment_id}.pdf'
|
object_key = f'issuedcerts/{enrollment_id}.pdf'
|
||||||
s3_uri = f's3://{BUCKET_NAME}/{object_key}'
|
s3_uri = f's3://{BUCKET_NAME}/{object_key}'
|
||||||
|
|
||||||
try:
|
|
||||||
s3_client.put_object(
|
s3_client.put_object(
|
||||||
Bucket=BUCKET_NAME,
|
Bucket=BUCKET_NAME,
|
||||||
Key=object_key,
|
Key=object_key,
|
||||||
Body=r.content,
|
Body=r.content,
|
||||||
ContentType='application/pdf',
|
ContentType='application/pdf',
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
|
||||||
logger.exception(exc)
|
|
||||||
raise
|
|
||||||
|
|
||||||
logger.debug(f'PDF uploaded successfully to {s3_uri}')
|
logger.debug(f'PDF uploaded successfully to {s3_uri}')
|
||||||
|
except KeyError:
|
||||||
|
# PDF generation fails if template URI is missing
|
||||||
|
s3_uri = None
|
||||||
|
logger.debug('Template URI is missing')
|
||||||
|
except requests.exceptions.RequestException as exc:
|
||||||
|
logger.exception(exc)
|
||||||
|
raise
|
||||||
|
|
||||||
return enrollment_layer.update_item(
|
return enrollment_layer.update_item(
|
||||||
key=KeyPair(
|
key=KeyPair(
|
||||||
@@ -84,10 +91,10 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
|||||||
update_expr='SET issued_cert = :issued_cert',
|
update_expr='SET issued_cert = :issued_cert',
|
||||||
expr_attr_values={
|
expr_attr_values={
|
||||||
':issued_cert': {
|
':issued_cert': {
|
||||||
's3_uri': s3_uri,
|
|
||||||
'issued_at': now_,
|
'issued_at': now_,
|
||||||
'expires_at': cert_expires_at,
|
'expires_at': cert_expires_at,
|
||||||
},
|
}
|
||||||
|
| ({'s3_uri': s3_uri} if s3_uri else {}),
|
||||||
},
|
},
|
||||||
cond_expr='attribute_exists(sk)',
|
cond_expr='attribute_exists(sk)',
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ def update_progress(
|
|||||||
key=KeyPair(id, '0'),
|
key=KeyPair(id, '0'),
|
||||||
update_expr='SET progress = :progress, \
|
update_expr='SET progress = :progress, \
|
||||||
#status = :in_progress, \
|
#status = :in_progress, \
|
||||||
|
started_at = :now, \
|
||||||
updated_at = :now',
|
updated_at = :now',
|
||||||
cond_expr='#status = :pending',
|
cond_expr='#status = :pending',
|
||||||
expr_attr_names={
|
expr_attr_names={
|
||||||
@@ -73,7 +74,7 @@ def update_progress(
|
|||||||
item={
|
item={
|
||||||
'id': id,
|
'id': id,
|
||||||
'sk': 'STARTED',
|
'sk': 'STARTED',
|
||||||
'started_at': now_,
|
'created_at': now_,
|
||||||
},
|
},
|
||||||
cond_expr='attribute_not_exists(sk)',
|
cond_expr='attribute_not_exists(sk)',
|
||||||
)
|
)
|
||||||
@@ -191,6 +192,7 @@ def _set_status_as_completed(
|
|||||||
update_expr='SET #status = :completed, \
|
update_expr='SET #status = :completed, \
|
||||||
progress = :progress, \
|
progress = :progress, \
|
||||||
score = :score, \
|
score = :score, \
|
||||||
|
completed_at = :now, \
|
||||||
updated_at = :now',
|
updated_at = :now',
|
||||||
cond_expr='#status = :in_progress',
|
cond_expr='#status = :in_progress',
|
||||||
expr_attr_names={'#status': 'status'},
|
expr_attr_names={'#status': 'status'},
|
||||||
@@ -207,7 +209,7 @@ def _set_status_as_completed(
|
|||||||
item={
|
item={
|
||||||
'id': id,
|
'id': id,
|
||||||
'sk': 'COMPLETED',
|
'sk': 'COMPLETED',
|
||||||
'completed_at': now_,
|
'created_at': now_,
|
||||||
},
|
},
|
||||||
cond_expr='attribute_not_exists(sk)',
|
cond_expr='attribute_not_exists(sk)',
|
||||||
)
|
)
|
||||||
@@ -291,6 +293,7 @@ def _set_status_as_failed(
|
|||||||
progress = :progress, \
|
progress = :progress, \
|
||||||
score = :score, \
|
score = :score, \
|
||||||
access_expired = :true, \
|
access_expired = :true, \
|
||||||
|
failed_at = :now, \
|
||||||
updated_at = :now',
|
updated_at = :now',
|
||||||
cond_expr='#status = :in_progress',
|
cond_expr='#status = :in_progress',
|
||||||
expr_attr_names={'#status': 'status'},
|
expr_attr_names={'#status': 'status'},
|
||||||
@@ -308,7 +311,7 @@ def _set_status_as_failed(
|
|||||||
item={
|
item={
|
||||||
'id': id,
|
'id': id,
|
||||||
'sk': 'FAILED',
|
'sk': 'FAILED',
|
||||||
'failed_at': now_,
|
'created_at': now_,
|
||||||
},
|
},
|
||||||
cond_expr='attribute_not_exists(sk)',
|
cond_expr='attribute_not_exists(sk)',
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user