Commit 5a45530a29a4bdd9e7ada290b6826db28245ad6e

Authored by Braulio Bhavamitra
2 parents ce257d5c 283dd97a

Merge branch 'community_notifications' into 'master'

environment_notification plugin improved

- Added notifications for Organizations;
    - Only the profile admin can create them;
    - show_only_in_homepage option here works with profile homepage;
 - Rename plugin to be more consistent with new features;
 - Adds plugin namespace to tables, classes and modules;

Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Signed-off-by: Lucas Severo <lucassalves65@gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza@gmail.com>

fixes migration and translations

See merge request !838
Showing 83 changed files with 1856 additions and 1666 deletions   Show diff stats
plugins/admin_notifications/README 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +This plugin is the new version of "environment_notification" plugin.
  2 +
  3 +New features added:
  4 + - Create a notification for an organization;
  5 + - Only profile admin can create notifications;
  6 + - Organization notifications can be seen by members from any of the organization pages;
  7 + - home_page option set the notification to be seen only at organization homepage;
... ...
plugins/admin_notifications/controllers/admin_notifications_plugin_admin_controller.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +class AdminNotificationsPluginAdminController < AdminController
  2 +
  3 + include AdminNotificationsPlugin::NotificationManager
  4 +
  5 + before_filter :admin_required
  6 +
  7 + protected
  8 + def target
  9 + environment
  10 + end
  11 +
  12 + def admin_required
  13 + redirect_to :root unless current_person.is_admin?
  14 + end
  15 +
  16 +end
... ...
plugins/admin_notifications/controllers/admin_notifications_plugin_myprofile_controller.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +class AdminNotificationsPluginMyprofileController < MyProfileController
  2 +
  3 + include AdminNotificationsPlugin::NotificationManager
  4 +
  5 + before_filter :admin_required
  6 +
  7 + protected
  8 + def target
  9 + profile
  10 + end
  11 +
  12 + def admin_required
  13 + redirect_to :root unless target.is_admin?(current_person)
  14 + end
  15 +
  16 +end
... ...
plugins/admin_notifications/controllers/public/admin_notifications_plugin_public_controller.rb 0 → 100644
... ... @@ -0,0 +1,48 @@
  1 +class AdminNotificationsPluginPublicController < PublicController
  2 +
  3 + helper AdminNotificationsPlugin::NotificationHelper
  4 + include AdminNotificationsPlugin::NotificationHelper
  5 +
  6 + def notifications_with_popup
  7 + @hide_notifications = hide_notifications
  8 + if params[:previous_path]
  9 + @previous_path = params[:previous_path]
  10 + else
  11 + @previous_path = nil
  12 + end
  13 + end
  14 +
  15 + def close_notification
  16 + result = false
  17 +
  18 + if logged_in?
  19 + @notification = AdminNotificationsPlugin::Notification.find_by_id(params[:notification_id])
  20 +
  21 + if @notification
  22 + @notification.users << current_user
  23 + result = @notification.users.include?(current_user)
  24 + end
  25 + end
  26 +
  27 + render json: result
  28 + end
  29 +
  30 + def hide_notification
  31 + result = false
  32 +
  33 + if logged_in?
  34 + @notification = AdminNotificationsPlugin::Notification.find_by_id(params[:notification_id])
  35 +
  36 + if @notification
  37 + current_notificaions = []
  38 + current_notificaions = JSON.parse(cookies[:hide_notifications]) unless cookies[:hide_notifications].blank?
  39 + current_notificaions << @notification.id unless current_notificaions.include? @notification.id
  40 + cookies[:hide_notifications] = JSON.generate(current_notificaions)
  41 + result = current_notificaions.include? @notification.id
  42 + end
  43 + end
  44 +
  45 + render json: result
  46 + end
  47 +
  48 +end
... ...
plugins/admin_notifications/db/migrate/20150721132025_create_notification_table.rb 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +class CreateNotificationTable < ActiveRecord::Migration
  2 + def up
  3 + create_table :environment_notifications do |t|
  4 + t.text :message
  5 + t.integer :environment_id
  6 + t.string :type
  7 + t.string :title
  8 + t.boolean :active
  9 + t.boolean :display_only_in_homepage, :default => false
  10 + t.boolean :display_to_all_users, :default => false
  11 + t.boolean :display_popup, :default => false
  12 + t.column :created_at, :datetime
  13 + t.column :updated_at, :datetime
  14 + end
  15 +
  16 + create_table :environment_notifications_users, id: false do |t|
  17 + t.belongs_to :environment_notification
  18 + t.belongs_to :user
  19 + end
  20 + add_index :environment_notifications_users, [:environment_notification_id], name: :index_Zaem6uuw
  21 + add_index :environment_notifications_users, [:user_id], name: :index_ap3nohR9
  22 + end
  23 +
  24 + def down
  25 + drop_table :environment_notifications
  26 + drop_table :environment_notifications_users
  27 + end
  28 +end
