Implement dynamic subject class handling in generalnotification [SCI-9825]

This commit is contained in:
Ivan Kljun 2023-12-11 15:41:24 +01:00
parent 41c5ecf1d8
commit 0f12be6a26
2 changed files with 7 additions and 2 deletions

View file

@ -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
}
)

View file

@ -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