Allow notifications with explicit/unexistent links

Notifications usually link to the associated notifiable, but the new
AdminNotifications have a link attribute that may be empty or contain an
external or internal url.
This commit is contained in:
Bertocq
2018-02-28 21:00:45 +01:00
committed by decabeza
parent a683fcff98
commit 4a5235f96f
2 changed files with 16 additions and 2 deletions

View File

@@ -43,9 +43,13 @@ class NotificationsController < ApplicationController
budget_investment_path @notification.linkable_resource.budget, @notification.linkable_resource budget_investment_path @notification.linkable_resource.budget, @notification.linkable_resource
when "Topic" when "Topic"
community_topic_path @notification.linkable_resource.community, @notification.linkable_resource community_topic_path @notification.linkable_resource.community, @notification.linkable_resource
else
if @notification.linkable_resource.is_a?(AdminNotification)
@notification.linkable_resource.link || notifications_path
else else
url_for @notification.linkable_resource url_for @notification.linkable_resource
end end
end end
end
end end

View File

@@ -53,9 +53,19 @@ class Notification < ActiveRecord::Base
"proposal_notification" "proposal_notification"
when "Comment" when "Comment"
"replies_to" "replies_to"
when "AdminNotification"
nil
else else
"comments_on" "comments_on"
end end
end end
def link
if notifiable.is_a?(AdminNotification) && notifiable.link.blank?
nil
else
self
end
end
end end