... ...
plugins/admin_notifications/db/migrate/20160321190726_change_notification_relation_to_polymorphic.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class ChangeNotificationRelationToPolymorphic < ActiveRecord::Migration
  2 + def up
  3 + rename_column(:environment_notifications, :environment_id, :target_id)
  4 + add_column(:environment_notifications, :target_type, :string)
  5 +
  6 + execute("UPDATE environment_notifications SET target_type = 'Environment'")
  7 + end
  8 +
  9 + def down
  10 + rename_column(:environment_notifications, :target_id, :environment_id)
  11 + remove_column(:environment_notifications, :target_type)
  12 + end
  13 +end
... ...
plugins/admin_notifications/db/migrate/20160330171610_rename_plugin_tables.rb 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +class RenamePluginTables < ActiveRecord::Migration
  2 + def up
  3 + remove_index :environment_notifications_users, name: :index_Zaem6uuw
  4 + remove_index :environment_notifications_users, name: :index_ap3nohR9
  5 +
  6 + rename_column :environment_notifications_users, :environment_notification_id, :notification_id
  7 +
  8 + rename_table :environment_notifications, :admin_notifications_plugin_notifications
  9 + rename_table :environment_notifications_users, :admin_notifications_plugin_notifications_users
  10 +
  11 + add_index :admin_notifications_plugin_notifications_users, [:notification_id], :name => :index_notifications_users_notification_id
  12 + add_index :admin_notifications_plugin_notifications_users, [:user_id], :name => :index_notifications_users_user_id
  13 +
  14 + Environment.all.each do |e|
  15 + if e.enabled_plugins.include?('EnvironmentNotificationPlugin')
  16 + e.enabled_plugins -= ['EnvironmentNotificationPlugin']
  17 + e.enabled_plugins += ['AdminNotificationsPlugin']
  18 + e.save!
  19 + end
  20 + end
  21 + end
  22 +
  23 + def down
  24 + remove_index :admin_notifications_plugin_notifications_users, :name => :index_notifications_users_notification_id
  25 + remove_index :admin_notifications_plugin_notifications_users, :name => :index_notifications_users_user_id
  26 +
  27 + rename_table :admin_notifications_plugin_notifications, :environment_notifications
  28 + rename_table :admin_notifications_plugin_notifications_users, :environment_notifications_users
  29 +
  30 + rename_column :environment_notifications_users, :notification_id, :environment_notification_id
  31 +
  32 + add_index :environment_notifications_users, [:environment_notification_id], name: :index_Zaem6uuw
  33 + add_index :environment_notifications_users, [:user_id], name: :index_ap3nohR9
  34 + end
  35 +
  36 + Environment.all.each do |e|
  37 + if e.enabled_plugins.include?('AdminNotificationsPlugin')
  38 + e.enabled_plugins -= ['AdminNotificationsPlugin']
  39 + e.enabled_plugins += ['EnvironmentNotificationPlugin']
  40 + e.save!
  41 + end
  42 + end
  43 +end
... ...
plugins/admin_notifications/db/migrate/20160505142214_change_type_to_new_namespace.rb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +class ChangeTypeToNewNamespace < ActiveRecord::Migration
  2 + def up
  3 + notification_types = %w(InformationNotification DangerNotification SuccessNotification WarningNotification)
  4 + notification_types.each do |notification_type|
  5 + execute("update admin_notifications_plugin_notifications set type = 'AdminNotificationsPlugin::#{notification_type}' where type = 'EnvironmentNotificationPlugin::#{notification_type}'")
  6 + end
  7 + end
  8 +end
... ...
plugins/admin_notifications/features/message_edition.feature 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +Feature: Create envronment notification message
  2 + As an admin user
  3 + I want to create a notification
  4 + In order to notificate users
  5 +
  6 + @selenium
  7 + Scenario: mce restricted mode should show on message creation
  8 + Given I am logged in as admin
  9 + And I follow "Administration"
  10 + And I follow "Plugins"
  11 + And I follow "Configuration"
  12 + And I follow "New Notification"
  13 + Then The tinymce "toolbar1" should be "bold italic underline | link"
  14 + Then The tinymce "menubar" should be "false"
