Commit 413e4545d352849ee572cb6505324cdad85d6e6a

Authored by Marcos Pereira
1 parent 20be7887

fixes list of notifications

plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb
@@ -14,7 +14,7 @@ class EnvironmentNotificationPluginAdminController < AdminController @@ -14,7 +14,7 @@ class EnvironmentNotificationPluginAdminController < AdminController
14 if request.post? 14 if request.post?
15 @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new(params[:notifications]) 15 @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new(params[:notifications])
16 @notification.message = @notification.message.html_safe 16 @notification.message = @notification.message.html_safe
17 - @notification.environment_id = environment.id 17 + @notification.target = environment
18 if @notification.save 18 if @notification.save
19 session[:notice] = _("Notification successfully created") 19 session[:notice] = _("Notification successfully created")
20 redirect_to :action => :index 20 redirect_to :action => :index
plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb
@@ -32,6 +32,10 @@ class EnvironmentNotificationPlugin::EnvironmentNotification < ActiveRecord::Bas @@ -32,6 +32,10 @@ class EnvironmentNotificationPlugin::EnvironmentNotification < ActiveRecord::Bas
32 def self.visibles(target, user, controller_path) 32 def self.visibles(target, user, controller_path)
33 notifications = EnvironmentNotificationPlugin::EnvironmentNotification.active(target).order('updated_at DESC') 33 notifications = EnvironmentNotificationPlugin::EnvironmentNotification.active(target).order('updated_at DESC')
34 34
  35 + if target.kind_of?(Organization) && target.environment.present?
  36 + env_notifications = EnvironmentNotificationPlugin::EnvironmentNotification.active(target.environment).order('updated_at DESC')
  37 + end
  38 +
35 if user 39 if user
36 active_notifications_ids = notifications.pluck(:id) - user.environment_notifications.pluck(:id) 40 active_notifications_ids = notifications.pluck(:id) - user.environment_notifications.pluck(:id)
37 41
plugins/environment_notification/views/shared/show_notification.html.erb
@@ -14,7 +14,9 @@ @@ -14,7 +14,9 @@
14 <% end %> 14 <% end %>
15 <% end %> 15 <% end %>
16 16
17 -<% @notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(environment, current_user, controller_path).where("id NOT IN (?)", hide_notifications) %> 17 +<% target = profile.present? ? profile : environment %>
  18 +
  19 +<% @notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(target, current_user, controller_path).where("id NOT IN (?)", hide_notifications) %>
18 20
19 <div class="environment-notification-plugin-notification-bar"> 21 <div class="environment-notification-plugin-notification-bar">
20 <% @notifications.each do |notification| %> 22 <% @notifications.each do |notification| %>