Skip to content

Commit

Permalink
Send link with the text_bindings in notifications when link_to is set
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Aug 29, 2018
1 parent 01044b9 commit e8f30a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions app/models/notification_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down

0 comments on commit e8f30a2

Please sign in to comment.