... ...
plugins/admin_notifications/lib/admin_notifications_plugin.rb 0 → 100644
... ... @@ -0,0 +1,59 @@
  1 +class AdminNotificationsPlugin < Noosfero::Plugin
  2 +
  3 + def self.plugin_name
  4 + "Notifications Plugin"
  5 + end
  6 +
  7 + def self.plugin_description
  8 + _("A plugin for notifications.")
  9 + end
  10 +
  11 + def stylesheet?
  12 + true
  13 + end
  14 +
  15 + def js_files
  16 + %w(
  17 + admin_notifications_plugin.js
  18 + )
  19 + end
  20 +
  21 + def body_beginning
  22 + lambda do
  23 + extend AdminNotificationsPlugin::NotificationHelper
  24 + render template: 'shared/show_notification'
  25 + end
  26 + end
  27 +
  28 + def admin_panel_links
  29 + {:title => _('Notification Manager'), :url => {:controller => 'admin_notifications_plugin_admin', :action => 'index'}}
  30 + end
  31 +
  32 + def control_panel_buttons
  33 + if context.profile.organization?
  34 + {
  35 + :title => _('Manage Notifications'),
  36 + :icon => 'important',
  37 + :url => {
  38 + :controller => 'admin_notifications_plugin_myprofile',
  39 + :action => 'index'
  40 + }
  41 + }
  42 + end
  43 + end
  44 +
  45 + def account_controller_filters
  46 + block = proc do
  47 + if !logged_in?
  48 + cookies[:hide_notifications] = nil
  49 + end
  50 + end
  51 +
  52 + [{
  53 + :type => "after_filter",
  54 + :method_name => "clean_hide_notifications_cookie",
  55 + :options => { },
  56 + :block => block
  57 + }]
  58 + end
  59 +end
... ...
plugins/admin_notifications/lib/admin_notifications_plugin/notification_helper.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +module AdminNotificationsPlugin::NotificationHelper
  2 +
  3 + def hide_notifications
  4 + invalid_id = -1
  5 + hide_notifications_ids = [invalid_id]
  6 + hide_notifications_ids = JSON.parse(cookies[:hide_notifications]) unless cookies[:hide_notifications].blank?
  7 + hide_notifications_ids
  8 + end
  9 +
  10 + def self.substitute_variables(message, user)
  11 + if user
  12 + message = message.gsub("%{email}", user.person.email).gsub("%{name}", user.person.name)
  13 + end
  14 +
  15 + message
  16 + end
  17 +
  18 +end
... ...
plugins/admin_notifications/lib/admin_notifications_plugin/notification_manager.rb 0 → 100644
... ... @@ -0,0 +1,60 @@
  1 +module AdminNotificationsPlugin::NotificationManager
  2 +
  3 + def index
  4 + @notifications = target.notifications.order('updated_at DESC')
  5 + end
  6 +
  7 + def new
  8 + @notification = AdminNotificationsPlugin::Notification.new
  9 + if request.post?
  10 + @notification = AdminNotificationsPlugin::Notification.new(params[:notifications])
  11 + @notification.message = @notification.message.html_safe
  12 + @notification.target = target
  13 + if @notification.save
  14 + session[:notice] = _("Notification successfully created")
  15 + redirect_to :action => :index
  16 + else
  17 + session[:notice] = _("Notification couldn't be created")
  18 + end
  19 + end
  20 + end
  21 +
  22 + def destroy
  23 + if request.delete?
  24 + notification = target.notifications.find_by id: params[:id]
  25 + if notification && notification.destroy
  26 + session[:notice] = _('The notification was deleted.')
  27 + else
  28 + session[:notice] = _('Could not remove the notification')
  29 + end
  30 + end
  31 + redirect_to :action => :index
  32 + end
  33 +
  34 + def edit
  35 + @notification = target.notifications.find_by id: params[:id]
  36 + if request.post?
  37 + if @notification.update_attributes(params[:notifications])
  38 + session[:notice] = _('The notification was edited.')
  39 + else
  40 + session[:notice] = _('Could not edit the notification.')
  41 + end
  42 + redirect_to :action => :index
  43 + end
  44 + end
  45 +
  46 + def change_status
  47 + @notification = target.notifications.find_by id: params[:id]
  48 +
  49 + @notification.active = !@notification.active
  50 +
  51 + if @notification.save!
  52 + session[:notice] = _('The status of the notification was changed.')
  53 + else
  54 + session[:notice] = _('Could not change the status of the notification.')
  55 + end
  56 +
  57 + redirect_to :action => :index
  58 + end
  59 +
  60 +end
... ...
plugins/admin_notifications/lib/admin_notifications_plugin/notifications_user.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class AdminNotificationsPlugin::NotificationsUser < ActiveRecord::Base
  2 + self.table_name = "admin_notifications_plugin_notifications_users"
  3 +
  4 + belongs_to :user
  5 + belongs_to :notification, class_name: 'AdminNotificationsPlugin::Notification'
  6 +
  7 + attr_accessible :user_id, :notification_id
  8 +
  9 + validates_uniqueness_of :user_id, :scope => :notification_id
  10 +end
... ...
plugins/admin_notifications/lib/ext/environment.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +require_dependency 'environment'
  2 +
  3 +class Environment
  4 + has_many :notifications, class_name: 'AdminNotificationsPlugin::Notification', :as => :target
  5 +end
... ...
plugins/admin_notifications/lib/ext/organization.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +require_dependency 'organization'
  2 +
  3 +class Organization
  4 + has_many :notifications, class_name: 'AdminNotificationsPlugin::Notification', :as => :target
  5 +end
