From 1debf11c40fa377cb8a8bacc42750d1e8d452b47 Mon Sep 17 00:00:00 2001 From: Gabriel Silva Date: Mon, 21 Mar 2016 19:48:03 +0000 Subject: [PATCH] environment_notification plugin improved --- plugins/admin_notifications/README | 7 +++++++ plugins/admin_notifications/controllers/admin_notifications_plugin_admin_controller.rb | 16 ++++++++++++++++ plugins/admin_notifications/controllers/admin_notifications_plugin_myprofile_controller.rb | 16 ++++++++++++++++ plugins/admin_notifications/controllers/public/admin_notifications_plugin_public_controller.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/db/migrate/20150721132025_create_notification_table.rb | 28 ++++++++++++++++++++++++++++ plugins/admin_notifications/db/migrate/20160321190726_change_notification_relation_to_polymorphic.rb | 13 +++++++++++++ plugins/admin_notifications/db/migrate/20160330171610_rename_plugin_tables.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/db/migrate/20160505142214_change_type_to_new_namespace.rb | 8 ++++++++ plugins/admin_notifications/features/message_edition.feature | 14 ++++++++++++++ plugins/admin_notifications/lib/admin_notifications_plugin.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/lib/admin_notifications_plugin/notification_helper.rb | 18 ++++++++++++++++++ plugins/admin_notifications/lib/admin_notifications_plugin/notification_manager.rb | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/lib/admin_notifications_plugin/notifications_user.rb | 10 ++++++++++ plugins/admin_notifications/lib/ext/environment.rb | 5 +++++ plugins/admin_notifications/lib/ext/organization.rb | 5 +++++ plugins/admin_notifications/lib/ext/user.rb | 6 ++++++ plugins/admin_notifications/models/admin_notifications_plugin/danger_notification.rb | 2 ++ plugins/admin_notifications/models/admin_notifications_plugin/information_notification.rb | 2 ++ plugins/admin_notifications/models/admin_notifications_plugin/notification.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/models/admin_notifications_plugin/success_notification.rb | 2 ++ plugins/admin_notifications/models/admin_notifications_plugin/warning_notification.rb | 2 ++ plugins/admin_notifications/po/notification.pot | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/public/admin_notifications_plugin.js | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/public/images/close.png | Bin 0 -> 240 bytes plugins/admin_notifications/public/images/greenhide.png | Bin 0 -> 794 bytes plugins/admin_notifications/public/images/hide.png | Bin 0 -> 389 bytes plugins/admin_notifications/public/images/redclose.png | Bin 0 -> 552 bytes plugins/admin_notifications/public/images/show.png | Bin 0 -> 364 bytes plugins/admin_notifications/public/style.css | 250 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/test/functional/account_controller_test.rb | 36 ++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/test/functional/admin_notifications_plugin_admin_controller_test.rb | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/test/functional/admin_notifications_plugin_myprofile_controller_test.rb | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/test/functional/admin_notifications_plugin_public_controller_test.rb | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/test/functional/home_controller_test.rb | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/test/helpers/notification_test_helper.rb | 10 ++++++++++ plugins/admin_notifications/test/unit/notification_helper_test.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/test/unit/notification_test.rb | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/views/admin_notifications_plugin_admin/edit.html.erb | 1 + plugins/admin_notifications/views/admin_notifications_plugin_admin/index.html.erb | 1 + plugins/admin_notifications/views/admin_notifications_plugin_admin/new.html.erb | 1 + plugins/admin_notifications/views/admin_notifications_plugin_myprofile/edit.html.erb | 1 + plugins/admin_notifications/views/admin_notifications_plugin_myprofile/index.html.erb | 1 + plugins/admin_notifications/views/admin_notifications_plugin_myprofile/new.html.erb | 1 + plugins/admin_notifications/views/admin_notifications_plugin_public/notifications_with_popup.html.erb | 22 ++++++++++++++++++++++ plugins/admin_notifications/views/shared/_form.html.erb | 39 +++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/views/shared/_notifications_list.html.erb | 39 +++++++++++++++++++++++++++++++++++++++ plugins/admin_notifications/views/shared/show_notification.html.erb | 33 +++++++++++++++++++++++++++++++++ plugins/environment_notification/README | 7 +++++++ plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb | 103 ------------------------------------------------------------------------------------------------------- plugins/environment_notification/controllers/public/environment_notification_plugin_public_controller.rb | 15 --------------- plugins/environment_notification/db/migrate/20150721132025_create_notification_table.rb | 28 ---------------------------- plugins/environment_notification/db/migrate/20160321190725_reactivate_plugin_after_rename.rb | 14 ++++++++++++++ plugins/environment_notification/features/message_edition.feature | 14 -------------- plugins/environment_notification/lib/environment_notification_helper.rb | 18 ------------------ plugins/environment_notification/lib/environment_notification_plugin.rb | 41 ++--------------------------------------- plugins/environment_notification/lib/environment_notifications_user.rb | 10 ---------- plugins/environment_notification/lib/ext/environment.rb | 5 ----- plugins/environment_notification/lib/ext/user.rb | 6 ------ plugins/environment_notification/models/environment_notification_plugin/danger_notification.rb | 2 -- plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb | 50 -------------------------------------------------- plugins/environment_notification/models/environment_notification_plugin/information_notification.rb | 2 -- plugins/environment_notification/models/environment_notification_plugin/success_notification.rb | 2 -- plugins/environment_notification/models/environment_notification_plugin/warning_notification.rb | 2 -- plugins/environment_notification/po/environment_notification.pot | 178 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- plugins/environment_notification/po/pt/environment_notification.po | 178 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- plugins/environment_notification/public/environment_notification_plugin.js | 84 ------------------------------------------------------------------------------------ plugins/environment_notification/public/images/close.png | Bin 240 -> 0 bytes plugins/environment_notification/public/images/greenhide.png | Bin 794 -> 0 bytes plugins/environment_notification/public/images/hide.png | Bin 389 -> 0 bytes plugins/environment_notification/public/images/redclose.png | Bin 552 -> 0 bytes plugins/environment_notification/public/images/show.png | Bin 364 -> 0 bytes plugins/environment_notification/public/style.css | 250 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- plugins/environment_notification/test/functional/account_controller_test.rb | 36 ------------------------------------ plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb | 186 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ plugins/environment_notification/test/functional/home_controller_test.rb | 120 ------------------------------------------------------------------------------------------------------------------------ plugins/environment_notification/test/unit/environment_notification_helper_test.rb | 46 ---------------------------------------------- plugins/environment_notification/test/unit/environment_notification_test.rb | 162 ------------------------------------------------------------------------------------------------------------------------------------------------------------------ plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb | 39 --------------------------------------- plugins/environment_notification/views/environment_notification_plugin_admin/edit.html.erb | 1 - plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb | 40 ---------------------------------------- plugins/environment_notification/views/environment_notification_plugin_admin/new.html.erb | 1 - plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb | 31 ------------------------------- plugins/environment_notification/views/environment_notification_plugin_public/notifications_with_popup.html.erb | 22 ---------------------- 83 files changed, 1856 insertions(+), 1670 deletions(-) create mode 100644 plugins/admin_notifications/README create mode 100644 plugins/admin_notifications/controllers/admin_notifications_plugin_admin_controller.rb create mode 100644 plugins/admin_notifications/controllers/admin_notifications_plugin_myprofile_controller.rb create mode 100644 plugins/admin_notifications/controllers/public/admin_notifications_plugin_public_controller.rb create mode 100644 plugins/admin_notifications/db/migrate/20150721132025_create_notification_table.rb create mode 100644 plugins/admin_notifications/db/migrate/20160321190726_change_notification_relation_to_polymorphic.rb create mode 100644 plugins/admin_notifications/db/migrate/20160330171610_rename_plugin_tables.rb create mode 100644 plugins/admin_notifications/db/migrate/20160505142214_change_type_to_new_namespace.rb create mode 100644 plugins/admin_notifications/features/message_edition.feature create mode 100644 plugins/admin_notifications/lib/admin_notifications_plugin.rb create mode 100644 plugins/admin_notifications/lib/admin_notifications_plugin/notification_helper.rb create mode 100644 plugins/admin_notifications/lib/admin_notifications_plugin/notification_manager.rb create mode 100644 plugins/admin_notifications/lib/admin_notifications_plugin/notifications_user.rb create mode 100644 plugins/admin_notifications/lib/ext/environment.rb create mode 100644 plugins/admin_notifications/lib/ext/organization.rb create mode 100644 plugins/admin_notifications/lib/ext/user.rb create mode 100644 plugins/admin_notifications/models/admin_notifications_plugin/danger_notification.rb create mode 100644 plugins/admin_notifications/models/admin_notifications_plugin/information_notification.rb create mode 100644 plugins/admin_notifications/models/admin_notifications_plugin/notification.rb create mode 100644 plugins/admin_notifications/models/admin_notifications_plugin/success_notification.rb create mode 100644 plugins/admin_notifications/models/admin_notifications_plugin/warning_notification.rb create mode 100644 plugins/admin_notifications/po/notification.pot create mode 100644 plugins/admin_notifications/public/admin_notifications_plugin.js create mode 100644 plugins/admin_notifications/public/images/close.png create mode 100644 plugins/admin_notifications/public/images/greenhide.png create mode 100644 plugins/admin_notifications/public/images/hide.png create mode 100644 plugins/admin_notifications/public/images/redclose.png create mode 100644 plugins/admin_notifications/public/images/show.png create mode 100644 plugins/admin_notifications/public/style.css create mode 100644 plugins/admin_notifications/test/functional/account_controller_test.rb create mode 100644 plugins/admin_notifications/test/functional/admin_notifications_plugin_admin_controller_test.rb create mode 100644 plugins/admin_notifications/test/functional/admin_notifications_plugin_myprofile_controller_test.rb create mode 100644 plugins/admin_notifications/test/functional/admin_notifications_plugin_public_controller_test.rb create mode 100644 plugins/admin_notifications/test/functional/home_controller_test.rb create mode 100644 plugins/admin_notifications/test/helpers/notification_test_helper.rb create mode 100644 plugins/admin_notifications/test/unit/notification_helper_test.rb create mode 100644 plugins/admin_notifications/test/unit/notification_test.rb create mode 100644 plugins/admin_notifications/views/admin_notifications_plugin_admin/edit.html.erb create mode 100644 plugins/admin_notifications/views/admin_notifications_plugin_admin/index.html.erb create mode 100644 plugins/admin_notifications/views/admin_notifications_plugin_admin/new.html.erb create mode 100644 plugins/admin_notifications/views/admin_notifications_plugin_myprofile/edit.html.erb create mode 100644 plugins/admin_notifications/views/admin_notifications_plugin_myprofile/index.html.erb create mode 100644 plugins/admin_notifications/views/admin_notifications_plugin_myprofile/new.html.erb create mode 100644 plugins/admin_notifications/views/admin_notifications_plugin_public/notifications_with_popup.html.erb create mode 100644 plugins/admin_notifications/views/shared/_form.html.erb create mode 100644 plugins/admin_notifications/views/shared/_notifications_list.html.erb create mode 100644 plugins/admin_notifications/views/shared/show_notification.html.erb create mode 100644 plugins/environment_notification/README delete mode 100644 plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb delete mode 100644 plugins/environment_notification/controllers/public/environment_notification_plugin_public_controller.rb delete mode 100644 plugins/environment_notification/db/migrate/20150721132025_create_notification_table.rb create mode 100644 plugins/environment_notification/db/migrate/20160321190725_reactivate_plugin_after_rename.rb delete mode 100644 plugins/environment_notification/features/message_edition.feature delete mode 100644 plugins/environment_notification/lib/environment_notification_helper.rb delete mode 100644 plugins/environment_notification/lib/environment_notifications_user.rb delete mode 100644 plugins/environment_notification/lib/ext/environment.rb delete mode 100644 plugins/environment_notification/lib/ext/user.rb delete mode 100644 plugins/environment_notification/models/environment_notification_plugin/danger_notification.rb delete mode 100644 plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb delete mode 100644 plugins/environment_notification/models/environment_notification_plugin/information_notification.rb delete mode 100644 plugins/environment_notification/models/environment_notification_plugin/success_notification.rb delete mode 100644 plugins/environment_notification/models/environment_notification_plugin/warning_notification.rb delete mode 100644 plugins/environment_notification/po/environment_notification.pot delete mode 100644 plugins/environment_notification/po/pt/environment_notification.po delete mode 100644 plugins/environment_notification/public/environment_notification_plugin.js delete mode 100644 plugins/environment_notification/public/images/close.png delete mode 100644 plugins/environment_notification/public/images/greenhide.png delete mode 100644 plugins/environment_notification/public/images/hide.png delete mode 100644 plugins/environment_notification/public/images/redclose.png delete mode 100644 plugins/environment_notification/public/images/show.png delete mode 100644 plugins/environment_notification/public/style.css delete mode 100644 plugins/environment_notification/test/functional/account_controller_test.rb delete mode 100644 plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb delete mode 100644 plugins/environment_notification/test/functional/home_controller_test.rb delete mode 100644 plugins/environment_notification/test/unit/environment_notification_helper_test.rb delete mode 100644 plugins/environment_notification/test/unit/environment_notification_test.rb delete mode 100644 plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb delete mode 100644 plugins/environment_notification/views/environment_notification_plugin_admin/edit.html.erb delete mode 100644 plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb delete mode 100644 plugins/environment_notification/views/environment_notification_plugin_admin/new.html.erb delete mode 100644 plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb delete mode 100644 plugins/environment_notification/views/environment_notification_plugin_public/notifications_with_popup.html.erb diff --git a/plugins/admin_notifications/README b/plugins/admin_notifications/README new file mode 100644 index 0000000..2ff0709 --- /dev/null +++ b/plugins/admin_notifications/README @@ -0,0 +1,7 @@ +This plugin is the new version of "environment_notification" plugin. + +New features added: + - Create a notification for an organization; + - Only profile admin can create notifications; + - Organization notifications can be seen by members from any of the organization pages; + - home_page option set the notification to be seen only at organization homepage; diff --git a/plugins/admin_notifications/controllers/admin_notifications_plugin_admin_controller.rb b/plugins/admin_notifications/controllers/admin_notifications_plugin_admin_controller.rb new file mode 100644 index 0000000..ece751a --- /dev/null +++ b/plugins/admin_notifications/controllers/admin_notifications_plugin_admin_controller.rb @@ -0,0 +1,16 @@ +class AdminNotificationsPluginAdminController < AdminController + + include AdminNotificationsPlugin::NotificationManager + + before_filter :admin_required + + protected + def target + environment + end + + def admin_required + redirect_to :root unless current_person.is_admin? + end + +end diff --git a/plugins/admin_notifications/controllers/admin_notifications_plugin_myprofile_controller.rb b/plugins/admin_notifications/controllers/admin_notifications_plugin_myprofile_controller.rb new file mode 100644 index 0000000..acdd5df --- /dev/null +++ b/plugins/admin_notifications/controllers/admin_notifications_plugin_myprofile_controller.rb @@ -0,0 +1,16 @@ +class AdminNotificationsPluginMyprofileController < MyProfileController + + include AdminNotificationsPlugin::NotificationManager + + before_filter :admin_required + + protected + def target + profile + end + + def admin_required + redirect_to :root unless target.is_admin?(current_person) + end + +end diff --git a/plugins/admin_notifications/controllers/public/admin_notifications_plugin_public_controller.rb b/plugins/admin_notifications/controllers/public/admin_notifications_plugin_public_controller.rb new file mode 100644 index 0000000..d529e4f --- /dev/null +++ b/plugins/admin_notifications/controllers/public/admin_notifications_plugin_public_controller.rb @@ -0,0 +1,48 @@ +class AdminNotificationsPluginPublicController < PublicController + + helper AdminNotificationsPlugin::NotificationHelper + include AdminNotificationsPlugin::NotificationHelper + + def notifications_with_popup + @hide_notifications = hide_notifications + if params[:previous_path] + @previous_path = params[:previous_path] + else + @previous_path = nil + end + end + + def close_notification + result = false + + if logged_in? + @notification = AdminNotificationsPlugin::Notification.find_by_id(params[:notification_id]) + + if @notification + @notification.users << current_user + result = @notification.users.include?(current_user) + end + end + + render json: result + end + + def hide_notification + result = false + + if logged_in? + @notification = AdminNotificationsPlugin::Notification.find_by_id(params[:notification_id]) + + if @notification + current_notificaions = [] + current_notificaions = JSON.parse(cookies[:hide_notifications]) unless cookies[:hide_notifications].blank? + current_notificaions << @notification.id unless current_notificaions.include? @notification.id + cookies[:hide_notifications] = JSON.generate(current_notificaions) + result = current_notificaions.include? @notification.id + end + end + + render json: result + end + +end diff --git a/plugins/admin_notifications/db/migrate/20150721132025_create_notification_table.rb b/plugins/admin_notifications/db/migrate/20150721132025_create_notification_table.rb new file mode 100644 index 0000000..a83cd10 --- /dev/null +++ b/plugins/admin_notifications/db/migrate/20150721132025_create_notification_table.rb @@ -0,0 +1,28 @@ +class CreateNotificationTable < ActiveRecord::Migration + def up + create_table :environment_notifications do |t| + t.text :message + t.integer :environment_id + t.string :type + t.string :title + t.boolean :active + t.boolean :display_only_in_homepage, :default => false + t.boolean :display_to_all_users, :default => false + t.boolean :display_popup, :default => false + t.column :created_at, :datetime + t.column :updated_at, :datetime + end + + create_table :environment_notifications_users, id: false do |t| + t.belongs_to :environment_notification + t.belongs_to :user + end + add_index :environment_notifications_users, [:environment_notification_id], name: :index_Zaem6uuw + add_index :environment_notifications_users, [:user_id], name: :index_ap3nohR9 + end + + def down + drop_table :environment_notifications + drop_table :environment_notifications_users + end +end diff --git a/plugins/admin_notifications/db/migrate/20160321190726_change_notification_relation_to_polymorphic.rb b/plugins/admin_notifications/db/migrate/20160321190726_change_notification_relation_to_polymorphic.rb new file mode 100644 index 0000000..faf67f6 --- /dev/null +++ b/plugins/admin_notifications/db/migrate/20160321190726_change_notification_relation_to_polymorphic.rb @@ -0,0 +1,13 @@ +class ChangeNotificationRelationToPolymorphic < ActiveRecord::Migration + def up + rename_column(:environment_notifications, :environment_id, :target_id) + add_column(:environment_notifications, :target_type, :string) + + execute("UPDATE environment_notifications SET target_type = 'Environment'") + end + + def down + rename_column(:environment_notifications, :target_id, :environment_id) + remove_column(:environment_notifications, :target_type) + end +end diff --git a/plugins/admin_notifications/db/migrate/20160330171610_rename_plugin_tables.rb b/plugins/admin_notifications/db/migrate/20160330171610_rename_plugin_tables.rb new file mode 100644 index 0000000..8b5246b --- /dev/null +++ b/plugins/admin_notifications/db/migrate/20160330171610_rename_plugin_tables.rb @@ -0,0 +1,43 @@ +class RenamePluginTables < ActiveRecord::Migration + def up + remove_index :environment_notifications_users, name: :index_Zaem6uuw + remove_index :environment_notifications_users, name: :index_ap3nohR9 + + rename_column :environment_notifications_users, :environment_notification_id, :notification_id + + rename_table :environment_notifications, :admin_notifications_plugin_notifications + rename_table :environment_notifications_users, :admin_notifications_plugin_notifications_users + + add_index :admin_notifications_plugin_notifications_users, [:notification_id], :name => :index_notifications_users_notification_id + add_index :admin_notifications_plugin_notifications_users, [:user_id], :name => :index_notifications_users_user_id + + Environment.all.each do |e| + if e.enabled_plugins.include?('EnvironmentNotificationPlugin') + e.enabled_plugins -= ['EnvironmentNotificationPlugin'] + e.enabled_plugins += ['AdminNotificationsPlugin'] + e.save! + end + end + end + + def down + remove_index :admin_notifications_plugin_notifications_users, :name => :index_notifications_users_notification_id + remove_index :admin_notifications_plugin_notifications_users, :name => :index_notifications_users_user_id + + rename_table :admin_notifications_plugin_notifications, :environment_notifications + rename_table :admin_notifications_plugin_notifications_users, :environment_notifications_users + + rename_column :environment_notifications_users, :notification_id, :environment_notification_id + + add_index :environment_notifications_users, [:environment_notification_id], name: :index_Zaem6uuw + add_index :environment_notifications_users, [:user_id], name: :index_ap3nohR9 + end + + Environment.all.each do |e| + if e.enabled_plugins.include?('AdminNotificationsPlugin') + e.enabled_plugins -= ['AdminNotificationsPlugin'] + e.enabled_plugins += ['EnvironmentNotificationPlugin'] + e.save! + end + end +end diff --git a/plugins/admin_notifications/db/migrate/20160505142214_change_type_to_new_namespace.rb b/plugins/admin_notifications/db/migrate/20160505142214_change_type_to_new_namespace.rb new file mode 100644 index 0000000..6def69d --- /dev/null +++ b/plugins/admin_notifications/db/migrate/20160505142214_change_type_to_new_namespace.rb @@ -0,0 +1,8 @@ +class ChangeTypeToNewNamespace < ActiveRecord::Migration + def up + notification_types = %w(InformationNotification DangerNotification SuccessNotification WarningNotification) + notification_types.each do |notification_type| + execute("update admin_notifications_plugin_notifications set type = 'AdminNotificationsPlugin::#{notification_type}' where type = 'EnvironmentNotificationPlugin::#{notification_type}'") + end + end +end diff --git a/plugins/admin_notifications/features/message_edition.feature b/plugins/admin_notifications/features/message_edition.feature new file mode 100644 index 0000000..7a6f5d3 --- /dev/null +++ b/plugins/admin_notifications/features/message_edition.feature @@ -0,0 +1,14 @@ +Feature: Create envronment notification message + As an admin user + I want to create a notification + In order to notificate users + + @selenium + Scenario: mce restricted mode should show on message creation + Given I am logged in as admin + And I follow "Administration" + And I follow "Plugins" + And I follow "Configuration" + And I follow "New Notification" + Then The tinymce "toolbar1" should be "bold italic underline | link" + Then The tinymce "menubar" should be "false" diff --git a/plugins/admin_notifications/lib/admin_notifications_plugin.rb b/plugins/admin_notifications/lib/admin_notifications_plugin.rb new file mode 100644 index 0000000..c6f94e8 --- /dev/null +++ b/plugins/admin_notifications/lib/admin_notifications_plugin.rb @@ -0,0 +1,59 @@ +class AdminNotificationsPlugin < Noosfero::Plugin + + def self.plugin_name + "Notifications Plugin" + end + + def self.plugin_description + _("A plugin for notifications.") + end + + def stylesheet? + true + end + + def js_files + %w( + admin_notifications_plugin.js + ) + end + + def body_beginning + lambda do + extend AdminNotificationsPlugin::NotificationHelper + render template: 'shared/show_notification' + end + end + + def admin_panel_links + {:title => _('Notification Manager'), :url => {:controller => 'admin_notifications_plugin_admin', :action => 'index'}} + end + + def control_panel_buttons + if context.profile.organization? + { + :title => _('Manage Notifications'), + :icon => 'important', + :url => { + :controller => 'admin_notifications_plugin_myprofile', + :action => 'index' + } + } + end + end + + def account_controller_filters + block = proc do + if !logged_in? + cookies[:hide_notifications] = nil + end + end + + [{ + :type => "after_filter", + :method_name => "clean_hide_notifications_cookie", + :options => { }, + :block => block + }] + end +end diff --git a/plugins/admin_notifications/lib/admin_notifications_plugin/notification_helper.rb b/plugins/admin_notifications/lib/admin_notifications_plugin/notification_helper.rb new file mode 100644 index 0000000..88f39d7 --- /dev/null +++ b/plugins/admin_notifications/lib/admin_notifications_plugin/notification_helper.rb @@ -0,0 +1,18 @@ +module AdminNotificationsPlugin::NotificationHelper + + def hide_notifications + invalid_id = -1 + hide_notifications_ids = [invalid_id] + hide_notifications_ids = JSON.parse(cookies[:hide_notifications]) unless cookies[:hide_notifications].blank? + hide_notifications_ids + end + + def self.substitute_variables(message, user) + if user + message = message.gsub("%{email}", user.person.email).gsub("%{name}", user.person.name) + end + + message + end + +end diff --git a/plugins/admin_notifications/lib/admin_notifications_plugin/notification_manager.rb b/plugins/admin_notifications/lib/admin_notifications_plugin/notification_manager.rb new file mode 100644 index 0000000..8e3a9c8 --- /dev/null +++ b/plugins/admin_notifications/lib/admin_notifications_plugin/notification_manager.rb @@ -0,0 +1,60 @@ +module AdminNotificationsPlugin::NotificationManager + + def index + @notifications = target.notifications.order('updated_at DESC') + end + + def new + @notification = AdminNotificationsPlugin::Notification.new + if request.post? + @notification = AdminNotificationsPlugin::Notification.new(params[:notifications]) + @notification.message = @notification.message.html_safe + @notification.target = target + if @notification.save + session[:notice] = _("Notification successfully created") + redirect_to :action => :index + else + session[:notice] = _("Notification couldn't be created") + end + end + end + + def destroy + if request.delete? + notification = target.notifications.find_by id: params[:id] + if notification && notification.destroy + session[:notice] = _('The notification was deleted.') + else + session[:notice] = _('Could not remove the notification') + end + end + redirect_to :action => :index + end + + def edit + @notification = target.notifications.find_by id: params[:id] + if request.post? + if @notification.update_attributes(params[:notifications]) + session[:notice] = _('The notification was edited.') + else + session[:notice] = _('Could not edit the notification.') + end + redirect_to :action => :index + end + end + + def change_status + @notification = target.notifications.find_by id: params[:id] + + @notification.active = !@notification.active + + if @notification.save! + session[:notice] = _('The status of the notification was changed.') + else + session[:notice] = _('Could not change the status of the notification.') + end + + redirect_to :action => :index + end + +end diff --git a/plugins/admin_notifications/lib/admin_notifications_plugin/notifications_user.rb b/plugins/admin_notifications/lib/admin_notifications_plugin/notifications_user.rb new file mode 100644 index 0000000..1a02be2 --- /dev/null +++ b/plugins/admin_notifications/lib/admin_notifications_plugin/notifications_user.rb @@ -0,0 +1,10 @@ +class AdminNotificationsPlugin::NotificationsUser < ActiveRecord::Base + self.table_name = "admin_notifications_plugin_notifications_users" + + belongs_to :user + belongs_to :notification, class_name: 'AdminNotificationsPlugin::Notification' + + attr_accessible :user_id, :notification_id + + validates_uniqueness_of :user_id, :scope => :notification_id +end diff --git a/plugins/admin_notifications/lib/ext/environment.rb b/plugins/admin_notifications/lib/ext/environment.rb new file mode 100644 index 0000000..805aad4 --- /dev/null +++ b/plugins/admin_notifications/lib/ext/environment.rb @@ -0,0 +1,5 @@ +require_dependency 'environment' + +class Environment + has_many :notifications, class_name: 'AdminNotificationsPlugin::Notification', :as => :target +end diff --git a/plugins/admin_notifications/lib/ext/organization.rb b/plugins/admin_notifications/lib/ext/organization.rb new file mode 100644 index 0000000..23102d6 --- /dev/null +++ b/plugins/admin_notifications/lib/ext/organization.rb @@ -0,0 +1,5 @@ +require_dependency 'organization' + +class Organization + has_many :notifications, class_name: 'AdminNotificationsPlugin::Notification', :as => :target +end diff --git a/plugins/admin_notifications/lib/ext/user.rb b/plugins/admin_notifications/lib/ext/user.rb new file mode 100644 index 0000000..71b241c --- /dev/null +++ b/plugins/admin_notifications/lib/ext/user.rb @@ -0,0 +1,6 @@ +require_dependency 'user' + +class User + has_many :notifications_users, :class_name => 'AdminNotificationsPlugin::NotificationsUser' + has_many :notifications, :through => :notifications_users +end diff --git a/plugins/admin_notifications/models/admin_notifications_plugin/danger_notification.rb b/plugins/admin_notifications/models/admin_notifications_plugin/danger_notification.rb new file mode 100644 index 0000000..6fbe4ba --- /dev/null +++ b/plugins/admin_notifications/models/admin_notifications_plugin/danger_notification.rb @@ -0,0 +1,2 @@ +class AdminNotificationsPlugin::DangerNotification < AdminNotificationsPlugin::Notification +end diff --git a/plugins/admin_notifications/models/admin_notifications_plugin/information_notification.rb b/plugins/admin_notifications/models/admin_notifications_plugin/information_notification.rb new file mode 100644 index 0000000..837391f --- /dev/null +++ b/plugins/admin_notifications/models/admin_notifications_plugin/information_notification.rb @@ -0,0 +1,2 @@ +class AdminNotificationsPlugin::InformationNotification < AdminNotificationsPlugin::Notification +end diff --git a/plugins/admin_notifications/models/admin_notifications_plugin/notification.rb b/plugins/admin_notifications/models/admin_notifications_plugin/notification.rb new file mode 100644 index 0000000..5aed708 --- /dev/null +++ b/plugins/admin_notifications/models/admin_notifications_plugin/notification.rb @@ -0,0 +1,56 @@ +class AdminNotificationsPlugin::Notification < ActiveRecord::Base + + self.table_name = "admin_notifications_plugin_notifications" + + TYPE_LIST = [ + "AdminNotificationsPlugin::WarningNotification", + "AdminNotificationsPlugin::SuccessNotification", + "AdminNotificationsPlugin::InformationNotification", + "AdminNotificationsPlugin::DangerNotification" + ] + + attr_accessible :message, :target_id, :active, :type, :display_only_in_homepage, :display_to_all_users, :display_popup, :title, :target + + has_many :notifications_users, :class_name => "AdminNotificationsPlugin::NotificationsUser" + has_many :users, :through => :notifications_users + + belongs_to :target, :polymorphic => true + + validates_presence_of :message + validates_presence_of :target_id + validate :notification_type_must_be_in_type_list + + def notification_type_must_be_in_type_list + unless TYPE_LIST.include?(type) + errors.add(:type, "invalid notification type") + end + end + + scope :active, lambda{|target| where(:target_id => (target.kind_of?(Organization) ? [target.id, target.environment.id] : target.id), :active => true)} + + def self.visibles(target, user, controller_path) + notifications = AdminNotificationsPlugin::Notification.active(target).order('updated_at DESC') + + if user + active_notifications_ids = notifications.pluck(:id) - user.notifications.pluck(:id) + + notifications = notifications.where(id: active_notifications_ids) + else + notifications = notifications.where(display_to_all_users: true) + end + + if controller_path != "home" + notifications = notifications.where.not("display_only_in_homepage = ? AND target_type = ?",true,"Environment") + if controller_path != "profile" + notifications = notifications.where.not("display_only_in_homepage = ? AND target_type = ?",true,"Profile") + end + end + + notifications + end + + def self.with_popup(target, user, previous_path) + AdminNotificationsPlugin::Notification.visibles(target, user, previous_path).where(display_popup: true) + end + +end diff --git a/plugins/admin_notifications/models/admin_notifications_plugin/success_notification.rb b/plugins/admin_notifications/models/admin_notifications_plugin/success_notification.rb new file mode 100644 index 0000000..6a6857f --- /dev/null +++ b/plugins/admin_notifications/models/admin_notifications_plugin/success_notification.rb @@ -0,0 +1,2 @@ +class AdminNotificationsPlugin::SuccessNotification < AdminNotificationsPlugin::Notification +end diff --git a/plugins/admin_notifications/models/admin_notifications_plugin/warning_notification.rb b/plugins/admin_notifications/models/admin_notifications_plugin/warning_notification.rb new file mode 100644 index 0000000..badb472 --- /dev/null +++ b/plugins/admin_notifications/models/admin_notifications_plugin/warning_notification.rb @@ -0,0 +1,2 @@ +class AdminNotificationsPlugin::WarningNotification < AdminNotificationsPlugin::Notification +end diff --git a/plugins/admin_notifications/po/notification.pot b/plugins/admin_notifications/po/notification.pot new file mode 100644 index 0000000..88f7ffd --- /dev/null +++ b/plugins/admin_notifications/po/notification.pot @@ -0,0 +1,187 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-03-31 15:02-0300\n" +"PO-Revision-Date: 2016-03-31 15:02-0300\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" + +#: ../lib/notification_plugin.rb:8 +msgid "A plugin for notifications." +msgstr "" + +#: ../lib/notification_plugin.rb:29 +msgid "Notification Manager" +msgstr "" + +#: ../lib/notification_plugin.rb:35 +msgid "Manage Notifications" +msgstr "" + +#: ../lib/notification_plugin/notification_manager.rb:14 +msgid "Notification successfully created" +msgstr "" + +#: ../lib/notification_plugin/notification_manager.rb:17 +msgid "Notification couldn't be created" +msgstr "" + +#: ../lib/notification_plugin/notification_manager.rb:26 +msgid "The notification was deleted." +msgstr "" + +#: ../lib/notification_plugin/notification_manager.rb:28 +msgid "Could not remove the notification" +msgstr "" + +#: ../lib/notification_plugin/notification_manager.rb:38 +msgid "The notification was edited." +msgstr "" + +#: ../lib/notification_plugin/notification_manager.rb:40 +msgid "Could not edit the notification." +msgstr "" + +#: ../lib/notification_plugin/notification_manager.rb:52 +msgid "The status of the notification was changed." +msgstr "" + +#: ../lib/notification_plugin/notification_manager.rb:54 +msgid "Could not change the status of the notification." +msgstr "" + +#: ../views/shared/_form.html.erb:5 +msgid "Back" +msgstr "" + +#: ../views/shared/_form.html.erb:11 +msgid "Optional Title:" +msgstr "" + +#: ../views/shared/_form.html.erb:13 +msgid "Enter your message here:" +msgstr "" + +#: ../views/shared/_form.html.erb:15 +msgid "" +"Obs: You can use %{name} and %{email} variables to put the user's name and ema" +"il in the message." +msgstr "" + +#: ../views/shared/_form.html.erb:18 +msgid "Notifications Status" +msgstr "" + +#: ../views/shared/_form.html.erb:18 +msgid "Active" +msgstr "" + +#: ../views/shared/_form.html.erb:18 +msgid "Inactive" +msgstr "" + +#: ../views/shared/_form.html.erb:20 +msgid "Notifications Color/Type" +msgstr "" + +#: ../views/shared/_form.html.erb:20 +msgid "Blue - Information" +msgstr "" + +#: ../views/shared/_form.html.erb:20 +msgid "Yellow - Warning" +msgstr "" + +#: ../views/shared/_form.html.erb:20 +msgid "Green - Success" +msgstr "" + +#: ../views/shared/_form.html.erb:20 +msgid "Red - Danger" +msgstr "" + +#: ../views/shared/_form.html.erb:23 +msgid "Display only in the homepage" +msgstr "" + +#: ../views/shared/_form.html.erb:27 +msgid "Display to not logged users too" +msgstr "" + +#: ../views/shared/_form.html.erb:31 +msgid "Display popup until user close the notification" +msgstr "" + +#: ../views/shared/_form.html.erb:35 +msgid "Save" +msgstr "" + +#: ../views/shared/_notifications_list.html.erb:3 +#: ../views/shared/_notifications_list.html.erb:16 +msgid "Notifications" +msgstr "" + +#: ../views/shared/_notifications_list.html.erb:7 +msgid "New Notification" +msgstr "" + +#: ../views/shared/_notifications_list.html.erb:10 +msgid "Back to control panel" +msgstr "" + +#: ../views/shared/_notifications_list.html.erb:19 +msgid "Actions" +msgstr "" + +#: ../views/shared/_notifications_list.html.erb:30 +msgid "Deactivate" +msgstr "" + +#: ../views/shared/_notifications_list.html.erb:30 +#: ../views/shared/_notifications_list.html.erb:32 +msgid "Do you want to change the status of this notification?" +msgstr "" + +#: ../views/shared/_notifications_list.html.erb:32 +msgid "Activate" +msgstr "" + +#: ../views/shared/_notifications_list.html.erb:34 +msgid "Edit" +msgstr "" + +#: ../views/shared/_notifications_list.html.erb:35 +msgid "Delete" +msgstr "" + +#: ../views/shared/_notifications_list.html.erb:35 +msgid "Do you want to delete this notification?" +msgstr "" + +#: ../views/shared/show_notification.html.erb:8 +msgid "There are active notifications in this environment!" +msgstr "" + +#: ../views/shared/show_notification.html.erb:9 +msgid "Manage all notifications here." +msgstr "" + +#: ../views/shared/show_notification.html.erb:28 +msgid "Do not show anymore" +msgstr "" + +#: ../views/shared/show_notification.html.erb:29 +msgid "Hide for now" +msgstr "" diff --git a/plugins/admin_notifications/public/admin_notifications_plugin.js b/plugins/admin_notifications/public/admin_notifications_plugin.js new file mode 100644 index 0000000..eaa643f --- /dev/null +++ b/plugins/admin_notifications/public/admin_notifications_plugin.js @@ -0,0 +1,84 @@ +(function($) { + "use strict"; + + var admin_notifications_plugin = { + + + notificationBar: function() { + var completeMessage = $(".notification-plugin-notification-bar").remove(); + $("#content-inner").before(completeMessage); + }, + + closeNotification: function(){ + var notification = $(this).parent(); + var id = notification.attr("data-notification"); + + $.ajax({ + url: noosfero_root()+'/plugin/admin_notifications/public/close_notification', + type: "POST", + data: {notification_id: id}, + success: function(response) { + notification.fadeOut(); + } + }); + }, + + hideNotification: function(){ + var notification = $(this).parent(); + var id = notification.attr("data-notification"); + + $.ajax({ + url: noosfero_root()+'/plugin/admin_notifications/public/hide_notification', + type: "POST", + data: {notification_id: id}, + success: function(response) { + notification.fadeOut(); + } + }); + }, + + hideUserNotification: function(){ + var ids = $.cookie('hide_notifications'); + if(ids === null) { + return null; + } + + if(ids.startsWith('[') && ids.endsWith(']')){ + ids = ids.substring(1, ids.length - 1); + ids = ids.split(","); + + for(var i = 0; i < ids.length; i++) { + $('[data-notification="' + ids[i] + '"]').fadeOut(); + } + } + }, + + showPopup: function() { + if($('.action-home-index').length > 0) { + jQuery(function($){ + $.colorbox({href: noosfero_root()+'/plugin/admin_notifications/public/notifications_with_popup?previous_path=home'}); + }); + } + else { + jQuery(function($){ + $.colorbox({href: noosfero_root()+'/plugin/admin_notifications/public/notifications_with_popup'}); + }); + } + }, + }; + + $(document).ready(function(){ + admin_notifications_plugin.notificationBar(); + $(".notification-plugin-notification-bar .notification-close").on("click", admin_notifications_plugin.closeNotification); + $(".notification-plugin-notification-bar .notification-hide").on("click", admin_notifications_plugin.hideNotification); + + if($('.notification-plugin-notification-bar').length > 0){ + admin_notifications_plugin.hideUserNotification(); + } + + if($('.notification-plugin-notification-bar [notification-display-popup="true"]').length > 0){ + admin_notifications_plugin.showPopup(); + } + }); + +})($); diff --git a/plugins/admin_notifications/public/images/close.png b/plugins/admin_notifications/public/images/close.png new file mode 100644 index 0000000..e51bbb9 Binary files /dev/null and b/plugins/admin_notifications/public/images/close.png differ diff --git a/plugins/admin_notifications/public/images/greenhide.png b/plugins/admin_notifications/public/images/greenhide.png new file mode 100644 index 0000000..c69cd9d Binary files /dev/null and b/plugins/admin_notifications/public/images/greenhide.png differ diff --git a/plugins/admin_notifications/public/images/hide.png b/plugins/admin_notifications/public/images/hide.png new file mode 100644 index 0000000..5804c92 Binary files /dev/null and b/plugins/admin_notifications/public/images/hide.png differ diff --git a/plugins/admin_notifications/public/images/redclose.png b/plugins/admin_notifications/public/images/redclose.png new file mode 100644 index 0000000..d65e786 Binary files /dev/null and b/plugins/admin_notifications/public/images/redclose.png differ diff --git a/plugins/admin_notifications/public/images/show.png b/plugins/admin_notifications/public/images/show.png new file mode 100644 index 0000000..477815e Binary files /dev/null and b/plugins/admin_notifications/public/images/show.png differ diff --git a/plugins/admin_notifications/public/style.css b/plugins/admin_notifications/public/style.css new file mode 100644 index 0000000..a4c60e6 --- /dev/null +++ b/plugins/admin_notifications/public/style.css @@ -0,0 +1,250 @@ +.notification-plugin-notification-bar{ + display: block; +} + +.notification-plugin-notification-bar .notification:hover, +.notification-plugin-notification-modal .notification:hover{ + opacity: 0.8; +} + +#notification-plugin-notification-manager{ + overflow: auto; +} + +.notification-plugin-notification-bar .notification .notification-close, +.notification-plugin-notification-modal .notification .notification-close{ + background: url(images/close.png) no-repeat; + background-position: center; + width: 20px; + height: 20px; +} + +.notification-plugin-notification-bar .warningnotification, +.notification-plugin-notification-bar .informationnotification, +.notification-plugin-notification-bar .successnotification, +.notification-plugin-notification-bar .dangernotification, +.notification-plugin-notification-bar .adminnotification, +.notification-plugin-notification-modal .warningnotification, +.notification-plugin-notification-modal .informationnotification, +.notification-plugin-notification-modal .successnotification, +.notification-plugin-notification-modal .dangernotification{ + margin-bottom: 10px; + padding: 7px 10px; + border-radius: 5px; + border: 1px solid blue; + font-size: 16px; + color: white; + overflow: auto; +} + +.notification-plugin-notification-bar .warningnotification p, +.notification-plugin-notification-bar .informationnotification p, +.notification-plugin-notification-bar .successnotification p, +.notification-plugin-notification-bar .dangernotification p, +.notification-plugin-notification-bar .adminnotification p, +.notification-plugin-notification-modal .warningnotification p, +.notification-plugin-notification-modal .informationnotification p, +.notification-plugin-notification-modal .successnotification p, +.notification-plugin-notification-modal .dangernotification p{ + margin: 0px; +} + +.notification-plugin-notification-bar .warningnotification, +.notification-plugin-notification-modal .warningnotification{ + background: #fcf8e3; + border: 1px solid #faebcc; + color: #8a6d3b; +} + +.notification-plugin-notification-bar .warningnotification p a, +.notification-plugin-notification-modal .warningnotification p a{ + font-weight: bold; + color: #8a6d3b; +} + + +.notification-plugin-notification-bar .informationnotification, +.notification-plugin-notification-modal .informationnotification{ + background: #d9edf7; + border: 1px solid #bce8f1; + color: #31708f; +} + +.notification-plugin-notification-bar .informationnotification p a, +.notification-plugin-notification-modal .informationnotification p a{ + font-weight: bold; + color: #31708f; +} + +.notification-plugin-notification-bar .successnotification, +.notification-plugin-notification-modal .successnotification{ + background: #dff0d8; + border: 1px solid #d6e9c6; + color: #3c763d; +} + +.notification-plugin-notification-bar .successnotification p a +.notification-plugin-notification-modal .successnotification p a{ + font-weight: bold; + color: #3c763d; +} + +.notification-plugin-notification-bar .dangernotification, +.notification-plugin-notification-modal .dangernotification{ + background: #f2dede; + border: 1px solid #ebccd1; + color: #a94442; +} + +.notification-plugin-notification-bar .dangernotification p a, +.notification-plugin-notification-modal .dangernotification p a{ + font-weight: bold; + color: #a94442; +} + +.notification-plugin-notification-bar .adminnotification, +.notification-plugin-notification-modal .adminnotification{ + background: #9a959a; + border: 1px solid #9a959a; +} + +.notification-plugin-notification-bar .adminnotification p a, +.notification-plugin-notification-modal .adminnotification p a{ + font-weight: bold; + color: white; +} + +#notification-plugin-notification-manager a.button.icon-deactivate{ + background: url(images/hide.png) no-repeat; + background-position: center; +} + +#notification-plugin-notification-manager a.button.icon-activate{ + background: url(images/show.png) no-repeat; + background-position: center; +} + +#notification-plugin-notification-manager .notification-line{ + display: inline; + padding-top: 10px; + vertical-align: middle; + border-bottom: 1px solid #ccc; +} + +#notification-plugin-notification-manager .notification-title-bar{ + float: left; + width: 100%; + font-style: 14px; + font-weight: 700; + border-bottom: 2px solid black; + padding: 9px 0; +} + +#notification-plugin-notification-manager .notification-title{ + width: 80%; + float: left; + text-align: center; +} + +.notification-plugin-notification-modal .notification-with-title{ + margin-bottom: 0px; +} + +.notification-plugin-notification-modal .notification .notification-title{ + width: 100%; + float: left; + font-weight: bold; + text-align: left; +} + +.notification-plugin-notification-modal .notification-with-title-message{ + width: 100%; + float: left; + border-radius: 3px; + margin-bottom: 10px; + background-color: #f5f5f5; + font-size: 14px; + overflow: auto; +} + +.notification-plugin-notification-modal .notification-with-title-message p{ + padding: 0px 7px; +} + +.notification-plugin-notification-modal .notification-with-title-message p a{ + color: black; + font-weight: bold; +} + + +#notification-plugin-notification-manager .action-title{ + width: 20%; + float: left; + text-align: center; +} + +#notification-plugin-notification-manager .notification-action{ + width: 18%; + float: left; + height: 30px; + padding-top: 9px; +} + +#notification-plugin-notification-manager .main-bar .button, +#notification-plugin-notification-manager .notification-action .button{ + border-radius: 3px; +} + +#notification-plugin-notification-manager .notification-message{ + width: 82%; + float: left; +} + +#notification-plugin-notification-manager .new-notification{ + float: right; + width: auto; +} + +#notification-plugin-notification-manager .back-button{ + float: left; +} + +#notification-plugin-notification-manager .main-bar{ + display: inline; + width: 100%; +} + +.notification-plugin-notification-bar .notification .notification-message, +.notification-plugin-notification-modal .notification .notification-message{ + width: 90%; + float: left; +} + +.notification-plugin-notification-bar .notification .notification-close{ + background: url(images/redclose.png) no-repeat; + background-position: center; + width: 20px; + height: 20px; + float: right; + cursor: pointer; +} + +.notification-plugin-notification-bar .notification .notification-hide{ + background: url(images/greenhide.png) no-repeat; + background-position: center; + width: 20px; + height: 20px; + float: right; + cursor: pointer; +} + +.notification-plugin-notification-modal{ + display: block; + min-width: 400px; + max-width: 700px; +} + +.notification-plugin-form .notification-variables-options{ + font-style: italic; + color: red; +} diff --git a/plugins/admin_notifications/test/functional/account_controller_test.rb b/plugins/admin_notifications/test/functional/account_controller_test.rb new file mode 100644 index 0000000..3f4e4fb --- /dev/null +++ b/plugins/admin_notifications/test/functional/account_controller_test.rb @@ -0,0 +1,36 @@ +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' +require 'account_controller' + +class AccountController + include AdminNotificationsPlugin::NotificationHelper +end + +class AccountControllerTest < ActionController::TestCase + def setup + @controller = AccountController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @person = create_user('person').person + + @environment = Environment.default + @environment.enable_plugin('AdminNotificationsPlugin') + @environment.save! + + login_as(@person.user.login) + end + + attr_accessor :person + + should 'clean hide_notifications cookie after logout' do + @request.cookies[:hide_notifications] = JSON.generate([1,2]) + get :index + assert !@request.cookies[:hide_notifications].blank? + + @request.cookies[:hide_notifications] = nil + get :logout + assert_nil session[:user] + assert_response :redirect + assert_equal 1, @controller.hide_notifications.count + assert @controller.hide_notifications.include?(-1) + end +end diff --git a/plugins/admin_notifications/test/functional/admin_notifications_plugin_admin_controller_test.rb b/plugins/admin_notifications/test/functional/admin_notifications_plugin_admin_controller_test.rb new file mode 100644 index 0000000..e39730e --- /dev/null +++ b/plugins/admin_notifications/test/functional/admin_notifications_plugin_admin_controller_test.rb @@ -0,0 +1,136 @@ +require 'test_helper' +require_relative '../../controllers/admin_notifications_plugin_admin_controller' + +class AdminNotificationsPluginAdminControllerTest < ActionController::TestCase + def setup + @controller = AdminNotificationsPluginAdminController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @person = create_user('person').person + + @environment = Environment.default + @environment.enable_plugin('AdminNotificationsPlugin') + @environment.save! + + login_as(@person.user.login) + end + + attr_accessor :person + + should 'an admin be able to create a notification' do + @environment.add_admin(@person) + post :new, :notifications => { + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + } + assert_redirected_to :action => 'index' + notification = AdminNotificationsPlugin::Notification.last + assert_equal "Message", notification.message + assert notification.active + assert_equal "AdminNotificationsPlugin::DangerNotification", notification.type + end + + should 'an user not to be able to create a notification' do + post :new, :notifications => { + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + } + assert_redirected_to :root + assert_nil AdminNotificationsPlugin::Notification.last + end + + should 'an admin be able to edit a notification' do + @environment.add_admin(@person) + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + post :edit, :id => @notification.id, :notifications => { + :message => "Edited Message", + :active => false, + :type => "AdminNotificationsPlugin::WarningNotification" + } + @notification = AdminNotificationsPlugin::Notification.last + assert_redirected_to :action => 'index' + assert_equal "Edited Message", @notification.message + assert !@notification.active + assert_equal "AdminNotificationsPlugin::WarningNotification", @notification.type + end + + should 'an user not to be able to edit a notification' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + post :edit, :notifications => { + :message => "Edited Message", + :active => false, + :type => "AdminNotificationsPlugin::DangerNotification" + } + @notification.reload + assert_redirected_to :root + assert_equal "Message", @notification.message + assert @notification.active + end + + should 'an admin be able to destroy a notification' do + @environment.add_admin(@person) + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + delete :destroy, :id => @notification.id + assert_nil AdminNotificationsPlugin::Notification.find_by id: @notification.id + end + + should 'an user not to be able to destroy a notification' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + delete :destroy, :id => @notification.id + + assert_redirected_to :root + assert_not_nil AdminNotificationsPlugin::Notification.find_by id: @notification.id + end + + should 'an admin be able to change Notification status' do + @environment.add_admin(@person) + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + post :change_status, :id => @notification.id + assert_redirected_to :action => 'index' + + @notification.reload + assert !@notification.active + end + + should 'an user not be able to change Notification status' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + post :change_status, :id => @notification.id + assert_redirected_to :root + + @notification.reload + assert @notification.active + end + +end diff --git a/plugins/admin_notifications/test/functional/admin_notifications_plugin_myprofile_controller_test.rb b/plugins/admin_notifications/test/functional/admin_notifications_plugin_myprofile_controller_test.rb new file mode 100644 index 0000000..1071c3f --- /dev/null +++ b/plugins/admin_notifications/test/functional/admin_notifications_plugin_myprofile_controller_test.rb @@ -0,0 +1,147 @@ +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' +require( + File.expand_path(File.dirname(__FILE__)) + + '/../../controllers/admin_notifications_plugin_myprofile_controller' +) + +class AdminNotificationsPluginMyprofileControllerTest < ActionController::TestCase + def setup + @controller = AdminNotificationsPluginMyprofileController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @person = create_user('person').person + @community = fast_create(Community) + + environment = Environment.default + environment.enable_plugin('AdminNotificationsPlugin') + environment.save! + + login_as(@person.user.login) + AdminNotificationsPluginMyprofileController.any_instance.stubs(:profile).returns(@community) + end + + attr_accessor :person + + should 'profile admin be able to create a notification' do + @community.add_admin(@person) + post :new, :profile => @community.identifier, + :notifications => { + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + } + assert_redirected_to :action => 'index' + notification = AdminNotificationsPlugin::Notification.last + assert_equal "Message", notification.message + assert notification.active + assert_equal "AdminNotificationsPlugin::DangerNotification", notification.type + end + + should 'a regular user not to be able to create a notification' do + post :new, :profile => @community.identifier, + :notifications => { + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + } + + assert_redirected_to :root + assert_nil AdminNotificationsPlugin::Notification.last + end + + should 'profile admin be able to edit a notification' do + @community.add_admin(@person) + @notification = AdminNotificationsPlugin::Notification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + + post :edit, :profile => @community.identifier, :id => @notification.id, + :notifications => { + :message => "Edited Message", + :active => false, + :type => "AdminNotificationsPlugin::WarningNotification" + } + @notification = AdminNotificationsPlugin::Notification.last + assert_redirected_to :action => 'index' + assert_equal "Edited Message", @notification.message + assert !@notification.active + assert_equal "AdminNotificationsPlugin::WarningNotification", @notification.type + end + + should 'a regular user not be able to edit a notification' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + post :edit, :profile => @community.identifier, + :notifications => { + :message => "Edited Message", + :active => false, + :type => "AdminNotificationsPlugin::DangerNotification" + } + @notification.reload + assert_redirected_to :root + assert_equal "Message", @notification.message + assert @notification.active + end + + should 'a profile admin be able to destroy a notification' do + @community.add_admin(@person) + @notification = AdminNotificationsPlugin::Notification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + delete :destroy, :profile => @community.identifier, :id => @notification.id + assert_nil AdminNotificationsPlugin::Notification.find_by_id(@notification.id) + end + + should 'a regular user not be able to destroy a notification' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + delete :destroy, :profile => @community.identifier, :id => @notification.id + + assert_redirected_to :root + assert_not_nil AdminNotificationsPlugin::Notification.find_by_id(@notification.id) + end + + should 'a profile admin be able to change Notification status' do + @community.add_admin(@person) + @notification = AdminNotificationsPlugin::Notification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + post :change_status, :profile => @community.identifier, :id => @notification.id + assert_redirected_to :action => 'index' + + @notification.reload + assert !@notification.active + end + + should 'a regular user not be able to change Notification status' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @community, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + post :change_status, :profile => @community.identifier, :id => @notification.id + assert_redirected_to :root + + @notification.reload + assert @notification.active + end + +end diff --git a/plugins/admin_notifications/test/functional/admin_notifications_plugin_public_controller_test.rb b/plugins/admin_notifications/test/functional/admin_notifications_plugin_public_controller_test.rb new file mode 100644 index 0000000..7d694a6 --- /dev/null +++ b/plugins/admin_notifications/test/functional/admin_notifications_plugin_public_controller_test.rb @@ -0,0 +1,65 @@ +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' +require( + File.expand_path(File.dirname(__FILE__)) + + '/../../controllers/public/admin_notifications_plugin_public_controller' +) + +class AdminNotificationsPluginPublicControllerTest < ActionController::TestCase + def setup + @controller = AdminNotificationsPluginPublicController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @person = create_user('person').person + + @environment = Environment.default + @environment.enable_plugin('AdminNotificationsPlugin') + @environment.save! + + login_as(@person.user.login) + end + + should 'a logged in user be able to permanently hide notifications' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + post :close_notification, :notification_id => @notification.id + assert_equal "true", @response.body + assert @notification.users.include?(@person.user) + end + + should 'a logged in user be able to momentarily hide notifications' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + + @another_notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Another Message", + :active => true, + :type => "AdminNotificationsPlugin::WarningNotification" + ) + post :hide_notification, :notification_id => @notification.id + assert_equal "true", @response.body + assert @controller.hide_notifications.include?(@notification.id) + assert !@controller.hide_notifications.include?(@another_notification.id) + end + + should 'not momentarily hide any notification if its id is not found' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + + post :hide_notification, :notification_id => nil + assert_equal "false", @response.body + assert !@controller.hide_notifications.include?(@notification.id) + end +end diff --git a/plugins/admin_notifications/test/functional/home_controller_test.rb b/plugins/admin_notifications/test/functional/home_controller_test.rb new file mode 100644 index 0000000..59aafad --- /dev/null +++ b/plugins/admin_notifications/test/functional/home_controller_test.rb @@ -0,0 +1,120 @@ +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' +require 'home_controller' + +class HomeController; def rescue_action(e) raise e end; +end + +class HomeControllerTest < ActionController::TestCase + def setup + @controller = HomeController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @person = create_user('person').person + + @environment = Environment.default + @environment.enable_plugin('AdminNotificationsPlugin') + @environment.save! + end + + attr_accessor :person + + should 'an active notification be displayed on home page for a logged in user' do + login_as(@person.user.login) + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Hello, this is a Notification Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + get :index + assert_match /Hello, this is a Notification Message/, @response.body + end + + + should 'an active notification not be displayed on home page for unlogged user' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Hello, this is a Notification Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + get :index + assert_no_match /Hello, this is a Notification Message/, @response.body + end + + should 'an active notification be displayed on home page for unlogged user' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Hello, this is a Notification Message", + :display_to_all_users => true, + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + get :index + assert_match /Hello, this is a Notification Message/, @response.body + end + + should 'only display the notification with display_to_all_users option for unlogged user ' do + @notification1 = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Hello, this is an old Notification Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + + @notification2 = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Hello, this is a new Notification Message", + :display_to_all_users => true, + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + + + get :index + assert_no_match /Hello, this is a Notification Message/, @response.body + assert_match /Hello, this is a new Notification Message/, @response.body + end + + should 'an inactive notification not be displayed on home page' do + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Hello, this is a Notification Message", + :active => false, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + get :index + assert_no_match /Hello, this is a Notification Message/, @response.body + end + + + should 'an active notification not be displayed to a logged in user after been closed by him' do + login_as(@person.user.login) + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Hello, this is a Notification Message", + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + @notification.users << @person.user + @notification.save! + assert_equal true, @notification.users.include?(@person.user) + get :index + assert_no_match /Hello, this is a Notification Message/, @response.body + end + + should 'a notification be displayed with a Popup' do + login_as(@person.user.login) + @notification = AdminNotificationsPlugin::Notification.create( + :target => @environment, + :message => "Message", + :display_popup => true, + :active => true, + :type => "AdminNotificationsPlugin::DangerNotification" + ) + assert_equal true, @notification.display_popup? + + get :index + assert_no_match /div id="cboxWrapper"/, @response.body + end +end diff --git a/plugins/admin_notifications/test/helpers/notification_test_helper.rb b/plugins/admin_notifications/test/helpers/notification_test_helper.rb new file mode 100644 index 0000000..dbe69d8 --- /dev/null +++ b/plugins/admin_notifications/test/helpers/notification_test_helper.rb @@ -0,0 +1,10 @@ +module NotificationTestHelper + def create_notification target, display_only_in_homepage=false, message="any_message", active=true + AdminNotificationsPlugin::WarningNotification.create!( + :target => target, + :message => message, + :active => active, + :display_only_in_homepage => display_only_in_homepage + ) + end +end diff --git a/plugins/admin_notifications/test/unit/notification_helper_test.rb b/plugins/admin_notifications/test/unit/notification_helper_test.rb new file mode 100644 index 0000000..523e462 --- /dev/null +++ b/plugins/admin_notifications/test/unit/notification_helper_test.rb @@ -0,0 +1,46 @@ +require 'test_helper' + +class NotificationHelperTest < ActiveSupport::TestCase + def setup + @env = Environment.default + @env.enable_plugin('AdminNotificationsPlugin') + + @user = User.create!(:environment_id => @env.id, :email => "user@domain.com", :login => "new_user", :password => "test", :password_confirmation => "test", :name => "UserName") + end + + should 'substitute all email variables to the current user email' do + message = "Hello user with email %{email}! please, update your current email (%{email})." + + new_message = AdminNotificationsPlugin::NotificationHelper.substitute_variables(message, @user) + + assert message != new_message + assert_equal new_message, "Hello user with email user@domain.com! please, update your current email (user@domain.com)." + end + + should 'not substitute emails variables if there is no current user' do + message = "Hello user with email %{email}! please, update your current email (%{email})." + + new_message = AdminNotificationsPlugin::NotificationHelper.substitute_variables(message, nil) + + assert_equal message, new_message + assert_not_includes new_message, "user@domain.com" + end + + should 'substitute all name variables to the current user name' do + message = "Hello %{name}! is %{name} your real name?." + + new_message = AdminNotificationsPlugin::NotificationHelper.substitute_variables(message, @user) + + assert message != new_message + assert_equal new_message, "Hello UserName! is UserName your real name?." + end + + should 'not substitute name variables if there is no current user' do + message = "Hello %{name}! is %{name} your real name?." + + new_message = AdminNotificationsPlugin::NotificationHelper.substitute_variables(message, nil) + + assert_equal message, new_message + assert_not_includes new_message, "UserName" + end +end diff --git a/plugins/admin_notifications/test/unit/notification_test.rb b/plugins/admin_notifications/test/unit/notification_test.rb new file mode 100644 index 0000000..dc06b61 --- /dev/null +++ b/plugins/admin_notifications/test/unit/notification_test.rb @@ -0,0 +1,193 @@ +require_relative '../../../../test/test_helper' +require_relative '../helpers/notification_test_helper' + +class NotificationTest < ActiveSupport::TestCase + + include NotificationTestHelper + + def setup + @env = Environment.default + @env.enable_plugin('AdminNotificationsPlugin') + + @user = User.create!(:environment_id => @env.id, :email => "user@domain.com", :login => "new_user", :password => "test", :password_confirmation => "test") + @danger_notification = AdminNotificationsPlugin::DangerNotification.create!( + :target => @env, + :message => "Danger Message", + :active => true, + ) + + @warning_notification = AdminNotificationsPlugin::WarningNotification.create!( + :target => @env, + :message => "Warning Message", + :active => true, + ) + + @information_notification = AdminNotificationsPlugin::InformationNotification.create!( + :target => @env, + :message => "Information Message", + :active => true, + ) + end + + should 'get all notifications that a user did not close' do + @information_notification.users << @user + + notifications = AdminNotificationsPlugin::Notification.visibles(@env, @user, nil) + + assert notifications.include?(@danger_notification) + assert notifications.include?(@warning_notification) + assert !notifications.include?(@information_notification) + end + + should 'get only notifications configured to be displayed to all users' do + @information_notification.display_to_all_users = true + @information_notification.save! + + notifications = AdminNotificationsPlugin::Notification.visibles(@env, nil, nil) + + assert !notifications.include?(@danger_notification) + assert !notifications.include?(@warning_notification) + assert notifications.include?(@information_notification) + end + + should 'get only notifications configured to be displayed to all users and in all pages' do + @information_notification.display_to_all_users = true + @information_notification.display_only_in_homepage = true + @information_notification.save! + + @danger_notification.display_to_all_users = true + @danger_notification.save! + + @warning_notification.display_only_in_homepage = true + @warning_notification.save! + + notifications = AdminNotificationsPlugin::Notification.visibles(@env, nil, 'not_home') + + assert notifications.include?(@danger_notification) + assert !notifications.include?(@warning_notification) + assert !notifications.include?(@information_notification) + end + + should 'get only notifications configured to be displayed in all pages' do + @danger_notification.display_to_all_users = true + @danger_notification.display_only_in_homepage = true + @danger_notification.save! + + notifications = AdminNotificationsPlugin::Notification.visibles(@env, @user, "not_home") + + assert !notifications.include?(@danger_notification) + assert notifications.include?(@warning_notification) + assert notifications.include?(@information_notification) + + notifications = AdminNotificationsPlugin::Notification.visibles(@env, nil, "home") + + assert notifications.include?(@danger_notification) + assert !notifications.include?(@warning_notification) + assert !notifications.include?(@information_notification) + end + + should 'get notifications configured to be displayed on profile' do + community = fast_create(Community) + + AdminNotificationsPlugin::Notification.destroy_all + env_home_notification = create_notification(@env, true) + env_not_home_notification = create_notification(@env, false) + profile_not_home_notification = create_notification(community, false) + profile_home_notification = create_notification(community, true) + + notifications = AdminNotificationsPlugin::Notification.visibles(community, @user, "profile") + assert_equivalent notifications.to_a, [env_not_home_notification, profile_not_home_notification, profile_home_notification] + + notifications = AdminNotificationsPlugin::Notification.visibles(community, @user, "profile_but_bot_homepage") + assert_equivalent notifications.to_a, [env_not_home_notification, profile_not_home_notification] + end + + should 'get notifications configured to be displayed on environment' do + community = fast_create(Community) + + AdminNotificationsPlugin::Notification.destroy_all + env_home_notification = create_notification(@env, true) + env_not_home_notification = create_notification(@env, false) + profile_not_home_notification = create_notification(community, false) + profile_home_notification = create_notification(community, true) + + notifications = AdminNotificationsPlugin::Notification.visibles(@env, @user, "home") + assert_equivalent notifications.to_a, [env_home_notification, env_not_home_notification] + + notifications = AdminNotificationsPlugin::Notification.visibles(@env, @user, "not_home_not_profile") + assert_equivalent notifications.to_a, [env_not_home_notification] + end + + should 'get only notifications configured to be displayed to all users and in all pages and not closed by an user' do + @information_notification.display_to_all_users = true + @information_notification.save! + + @danger_notification.display_to_all_users = true + @danger_notification.display_only_in_homepage = true + @danger_notification.save! + + @warning_notification.display_to_all_users = true + @warning_notification.save! + + @warning_notification.users << @user + + notifications = AdminNotificationsPlugin::Notification.visibles(@env, @user, 'not_home') + + assert !notifications.include?(@danger_notification) + assert !notifications.include?(@warning_notification) + assert notifications.include?(@information_notification) + end + + should 'get only active notifications' do + @information_notification.active = false + @information_notification.save! + + notifications = AdminNotificationsPlugin::Notification.visibles(@env, @user, 'home') + + assert notifications.include?(@danger_notification) + assert notifications.include?(@warning_notification) + assert !notifications.include?(@information_notification) + end + + should 'get only notifications with popup' do + @information_notification.display_popup = true + @information_notification.display_to_all_users = true + @information_notification.save! + + notifications = AdminNotificationsPlugin::Notification.with_popup(@env, @user, 'home') + + assert !notifications.include?(@danger_notification) + assert !notifications.include?(@warning_notification) + assert notifications.include?(@information_notification) + + notifications = AdminNotificationsPlugin::Notification.with_popup(@env, nil, nil) + + assert !notifications.include?(@danger_notification) + assert !notifications.include?(@warning_notification) + assert notifications.include?(@information_notification) + end + + should 'get only notifications with popup not closed by an user' do + @information_notification.display_popup = true + @information_notification.display_to_all_users = true + @information_notification.save! + + @danger_notification.display_popup = true + @danger_notification.display_to_all_users = true + @danger_notification.save! + + @danger_notification.users << @user + + notifications = AdminNotificationsPlugin::Notification.with_popup(@env, @user, 'home') + + assert !notifications.include?(@danger_notification) + assert !notifications.include?(@warning_notification) + assert notifications.include?(@information_notification) + + notifications = AdminNotificationsPlugin::Notification.with_popup(@env, nil, nil) + + assert notifications.include?(@danger_notification) + assert !notifications.include?(@warning_notification) + assert notifications.include?(@information_notification) + end +end diff --git a/plugins/admin_notifications/views/admin_notifications_plugin_admin/edit.html.erb b/plugins/admin_notifications/views/admin_notifications_plugin_admin/edit.html.erb new file mode 100644 index 0000000..85dd733 --- /dev/null +++ b/plugins/admin_notifications/views/admin_notifications_plugin_admin/edit.html.erb @@ -0,0 +1 @@ +<%= render :partial => "shared/form" %> diff --git a/plugins/admin_notifications/views/admin_notifications_plugin_admin/index.html.erb b/plugins/admin_notifications/views/admin_notifications_plugin_admin/index.html.erb new file mode 100644 index 0000000..21e19c4 --- /dev/null +++ b/plugins/admin_notifications/views/admin_notifications_plugin_admin/index.html.erb @@ -0,0 +1 @@ +<%= render :partial => "shared/notifications_list" %> diff --git a/plugins/admin_notifications/views/admin_notifications_plugin_admin/new.html.erb b/plugins/admin_notifications/views/admin_notifications_plugin_admin/new.html.erb new file mode 100644 index 0000000..85dd733 --- /dev/null +++ b/plugins/admin_notifications/views/admin_notifications_plugin_admin/new.html.erb @@ -0,0 +1 @@ +<%= render :partial => "shared/form" %> diff --git a/plugins/admin_notifications/views/admin_notifications_plugin_myprofile/edit.html.erb b/plugins/admin_notifications/views/admin_notifications_plugin_myprofile/edit.html.erb new file mode 100644 index 0000000..85dd733 --- /dev/null +++ b/plugins/admin_notifications/views/admin_notifications_plugin_myprofile/edit.html.erb @@ -0,0 +1 @@ +<%= render :partial => "shared/form" %> diff --git a/plugins/admin_notifications/views/admin_notifications_plugin_myprofile/index.html.erb b/plugins/admin_notifications/views/admin_notifications_plugin_myprofile/index.html.erb new file mode 100644 index 0000000..21e19c4 --- /dev/null +++ b/plugins/admin_notifications/views/admin_notifications_plugin_myprofile/index.html.erb @@ -0,0 +1 @@ +<%= render :partial => "shared/notifications_list" %> diff --git a/plugins/admin_notifications/views/admin_notifications_plugin_myprofile/new.html.erb b/plugins/admin_notifications/views/admin_notifications_plugin_myprofile/new.html.erb new file mode 100644 index 0000000..85dd733 --- /dev/null +++ b/plugins/admin_notifications/views/admin_notifications_plugin_myprofile/new.html.erb @@ -0,0 +1 @@ +<%= render :partial => "shared/form" %> diff --git a/plugins/admin_notifications/views/admin_notifications_plugin_public/notifications_with_popup.html.erb b/plugins/admin_notifications/views/admin_notifications_plugin_public/notifications_with_popup.html.erb new file mode 100644 index 0000000..f735e04 --- /dev/null +++ b/plugins/admin_notifications/views/admin_notifications_plugin_public/notifications_with_popup.html.erb @@ -0,0 +1,22 @@ +<% @notifications = AdminNotificationsPlugin::Notification.with_popup(environment, current_user, @previous_path).where("id NOT IN (?)", @hide_notifications) %> + +
+ <% @notifications.each do |notification| %> + <% if !notification.title.blank? %> +
notification notification-with-title" data-notification="<%=notification.id%>"> +
+ <%= notification.title %> +
+
+
+ <%= AdminNotificationsPlugin::NotificationHelper.substitute_variables(notification.message, current_user) %> +
+ <% else %> +
notification notification-without-title" data-notification="<%=notification.id%>"> +
+ <%= AdminNotificationsPlugin::NotificationHelper.substitute_variables(notification.message, current_user) %> +
+
+ <% end %> + <% end %> +
diff --git a/plugins/admin_notifications/views/shared/_form.html.erb b/plugins/admin_notifications/views/shared/_form.html.erb new file mode 100644 index 0000000..44e9409 --- /dev/null +++ b/plugins/admin_notifications/views/shared/_form.html.erb @@ -0,0 +1,39 @@ +
+ + <% abstract_options = {:value => @notification.message, :style => 'width: 100%; height: 200px;', :class => 'mceEditor'} %> + + <%= button :back, _('Back'), :controller => 'admin_notifications_plugin_admin' %> + + <%= form_for :notifications do |f| %> + + <%= render :file => 'shared/tiny_mce', :locals => {:mode => 'restricted'} %> + + <%= labelled_form_field(_("Optional Title:"), f.text_field(:title, value: @notification.title)) %> + + <%= labelled_form_field(_("Enter your message here:"), f.text_area(:message, abstract_options)) %> + + <%= _("Obs: You can use %{name} and %{email} variables to put the user's name and email in the message.") %> + + + <%= labelled_form_field(_('Notifications Status'), select(:notifications, :active, options_for_select_with_title({_("Active") => true, _("Inactive") => false}, @notification.active))) %> + + <%= labelled_form_field(_('Notifications Color/Type'), select(:notifications, :type, options_for_select_with_title({_("Blue - Information") => "AdminNotificationsPlugin::InformationNotification", _("Yellow - Warning") => "AdminNotificationsPlugin::WarningNotification", _("Green - Success") => "AdminNotificationsPlugin::SuccessNotification", _("Red - Danger") => "AdminNotificationsPlugin::DangerNotification"}, @notification.type))) %> + +
+ <%= labelled_check_box(_("Display only in the homepage"), 'notifications[display_only_in_homepage]', '1', @notification.display_only_in_homepage?) %> +
+ +
+ <%= labelled_check_box(_("Display to not logged users too"), 'notifications[display_to_all_users]', '1', @notification.display_to_all_users?) %> +
+ +
+ <%= labelled_check_box(_("Display popup until user close the notification"), 'notifications[display_popup]', '1', @notification.display_popup?) %> +
+ + <% button_bar do %> + <%= submit_button 'save', _('Save'), :cancel => { :action => 'index' } %> + <% end %> + + <% end %> +
diff --git a/plugins/admin_notifications/views/shared/_notifications_list.html.erb b/plugins/admin_notifications/views/shared/_notifications_list.html.erb new file mode 100644 index 0000000..6ee3c4c --- /dev/null +++ b/plugins/admin_notifications/views/shared/_notifications_list.html.erb @@ -0,0 +1,39 @@ +
+
+

