diff --git a/app/models/notification.rb b/app/models/notification.rb index 220a2ac43e6a..fea567caf57b 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -83,13 +83,17 @@ def backup_subject_name def text_bindings [:initiator, :subject, :cause].each_with_object(text_bindings_dynamic) do |key, result| value = public_send(key) + next unless value + + # Set the link based on the notification_type.link_to + result[:link] = { + :id => value.id, + :model => value.class.name + } if notification_type.link_to.try(:to_sym) == key + result[key] = { - :link => { - :id => value.id, - :model => value.class.name, - }, :text => value.try(:name) || value.try(:description) - } if value + } end end diff --git a/app/models/notification_type.rb b/app/models/notification_type.rb index a5dd9bf33ee3..26806b61abdc 100644 --- a/app/models/notification_type.rb +++ b/app/models/notification_type.rb @@ -9,6 +9,7 @@ class NotificationType < ApplicationRecord has_many :notifications validates :message, :presence => true validates :level, :inclusion => { :in => %w(success error warning info) } + validates :link_to, :inclusion => { :in => %w(subject initiator cause) }, :allow_blank => true validates :audience, :inclusion => { :in => [AUDIENCE_USER, AUDIENCE_GROUP, AUDIENCE_TENANT, AUDIENCE_GLOBAL, AUDIENCE_SUPERADMIN] }