... ...
plugins/admin_notifications/lib/ext/user.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +require_dependency 'user'
  2 +
  3 +class User
  4 + has_many :notifications_users, :class_name => 'AdminNotificationsPlugin::NotificationsUser'
  5 + has_many :notifications, :through => :notifications_users
  6 +end
... ...
plugins/admin_notifications/models/admin_notifications_plugin/danger_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class AdminNotificationsPlugin::DangerNotification < AdminNotificationsPlugin::Notification
  2 +end
... ...
plugins/admin_notifications/models/admin_notifications_plugin/information_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class AdminNotificationsPlugin::InformationNotification < AdminNotificationsPlugin::Notification
  2 +end
... ...
plugins/admin_notifications/models/admin_notifications_plugin/notification.rb 0 → 100644
... ... @@ -0,0 +1,56 @@
  1 +class AdminNotificationsPlugin::Notification < ActiveRecord::Base
  2 +
  3 + self.table_name = "admin_notifications_plugin_notifications"
  4 +
  5 + TYPE_LIST = [
  6 + "AdminNotificationsPlugin::WarningNotification",
  7 + "AdminNotificationsPlugin::SuccessNotification",
  8 + "AdminNotificationsPlugin::InformationNotification",
  9 + "AdminNotificationsPlugin::DangerNotification"
  10 + ]
  11 +
  12 + attr_accessible :message, :target_id, :active, :type, :display_only_in_homepage, :display_to_all_users, :display_popup, :title, :target
  13 +
  14 + has_many :notifications_users, :class_name => "AdminNotificationsPlugin::NotificationsUser"
  15 + has_many :users, :through => :notifications_users
  16 +
  17 + belongs_to :target, :polymorphic => true
  18 +
  19 + validates_presence_of :message
  20 + validates_presence_of :target_id
  21 + validate :notification_type_must_be_in_type_list
  22 +
  23 + def notification_type_must_be_in_type_list
  24 + unless TYPE_LIST.include?(type)
  25 + errors.add(:type, "invalid notification type")
  26 + end
  27 + end
  28 +
  29 + scope :active, lambda{|target| where(:target_id => (target.kind_of?(Organization) ? [target.id, target.environment.id] : target.id), :active => true)}
  30 +
  31 + def self.visibles(target, user, controller_path)
  32 + notifications = AdminNotificationsPlugin::Notification.active(target).order('updated_at DESC')
  33 +
  34 + if user
  35 + active_notifications_ids = notifications.pluck(:id) - user.notifications.pluck(:id)
  36 +
  37 + notifications = notifications.where(id: active_notifications_ids)
  38 + else
  39 + notifications = notifications.where(display_to_all_users: true)
  40 + end
  41 +
  42 + if controller_path != "home"
  43 + notifications = notifications.where.not("display_only_in_homepage = ? AND target_type = ?",true,"Environment")
  44 + if controller_path != "profile"
  45 + notifications = notifications.where.not("display_only_in_homepage = ? AND target_type = ?",true,"Profile")
  46 + end
  47 + end
  48 +
  49 + notifications
  50 + end
  51 +
  52 + def self.with_popup(target, user, previous_path)
  53 + AdminNotificationsPlugin::Notification.visibles(target, user, previous_path).where(display_popup: true)
  54 + end
  55 +
  56 +end
... ...
plugins/admin_notifications/models/admin_notifications_plugin/success_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class AdminNotificationsPlugin::SuccessNotification < AdminNotificationsPlugin::Notification
  2 +end
... ...
plugins/admin_notifications/models/admin_notifications_plugin/warning_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class AdminNotificationsPlugin::WarningNotification < AdminNotificationsPlugin::Notification
  2 +end
