From cffb761c4d5feb1c266c987b0c4cd4524a372f21 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Tue, 9 Jul 2024 14:20:28 +0200 Subject: [PATCH] fix: [backend:app] Make sure to cast uesr_id into integer and updated config.sample --- config.py.sample | 8 ++++++++ exercise.py | 9 +++++++-- notification.py | 6 +++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/config.py.sample b/config.py.sample index 8bd7b8c..66282f4 100644 --- a/config.py.sample +++ b/config.py.sample @@ -14,6 +14,14 @@ live_logs_accepted_scope = { 'tags': '*', } +user_activity_accepted_scope = { + 'events': ['view', 'add', 'edit', 'delete', 'restSearch',], + 'attributes': ['add', 'edit', 'delete', 'restSearch',], + 'objects': ['add', 'edit', 'delete',], + 'eventReports': ['view', 'add', 'edit', 'delete',], + 'tags': '*', +} + import logging logger = logging.getLogger('misp-exercise-dashboard') format = '[%(levelname)s] %(asctime)s - %(message)s' diff --git a/exercise.py b/exercise.py index de34964..7c3c207 100644 --- a/exercise.py +++ b/exercise.py @@ -77,8 +77,12 @@ def restore_exercices_progress(): data = json.load(f) db.EXERCISES_STATUS = data['EXERCISES_STATUS'] db.SELECTED_EXERCISES = data['SELECTED_EXERCISES'] - db.USER_ID_TO_EMAIL_MAPPING = data['USER_ID_TO_EMAIL_MAPPING'] - db.USER_ID_TO_AUTHKEY_MAPPING = data['USER_ID_TO_AUTHKEY_MAPPING'] + db.USER_ID_TO_EMAIL_MAPPING = {} + for user_id_str, email in data['USER_ID_TO_EMAIL_MAPPING']: + db.USER_ID_TO_EMAIL_MAPPING[int(user_id_str)] = email + db.USER_ID_TO_AUTHKEY_MAPPING = {} + for user_id_str, authkey in data['USER_ID_TO_AUTHKEY_MAPPING']: + db.USER_ID_TO_AUTHKEY_MAPPING[int(user_id_str)] = authkey except: logger.info('Could not restore exercise progress') @@ -323,6 +327,7 @@ def get_progress(): progress = {} for user_id in completion_for_users.keys(): if user_id not in db.USER_ID_TO_EMAIL_MAPPING: + print('unknown user id', user_id) continue progress[user_id] = { 'email': db.USER_ID_TO_EMAIL_MAPPING[user_id], diff --git a/notification.py b/notification.py index 01d815d..3d88cdc 100644 --- a/notification.py +++ b/notification.py @@ -209,9 +209,9 @@ def is_accepted_user_activity(notification) -> bool: return False scope, action = get_scope_action_from_url(notification['url']) - if scope in config.uesr_activity_accepted_scope: - if config.uesr_activity_accepted_scope == '*': + if scope in config.user_activity_accepted_scope: + if config.user_activity_accepted_scope == '*': return True - elif action in config.uesr_activity_accepted_scope[scope]: + elif action in config.user_activity_accepted_scope[scope]: return True return False \ No newline at end of file