Compare commits

...

2 commits

Author SHA1 Message Date
Sami Mokaddem
d637f2a0ee new: [backend:user_activity] Improved user activity filtering 2024-07-09 14:05:40 +02:00
Sami Mokaddem
7ed839d391 fix: [backend:exercise] Gracefully catch user_id without emails 2024-07-09 14:05:00 +02:00
3 changed files with 21 additions and 1 deletions

View file

@ -322,6 +322,8 @@ def get_progress():
completion_for_users = get_completion_for_users()
progress = {}
for user_id in completion_for_users.keys():
if user_id not in db.USER_ID_TO_EMAIL_MAPPING:
continue
progress[user_id] = {
'email': db.USER_ID_TO_EMAIL_MAPPING[user_id],
'exercises': {},

View file

@ -197,4 +197,21 @@ def is_accepted_notification(notification) -> bool:
return True
elif action in config.live_logs_accepted_scope[scope]:
return True
return False
def is_accepted_user_activity(notification) -> bool:
global VERBOSE_MODE
if notification['user_agent'] == 'misp-exercise-dashboard': # Ignore message generated from this app
return False
if '@' not in notification['user']: # Ignore message from system
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 == '*':
return True
elif action in config.uesr_activity_accepted_scope[scope]:
return True
return False

View file

@ -150,10 +150,11 @@ async def handleMessage(topic, s, message):
if notification_model.is_accepted_notification(notification):
notification_model.record_notification(notification)
ZMQ_MESSAGE_COUNT_LAST_TIMESPAN += 1
await sio.emit('notification', notification)
if notification_model.is_accepted_user_activity(notification):
user_id = notification_model.get_user_id(data)
if user_id is not None:
USER_ACTIVITY[user_id] += 1
await sio.emit('notification', notification)
user_id = notification_model.get_user_id(data)
if user_id is not None: