fix: [backend:exercise] Correctly restore email mapping

This commit is contained in:
Sami Mokaddem 2024-07-09 16:13:45 +02:00
parent f4a3a3d86a
commit 747c11ac85
2 changed files with 8 additions and 7 deletions

View file

@ -9,7 +9,7 @@ misp_skipssl = True
live_logs_accepted_scope = { live_logs_accepted_scope = {
'events': ['add', 'edit', 'delete', 'restSearch',], 'events': ['add', 'edit', 'delete', 'restSearch',],
'attributes': ['add', 'add_attachment', 'edit', 'delete', 'restSearch',], 'attributes': ['add', 'add_attachment', 'edit', 'revise_object', 'delete', 'restSearch',],
'eventReports': ['add', 'edit', 'delete',], 'eventReports': ['add', 'edit', 'delete',],
'tags': '*', 'tags': '*',
} }
@ -17,7 +17,7 @@ live_logs_accepted_scope = {
user_activity_accepted_scope = { user_activity_accepted_scope = {
'events': ['view', 'add', 'edit', 'delete', 'restSearch',], 'events': ['view', 'add', 'edit', 'delete', 'restSearch',],
'attributes': ['add', 'add_attachment', 'edit', 'delete', 'restSearch',], 'attributes': ['add', 'add_attachment', 'edit', 'delete', 'restSearch',],
'objects': ['add', 'edit', 'delete',], 'objects': ['add', 'edit', 'revise_object', 'delete',],
'eventReports': ['view', 'add', 'edit', 'delete',], 'eventReports': ['view', 'add', 'edit', 'delete',],
'tags': '*', 'tags': '*',
} }

View file

@ -73,15 +73,16 @@ def backup_exercises_progress():
def restore_exercices_progress(): def restore_exercices_progress():
try: try:
with open('backup.json', 'r') as f: with open('backup.json', 'r') as f:
data = json.load(f) data = json.load(f)
db.EXERCISES_STATUS = data['EXERCISES_STATUS'] db.EXERCISES_STATUS = data['EXERCISES_STATUS']
db.SELECTED_EXERCISES = data['SELECTED_EXERCISES'] db.SELECTED_EXERCISES = data['SELECTED_EXERCISES']
db.USER_ID_TO_EMAIL_MAPPING = {} db.USER_ID_TO_EMAIL_MAPPING = {}
for user_id_str, email in data['USER_ID_TO_EMAIL_MAPPING']: for user_id_str, email in data['USER_ID_TO_EMAIL_MAPPING'].items():
db.USER_ID_TO_EMAIL_MAPPING[int(user_id_str)] = email db.USER_ID_TO_EMAIL_MAPPING[int(user_id_str)] = email
db.USER_ID_TO_AUTHKEY_MAPPING = {} db.USER_ID_TO_AUTHKEY_MAPPING = {}
for user_id_str, authkey in data['USER_ID_TO_AUTHKEY_MAPPING']: for user_id_str, authkey in data['USER_ID_TO_AUTHKEY_MAPPING'].items():
db.USER_ID_TO_AUTHKEY_MAPPING[int(user_id_str)] = authkey db.USER_ID_TO_AUTHKEY_MAPPING[int(user_id_str)] = authkey
except: except:
logger.info('Could not restore exercise progress') logger.info('Could not restore exercise progress')
@ -212,14 +213,14 @@ def resetAllExerciseProgress():
def get_completed_tasks_for_user(user_id: int): def get_completed_tasks_for_user(user_id: int):
completion = get_completion_for_users()[user_id] completion = get_completion_for_users().get(user_id, {})
completed_tasks = {} completed_tasks = {}
for exec_uuid, tasks in completion.items(): for exec_uuid, tasks in completion.items():
completed_tasks[exec_uuid] = [task_uuid for task_uuid, completed in tasks.items() if completed] completed_tasks[exec_uuid] = [task_uuid for task_uuid, completed in tasks.items() if completed]
return completed_tasks return completed_tasks
def get_incomplete_tasks_for_user(user_id: int): def get_incomplete_tasks_for_user(user_id: int):
completion = get_completion_for_users()[user_id] completion = get_completion_for_users().get(user_id, {})
incomplete_tasks = {} incomplete_tasks = {}
for exec_uuid, tasks in completion.items(): for exec_uuid, tasks in completion.items():
incomplete_tasks[exec_uuid] = [task_uuid for task_uuid, completed in tasks.items() if not completed] incomplete_tasks[exec_uuid] = [task_uuid for task_uuid, completed in tasks.items() if not completed]
@ -367,7 +368,7 @@ def is_valid_evaluation_context(user_id: int, inject_evaluation: dict, data: dic
else: else:
logger.debug('Unknown request type') logger.debug('Unknown request type')
return False return False
return False return True
async def inject_checker_router(user_id: int, inject_evaluation: dict, data: dict, context: dict) -> bool: async def inject_checker_router(user_id: int, inject_evaluation: dict, data: dict, context: dict) -> bool:
if not is_valid_evaluation_context(user_id, inject_evaluation, data, context): if not is_valid_evaluation_context(user_id, inject_evaluation, data, context):