<%= _("Notifications") %>

+
+
+
+ <%= button :new, _('New Notification'), {:action => :new}, :method => :get %> +
+
+ <%= button :back, _('Back to control panel'), {:controller => 'admin_panel', :action => :index}, :method => :get %> +
+
+ +
+
+ <%= _('Notifications') %> +
+
+ <%= _('Actions') %> +
+
+ + <% @notifications.each do |notification| %> +
+
+ <%= truncate(notification.message, length: 50) %> +
+
+ <% if notification.active? %> + <%= button_without_text :deactivate, _('Deactivate'), {:action => :change_status, :id => notification}, :method => :post, :confirm => _("Do you want to change the status of this notification?") %> + <% else %> + <%= button_without_text :activate, _('Activate'), {:action => :change_status, :id => notification}, :method => :post, :confirm => _("Do you want to change the status of this notification?") %> + <% end %> + <%= button_without_text :edit, _('Edit'), {:action => 'edit', :id => notification.id} if !remove_content_button(:edit, notification) %> + <%= button_without_text :delete, _('Delete'), {:action => :destroy, :id => notification}, :method => :delete, :confirm => _("Do you want to delete this notification?") %> +
+
+ <% end %> +
diff --git a/plugins/admin_notifications/views/shared/show_notification.html.erb b/plugins/admin_notifications/views/shared/show_notification.html.erb new file mode 100644 index 0000000..9f74e76 --- /dev/null +++ b/plugins/admin_notifications/views/shared/show_notification.html.erb @@ -0,0 +1,33 @@ +<% if current_user && current_user.person.is_admin? %> + <% active_notifications = AdminNotificationsPlugin::Notification.active(environment) %> + <% unless active_notifications.blank? %> +
+
+
+

