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) %>