From b18b1d96971752b434df736e85c774c903c2f03c Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 23 Nov 2023 10:34:07 +0100 Subject: [PATCH] Fix invitation notifications [SCI-9609] --- app/helpers/notifications_helper.rb | 22 +++++++++++-------- .../recipients/direct_recipient.rb | 11 ++++++++++ .../extends/notification_extends.rb | 12 +++++----- 3 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 app/notifications/recipients/direct_recipient.rb diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 4635eb814..42d13db8a 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -10,17 +10,21 @@ module NotificationsHelper unassigned_user: target_user.name, team: team.name, unassigned_by_user: user.name) - title = I18n.t('notifications.assign_user_to_team', - assigned_user: target_user.name, - role: role, - team: team.name, - assigned_by_user: user.name) if role + if role + title = I18n.t('notifications.assign_user_to_team', + assigned_user: target_user.name, + role: role, + team: team.name, + assigned_by_user: user.name) + end message = "#{I18n.t('search.index.team')} #{team.name}" end - GeneralNotification.with( - title: sanitize_input(title), - message: sanitize_input(message) - ).deliver_later(target_user) + GeneralNotification.send_notifications({ + type: role ? :invite_user_to_team : :remove_user_from_team, + title: sanitize_input(title), + message: sanitize_input(message), + user: target_user + }) end end diff --git a/app/notifications/recipients/direct_recipient.rb b/app/notifications/recipients/direct_recipient.rb new file mode 100644 index 000000000..22cc75d06 --- /dev/null +++ b/app/notifications/recipients/direct_recipient.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class Recipients::DirectRecipient + def initialize(params) + @params = params + end + + def recipients + [@params[:user]] + end +end diff --git a/config/initializers/extends/notification_extends.rb b/config/initializers/extends/notification_extends.rb index 4efd576f5..6c3a98d66 100644 --- a/config/initializers/extends/notification_extends.rb +++ b/config/initializers/extends/notification_extends.rb @@ -86,13 +86,13 @@ class NotificationExtends smart_annotation_added: { recipients_module: :AnnotatedRecipients }, - invite_user_to_team_activity: { + invite_user_to_team: { code: 92, - recipients_module: :AssignedRecipients + recipients_module: :DirectRecipient }, - remove_user_from_team_activity: { + remove_user_from_team: { code: 93, - recipients_module: :AssignedRecipients + recipients_module: :DirectRecipient }, change_users_role_on_team_activity: { code: 94, @@ -148,8 +148,8 @@ class NotificationExtends smart_annotation_added ], other_team_invitation: %I[ - invite_user_to_team_activity - remove_user_from_team_activity + invite_user_to_team + remove_user_from_team change_users_role_on_team_activity ] }