+ <%= _("There are active notifications in this environment!") %> + <%= link_to _("Manage all notifications here."), AdminNotificationsPlugin.admin_url %> +

+
+
+
+ <% end %> +<% end %> + +<% target = profile.present? ? profile : environment %> + +<% @notifications = AdminNotificationsPlugin::Notification.visibles(target, current_user, controller_path).where("id NOT IN (?)", hide_notifications) %> + +
+ <% @notifications.each do |notification| %> +
notification" data-notification="<%=notification.id%>" notification-display-popup="<%=notification.display_popup?%>"> +
+ <%= AdminNotificationsPlugin::NotificationHelper.substitute_variables(notification.message, current_user) %> +
+ <% if logged_in? %> +
+
+ <% end %> +
+ <% end %> +
diff --git a/plugins/environment_notification/README b/plugins/environment_notification/README new file mode 100644 index 0000000..2058c6d --- /dev/null +++ b/plugins/environment_notification/README @@ -0,0 +1,7 @@ +**This plugin is deprecated. Please use "admin_notifications" plugin instead.** + +If you already were using this plugin, migrating* it will switch automatically to the new plugin. +If you want to start using this plugin from scratch, activate and use the new one instead. + +*NOTE: running Noosfero in production mode already runs + the migrations and therefore switch plugins automatically. diff --git a/plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb b/plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb deleted file mode 100644 index 4e2308f..0000000 --- a/plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb +++ /dev/null @@ -1,103 +0,0 @@ -class EnvironmentNotificationPluginAdminController < AdminController - - helper EnvironmentNotificationHelper - include EnvironmentNotificationHelper - - before_filter :admin_required, :except => [:close_notification, :hide_notification] - - def index - @notifications = environment.environment_notifications.order('updated_at DESC') - end - - def new - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new - if request.post? - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new(params[:notifications]) - @notification.message = @notification.message.html_safe - @notification.environment_id = environment.id - if @notification.save - session[:notice] = _("Notification successfully created") - redirect_to :action => :index - else - session[:notice] = _("Notification couldn't be created") - end - end - end - - def destroy - if request.delete? - notification = environment.environment_notifications.find_by_id(params[:id]) - if notification && notification.destroy - session[:notice] = _('The notification was deleted.') - else - session[:notice] = _('Could not remove the notification') - end - end - redirect_to :action => :index - end - - def edit - @notification = environment.environment_notifications.find_by_id(params[:id]) - if request.post? - if @notification.update_attributes(params[:notifications]) - session[:notice] = _('The notification was edited.') - else - session[:notice] = _('Could not edit the notification.') - end - redirect_to :action => :index - end - end - - def change_status - @notification = environment.environment_notifications.find_by_id(params[:id]) - - @notification.active = !@notification.active - - if @notification.save! - session[:notice] = _('The status of the notification was changed.') - else - session[:notice] = _('Could not change the status of the notification.') - end - - redirect_to :action => :index - end - - def close_notification - result = false - - if logged_in? - @notification = environment.environment_notifications.find_by_id(params[:notification_id]) - - if @notification - @notification.users << current_user - result = @notification.users.include?(current_user) - end - end - - render json: result - end - - def hide_notification - result = false - - if logged_in? - @notification = environment.environment_notifications.find_by_id(params[:notification_id]) - - if @notification - current_notificaions = [] - current_notificaions = JSON.parse(cookies[:hide_notifications]) unless cookies[:hide_notifications].blank? - current_notificaions << @notification.id unless current_notificaions.include? @notification.id - cookies[:hide_notifications] = JSON.generate(current_notificaions) - result = current_notificaions.include? @notification.id - end - end - - render json: result - end - - protected - def admin_required - redirect_to :root unless current_user.person.is_admin? - end - -end diff --git a/plugins/environment_notification/controllers/public/environment_notification_plugin_public_controller.rb b/plugins/environment_notification/controllers/public/environment_notification_plugin_public_controller.rb deleted file mode 100644 index cf6fea6..0000000 --- a/plugins/environment_notification/controllers/public/environment_notification_plugin_public_controller.rb +++ /dev/null @@ -1,15 +0,0 @@ -class EnvironmentNotificationPluginPublicController < PublicController - - helper EnvironmentNotificationHelper - include EnvironmentNotificationHelper - - def notifications_with_popup - @hide_notifications = hide_notifications - if params[:previous_path] - @previous_path = params[:previous_path] - else - @previous_path = nil - end - end - -end diff --git a/plugins/environment_notification/db/migrate/20150721132025_create_notification_table.rb b/plugins/environment_notification/db/migrate/20150721132025_create_notification_table.rb deleted file mode 100644 index a83cd10..0000000 --- a/plugins/environment_notification/db/migrate/20150721132025_create_notification_table.rb +++ /dev/null @@ -1,28 +0,0 @@ -class CreateNotificationTable < ActiveRecord::Migration - def up - create_table :environment_notifications do |t| - t.text :message - t.integer :environment_id - t.string :type - t.string :title - t.boolean :active - t.boolean :display_only_in_homepage, :default => false - t.boolean :display_to_all_users, :default => false - t.boolean :display_popup, :default => false - t.column :created_at, :datetime - t.column :updated_at, :datetime - end - - create_table :environment_notifications_users, id: false do |t| - t.belongs_to :environment_notification - t.belongs_to :user - end - add_index :environment_notifications_users, [:environment_notification_id], name: :index_Zaem6uuw - add_index :environment_notifications_users, [:user_id], name: :index_ap3nohR9 - end - - def down - drop_table :environment_notifications - drop_table :environment_notifications_users - end -end diff --git a/plugins/environment_notification/db/migrate/20160321190725_reactivate_plugin_after_rename.rb b/plugins/environment_notification/db/migrate/20160321190725_reactivate_plugin_after_rename.rb new file mode 100644 index 0000000..2524502 --- /dev/null +++ b/plugins/environment_notification/db/migrate/20160321190725_reactivate_plugin_after_rename.rb @@ -0,0 +1,14 @@ +class ReactivatePluginAfterRename < ActiveRecord::Migration + def up + script_path = Rails.root.join('script').to_s + system(script_path + '/noosfero-plugins disable environment_notification') + system(script_path + '/noosfero-plugins enable admin_notifications') + + system("rake db:migrate") + end + + def down + raise ActiveRecord::IrreversibleMigration + end + +end diff --git a/plugins/environment_notification/features/message_edition.feature b/plugins/environment_notification/features/message_edition.feature deleted file mode 100644 index 13a1763..0000000 --- a/plugins/environment_notification/features/message_edition.feature +++ /dev/null @@ -1,14 +0,0 @@ -Feature: Create envronment notification message - As an admin user - I want to create an environment notification - In order to notificate users - - @selenium - Scenario: mce restricted mode should show on message creation - Given I am logged in as admin - And I follow "Administration" - And I follow "Plugins" - And I follow "Configuration" - And I follow "New Notification" - Then The tinymce "toolbar1" should be "bold italic underline | link" - Then The tinymce "menubar" should be "false" diff --git a/plugins/environment_notification/lib/environment_notification_helper.rb b/plugins/environment_notification/lib/environment_notification_helper.rb deleted file mode 100644 index 1933bd6..0000000 --- a/plugins/environment_notification/lib/environment_notification_helper.rb +++ /dev/null @@ -1,18 +0,0 @@ -module EnvironmentNotificationHelper - - def hide_notifications - invalid_id = -1 - hide_notifications_ids = [invalid_id] - hide_notifications_ids = JSON.parse(cookies[:hide_notifications]) unless cookies[:hide_notifications].blank? - hide_notifications_ids - end - - def self.substitute_variables(message, user) - if user - message = message.gsub("%{email}", user.person.email).gsub("%{name}", user.person.name) - end - - message - end - -end diff --git a/plugins/environment_notification/lib/environment_notification_plugin.rb b/plugins/environment_notification/lib/environment_notification_plugin.rb index 2e92035..e7dc07c 100644 --- a/plugins/environment_notification/lib/environment_notification_plugin.rb +++ b/plugins/environment_notification/lib/environment_notification_plugin.rb @@ -1,46 +1,9 @@ class EnvironmentNotificationPlugin < Noosfero::Plugin - def self.plugin_name - "Environment Notifications Plugin" + "Environment Notifications Plugin *DEPRECATED*" end def self.plugin_description - _("A plugin for environment notifications.") - end - - def stylesheet? - true - end - - def js_files - %w( - public/environment_notification_plugin.js - ) - end - - def body_beginning - lambda do - extend EnvironmentNotificationHelper - render template: 'environment_notification_plugin_admin/show_notification' - end - end - - def admin_panel_links - {:title => _('Notification Manager'), :url => {:controller => 'environment_notification_plugin_admin', :action => 'index'}} - end - - def account_controller_filters - block = proc do - if !logged_in? - cookies[:hide_notifications] = nil - end - end - - [{ - :type => "after_filter", - :method_name => "clean_hide_notifications_cookie", - :options => { }, - :block => block - }] + _("A plugin for environment notifications. *DEPRECATED*") end end diff --git a/plugins/environment_notification/lib/environment_notifications_user.rb b/plugins/environment_notification/lib/environment_notifications_user.rb deleted file mode 100644 index 69d63b8..0000000 --- a/plugins/environment_notification/lib/environment_notifications_user.rb +++ /dev/null @@ -1,10 +0,0 @@ -class EnvironmentNotificationsUser < ActiveRecord::Base - self.table_name = "environment_notifications_users" - - belongs_to :user - belongs_to :environment_notification, class_name: 'EnvironmentNotificationPlugin::EnvironmentNotification' - - attr_accessible :user_id, :environment_notification_id - - validates_uniqueness_of :user_id, :scope => :environment_notification_id -end diff --git a/plugins/environment_notification/lib/ext/environment.rb b/plugins/environment_notification/lib/ext/environment.rb deleted file mode 100644 index 0fd9264..0000000 --- a/plugins/environment_notification/lib/ext/environment.rb +++ /dev/null @@ -1,5 +0,0 @@ -require_dependency 'environment' - -class Environment - has_many :environment_notifications, class_name: 'EnvironmentNotificationPlugin::EnvironmentNotification' -end diff --git a/plugins/environment_notification/lib/ext/user.rb b/plugins/environment_notification/lib/ext/user.rb deleted file mode 100644 index 2cb316e..0000000 --- a/plugins/environment_notification/lib/ext/user.rb +++ /dev/null @@ -1,6 +0,0 @@ -require_dependency 'user' - -class User - has_many :environment_notifications_users - has_many :environment_notifications, :through => :environment_notifications_users -end diff --git a/plugins/environment_notification/models/environment_notification_plugin/danger_notification.rb b/plugins/environment_notification/models/environment_notification_plugin/danger_notification.rb deleted file mode 100644 index 35a6ce1..0000000 --- a/plugins/environment_notification/models/environment_notification_plugin/danger_notification.rb +++ /dev/null @@ -1,2 +0,0 @@ -class EnvironmentNotificationPlugin::DangerNotification < EnvironmentNotificationPlugin::EnvironmentNotification -end diff --git a/plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb b/plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb deleted file mode 100644 index ad91678..0000000 --- a/plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb +++ /dev/null @@ -1,50 +0,0 @@ -class EnvironmentNotificationPlugin::EnvironmentNotification < ActiveRecord::Base - - self.table_name = "environment_notifications" - - TYPE_LIST = [ - "EnvironmentNotificationPlugin::WarningNotification", - "EnvironmentNotificationPlugin::SuccessNotification", - "EnvironmentNotificationPlugin::InformationNotification", - "EnvironmentNotificationPlugin::DangerNotification" - ] - - attr_accessible :message, :environment_id, :active, :type, :display_only_in_homepage, :display_to_all_users, :display_popup, :title - - has_many :environment_notifications_users - has_many :users, :through => :environment_notifications_users - - validates_presence_of :message - validates_presence_of :environment_id - validate :notification_type_must_be_in_type_list - - def notification_type_must_be_in_type_list - unless TYPE_LIST.include?(type) - errors.add(:type, "invalid notification type") - end - end - - scope :active, lambda{|environment| { :conditions => { :environment_id => environment.id, :active => true } } } - - def self.visibles(environment, user, controller_path) - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.active(environment).order('updated_at DESC') - - if user - active_notifications_ids = notifications.pluck(:id) - user.environment_notifications.pluck(:id) - - notifications = notifications.where(id: active_notifications_ids) - else - notifications = notifications.where(display_to_all_users: true) - end - - if controller_path != "home" - notifications = notifications.where(display_only_in_homepage: false) - end - - notifications - end - - def self.with_popup(environment, user, previous_path) - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(environment, user, previous_path).where(display_popup: true) - end -end diff --git a/plugins/environment_notification/models/environment_notification_plugin/information_notification.rb b/plugins/environment_notification/models/environment_notification_plugin/information_notification.rb deleted file mode 100644 index 661ecdb..0000000 --- a/plugins/environment_notification/models/environment_notification_plugin/information_notification.rb +++ /dev/null @@ -1,2 +0,0 @@ -class EnvironmentNotificationPlugin::InformationNotification < EnvironmentNotificationPlugin::EnvironmentNotification -end diff --git a/plugins/environment_notification/models/environment_notification_plugin/success_notification.rb b/plugins/environment_notification/models/environment_notification_plugin/success_notification.rb deleted file mode 100644 index 22db359..0000000 --- a/plugins/environment_notification/models/environment_notification_plugin/success_notification.rb +++ /dev/null @@ -1,2 +0,0 @@ -class EnvironmentNotificationPlugin::SuccessNotification < EnvironmentNotificationPlugin::EnvironmentNotification -end diff --git a/plugins/environment_notification/models/environment_notification_plugin/warning_notification.rb b/plugins/environment_notification/models/environment_notification_plugin/warning_notification.rb deleted file mode 100644 index 378bd5a..0000000 --- a/plugins/environment_notification/models/environment_notification_plugin/warning_notification.rb +++ /dev/null @@ -1,2 +0,0 @@ -class EnvironmentNotificationPlugin::WarningNotification < EnvironmentNotificationPlugin::EnvironmentNotification -end diff --git a/plugins/environment_notification/po/environment_notification.pot b/plugins/environment_notification/po/environment_notification.pot deleted file mode 100644 index 3b83e6a..0000000 --- a/plugins/environment_notification/po/environment_notification.pot +++ /dev/null @@ -1,178 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: 1.5\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-04-19 15:00+0000\n" -"PO-Revision-Date: 2016-04-19 15:00+0000\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:19 -msgid "Notification successfully created" -msgstr "" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:22 -msgid "Notification couldn't be created" -msgstr "" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:31 -msgid "The notification was deleted." -msgstr "" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:33 -msgid "Could not remove the notification" -msgstr "" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:43 -msgid "The notification was edited." -msgstr "" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:45 -msgid "Could not edit the notification." -msgstr "" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:57 -msgid "The status of the notification was changed." -msgstr "" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:59 -msgid "Could not change the status of the notification." -msgstr "" - -#: ../lib/environment_notification_plugin.rb:8 -msgid "A plugin for environment notifications." -msgstr "" - -#: ../lib/environment_notification_plugin.rb:29 -msgid "Notification Manager" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:5 -msgid "Back" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:11 -msgid "Optional Title:" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:13 -msgid "Enter your message here:" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:15 -msgid "" -"Obs: You can use %{name} and %{email} variables to put the user's name and ema" -"il in the message." -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:18 -msgid "Notifications Status" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:20 -msgid "Blue - Information" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:20 -msgid "Yellow - Warning" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:20 -msgid "Green - Success" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:20 -msgid "Red - Danger" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:20 -msgid "Notifications Color/Type" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:23 -msgid "Display only in the homepage" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:27 -msgid "Display to not logged users too" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:31 -msgid "Display popup until user close the notification" -msgstr "" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:35 -msgid "Save" -msgstr "" - -#: ../views/environment_notification_plugin_admin/index.html.erb:3 -msgid "Environment Notifications" -msgstr "" - -#: ../views/environment_notification_plugin_admin/index.html.erb:7 -msgid "New Notification" -msgstr "" - -#: ../views/environment_notification_plugin_admin/index.html.erb:10 -msgid "Back to control panel" -msgstr "" - -#: ../views/environment_notification_plugin_admin/index.html.erb:16 -msgid "Notifications" -msgstr "" - -#: ../views/environment_notification_plugin_admin/index.html.erb:19 -msgid "Actions" -msgstr "" - -#: ../views/environment_notification_plugin_admin/index.html.erb:30 -#: ../views/environment_notification_plugin_admin/index.html.erb:32 -msgid "Do you want to change the status of this notification?" -msgstr "" - -#: ../views/environment_notification_plugin_admin/index.html.erb:30 -msgid "Deactivate" -msgstr "" - -#: ../views/environment_notification_plugin_admin/index.html.erb:32 -msgid "Activate" -msgstr "" - -#: ../views/environment_notification_plugin_admin/index.html.erb:34 -msgid "Edit" -msgstr "" - -#: ../views/environment_notification_plugin_admin/index.html.erb:35 -msgid "Delete" -msgstr "" - -#: ../views/environment_notification_plugin_admin/index.html.erb:35 -msgid "Do you want to delete this notification?" -msgstr "" - -#: ../views/environment_notification_plugin_admin/show_notification.html.erb:8 -msgid "There are active notifications in this environment!" -msgstr "" - -#: ../views/environment_notification_plugin_admin/show_notification.html.erb:9 -msgid "Manage all notifications here." -msgstr "" - -#: ../views/environment_notification_plugin_admin/show_notification.html.erb:26 -msgid "Do not show anymore" -msgstr "" - -#: ../views/environment_notification_plugin_admin/show_notification.html.erb:27 -msgid "Hide for now" -msgstr "" diff --git a/plugins/environment_notification/po/pt/environment_notification.po b/plugins/environment_notification/po/pt/environment_notification.po deleted file mode 100644 index 544b393..0000000 --- a/plugins/environment_notification/po/pt/environment_notification.po +++ /dev/null @@ -1,178 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. -# FIRST AUTHOR , YEAR. -# -msgid "" -msgstr "" -"Project-Id-Version: 1.3~rc2-1-ga15645d\n" -"POT-Creation-Date: 2016-04-19 15:00+0000\n" -"PO-Revision-Date: 2015-09-14 12:12-0000\n" -"Last-Translator: FULL NAME \n" -"Language-Team: Portuguese\n" -"Language: Portuguese\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:19 -msgid "Notification successfully created" -msgstr "Notificação criada com sucesso" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:22 -msgid "Notification couldn't be created" -msgstr "Não foi possível criar notificação" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:31 -msgid "The notification was deleted." -msgstr "A notificação foi removida" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:33 -msgid "Could not remove the notification" -msgstr "Não foi possível remover a notificação" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:43 -msgid "The notification was edited." -msgstr "A notificação foi editada." - -#: ../controllers/environment_notification_plugin_admin_controller.rb:45 -msgid "Could not edit the notification." -msgstr "Não foi possível editar a notificação." - -#: ../controllers/environment_notification_plugin_admin_controller.rb:57 -msgid "The status of the notification was changed." -msgstr "O status da notificação foi modificado" - -#: ../controllers/environment_notification_plugin_admin_controller.rb:59 -msgid "Could not change the status of the notification." -msgstr "Não foi possível alterar o status da notificação" - -#: ../lib/environment_notification_plugin.rb:8 -msgid "A plugin for environment notifications." -msgstr "Plugin para notificações do ambiente" - -#: ../lib/environment_notification_plugin.rb:29 -msgid "Notification Manager" -msgstr "Gerenciador de Notificações" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:5 -msgid "Back" -msgstr "Voltar" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:11 -msgid "Optional Title:" -msgstr "Título Opcional:" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:13 -msgid "Enter your message here:" -msgstr "Entre com a sua mensagem aqui:" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:15 -msgid "" -"Obs: You can use %{name} and %{email} variables to put the user's name and " -"email in the message." -msgstr "" -"Obs: Você pode usar as variáveis %{name} e %{email} para inserir o nome e " -"email do usuário logado na mensagem." - -#: ../views/environment_notification_plugin_admin/_form.html.erb:18 -msgid "Notifications Status" -msgstr "Status da Notificação" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:20 -msgid "Blue - Information" -msgstr "Azul - Informação" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:20 -msgid "Yellow - Warning" -msgstr "Amarelo - Atenção" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:20 -msgid "Green - Success" -msgstr "Verde - Sucesso" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:20 -msgid "Red - Danger" -msgstr "Vermelho - Perigo" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:20 -msgid "Notifications Color/Type" -msgstr "Cor/Tipo de Notificação" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:23 -msgid "Display only in the homepage" -msgstr "Apresentar apenas na página inicial" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:27 -msgid "Display to not logged users too" -msgstr "Apresentar notificação para usuários não logados também" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:31 -msgid "Display popup until user close the notification" -msgstr "Apresentar Popup da notificação até que o usuário a feche" - -#: ../views/environment_notification_plugin_admin/_form.html.erb:35 -msgid "Save" -msgstr "Salvar" - -#: ../views/environment_notification_plugin_admin/index.html.erb:3 -msgid "Environment Notifications" -msgstr "Notificações do Ambiente" - -#: ../views/environment_notification_plugin_admin/index.html.erb:7 -msgid "New Notification" -msgstr "Nova Notificação" - -#: ../views/environment_notification_plugin_admin/index.html.erb:10 -msgid "Back to control panel" -msgstr "Voltar ao Painel de Controle" - -#: ../views/environment_notification_plugin_admin/index.html.erb:16 -msgid "Notifications" -msgstr "Notificações" - -#: ../views/environment_notification_plugin_admin/index.html.erb:19 -msgid "Actions" -msgstr "Ações" - -#: ../views/environment_notification_plugin_admin/index.html.erb:30 -msgid "Deactivate" -msgstr "Desativar" - -#: ../views/environment_notification_plugin_admin/index.html.erb:30 -#: ../views/environment_notification_plugin_admin/index.html.erb:32 -msgid "Do you want to change the status of this notification?" -msgstr "Você quer alterar o status dessa notificação?" - -#: ../views/environment_notification_plugin_admin/index.html.erb:32 -msgid "Activate" -msgstr "Ativar" - -#: ../views/environment_notification_plugin_admin/index.html.erb:34 -msgid "Edit" -msgstr "Editar" - -#: ../views/environment_notification_plugin_admin/index.html.erb:35 -msgid "Delete" -msgstr "Remover" - -#: ../views/environment_notification_plugin_admin/index.html.erb:35 -msgid "Do you want to delete this notification?" -msgstr "Você quer remover essa notificação?" - -#: ../views/environment_notification_plugin_admin/show_notification.html.erb:8 -msgid "There are active notifications in this environment!" -msgstr "Existem notificações ativas neste ambiente!" - -#: ../views/environment_notification_plugin_admin/show_notification.html.erb:9 -msgid "Manage all notifications here." -msgstr "Gerencie todas as notificações aqui." - -#: ../views/environment_notification_plugin_admin/show_notification.html.erb:26 -msgid "Do not show anymore" -msgstr "Não mostrar mais" - -#: ../views/environment_notification_plugin_admin/show_notification.html.erb:27 -msgid "Hide for now" -msgstr "Ocultar momentaneamente" diff --git a/plugins/environment_notification/public/environment_notification_plugin.js b/plugins/environment_notification/public/environment_notification_plugin.js deleted file mode 100644 index 0556aa1..0000000 --- a/plugins/environment_notification/public/environment_notification_plugin.js +++ /dev/null @@ -1,84 +0,0 @@ -(function($) { - "use strict"; - - var environment_notification_plugin = { - - - notificationBar: function() { - var completeMessage = $(".environment-notification-plugin-notification-bar").remove(); - $("#content-inner").before(completeMessage); - }, - - closeNotification: function(){ - var notification = $(this).parent(); - var id = notification.attr("data-notification"); - - $.ajax({ - url: noosfero_root()+"/admin/plugin/environment_notification/close_notification", - type: "POST", - data: {notification_id: id}, - success: function(response) { - notification.fadeOut(); - } - }); - }, - - hideNotification: function(){ - var notification = $(this).parent(); - var id = notification.attr("data-notification"); - - $.ajax({ - url: noosfero_root()+"/admin/plugin/environment_notification/hide_notification", - type: "POST", - data: {notification_id: id}, - success: function(response) { - notification.fadeOut(); - } - }); - }, - - hideUserNotification: function(){ - var ids = $.cookie('hide_notifications'); - if(ids === null) { - return null; - } - - if(ids.startsWith('[') && ids.endsWith(']')){ - ids = ids.substring(1, ids.length - 1); - ids = ids.split(","); - - for(var i = 0; i < ids.length; i++) { - $('[data-notification="' + ids[i] + '"]').fadeOut(); - } - } - }, - - showPopup: function() { - if($('.action-home-index').length > 0) { - jQuery(function($){ - $.colorbox({href: noosfero_root()+'/plugin/environment_notification/public/notifications_with_popup?previous_path=home'}); - }); - } - else { - jQuery(function($){ - $.colorbox({href: noosfero_root()+'/plugin/environment_notification/public/notifications_with_popup'}); - }); - } - }, - }; - - $(document).ready(function(){ - environment_notification_plugin.notificationBar(); - $(".environment-notification-plugin-notification-bar .notification-close").on("click", environment_notification_plugin.closeNotification); - $(".environment-notification-plugin-notification-bar .notification-hide").on("click", environment_notification_plugin.hideNotification); - - if($('.environment-notification-plugin-notification-bar').length > 0){ - environment_notification_plugin.hideUserNotification(); - } - - if($('.environment-notification-plugin-notification-bar [notification-display-popup="true"]').length > 0){ - environment_notification_plugin.showPopup(); - } - }); - -})($); diff --git a/plugins/environment_notification/public/images/close.png b/plugins/environment_notification/public/images/close.png deleted file mode 100644 index e51bbb9..0000000 Binary files a/plugins/environment_notification/public/images/close.png and /dev/null differ diff --git a/plugins/environment_notification/public/images/greenhide.png b/plugins/environment_notification/public/images/greenhide.png deleted file mode 100644 index c69cd9d..0000000 Binary files a/plugins/environment_notification/public/images/greenhide.png and /dev/null differ diff --git a/plugins/environment_notification/public/images/hide.png b/plugins/environment_notification/public/images/hide.png deleted file mode 100644 index 5804c92..0000000 Binary files a/plugins/environment_notification/public/images/hide.png and /dev/null differ diff --git a/plugins/environment_notification/public/images/redclose.png b/plugins/environment_notification/public/images/redclose.png deleted file mode 100644 index d65e786..0000000 Binary files a/plugins/environment_notification/public/images/redclose.png and /dev/null differ diff --git a/plugins/environment_notification/public/images/show.png b/plugins/environment_notification/public/images/show.png deleted file mode 100644 index 477815e..0000000 Binary files a/plugins/environment_notification/public/images/show.png and /dev/null differ diff --git a/plugins/environment_notification/public/style.css b/plugins/environment_notification/public/style.css deleted file mode 100644 index 93aa840..0000000 --- a/plugins/environment_notification/public/style.css +++ /dev/null @@ -1,250 +0,0 @@ -.environment-notification-plugin-notification-bar{ - display: block; -} - -.environment-notification-plugin-notification-bar .notification:hover, -.environment-notification-plugin-notification-notification-modal .notification:hover{ - opacity: 0.8; -} - -#environment-notification-plugin-notification-manager{ - overflow: auto; -} - -.environment-notification-plugin-notification-bar .notification .notification-close, -.environment-notification-plugin-notification-notification-modal .notification .notification-close{ - background: url(images/close.png) no-repeat; - background-position: center; - width: 20px; - height: 20px; -} - -.environment-notification-plugin-notification-bar .warningnotification, -.environment-notification-plugin-notification-bar .informationnotification, -.environment-notification-plugin-notification-bar .successnotification, -.environment-notification-plugin-notification-bar .dangernotification, -.environment-notification-plugin-notification-bar .adminnotification, -.environment-notification-plugin-notification-notification-modal .warningnotification, -.environment-notification-plugin-notification-notification-modal .informationnotification, -.environment-notification-plugin-notification-notification-modal .successnotification, -.environment-notification-plugin-notification-notification-modal .dangernotification{ - margin-bottom: 10px; - padding: 7px 10px; - border-radius: 5px; - border: 1px solid blue; - font-size: 16px; - color: white; - overflow: auto; -} - -.environment-notification-plugin-notification-bar .warningnotification p, -.environment-notification-plugin-notification-bar .informationnotification p, -.environment-notification-plugin-notification-bar .successnotification p, -.environment-notification-plugin-notification-bar .dangernotification p, -.environment-notification-plugin-notification-bar .adminnotification p, -.environment-notification-plugin-notification-notification-modal .warningnotification p, -.environment-notification-plugin-notification-notification-modal .informationnotification p, -.environment-notification-plugin-notification-notification-modal .successnotification p, -.environment-notification-plugin-notification-notification-modal .dangernotification p{ - margin: 0px; -} - -.environment-notification-plugin-notification-bar .warningnotification, -.environment-notification-plugin-notification-notification-modal .warningnotification{ - background: #fcf8e3; - border: 1px solid #faebcc; - color: #8a6d3b; -} - -.environment-notification-plugin-notification-bar .warningnotification p a, -.environment-notification-plugin-notification-notification-modal .warningnotification p a{ - font-weight: bold; - color: #8a6d3b; -} - - -.environment-notification-plugin-notification-bar .informationnotification, -.environment-notification-plugin-notification-notification-modal .informationnotification{ - background: #d9edf7; - border: 1px solid #bce8f1; - color: #31708f; -} - -.environment-notification-plugin-notification-bar .informationnotification p a, -.environment-notification-plugin-notification-notification-modal .informationnotification p a{ - font-weight: bold; - color: #31708f; -} - -.environment-notification-plugin-notification-bar .successnotification, -.environment-notification-plugin-notification-notification-modal .successnotification{ - background: #dff0d8; - border: 1px solid #d6e9c6; - color: #3c763d; -} - -.environment-notification-plugin-notification-bar .successnotification p a -.environment-notification-plugin-notification-notification-modal .successnotification p a{ - font-weight: bold; - color: #3c763d; -} - -.environment-notification-plugin-notification-bar .dangernotification, -.environment-notification-plugin-notification-notification-modal .dangernotification{ - background: #f2dede; - border: 1px solid #ebccd1; - color: #a94442; -} - -.environment-notification-plugin-notification-bar .dangernotification p a, -.environment-notification-plugin-notification-notification-modal .dangernotification p a{ - font-weight: bold; - color: #a94442; -} - -.environment-notification-plugin-notification-bar .adminnotification, -.environment-notification-plugin-notification-notification-modal .adminnotification{ - background: #9a959a; - border: 1px solid #9a959a; -} - -.environment-notification-plugin-notification-bar .adminnotification p a, -.environment-notification-plugin-notification-notification-modal .adminnotification p a{ - font-weight: bold; - color: white; -} - -#environment-notification-plugin-notification-manager a.button.icon-deactivate{ - background: url(images/hide.png) no-repeat; - background-position: center; -} - -#environment-notification-plugin-notification-manager a.button.icon-activate{ - background: url(images/show.png) no-repeat; - background-position: center; -} - -#environment-notification-plugin-notification-manager .notification-line{ - display: inline; - padding-top: 10px; - vertical-align: middle; - border-bottom: 1px solid #ccc; -} - -#environment-notification-plugin-notification-manager .notification-title-bar{ - float: left; - width: 100%; - font-style: 14px; - font-weight: 700; - border-bottom: 2px solid black; - padding: 9px 0; -} - -#environment-notification-plugin-notification-manager .notification-title{ - width: 80%; - float: left; - text-align: center; -} - -.environment-notification-plugin-notification-notification-modal .notification-with-title{ - margin-bottom: 0px; -} - -.environment-notification-plugin-notification-notification-modal .notification .notification-title{ - width: 100%; - float: left; - font-weight: bold; - text-align: left; -} - -.environment-notification-plugin-notification-notification-modal .notification-with-title-message{ - width: 100%; - float: left; - border-radius: 3px; - margin-bottom: 10px; - background-color: #f5f5f5; - font-size: 14px; - overflow: auto; -} - -.environment-notification-plugin-notification-notification-modal .notification-with-title-message p{ - padding: 0px 7px; -} - -.environment-notification-plugin-notification-notification-modal .notification-with-title-message p a{ - color: black; - font-weight: bold; -} - - -#environment-notification-plugin-notification-manager .action-title{ - width: 20%; - float: left; - text-align: center; -} - -#environment-notification-plugin-notification-manager .notification-action{ - width: 18%; - float: left; - height: 30px; - padding-top: 9px; -} - -#environment-notification-plugin-notification-manager .main-bar .button, -#environment-notification-plugin-notification-manager .notification-action .button{ - border-radius: 3px; -} - -#environment-notification-plugin-notification-manager .notification-message{ - width: 82%; - float: left; -} - -#environment-notification-plugin-notification-manager .new-notification{ - float: right; - width: auto; -} - -#environment-notification-plugin-notification-manager .back-button{ - float: left; -} - -#environment-notification-plugin-notification-manager .main-bar{ - display: inline; - width: 100%; -} - -.environment-notification-plugin-notification-bar .notification .notification-message, -.environment-notification-plugin-notification-notification-modal .notification .notification-message{ - width: 90%; - float: left; -} - -.environment-notification-plugin-notification-bar .notification .notification-close{ - background: url(images/redclose.png) no-repeat; - background-position: center; - width: 20px; - height: 20px; - float: right; - cursor: pointer; -} - -.environment-notification-plugin-notification-bar .notification .notification-hide{ - background: url(images/greenhide.png) no-repeat; - background-position: center; - width: 20px; - height: 20px; - float: right; - cursor: pointer; -} - -.environment-notification-plugin-notification-notification-modal{ - display: block; - min-width: 400px; - max-width: 700px; -} - -.environment-notification-plugin-form .notification-variables-options{ - font-style: italic; - color: red; -} diff --git a/plugins/environment_notification/test/functional/account_controller_test.rb b/plugins/environment_notification/test/functional/account_controller_test.rb deleted file mode 100644 index 8eef307..0000000 --- a/plugins/environment_notification/test/functional/account_controller_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' -require 'account_controller' - -class AccountController - include EnvironmentNotificationHelper -end - -class AccountControllerTest < ActionController::TestCase - def setup - @controller = AccountController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - @person = create_user('person').person - - @environment = Environment.default - @environment.enable_plugin('EnvironmentNotificationPlugin') - @environment.save! - - login_as(@person.user.login) - end - - attr_accessor :person - - should 'clean hide_notifications cookie after logout' do - @request.cookies[:hide_notifications] = JSON.generate([1,2]) - get :index - assert !@request.cookies[:hide_notifications].blank? - - @request.cookies[:hide_notifications] = nil - get :logout - assert_nil session[:user] - assert_response :redirect - assert_equal 1, @controller.hide_notifications.count - assert @controller.hide_notifications.include?(-1) - end -end diff --git a/plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb b/plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb deleted file mode 100644 index 1ff4671..0000000 --- a/plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb +++ /dev/null @@ -1,186 +0,0 @@ -require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' -require( - File.expand_path(File.dirname(__FILE__)) + - '/../../controllers/environment_notification_plugin_admin_controller' -) - -class EnvironmentNotificationPluginAdminController; def rescue_action(e) raise e end; -end - -class EnvironmentNotificationPluginAdminControllerTest < ActionController::TestCase - def setup - @controller = EnvironmentNotificationPluginAdminController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - @person = create_user('person').person - - @environment = Environment.default - @environment.enable_plugin('EnvironmentNotificationPlugin') - @environment.save! - - login_as(@person.user.login) - end - - attr_accessor :person - - should 'an admin be able to create a notification' do - @environment.add_admin(@person) - post :new, :notifications => { - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - } - assert_redirected_to :action => 'index' - notification = EnvironmentNotificationPlugin::EnvironmentNotification.last - assert_equal "Message", notification.message - assert notification.active - assert_equal "EnvironmentNotificationPlugin::DangerNotification", notification.type - end - - should 'an user not to be able to create a notification' do - post :new, :notifications => { - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - } - assert_redirected_to :root - assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.last - end - - should 'an admin be able to edit a notification' do - @environment.add_admin(@person) - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - post :edit, :id => @notification.id, :notifications => { - :message => "Edited Message", - :active => false, - :type => "EnvironmentNotificationPlugin::WarningNotification" - } - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.last - assert_redirected_to :action => 'index' - assert_equal "Edited Message", @notification.message - assert !@notification.active - assert_equal "EnvironmentNotificationPlugin::WarningNotification", @notification.type - end - - should 'an user not to be able to edit a notification' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - post :edit, :notifications => { - :message => "Edited Message", - :active => false, - :type => "EnvironmentNotificationPlugin::DangerNotification" - } - @notification.reload - assert_redirected_to :root - assert_equal "Message", @notification.message - assert @notification.active - end - - should 'an admin be able to destroy a notification' do - @environment.add_admin(@person) - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - delete :destroy, :id => @notification.id - assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id) - end - - should 'an user not to be able to destroy a notification' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - delete :destroy, :id => @notification.id - - assert_redirected_to :root - assert_not_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id) - end - - should 'an admin be able to change Notification status' do - @environment.add_admin(@person) - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - post :change_status, :id => @notification.id - assert_redirected_to :action => 'index' - - @notification.reload - assert !@notification.active - end - - should 'an user not be able to change Notification status' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - post :change_status, :id => @notification.id - assert_redirected_to :root - - @notification.reload - assert @notification.active - end - - should 'a logged in user be able to permanently hide notifications' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - post :close_notification, :notification_id => @notification.id - assert_equal "true", @response.body - assert @notification.users.include?(@person.user) - end - - should 'a logged in user be able to momentarily hide notifications' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - - @another_notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Another Message", - :active => true, - :type => "EnvironmentNotificationPlugin::WarningNotification" - ) - post :hide_notification, :notification_id => @notification.id - assert_equal "true", @response.body - assert @controller.hide_notifications.include?(@notification.id) - assert !@controller.hide_notifications.include?(@another_notification.id) - end - - should 'not momentarily hide any notification if its id is not found' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - - post :hide_notification, :notification_id => nil - assert_equal "false", @response.body - assert !@controller.hide_notifications.include?(@notification.id) - end -end diff --git a/plugins/environment_notification/test/functional/home_controller_test.rb b/plugins/environment_notification/test/functional/home_controller_test.rb deleted file mode 100644 index 73dfd33..0000000 --- a/plugins/environment_notification/test/functional/home_controller_test.rb +++ /dev/null @@ -1,120 +0,0 @@ -require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper' -require 'home_controller' - -class HomeController; def rescue_action(e) raise e end; -end - -class HomeControllerTest < ActionController::TestCase - def setup - @controller = HomeController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - @person = create_user('person').person - - @environment = Environment.default - @environment.enable_plugin('EnvironmentNotificationPlugin') - @environment.save! - end - - attr_accessor :person - - should 'an active notification be displayed on home page for a logged in user' do - login_as(@person.user.login) - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Hello, this is a Notification Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - get :index - assert_match /Hello, this is a Notification Message/, @response.body - end - - - should 'an active notification not be displayed on home page for unlogged user' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Hello, this is a Notification Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - get :index - assert_no_match /Hello, this is a Notification Message/, @response.body - end - - should 'an active notification be displayed on home page for unlogged user' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Hello, this is a Notification Message", - :display_to_all_users => true, - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - get :index - assert_match /Hello, this is a Notification Message/, @response.body - end - - should 'only display the notification with display_to_all_users option for unlogged user ' do - @notification1 = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Hello, this is an old Notification Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - - @notification2 = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Hello, this is a new Notification Message", - :display_to_all_users => true, - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - - - get :index - assert_no_match /Hello, this is a Notification Message/, @response.body - assert_match /Hello, this is a new Notification Message/, @response.body - end - - should 'an inactive notification not be displayed on home page' do - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Hello, this is a Notification Message", - :active => false, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - get :index - assert_no_match /Hello, this is a Notification Message/, @response.body - end - - - should 'an active notification not be displayed to a logged in user after been closed by him' do - login_as(@person.user.login) - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Hello, this is a Notification Message", - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - @notification.users << @person.user - @notification.save! - assert_equal true, @notification.users.include?(@person.user) - get :index - assert_no_match /Hello, this is a Notification Message/, @response.body - end - - should 'a notification be displayed with a Popup' do - login_as(@person.user.login) - @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create( - :environment_id => @environment.id, - :message => "Message", - :display_popup => true, - :active => true, - :type => "EnvironmentNotificationPlugin::DangerNotification" - ) - assert_equal true, @notification.display_popup? - - get :index - assert_no_match /div id="cboxWrapper"/, @response.body - end -end diff --git a/plugins/environment_notification/test/unit/environment_notification_helper_test.rb b/plugins/environment_notification/test/unit/environment_notification_helper_test.rb deleted file mode 100644 index 6d6bb88..0000000 --- a/plugins/environment_notification/test/unit/environment_notification_helper_test.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'test_helper' - -class EnvironmentNotificationHelperTest < ActiveSupport::TestCase - def setup - @env = Environment.default - @env.enable_plugin('EnvironmentNotificationPlugin') - - @user = User.create!(:environment_id => @env.id, :email => "user@domain.com", :login => "new_user", :password => "test", :password_confirmation => "test", :name => "UserName") - end - - should 'substitute all email variables to the current user email' do - message = "Hello user with email %{email}! please, update your current email (%{email})." - - new_message = EnvironmentNotificationHelper.substitute_variables(message, @user) - - assert message != new_message - assert_equal new_message, "Hello user with email user@domain.com! please, update your current email (user@domain.com)." - end - - should 'not substitute emails variables if there is no current user' do - message = "Hello user with email %{email}! please, update your current email (%{email})." - - new_message = EnvironmentNotificationHelper.substitute_variables(message, nil) - - assert_equal message, new_message - assert_not_includes new_message, "user@domain.com" - end - - should 'substitute all name variables to the current user name' do - message = "Hello %{name}! is %{name} your real name?." - - new_message = EnvironmentNotificationHelper.substitute_variables(message, @user) - - assert message != new_message - assert_equal new_message, "Hello UserName! is UserName your real name?." - end - - should 'not substitute name variables if there is no current user' do - message = "Hello %{name}! is %{name} your real name?." - - new_message = EnvironmentNotificationHelper.substitute_variables(message, nil) - - assert_equal message, new_message - assert_not_includes new_message, "UserName" - end -end diff --git a/plugins/environment_notification/test/unit/environment_notification_test.rb b/plugins/environment_notification/test/unit/environment_notification_test.rb deleted file mode 100644 index b2e0aab..0000000 --- a/plugins/environment_notification/test/unit/environment_notification_test.rb +++ /dev/null @@ -1,162 +0,0 @@ -require_relative '../../../../test/test_helper' - -class EnvironmentNotificationTest < ActiveSupport::TestCase - - def setup - @env = Environment.default - @env.enable_plugin('EnvironmentNotificationPlugin') - - User.destroy_all - EnvironmentNotificationPlugin::EnvironmentNotification.destroy_all - EnvironmentNotificationsUser.destroy_all - - @user = User.create!(:environment_id => @env.id, :email => "user@domain.com", :login => "new_user", :password => "test", :password_confirmation => "test") - @danger_notification = EnvironmentNotificationPlugin::DangerNotification.create!( - :environment_id => @env.id, - :message => "Danger Message", - :active => true, - ) - - @warning_notification = EnvironmentNotificationPlugin::WarningNotification.create!( - :environment_id => @env.id, - :message => "Warning Message", - :active => true, - ) - - @information_notification = EnvironmentNotificationPlugin::InformationNotification.create!( - :environment_id => @env.id, - :message => "Information Message", - :active => true, - ) - end - - should 'get all notifications that a user did not closed' do - @information_notification.users << @user - - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, nil) - - assert notifications.include?(@danger_notification) - assert notifications.include?(@warning_notification) - assert !notifications.include?(@information_notification) - end - - should 'get only notifications configured to be displayed to all users' do - @information_notification.display_to_all_users = true - @information_notification.save! - - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, nil, nil) - - assert !notifications.include?(@danger_notification) - assert !notifications.include?(@warning_notification) - assert notifications.include?(@information_notification) - end - - should 'get only notifications configured to be displayed to all users and in all pages' do - @information_notification.display_to_all_users = true - @information_notification.display_only_in_homepage = true - @information_notification.save! - - @danger_notification.display_to_all_users = true - @danger_notification.save! - - @warning_notification.display_only_in_homepage = true - @warning_notification.save! - - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, nil, 'not_home') - - assert notifications.include?(@danger_notification) - assert !notifications.include?(@warning_notification) - assert !notifications.include?(@information_notification) - end - - should 'get only notifications configured to be displayed in all pages' do - @danger_notification.display_to_all_users = true - @danger_notification.display_only_in_homepage = true - @danger_notification.save! - - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, "not_home") - - assert !notifications.include?(@danger_notification) - assert notifications.include?(@warning_notification) - assert notifications.include?(@information_notification) - - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, nil, "home") - - assert notifications.include?(@danger_notification) - assert !notifications.include?(@warning_notification) - assert !notifications.include?(@information_notification) - end - - should 'get only notifications configured to be displayed to all users and in all pages and not closed by an user' do - @information_notification.display_to_all_users = true - @information_notification.save! - - @danger_notification.display_to_all_users = true - @danger_notification.display_only_in_homepage = true - @danger_notification.save! - - @warning_notification.display_to_all_users = true - @warning_notification.save! - - @warning_notification.users << @user - - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, 'not_home') - - assert !notifications.include?(@danger_notification) - assert !notifications.include?(@warning_notification) - assert notifications.include?(@information_notification) - end - - should 'get only active notifications' do - @information_notification.active = false - @information_notification.save! - - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, 'home') - - assert notifications.include?(@danger_notification) - assert notifications.include?(@warning_notification) - assert !notifications.include?(@information_notification) - end - - should 'get only notifications with popup' do - @information_notification.display_popup = true - @information_notification.display_to_all_users = true - @information_notification.save! - - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, @user, 'home') - - assert !notifications.include?(@danger_notification) - assert !notifications.include?(@warning_notification) - assert notifications.include?(@information_notification) - - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, nil, nil) - - assert !notifications.include?(@danger_notification) - assert !notifications.include?(@warning_notification) - assert notifications.include?(@information_notification) - end - - should 'get only notifications with popup not closed by an user' do - @information_notification.display_popup = true - @information_notification.display_to_all_users = true - @information_notification.save! - - @danger_notification.display_popup = true - @danger_notification.display_to_all_users = true - @danger_notification.save! - - @danger_notification.users << @user - - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, @user, 'home') - - assert !notifications.include?(@danger_notification) - assert !notifications.include?(@warning_notification) - assert notifications.include?(@information_notification) - - notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, nil, nil) - - assert notifications.include?(@danger_notification) - assert !notifications.include?(@warning_notification) - assert notifications.include?(@information_notification) - end -end diff --git a/plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb b/plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb deleted file mode 100644 index f441219..0000000 --- a/plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb +++ /dev/null @@ -1,39 +0,0 @@ -
- - <% abstract_options = {:value => @notification.message, :style => 'width: 100%; height: 200px;', :class => 'mceEditor'} %> - - <%= button :back, _('Back'), :controller => 'environment_notification_plugin_admin' %> - - <%= form_for :notifications do |f| %> - - <%= render :file => 'shared/tiny_mce', :locals => {:mode => 'restricted'} %> - - <%= labelled_form_field(_("Optional Title:"), f.text_field(:title, value: @notification.title)) %> - - <%= labelled_form_field(_("Enter your message here:"), f.text_area(:message, abstract_options)) %> - - <%= _("Obs: You can use %{name} and %{email} variables to put the user's name and email in the message.") %> - - - <%= labelled_form_field(_('Notifications Status'), select(:notifications, :active, options_for_select_with_title({"Active" => true, "Inactive" => false}, @notification.active))) %> - - <%= labelled_form_field(_('Notifications Color/Type'), select(:notifications, :type, options_for_select_with_title({_("Blue - Information") => "EnvironmentNotificationPlugin::InformationNotification", _("Yellow - Warning") => "EnvironmentNotificationPlugin::WarningNotification", _("Green - Success") => "EnvironmentNotificationPlugin::SuccessNotification", _("Red - Danger") => "EnvironmentNotificationPlugin::DangerNotification"}, @notification.type))) %> - -
- <%= labelled_check_box(_("Display only in the homepage"), 'notifications[display_only_in_homepage]', '1', @notification.display_only_in_homepage?) %> -
- -
- <%= labelled_check_box(_("Display to not logged users too"), 'notifications[display_to_all_users]', '1', @notification.display_to_all_users?) %> -
- -
- <%= labelled_check_box(_("Display popup until user close the notification"), 'notifications[display_popup]', '1', @notification.display_popup?) %> -
- - <% button_bar do %> - <%= submit_button 'save', _('Save'), :cancel => { :action => 'index' } %> - <% end %> - - <% end %> -
diff --git a/plugins/environment_notification/views/environment_notification_plugin_admin/edit.html.erb b/plugins/environment_notification/views/environment_notification_plugin_admin/edit.html.erb deleted file mode 100644 index 2872e82..0000000 --- a/plugins/environment_notification/views/environment_notification_plugin_admin/edit.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render :partial => "form" %> diff --git a/plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb b/plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb deleted file mode 100644 index f91fc60..0000000 --- a/plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb +++ /dev/null @@ -1,40 +0,0 @@ -
-
-

