fix issued cert
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
"""
|
||||
If a certificate exists, remind the user that the certificate expired.
|
||||
"""
|
||||
|
||||
SUBJECT = 'Seu certificado {course} expirou!'
|
||||
MESSAGE = """
|
||||
Oi {first_name}, tudo bem?<br/><br/>
|
||||
|
||||
O certificado do curso <b>{course}</b> expirou.<br/>
|
||||
Para manter sua certificação válida, é necessário refazer o curso.<br/><br/>
|
||||
|
||||
<a href="https://saladeaula.digital">👉 Acesse o curso e renove sua certificação</a>
|
||||
"""
|
||||
@@ -15,7 +15,7 @@ from boto3clients import dynamodb_client, s3_client
|
||||
from config import BUCKET_NAME, ENROLLMENT_TABLE, PAPERFORGE_API
|
||||
|
||||
logger = Logger(__name__)
|
||||
enrollment_layer = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@event_source(data_class=EventBridgeEvent)
|
||||
@@ -24,24 +24,23 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
new_image = event.detail['new_image']
|
||||
now_ = now()
|
||||
enrollment_id = new_image['id']
|
||||
course = enrollment_layer.collection.get_items(
|
||||
TransactKey(new_image['id'])
|
||||
+ 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('COMPLETED', path_spec='completed_at', rename_key='completed_at'),
|
||||
flatten_top=False,
|
||||
cert = dyn.collection.get_item(
|
||||
KeyPair(
|
||||
pk=new_image['id'],
|
||||
sk=SortKey('METADATA#COURSE', path_spec='cert', rename_key='cert'),
|
||||
),
|
||||
raise_on_error=False,
|
||||
default=False,
|
||||
)
|
||||
|
||||
if 'cert' not in course:
|
||||
if not cert:
|
||||
logger.debug('Certificate not found')
|
||||
# There is no certificate to issue from metadata
|
||||
return False
|
||||
|
||||
cert = course['cert']
|
||||
started_at: datetime = fromisoformat(course['started_at']) # type: ignore
|
||||
completed_at: datetime = fromisoformat(course['completed_at']) # type: ignore
|
||||
cert_expires_at = now_ + timedelta(days=int(cert['exp_interval']))
|
||||
started_at: datetime = fromisoformat(new_image['started_at']) # type: ignore
|
||||
completed_at: datetime = fromisoformat(new_image['completed_at']) # type: ignore
|
||||
cert_expires_at = completed_at + timedelta(days=int(cert['exp_interval']))
|
||||
|
||||
try:
|
||||
# Send template URI and data to Paperforge API to generate a PDF
|
||||
@@ -83,13 +82,14 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
logger.exception(exc)
|
||||
raise
|
||||
|
||||
return enrollment_layer.update_item(
|
||||
return dyn.update_item(
|
||||
key=KeyPair(
|
||||
pk=enrollment_id,
|
||||
sk='0',
|
||||
),
|
||||
update_expr='SET issued_cert = :issued_cert',
|
||||
update_expr='SET issued_cert = :issued_cert, uploaded_at = :now',
|
||||
expr_attr_values={
|
||||
':now': now_,
|
||||
':issued_cert': {
|
||||
'issued_at': now_,
|
||||
'expires_at': cert_expires_at,
|
||||
|
||||
Reference in New Issue
Block a user