diff --git a/src/server/BreCal/services/schedule_routines.py b/src/server/BreCal/services/schedule_routines.py index 5737e1d..f108933 100644 --- a/src/server/BreCal/services/schedule_routines.py +++ b/src/server/BreCal/services/schedule_routines.py @@ -114,11 +114,11 @@ def SendEmails(email_dict): defs.message_types = json.load(f) f.close() - for user, notifications in email_dict.items(): + for user_email, notifications in email_dict.items(): msg = EmailMessage() msg["Subject"] = '[Bremen calling] Notification' msg["From"] = defs.email_credentials["sender"] - msg["To"] = user["user_email"] + msg["To"] = user_email with open(os.path.join(current_path,'../msg/notification_template.html'), mode="r", encoding="utf-8") as file: body = file.read() @@ -170,7 +170,7 @@ def SendEmails(email_dict): body = body.replace("[[NOTIFICATION_ELEMENTS]]", replacement) msg.set_content(body, subtype='html', charset='utf-8', cte='8bit') - conn.sendmail(defs.email_credentials["sender"], user["user_email"], msg.as_string()) + conn.sendmail(defs.email_credentials["sender"], user_email, msg.as_string()) except Exception as ex: logging.error(ex) @@ -212,13 +212,15 @@ def SendNotifications(): p_query = "SELECT * from shipcall_participant_map where shipcall_id = ?id?" assigned_participants = commands.query(p_query, model=model.ShipcallParticipantMap, param={"id":notification.shipcall_id}) for assigned_participant in assigned_participants: + if not assigned_participant.participant_id in users_dict: + continue users = users_dict[assigned_participant.participant_id] for user in users: # send notification to user if user["notify_email"]: - if user not in email_dict: - email_dict[user] = [] - email_dict[user].append(notification) + if user["user_email"] not in email_dict: + email_dict[user["user_email"]] = [] + email_dict[user["user_email"]].append(notification) if user["notify_whatsapp"]: # TBD pass @@ -226,20 +228,21 @@ def SendNotifications(): # TBD pass else: - users = users_dict[notification.participant_id] - for user in users: - user_notifications = model.bitflag_to_list(user["notify_event"]) - # send notification to user - if user["notify_email"] and notification.type in user_notifications: - if user not in email_dict: - email_dict[user] = [] - email_dict[user].append(notification) - if user["notify_whatsapp"] and notification.type in user_notifications: - # TBD - pass - if user["notify_signal"] and notification.type in user_notifications: - # TBD - pass + if notification.participant_id in users_dict: + users = users_dict[notification.participant_id] + for user in users: + user_notifications = model.bitflag_to_list(user["notify_event"]) + # send notification to user + if user["notify_email"] and notification.type in user_notifications: + if user["user_email"] not in email_dict: + email_dict[user["user_email"]] = [] + email_dict[user["user_email"]].append(notification) + if user["notify_whatsapp"] and notification.type in user_notifications: + # TBD + pass + if user["notify_signal"] and notification.type in user_notifications: + # TBD + pass # mark as sent commands.execute("UPDATE notification SET level = 2 WHERE id = ?id?", param={"id":notification.id})