... ...
plugins/admin_notifications/po/notification.pot 0 → 100644
... ... @@ -0,0 +1,187 @@
  1 +# SOME DESCRIPTIVE TITLE.
  2 +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
  3 +# This file is distributed under the same license as the PACKAGE package.
  4 +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
  5 +#
  6 +#, fuzzy
  7 +msgid ""
  8 +msgstr ""
  9 +"Project-Id-Version: PACKAGE VERSION\n"
  10 +"Report-Msgid-Bugs-To: \n"
  11 +"POT-Creation-Date: 2016-03-31 15:02-0300\n"
  12 +"PO-Revision-Date: 2016-03-31 15:02-0300\n"
  13 +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  14 +"Language-Team: LANGUAGE <LL@li.org>\n"
  15 +"Language: \n"
  16 +"MIME-Version: 1.0\n"
  17 +"Content-Type: text/plain; charset=UTF-8\n"
  18 +"Content-Transfer-Encoding: 8bit\n"
  19 +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
  20 +
  21 +#: ../lib/notification_plugin.rb:8
  22 +msgid "A plugin for notifications."
  23 +msgstr ""
  24 +
  25 +#: ../lib/notification_plugin.rb:29
  26 +msgid "Notification Manager"
  27 +msgstr ""
  28 +
  29 +#: ../lib/notification_plugin.rb:35
  30 +msgid "Manage Notifications"
  31 +msgstr ""
  32 +
  33 +#: ../lib/notification_plugin/notification_manager.rb:14
  34 +msgid "Notification successfully created"
  35 +msgstr ""
  36 +
  37 +#: ../lib/notification_plugin/notification_manager.rb:17
  38 +msgid "Notification couldn't be created"
  39 +msgstr ""
  40 +
  41 +#: ../lib/notification_plugin/notification_manager.rb:26
  42 +msgid "The notification was deleted."
  43 +msgstr ""
  44 +
  45 +#: ../lib/notification_plugin/notification_manager.rb:28
  46 +msgid "Could not remove the notification"
  47 +msgstr ""
  48 +
  49 +#: ../lib/notification_plugin/notification_manager.rb:38
  50 +msgid "The notification was edited."
  51 +msgstr ""
  52 +
  53 +#: ../lib/notification_plugin/notification_manager.rb:40
  54 +msgid "Could not edit the notification."
  55 +msgstr ""
  56 +
  57 +#: ../lib/notification_plugin/notification_manager.rb:52
  58 +msgid "The status of the notification was changed."
  59 +msgstr ""
  60 +
  61 +#: ../lib/notification_plugin/notification_manager.rb:54
  62 +msgid "Could not change the status of the notification."
  63 +msgstr ""
  64 +
  65 +#: ../views/shared/_form.html.erb:5
  66 +msgid "Back"
  67 +msgstr ""
  68 +
  69 +#: ../views/shared/_form.html.erb:11
  70 +msgid "Optional Title:"
  71 +msgstr ""
  72 +
  73 +#: ../views/shared/_form.html.erb:13
  74 +msgid "Enter your message here:"
  75 +msgstr ""
  76 +
  77 +#: ../views/shared/_form.html.erb:15
  78 +msgid ""
  79 +"Obs: You can use %{name} and %{email} variables to put the user's name and ema"
  80 +"il in the message."
  81 +msgstr ""
  82 +
  83 +#: ../views/shared/_form.html.erb:18
  84 +msgid "Notifications Status"
  85 +msgstr ""
  86 +
  87 +#: ../views/shared/_form.html.erb:18
  88 +msgid "Active"
  89 +msgstr ""
  90 +
  91 +#: ../views/shared/_form.html.erb:18
  92 +msgid "Inactive"
  93 +msgstr ""
  94 +
  95 +#: ../views/shared/_form.html.erb:20
  96 +msgid "Notifications Color/Type"
  97 +msgstr ""
  98 +
  99 +#: ../views/shared/_form.html.erb:20
  100 +msgid "Blue - Information"
  101 +msgstr ""
  102 +
  103 +#: ../views/shared/_form.html.erb:20
  104 +msgid "Yellow - Warning"
  105 +msgstr ""
  106 +
  107 +#: ../views/shared/_form.html.erb:20
  108 +msgid "Green - Success"
  109 +msgstr ""
  110 +
  111 +#: ../views/shared/_form.html.erb:20
  112 +msgid "Red - Danger"
  113 +msgstr ""
  114 +
  115 +#: ../views/shared/_form.html.erb:23
  116 +msgid "Display only in the homepage"
  117 +msgstr ""
  118 +
  119 +#: ../views/shared/_form.html.erb:27
  120 +msgid "Display to not logged users too"
  121 +msgstr ""
  122 +
  123 +#: ../views/shared/_form.html.erb:31
  124 +msgid "Display popup until user close the notification"
  125 +msgstr ""
  126 +
  127 +#: ../views/shared/_form.html.erb:35
  128 +msgid "Save"
  129 +msgstr ""
  130 +
  131 +#: ../views/shared/_notifications_list.html.erb:3
  132 +#: ../views/shared/_notifications_list.html.erb:16
  133 +msgid "Notifications"
  134 +msgstr ""
  135 +
  136 +#: ../views/shared/_notifications_list.html.erb:7
  137 +msgid "New Notification"
  138 +msgstr ""
  139 +
  140 +#: ../views/shared/_notifications_list.html.erb:10
  141 +msgid "Back to control panel"
  142 +msgstr ""
  143 +
  144 +#: ../views/shared/_notifications_list.html.erb:19
  145 +msgid "Actions"
  146 +msgstr ""
  147 +
  148 +#: ../views/shared/_notifications_list.html.erb:30
  149 +msgid "Deactivate"
  150 +msgstr ""
  151 +
  152 +#: ../views/shared/_notifications_list.html.erb:30
  153 +#: ../views/shared/_notifications_list.html.erb:32
  154 +msgid "Do you want to change the status of this notification?"
  155 +msgstr ""
  156 +
  157 +#: ../views/shared/_notifications_list.html.erb:32
  158 +msgid "Activate"
  159 +msgstr ""
  160 +
  161 +#: ../views/shared/_notifications_list.html.erb:34
  162 +msgid "Edit"
  163 +msgstr ""
  164 +
  165 +#: ../views/shared/_notifications_list.html.erb:35
  166 +msgid "Delete"
  167 +msgstr ""
  168 +
  169 +#: ../views/shared/_notifications_list.html.erb:35
  170 +msgid "Do you want to delete this notification?"
  171 +msgstr ""
  172 +
  173 +#: ../views/shared/show_notification.html.erb:8
  174 +msgid "There are active notifications in this environment!"
  175 +msgstr ""
  176 +
  177 +#: ../views/shared/show_notification.html.erb:9
  178 +msgid "Manage all notifications here."
  179 +msgstr ""
  180 +
  181 +#: ../views/shared/show_notification.html.erb:28
  182 +msgid "Do not show anymore"
  183 +msgstr ""
  184 +
  185 +#: ../views/shared/show_notification.html.erb:29
  186 +msgid "Hide for now"
  187 +msgstr ""
