notifications: use an explicit FK mark when creating notifications, previous way was prone to cache problems.

This commit is contained in:
Marcin Kuzminski 2018-07-16 19:07:27 +02:00
parent 1bd980d752
commit c4e1783d4f
2 changed files with 4 additions and 1 deletions

View file

@ -155,6 +155,7 @@ class TestNotificationsController(TestController):
notification = NotificationModel().create(
created_by=cur_user, notification_subject=subject,
notification_body=notif_body, recipients=[cur_user, u1, u2])
Session().commit()
response = self.app.get(
route_path('notifications_show',

View file

@ -3909,16 +3909,18 @@ class Notification(Base, BaseModel):
notification.type_ = type_
notification.created_on = datetime.datetime.now()
# For each recipient link the created notification to his account
for u in recipients:
assoc = UserNotification()
assoc.user_id = u.user_id
assoc.notification = notification
# if created_by is inside recipients mark his notification
# as read
if u.user_id == created_by.user_id:
assoc.read = True
Session().add(assoc)
u.notifications.append(assoc)
Session().add(notification)
return notification