<%= _("Environment Notifications") %>

-
-
-
- <%= button :new, _('New Notification'), {:action => :new}, :method => :get %> -
-
- <%= button :back, _('Back to control panel'), {:controller => 'admin_panel', :action => :index}, :method => :get %> -
-
- -
-
- <%= _('Notifications') %> -
-
- <%= _('Actions') %> -
-
- - <% @notifications.each do |notification| %> -
-
- <%= truncate(notification.message, length: 50) %> -
-
- <% if notification.active? %> - <%= button_without_text :deactivate, _('Deactivate'), {:action => :change_status, :id => notification}, :method => :post, :confirm => _("Do you want to change the status of this notification?") %> - <% else %> - <%= button_without_text :activate, _('Activate'), {:action => :change_status, :id => notification}, :method => :post, :confirm => _("Do you want to change the status of this notification?") %> - <% end %> - <%= button_without_text :edit, _('Edit'), {:action => 'edit', :id => notification.id} if !remove_content_button(:edit, notification) %> - <%= button_without_text :delete, _('Delete'), {:action => :destroy, :id => notification}, :method => :delete, :confirm => _("Do you want to delete this notification?") %> -
-
- <% end %> -
- diff --git a/plugins/environment_notification/views/environment_notification_plugin_admin/new.html.erb b/plugins/environment_notification/views/environment_notification_plugin_admin/new.html.erb deleted file mode 100644 index 2872e82..0000000 --- a/plugins/environment_notification/views/environment_notification_plugin_admin/new.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render :partial => "form" %> diff --git a/plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb b/plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb deleted file mode 100644 index 514cf2c..0000000 --- a/plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb +++ /dev/null @@ -1,31 +0,0 @@ -<% if current_user && current_user.person.is_admin? %> - <% active_notifications = EnvironmentNotificationPlugin::EnvironmentNotification.active(environment) %> - <% unless active_notifications.blank? %> -
-
-
-