... ...
plugins/admin_notifications/public/admin_notifications_plugin.js 0 → 100644
... ... @@ -0,0 +1,84 @@
  1 +(function($) {
  2 + "use strict";
  3 +
  4 + var admin_notifications_plugin = {
  5 +
  6 +
  7 + notificationBar: function() {
  8 + var completeMessage = $(".notification-plugin-notification-bar").remove();
  9 + $("#content-inner").before(completeMessage);
  10 + },
  11 +
  12 + closeNotification: function(){
  13 + var notification = $(this).parent();
  14 + var id = notification.attr("data-notification");
  15 +
  16 + $.ajax({
  17 + url: noosfero_root()+'/plugin/admin_notifications/public/close_notification',
  18 + type: "POST",
  19 + data: {notification_id: id},
  20 + success: function(response) {
  21 + notification.fadeOut();
  22 + }
  23 + });
  24 + },
  25 +
  26 + hideNotification: function(){
  27 + var notification = $(this).parent();
  28 + var id = notification.attr("data-notification");
  29 +
  30 + $.ajax({
  31 + url: noosfero_root()+'/plugin/admin_notifications/public/hide_notification',
  32 + type: "POST",
  33 + data: {notification_id: id},
  34 + success: function(response) {
  35 + notification.fadeOut();
  36 + }
  37 + });
  38 + },
  39 +
  40 + hideUserNotification: function(){
  41 + var ids = $.cookie('hide_notifications');
  42 + if(ids === null) {
  43 + return null;
  44 + }
  45 +
  46 + if(ids.startsWith('[') && ids.endsWith(']')){
  47 + ids = ids.substring(1, ids.length - 1);
  48 + ids = ids.split(",");
  49 +
  50 + for(var i = 0; i < ids.length; i++) {
  51 + $('[data-notification="' + ids[i] + '"]').fadeOut();
  52 + }
  53 + }
  54 + },
  55 +
  56 + showPopup: function() {
  57 + if($('.action-home-index').length > 0) {
  58 + jQuery(function($){
  59 + $.colorbox({href: noosfero_root()+'/plugin/admin_notifications/public/notifications_with_popup?previous_path=home'});
  60 + });
  61 + }
  62 + else {
  63 + jQuery(function($){
  64 + $.colorbox({href: noosfero_root()+'/plugin/admin_notifications/public/notifications_with_popup'});
  65 + });
  66 + }
  67 + },
  68 + };
  69 +
  70 + $(document).ready(function(){
  71 + admin_notifications_plugin.notificationBar();
  72 + $(".notification-plugin-notification-bar .notification-close").on("click", admin_notifications_plugin.closeNotification);
  73 + $(".notification-plugin-notification-bar .notification-hide").on("click", admin_notifications_plugin.hideNotification);
  74 +
  75 + if($('.notification-plugin-notification-bar').length > 0){
  76 + admin_notifications_plugin.hideUserNotification();
  77 + }
  78 +
  79 + if($('.notification-plugin-notification-bar [notification-display-popup="true"]').length > 0){
  80 + admin_notifications_plugin.showPopup();
  81 + }
  82 + });
  83 +
  84 +})($);
... ...
plugins/admin_notifications/public/images/close.png 0 → 100644

240 Bytes

plugins/admin_notifications/public/images/greenhide.png 0 → 100644

794 Bytes

plugins/admin_notifications/public/images/hide.png 0 → 100644

389 Bytes

plugins/admin_notifications/public/images/redclose.png 0 → 100644

552 Bytes

plugins/admin_notifications/public/images/show.png 0 → 100644

364 Bytes

