Skip to content

Commit

Permalink
refactor(tasks): ♻️ rename users property to user_notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kikkomep committed Aug 30, 2024
1 parent d11f1ce commit 6c59784
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lifemonitor/api/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def deleteUserNotification(user: User, notitification_uuid: str):
logger.debug("Search result notification %r ...", n)
if n is None:
return lm_exceptions.EntityNotFoundException(Notification, entity_id=notitification_uuid)
user.notifications.remove(n)
user.user_notifications.remove(n)
user.save()

@staticmethod
Expand All @@ -721,7 +721,7 @@ def deleteUserNotifications(user: User, list_of_uuids: List[str]):
logger.debug("Search result notification %r ...", n)
if n is None:
return lm_exceptions.EntityNotFoundException(Notification, entity_id=n_uuid)
user.notifications.remove(n)
user.user_notifications.remove(n)
user.save()

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions lifemonitor/auth/oauth2/client/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def merge_users(merge_from: User, merge_into: User, provider: str = None):
db.session.add(auth)

# move all the notification of the user "merge_from" to the user "merge_into"
merge_into_notification_ids = [un.notification.id for un in merge_into.notifications]
for user_notification in list(merge_from.notifications):
merge_into_notification_ids = [un.notification.id for un in merge_into.user_notifications]
for user_notification in list(merge_from.user_notifications):
if user_notification.notification.id not in merge_into_notification_ids:
user_notification.user = merge_into
db.session.add(user_notification)
Expand Down
2 changes: 1 addition & 1 deletion lifemonitor/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def send_notification(n: Notification, recipients: List[str] = None) -> Optional
logger.debug("Mail recipients for notification '%r': %r", n.id, recipients)
if not recipients:
recipients = [
u.user.email for u in n.users
u.user.email for u in n.user_notifications
if u.emailed is None and u.user.email_notifications_enabled and u.user.email
]
if len(recipients) > 0:
Expand Down
6 changes: 3 additions & 3 deletions lifemonitor/tasks/jobs/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from apscheduler.triggers.cron import CronTrigger
from apscheduler.triggers.interval import IntervalTrigger
from lifemonitor.auth.models import (Notification,
UnconfiguredEmailNotification, User)
UnconfiguredEmailNotification, User, UserNotification)
from lifemonitor.mail import send_notification
from lifemonitor.tasks.scheduler import TASK_EXPIRATION_TIME, schedule

Expand All @@ -45,14 +45,14 @@ def send_email_notifications():
for n in notifications:
logger.debug("Processing notification %r ...", n)
recipients = [
u.user.email for u in n.users
u.user.email for u in n.user_notifications
if u.emailed is None and u.user.email_notifications_enabled and u.user.email
]
sent = send_notification(n, recipients=recipients)
logger.debug("Notification email sent: %r", sent is not None)
if sent:
logger.debug("Notification '%r' sent by email @ %r", n.id, sent)
for u in n.users:
for u in n.user_notifications:
if u.user.email in recipients:
u.emailed = sent
n.save()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/tasks/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_unconfigured_email_notification(mail, app_settings, app_context, user1)
assert len(notifications) == 1, "Unexpected number of notifications"

n: Notification = notifications[0]
un: UserNotification = next((_.user for _ in n.users if _.user_id == user.id), None)
un: UserNotification = next((_.user for _ in n.user_notifications if _.user_id == user.id), None)
assert un is not None, "User1 should be notified"

# no additional notification should be generated
Expand Down

0 comments on commit 6c59784

Please sign in to comment.