- <%= _("There are active notifications in this environment!") %> - <%= link_to _("Manage all notifications here."), EnvironmentNotificationPlugin.admin_url %> -

-
-
-
- <% end %> -<% end %> - -<% @notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(environment, current_user, controller_path).where("id NOT IN (?)", hide_notifications) %> - -
- <% @notifications.each do |notification| %> -
notification" data-notification="<%=notification.id%>" notification-display-popup="<%=notification.display_popup?%>"> -
- <%= EnvironmentNotificationHelper.substitute_variables(notification.message, current_user) %> -
- <% if logged_in? %> -
-
- <% end %> -
- <% end %> -
diff --git a/plugins/environment_notification/views/environment_notification_plugin_public/notifications_with_popup.html.erb b/plugins/environment_notification/views/environment_notification_plugin_public/notifications_with_popup.html.erb deleted file mode 100644 index 5ab872f..0000000 --- a/plugins/environment_notification/views/environment_notification_plugin_public/notifications_with_popup.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -<% @notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(environment, current_user, @previous_path).where("id NOT IN (?)", @hide_notifications) %> - -
- <% @notifications.each do |notification| %> - <% if !notification.title.blank? %> -
notification notification-with-title" data-notification="<%=notification.id%>"> -
- <%= notification.title %> -
-
-
- <%= EnvironmentNotificationHelper.substitute_variables(notification.message, current_user) %> -
- <% else %> -
notification notification-without-title" data-notification="<%=notification.id%>"> -
- <%= EnvironmentNotificationHelper.substitute_variables(notification.message, current_user) %> -
-
- <% end %> - <% end %> -
-- libgit2 0.21.2