fix enrollment
This commit is contained in:
@@ -63,6 +63,7 @@ def enroll(
|
||||
user = enrollment.user
|
||||
course = enrollment.course
|
||||
tenant_id = tenant['id']
|
||||
lock_hash = md5_hash('%s%s' % (user.id, course.id))
|
||||
|
||||
with persistence_layer.transact_writer() as transact:
|
||||
transact.put(
|
||||
@@ -117,19 +118,24 @@ def enroll(
|
||||
},
|
||||
)
|
||||
|
||||
class DeduplicationConflictError(Exception):
|
||||
def __init__(self, *args):
|
||||
super().__init__('Enrollment already exists')
|
||||
|
||||
# Prevents the user from enrolling in the same course again until
|
||||
# the deduplication window expires or is removed
|
||||
transact.condition(
|
||||
key=KeyPair('lock', lock_hash),
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
exc_cls=DeduplicationConflictError,
|
||||
)
|
||||
|
||||
if deduplication_window:
|
||||
lock_hash = md5_hash('%s%s' % (user.id, course.id))
|
||||
offset_days = deduplication_window['offset_days']
|
||||
ttl_expiration = ttl(
|
||||
start_dt=now_ + timedelta(days=course.access_period - offset_days)
|
||||
)
|
||||
|
||||
class DeduplicationConflictError(Exception):
|
||||
def __init__(self, *args):
|
||||
super().__init__('Enrollment already exists')
|
||||
|
||||
transact.put(
|
||||
item={
|
||||
'id': 'lock',
|
||||
@@ -138,8 +144,6 @@ def enroll(
|
||||
'create_date': now_,
|
||||
'ttl': ttl_expiration,
|
||||
},
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
exc_cls=DeduplicationConflictError,
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
|
||||
Reference in New Issue
Block a user