plugins/admin_notifications/public/style.css 0 → 100644
... ... @@ -0,0 +1,250 @@
  1 +.notification-plugin-notification-bar{
  2 + display: block;
  3 +}
  4 +
  5 +.notification-plugin-notification-bar .notification:hover,
  6 +.notification-plugin-notification-modal .notification:hover{
  7 + opacity: 0.8;
  8 +}
  9 +
  10 +#notification-plugin-notification-manager{
  11 + overflow: auto;
  12 +}
  13 +
  14 +.notification-plugin-notification-bar .notification .notification-close,
  15 +.notification-plugin-notification-modal .notification .notification-close{
  16 + background: url(images/close.png) no-repeat;
  17 + background-position: center;
  18 + width: 20px;
  19 + height: 20px;
  20 +}
  21 +
  22 +.notification-plugin-notification-bar .warningnotification,
  23 +.notification-plugin-notification-bar .informationnotification,
  24 +.notification-plugin-notification-bar .successnotification,
  25 +.notification-plugin-notification-bar .dangernotification,
  26 +.notification-plugin-notification-bar .adminnotification,
  27 +.notification-plugin-notification-modal .warningnotification,
  28 +.notification-plugin-notification-modal .informationnotification,
  29 +.notification-plugin-notification-modal .successnotification,
  30 +.notification-plugin-notification-modal .dangernotification{
  31 + margin-bottom: 10px;
  32 + padding: 7px 10px;
  33 + border-radius: 5px;
  34 + border: 1px solid blue;
  35 + font-size: 16px;
  36 + color: white;
  37 + overflow: auto;
  38 +}
  39 +
  40 +.notification-plugin-notification-bar .warningnotification p,
  41 +.notification-plugin-notification-bar .informationnotification p,
  42 +.notification-plugin-notification-bar .successnotification p,
  43 +.notification-plugin-notification-bar .dangernotification p,
  44 +.notification-plugin-notification-bar .adminnotification p,
  45 +.notification-plugin-notification-modal .warningnotification p,
  46 +.notification-plugin-notification-modal .informationnotification p,
  47 +.notification-plugin-notification-modal .successnotification p,
  48 +.notification-plugin-notification-modal .dangernotification p{
  49 + margin: 0px;
  50 +}
  51 +
  52 +.notification-plugin-notification-bar .warningnotification,
  53 +.notification-plugin-notification-modal .warningnotification{
  54 + background: #fcf8e3;
  55 + border: 1px solid #faebcc;
  56 + color: #8a6d3b;
  57 +}
  58 +
  59 +.notification-plugin-notification-bar .warningnotification p a,
  60 +.notification-plugin-notification-modal .warningnotification p a{
  61 + font-weight: bold;
  62 + color: #8a6d3b;
  63 +}
  64 +
  65 +
  66 +.notification-plugin-notification-bar .informationnotification,
  67 +.notification-plugin-notification-modal .informationnotification{
  68 + background: #d9edf7;
  69 + border: 1px solid #bce8f1;
  70 + color: #31708f;
  71 +}
  72 +
  73 +.notification-plugin-notification-bar .informationnotification p a,
  74 +.notification-plugin-notification-modal .informationnotification p a{
  75 + font-weight: bold;
  76 + color: #31708f;
  77 +}
  78 +
  79 +.notification-plugin-notification-bar .successnotification,
  80 +.notification-plugin-notification-modal .successnotification{
  81 + background: #dff0d8;
  82 + border: 1px solid #d6e9c6;
  83 + color: #3c763d;
  84 +}
  85 +
  86 +.notification-plugin-notification-bar .successnotification p a
  87 +.notification-plugin-notification-modal .successnotification p a{
  88 + font-weight: bold;
  89 + color: #3c763d;
  90 +}
  91 +
  92 +.notification-plugin-notification-bar .dangernotification,
  93 +.notification-plugin-notification-modal .dangernotification{
  94 + background: #f2dede;
  95 + border: 1px solid #ebccd1;
  96 + color: #a94442;
  97 +}
  98 +
  99 +.notification-plugin-notification-bar .dangernotification p a,
  100 +.notification-plugin-notification-modal .dangernotification p a{
  101 + font-weight: bold;
  102 + color: #a94442;
  103 +}
  104 +
  105 +.notification-plugin-notification-bar .adminnotification,
  106 +.notification-plugin-notification-modal .adminnotification{
  107 + background: #9a959a;
  108 + border: 1px solid #9a959a;
  109 +}
  110 +
  111 +.notification-plugin-notification-bar .adminnotification p a,
  112 +.notification-plugin-notification-modal .adminnotification p a{
  113 + font-weight: bold;
  114 + color: white;
  115 +}
  116 +
  117 +#notification-plugin-notification-manager a.button.icon-deactivate{
  118 + background: url(images/hide.png) no-repeat;
  119 + background-position: center;
  120 +}
  121 +
  122 +#notification-plugin-notification-manager a.button.icon-activate{
  123 + background: url(images/show.png) no-repeat;
  124 + background-position: center;
  125 +}
  126 +
  127 +#notification-plugin-notification-manager .notification-line{
  128 + display: inline;
  129 + padding-top: 10px;
  130 + vertical-align: middle;
  131 + border-bottom: 1px solid #ccc;
  132 +}
  133 +
  134 +#notification-plugin-notification-manager .notification-title-bar{
  135 + float: left;
  136 + width: 100%;
  137 + font-style: 14px;
  138 + font-weight: 700;
  139 + border-bottom: 2px solid black;
  140 + padding: 9px 0;
  141 +}
  142 +
  143 +#notification-plugin-notification-manager .notification-title{
  144 + width: 80%;
  145 + float: left;
  146 + text-align: center;
  147 +}
  148 +
  149 +.notification-plugin-notification-modal .notification-with-title{
  150 + margin-bottom: 0px;
  151 +}
  152 +
  153 +.notification-plugin-notification-modal .notification .notification-title{
  154 + width: 100%;
  155 + float: left;
  156 + font-weight: bold;
  157 + text-align: left;
  158 +}
  159 +
  160 +.notification-plugin-notification-modal .notification-with-title-message{
  161 + width: 100%;
  162 + float: left;
  163 + border-radius: 3px;
  164 + margin-bottom: 10px;
  165 + background-color: #f5f5f5;
  166 + font-size: 14px;
  167 + overflow: auto;
  168 +}
  169 +
  170 +.notification-plugin-notification-modal .notification-with-title-message p{
  171 + padding: 0px 7px;
  172 +}
  173 +
  174 +.notification-plugin-notification-modal .notification-with-title-message p a{
  175 + color: black;
  176 + font-weight: bold;
  177 +}
  178 +
  179 +
  180 +#notification-plugin-notification-manager .action-title{
  181 + width: 20%;
  182 + float: left;
  183 + text-align: center;
  184 +}
  185 +
  186 +#notification-plugin-notification-manager .notification-action{
  187 + width: 18%;
  188 + float: left;
  189 + height: 30px;
  190 + padding-top: 9px;
  191 +}
  192 +
  193 +#notification-plugin-notification-manager .main-bar .button,
  194 +#notification-plugin-notification-manager .notification-action .button{
  195 + border-radius: 3px;
  196 +}
  197 +
  198 +#notification-plugin-notification-manager .notification-message{
  199 + width: 82%;
  200 + float: left;
  201 +}
  202 +
  203 +#notification-plugin-notification-manager .new-notification{
  204 + float: right;
  205 + width: auto;
  206 +}
  207 +
  208 +#notification-plugin-notification-manager .back-button{
  209 + float: left;
  210 +}
  211 +
  212 +#notification-plugin-notification-manager .main-bar{
  213 + display: inline;
  214 + width: 100%;
  215 +}
  216 +
  217 +.notification-plugin-notification-bar .notification .notification-message,
  218 +.notification-plugin-notification-modal .notification .notification-message{
  219 + width: 90%;
  220 + float: left;
  221 +}
  222 +
  223 +.notification-plugin-notification-bar .notification .notification-close{
  224 + background: url(images/redclose.png) no-repeat;
  225 + background-position: center;
  226 + width: 20px;
  227 + height: 20px;
  228 + float: right;
  229 + cursor: pointer;
  230 +}
  231 +
  232 +.notification-plugin-notification-bar .notification .notification-hide{
  233 + background: url(images/greenhide.png) no-repeat;
  234 + background-position: center;
  235 + width: 20px;
  236 + height: 20px;
  237 + float: right;
  238 + cursor: pointer;
  239 +}
  240 +
  241 +.notification-plugin-notification-modal{
  242 + display: block;
  243 + min-width: 400px;
  244 + max-width: 700px;
  245 +}
  246 +
  247 +.notification-plugin-form .notification-variables-options{
  248 + font-style: italic;
  249 + color: red;
  250 +}
... ...
plugins/admin_notifications/test/functional/account_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
  2 +require 'account_controller'
  3 +
  4 +class AccountController
  5 + include AdminNotificationsPlugin::NotificationHelper
  6 +end
  7 +
  8 +class AccountControllerTest < ActionController::TestCase
  9 + def setup
  10 + @controller = AccountController.new
  11 + @request = ActionController::TestRequest.new
  12 + @response = ActionController::TestResponse.new
  13 + @person = create_user('person').person
  14 +
  15 + @environment = Environment.default
  16 + @environment.enable_plugin('AdminNotificationsPlugin')
  17 + @environment.save!
  18 +
  19 + login_as(@person.user.login)
  20 + end
  21 +
  22 + attr_accessor :person
  23 +
  24 + should 'clean hide_notifications cookie after logout' do
  25 + @request.cookies[:hide_notifications] = JSON.generate([1,2])
  26 + get :index
  27 + assert !@request.cookies[:hide_notifications].blank?