From 413e4545d352849ee572cb6505324cdad85d6e6a Mon Sep 17 00:00:00 2001 From: Marcos Ronaldo Date: Mon, 21 Mar 2016 18:18:14 -0300 Subject: [PATCH] fixes list of notifications --- plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb | 2 +- plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb | 4 ++++ plugins/environment_notification/views/shared/show_notification.html.erb | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb b/plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb index 4e2308f..75f3be2 100644 --- a/plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb +++ b/plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb @@ -14,7 +14,7 @@ class EnvironmentNotificationPluginAdminController < AdminController if request.post? @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new(params[:notifications]) @notification.message = @notification.message.html_safe - @notification.environment_id = environment.id + @notification.target = environment if @notification.save session[:notice] = _("Notification successfully created") redirect_to :action => :index diff --git a/plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb b/plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb index 7962afc..f623bb2 100644 --- a/plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb +++ b/plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb @@ -32,6 +32,10 @@ class EnvironmentNotificationPlugin::EnvironmentNotification < ActiveRecord::Bas def self.visibles(target, user, controller_path) notifications = EnvironmentNotificationPlugin::EnvironmentNotification.active(target).order('updated_at DESC') + if target.kind_of?(Organization) && target.environment.present? + env_notifications = EnvironmentNotificationPlugin::EnvironmentNotification.active(target.environment).order('updated_at DESC') + end + if user active_notifications_ids = notifications.pluck(:id) - user.environment_notifications.pluck(:id) diff --git a/plugins/environment_notification/views/shared/show_notification.html.erb b/plugins/environment_notification/views/shared/show_notification.html.erb index 514cf2c..4b1656b 100644 --- a/plugins/environment_notification/views/shared/show_notification.html.erb +++ b/plugins/environment_notification/views/shared/show_notification.html.erb @@ -14,7 +14,9 @@ <% end %> <% end %> -<% @notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(environment, current_user, controller_path).where("id NOT IN (?)", hide_notifications) %> +<% target = profile.present? ? profile : environment %> + +<% @notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(target, current_user, controller_path).where("id NOT IN (?)", hide_notifications) %>
<% @notifications.each do |notification| %> -- libgit2 0.21.2