From 0f12be6a26f4ee693cc0f8e296871bd56edeb44f Mon Sep 17 00:00:00 2001 From: Ivan Kljun Date: Mon, 11 Dec 2023 15:41:24 +0100 Subject: [PATCH] Implement dynamic subject class handling in generalnotification [SCI-9825] --- app/helpers/application_helper.rb | 4 +++- app/notifications/general_notification.rb | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 22eb85297..e84f9a003 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -106,7 +106,9 @@ module ApplicationHelper { type: :smart_annotation_added, title: sanitize_input(title), - subject: subject, + subject_id: subject.id, + subject_class: subject.class.name, + subject_name: subject.respond_to?(:name) && subject.name, user: target_user } ) diff --git a/app/notifications/general_notification.rb b/app/notifications/general_notification.rb index 67674175b..f74c2a298 100644 --- a/app/notifications/general_notification.rb +++ b/app/notifications/general_notification.rb @@ -14,6 +14,9 @@ class GeneralNotification < BaseNotification end def subject - params[:subject] + subject_class = params[:subject_class].constantize + subject_class.find(params[:subject_id]) + rescue NameError, ActiveRecord::RecordNotFound + NonExistantRecord.new(params[:subject_name]) end end