diff --git a/app/controllers/concerns/steps_actions.rb b/app/controllers/concerns/steps_actions.rb index 73b40842b..7103d62f1 100644 --- a/app/controllers/concerns/steps_actions.rb +++ b/app/controllers/concerns/steps_actions.rb @@ -48,6 +48,7 @@ module StepsActions smart_annotation_notification( old_text: old_text, new_text: checklist_item.text, + subject: step, title: t('notifications.checklist_title', user: current_user.full_name, step: step.name), @@ -59,6 +60,7 @@ module StepsActions smart_annotation_notification( old_text: old_text, new_text: step_text.text, + subject: step, title: t('notifications.step_text_title', user: current_user.full_name, step: step.name), @@ -70,6 +72,7 @@ module StepsActions smart_annotation_notification( old_text: old_text, new_text: checklist.name, + subject: step, title: t('notifications.checklist_title', user: current_user.full_name, step: step.name), @@ -81,6 +84,7 @@ module StepsActions smart_annotation_notification( old_text: old_text, new_text: step.description, + subject: step, title: t('notifications.step_description_title', user: current_user.full_name, step: step.name), diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index 32542e5a2..dab2cb19e 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -602,6 +602,7 @@ class ExperimentsController < ApplicationController smart_annotation_notification( old_text: old_text, new_text: @experiment.description, + subject: @experiment, title: t('notifications.experiment_annotation_title', experiment: @experiment.name, user: current_user.full_name), diff --git a/app/controllers/my_module_repositories_controller.rb b/app/controllers/my_module_repositories_controller.rb index 18bf9112f..e32d8cf4d 100644 --- a/app/controllers/my_module_repositories_controller.rb +++ b/app/controllers/my_module_repositories_controller.rb @@ -264,6 +264,7 @@ class MyModuleRepositoriesController < ApplicationController smart_annotation_notification( old_text: nil, new_text: comment, + subject: module_repository_row.repository_row, title: t('notifications.my_module_consumption_comment_annotation_title', repository_item: module_repository_row.repository_row.name, repository: @repository.name, diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index 64552ee7f..ab63578e9 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -561,6 +561,7 @@ class MyModulesController < ApplicationController smart_annotation_notification( old_text: old_text, new_text: @my_module.description, + subject: @my_module, title: t('notifications.my_module_description_annotation_title', my_module: @my_module.name, user: current_user.full_name), @@ -575,6 +576,7 @@ class MyModulesController < ApplicationController smart_annotation_notification( old_text: old_text, new_text: @my_module.protocol.description, + subject: @my_module, title: t('notifications.my_module_protocol_annotation_title', my_module: @my_module.name, user: current_user.full_name), diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 8b524e40f..42d9fd3d0 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -1079,6 +1079,7 @@ class ProtocolsController < ApplicationController smart_annotation_notification( old_text: old_text, new_text: @protocol.description, + subject: @protocol, title: t('notifications.protocol_description_annotation_title', user: current_user.full_name, protocol: @protocol.name), diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index ee815b042..445d032e0 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -452,6 +452,7 @@ class RepositoryRowsController < ApplicationController smart_annotation_notification( old_text: old_text, new_text: cell.value.data, + subject: cell.repository_column.repository, title: t('notifications.repository_annotation_title', user: current_user.full_name, column: cell.repository_column.name, diff --git a/app/controllers/result_elements/texts_controller.rb b/app/controllers/result_elements/texts_controller.rb index 832df5a86..df3e7c675 100644 --- a/app/controllers/result_elements/texts_controller.rb +++ b/app/controllers/result_elements/texts_controller.rb @@ -100,6 +100,7 @@ module ResultElements smart_annotation_notification( old_text: (old_text if old_text), new_text: @result_text.text, + subject: @result, title: t('notifications.result_annotation_title', result: @result.name, user: current_user.full_name), diff --git a/app/controllers/result_texts_controller.rb b/app/controllers/result_texts_controller.rb index 9be9ad5e4..a985bc825 100644 --- a/app/controllers/result_texts_controller.rb +++ b/app/controllers/result_texts_controller.rb @@ -121,6 +121,7 @@ class ResultTextsController < ApplicationController smart_annotation_notification( old_text: (old_text if old_text), new_text: @result_text.text, + subject: @result, title: t('notifications.result_annotation_title', result: @result.name, user: current_user.full_name), diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 63bbddfa8..22eb85297 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -71,6 +71,7 @@ module ApplicationHelper message = options.fetch(:message) { :message_must_be_present } old_text = options[:old_text] || '' new_text = options[:new_text] + subject = options[:subject] return if new_text.blank? sa_user = /\[\@(.*?)~([0-9a-zA-Z]+)\]/ @@ -96,15 +97,19 @@ module ApplicationHelper target_user = User.find_by_id(user_id) next unless target_user - generate_annotation_notification(target_user, title, message) + generate_annotation_notification(target_user, title, subject) end end - def generate_annotation_notification(target_user, title, message) - GeneralNotification.with( - title: sanitize_input(title), - message: sanitize_input(message) - ).deliver_later(target_user) + def generate_annotation_notification(target_user, title, subject) + GeneralNotification.send_notifications( + { + type: :smart_annotation_added, + title: sanitize_input(title), + subject: subject, + user: target_user + } + ) end def custom_link_open_new_tab(text) diff --git a/app/helpers/comment_helper.rb b/app/helpers/comment_helper.rb index 5a3364208..ba6dc2566 100644 --- a/app/helpers/comment_helper.rb +++ b/app/helpers/comment_helper.rb @@ -125,6 +125,7 @@ module CommentHelper smart_annotation_notification( old_text: old_text, new_text: comment.message, + subject: result, title: t('notifications.result_comment_annotation_title', result: result.name, user: current_user.full_name), @@ -147,6 +148,7 @@ module CommentHelper smart_annotation_notification( old_text: old_text, new_text: comment.message, + subject: project, title: t('notifications.project_comment_annotation_title', project: project.name, user: current_user.full_name), @@ -160,6 +162,7 @@ module CommentHelper smart_annotation_notification( old_text: old_text, new_text: comment.message, + subject: step, title: t('notifications.step_comment_annotation_title', step: step.name, user: current_user.full_name), @@ -184,6 +187,7 @@ module CommentHelper smart_annotation_notification( old_text: old_text, new_text: comment.message, + subject: my_module, title: t('notifications.my_module_comment_annotation_title', my_module: my_module.name, user: current_user.full_name), diff --git a/app/notifications/general_notification.rb b/app/notifications/general_notification.rb index 38915252d..67674175b 100644 --- a/app/notifications/general_notification.rb +++ b/app/notifications/general_notification.rb @@ -12,4 +12,8 @@ class GeneralNotification < BaseNotification def subtype params[:type] end + + def subject + params[:subject] + end end diff --git a/app/notifications/recipients/designate_to_my_module_recipients.rb b/app/notifications/recipients/designate_to_my_module_recipients.rb new file mode 100644 index 000000000..dbc35e126 --- /dev/null +++ b/app/notifications/recipients/designate_to_my_module_recipients.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Recipients + class DesignateToMyModuleRecipients < MyModuleDesignatedRecipients + private + + def activity_recipients + activity = Activity.find(@params[:activity_id]) + user = User.find_by(id: activity.values.dig('message_items', 'user_target', 'id')) + [user] + end + end +end diff --git a/config/initializers/extends/notification_extends.rb b/config/initializers/extends/notification_extends.rb index 6c3a98d66..9034c4b8d 100644 --- a/config/initializers/extends/notification_extends.rb +++ b/config/initializers/extends/notification_extends.rb @@ -4,11 +4,11 @@ class NotificationExtends NOTIFICATIONS_TYPES = { designate_user_to_my_module_activity: { code: 13, - recipients_module: :MyModuleDesignatedRecipients + recipients_module: :DesignateToMyModuleRecipients }, undesignate_user_from_my_module_activity: { code: 14, - recipients_module: :MyModuleDesignatedRecipients + recipients_module: :DesignateToMyModuleRecipients }, my_module_due_date_reminder: { recipients_module: :MyModuleDesignatedRecipients @@ -84,7 +84,7 @@ class NotificationExtends recipients_module: :RepositoryRowCreator }, smart_annotation_added: { - recipients_module: :AnnotatedRecipients + recipients_module: :DirectRecipient }, invite_user_to_team: { code: 92,