Commit a4dd34ff72c437b37ad82c6c8b7678cfc6d30320

Authored by Eduardo Vital
Committed by Daniela Feitosa
1 parent f91b143d

Create environment notification plugin

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Eduardo Vital <vitaldu@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Jéssica Cristina <jessica.cris1127@gmail.com>
Signed-off-by: Simião Carvalho <simiaosimis@gmail.com>
Signed-off-by: Victor Navarro <victor.matias.navarro@gmail.com>
Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@yahoo.com.br>
(cherry picked from commit e1ab4612e1133ff198ea04d42954b8aab3b18419)
Showing 35 changed files with 1635 additions and 0 deletions   Show diff stats
plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb 0 → 100644
... ... @@ -0,0 +1,98 @@
  1 +class EnvironmentNotificationPluginAdminController < AdminController
  2 + before_filter :admin_required, :except => [:close_notification, :hide_notification]
  3 + def index
  4 + @notifications = environment.environment_notifications.order('updated_at DESC')
  5 + end
  6 +
  7 + def new
  8 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new
  9 + if request.post?
  10 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new(params[:notifications])
  11 + @notification.message = @notification.message.html_safe
  12 + @notification.environment_id = environment.id
  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 = environment.environment_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 = environment.environment_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 = environment.environment_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 + def close_notification
  61 + result = false
  62 +
  63 + if logged_in?
  64 + @notification = environment.environment_notifications.find_by_id(params[:notification_id])
  65 +
  66 + if @notification
  67 + @notification.users << current_user
  68 + result = @notification.users.include?(current_user)
  69 + end
  70 + end
  71 +
  72 + render json: result
  73 + end
  74 +
  75 + def hide_notification
  76 + result = false
  77 +
  78 + if logged_in?
  79 + @notification = environment.environment_notifications.find_by_id(params[:notification_id])
  80 +
  81 + if @notification
  82 + current_notificaions = []
  83 + current_notificaions = JSON.parse(cookies[:hide_notifications]) unless cookies[:hide_notifications].blank?
  84 + current_notificaions << @notification.id unless current_notificaions.include? @notification.id
  85 + cookies[:hide_notifications] = JSON.generate(current_notificaions)
  86 + result = current_notificaions.include? @notification.id
  87 + end
  88 + end
  89 +
  90 + render json: result
  91 + end
  92 +
  93 + protected
  94 + def admin_required
  95 + redirect_to :root unless current_user.person.is_admin?
  96 + end
  97 +
  98 +end
... ...
plugins/environment_notification/controllers/public/environment_notification_plugin_public_controller.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class EnvironmentNotificationPluginPublicController < PublicController
  2 + def notifications_with_popup
  3 + @hide_notifications = hide_notifications
  4 + if params[:previous_path]
  5 + @previous_path = params[:previous_path]
  6 + else
  7 + @previous_path = nil
  8 + end
  9 + end
  10 +end
... ...
plugins/environment_notification/db/migrate/20150721132025_create_notification_table.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  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, index: true
  18 + t.belongs_to :user, index: true
  19 + end
  20 + end
  21 +
  22 + def down
  23 + drop_table :environment_notifications
  24 + drop_table :environment_notifications_users
  25 + end
  26 +end
... ...
plugins/environment_notification/lib/environment_notification_helper.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +module EnvironmentNotificationHelper
  2 + def self.substitute_variables(message, user)
  3 + if user
  4 + message = message.gsub("%{email}", user.person.email).gsub("%{name}", user.person.name)
  5 + end
  6 +
  7 + message
  8 + end
  9 +end
0 10 \ No newline at end of file
... ...
plugins/environment_notification/lib/environment_notification_plugin.rb 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +class EnvironmentNotificationPlugin < Noosfero::Plugin
  2 +
  3 + include ActionView::Helpers::JavaScriptHelper
  4 + include ActionView::Helpers::TagHelper
  5 +
  6 + def self.plugin_name
  7 + "Environment Notifications Plugin"
  8 + end
  9 +
  10 + def self.plugin_description
  11 + _("A plugin for environment notifications.")
  12 + end
  13 +
  14 + def stylesheet?
  15 + true
  16 + end
  17 +
  18 + def js_files
  19 + %w(
  20 + public/environment_notification_plugin.js
  21 + )
  22 + end
  23 +
  24 + def body_beginning
  25 + expanded_template('environment_notification_plugin_admin/show_notification.html.erb')
  26 + end
  27 +
  28 + def admin_panel_links
  29 + {:title => _('Notification Manager'), :url => {:controller => 'environment_notification_plugin_admin', :action => 'index'}}
  30 + end
  31 +
  32 + def account_controller_filters
  33 + block = proc do
  34 + if !logged_in?
  35 + cookies[:hide_notifications] = nil
  36 + end
  37 + end
  38 +
  39 + [{
  40 + :type => "after_filter",
  41 + :method_name => "clean_hide_notifications_cookie",
  42 + :options => { },
  43 + :block => block
  44 + }]
  45 + end
  46 +end
... ...
plugins/environment_notification/lib/environment_notifications_user.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class EnvironmentNotificationsUser < ActiveRecord::Base
  2 + self.table_name = "environment_notifications_users"
  3 +
  4 + belongs_to :user
  5 + belongs_to :environment_notification, class_name: 'EnvironmentNotificationPlugin::EnvironmentNotification'
  6 +
  7 + attr_accessible :user_id, :environment_notification_id
  8 +
  9 + validates_uniqueness_of :user_id, :scope => :environment_notification_id
  10 +end
... ...
plugins/environment_notification/lib/ext/application_controller.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +require_dependency 'application_controller'
  2 +
  3 +class ApplicationController
  4 + def hide_notifications
  5 + invalid_id = -1
  6 + hide_notifications_ids = [-1]
  7 + hide_notifications_ids = JSON.parse(cookies[:hide_notifications]) unless cookies[:hide_notifications].blank?
  8 + hide_notifications_ids
  9 + end
  10 +end
... ...
plugins/environment_notification/lib/ext/environment.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +require_dependency 'environment'
  2 +
  3 +class Environment
  4 + has_many :environment_notifications, class_name: 'EnvironmentNotificationPlugin::EnvironmentNotification'
  5 +end
... ...
plugins/environment_notification/lib/ext/user.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +require_dependency 'user'
  2 +
  3 +class User
  4 + has_many :environment_notifications_users
  5 + has_many :environment_notifications, :through => :environment_notifications_users
  6 +end
... ...
plugins/environment_notification/models/environment_notification_plugin/danger_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class EnvironmentNotificationPlugin::DangerNotification < EnvironmentNotificationPlugin::EnvironmentNotification
  2 +end
... ...
plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +class EnvironmentNotificationPlugin::EnvironmentNotification < ActiveRecord::Base
  2 +
  3 + self.table_name = "environment_notifications"
  4 +
  5 + TYPE_LIST = [
  6 + "EnvironmentNotificationPlugin::WarningNotification",
  7 + "EnvironmentNotificationPlugin::SuccessNotification",
  8 + "EnvironmentNotificationPlugin::InformationNotification",
  9 + "EnvironmentNotificationPlugin::DangerNotification"
  10 + ]
  11 +
  12 + attr_accessible :message, :environment_id, :active, :type, :display_only_in_homepage, :display_to_all_users, :display_popup, :title
  13 +
  14 + has_many :environment_notifications_users
  15 + has_many :users, :through => :environment_notifications_users
  16 +
  17 + validates_presence_of :message
  18 + validates_presence_of :environment_id
  19 + validate :notification_type_must_be_in_type_list
  20 +
  21 + def notification_type_must_be_in_type_list
  22 + unless TYPE_LIST.include?(type)
  23 + errors.add(:type, "invalid notification type")
  24 + end
  25 + end
  26 +
  27 + scope :active, lambda{|environment| { :conditions => { :environment_id => environment.id, :active => true } } }
  28 +
  29 + def self.visibles(environment, user, controller_path)
  30 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.active(environment).order('updated_at DESC')
  31 +
  32 + if user
  33 + active_notifications_ids = notifications.pluck(:id) - user.environment_notifications.pluck(:id)
  34 +
  35 + notifications = notifications.where(id: active_notifications_ids)
  36 + else
  37 + notifications = notifications.where(display_to_all_users: true)
  38 + end
  39 +
  40 + if controller_path != "home"
  41 + notifications = notifications.where(display_only_in_homepage: false)
  42 + end
  43 +
  44 + notifications
  45 + end
  46 +
  47 + def self.with_popup(environment, user, previous_path)
  48 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(environment, user, previous_path).where(display_popup: true)
  49 + end
  50 +end
... ...
plugins/environment_notification/models/environment_notification_plugin/information_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class EnvironmentNotificationPlugin::InformationNotification < EnvironmentNotificationPlugin::EnvironmentNotification
  2 +end
... ...
plugins/environment_notification/models/environment_notification_plugin/success_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class EnvironmentNotificationPlugin::SuccessNotification < EnvironmentNotificationPlugin::EnvironmentNotification
  2 +end
... ...
plugins/environment_notification/models/environment_notification_plugin/warning_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class EnvironmentNotificationPlugin::WarningNotification < EnvironmentNotificationPlugin::EnvironmentNotification
  2 +end
... ...
plugins/environment_notification/po/environment_notification.pot 0 → 100644
... ... @@ -0,0 +1,177 @@
  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: 1.2-514-gc258618\n"
  10 +"POT-Creation-Date: 2015-09-24 19:03-0000\n"
  11 +"PO-Revision-Date: 2015-09-14 12:12-0000\n"
  12 +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  13 +"Language-Team: LANGUAGE <LL@li.org>\n"
  14 +"Language: \n"
  15 +"MIME-Version: 1.0\n"
  16 +"Content-Type: text/plain; charset=UTF-8\n"
  17 +"Content-Transfer-Encoding: 8bit\n"
  18 +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
  19 +
  20 +#: plugins/environment_notification/lib/environment_notification_plugin.rb:11
  21 +msgid "A plugin for environment notifications."
  22 +msgstr ""
  23 +
  24 +#: plugins/environment_notification/lib/environment_notification_plugin.rb:29
  25 +msgid "Notification Manager"
  26 +msgstr ""
  27 +
  28 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:14
  29 +msgid "Notification successfully created"
  30 +msgstr ""
  31 +
  32 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:17
  33 +msgid "Notification couldn't be created"
  34 +msgstr ""
  35 +
  36 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:26
  37 +msgid "The notification was deleted."
  38 +msgstr ""
  39 +
  40 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:28
  41 +msgid "Could not remove the notification"
  42 +msgstr ""
  43 +
  44 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:38
  45 +msgid "The notification was edited."
  46 +msgstr ""
  47 +
  48 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:40
  49 +msgid "Could not edit the notification."
  50 +msgstr ""
  51 +
  52 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:52
  53 +msgid "The status of the notification was changed."
  54 +msgstr ""
  55 +
  56 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:54
  57 +msgid "Could not change the status of the notification."
  58 +msgstr ""
  59 +
  60 +#: plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb:8
  61 +msgid "There are active notifications in this environment! You can "
  62 +msgstr ""
  63 +
  64 +#: plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb:10
  65 +msgid "manage all notifications here."
  66 +msgstr ""
  67 +
  68 +#: plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb:28
  69 +msgid "Do not show anymore"
  70 +msgstr ""
  71 +
  72 +#: plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb:29
  73 +msgid "Hide for now"
  74 +msgstr ""
  75 +
  76 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:3
  77 +msgid "Environment Notifications"
  78 +msgstr ""
  79 +
  80 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:7
  81 +msgid "New Notification"
  82 +msgstr ""
  83 +
  84 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:10
  85 +msgid "Back to control panel"
  86 +msgstr ""
  87 +
  88 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:16
  89 +msgid "Notifications"
  90 +msgstr ""
  91 +
  92 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:19
  93 +msgid "Actions"
  94 +msgstr ""
  95 +
  96 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:30
  97 +msgid "Deactivate"
  98 +msgstr ""
  99 +
  100 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:30
  101 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:32
  102 +msgid "Do you want to change the status of this notification?"
  103 +msgstr ""
  104 +
  105 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:32
  106 +msgid "Activate"
  107 +msgstr ""
  108 +
  109 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:34
  110 +msgid "Edit"
  111 +msgstr ""
  112 +
  113 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:35
  114 +msgid "Delete"
  115 +msgstr ""
  116 +
  117 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:35
  118 +msgid "Do you want to delete this notification?"
  119 +msgstr ""
  120 +
  121 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:3
  122 +msgid "Back"
  123 +msgstr ""
  124 +
  125 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:9
  126 +msgid "Optional Title:"
  127 +msgstr ""
  128 +
  129 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:11
  130 +msgid "Enter your message here:"
  131 +msgstr ""
  132 +
  133 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:13
  134 +msgid ""
  135 +"Obs: You can use %{name} and %{email} variables to put the user's name and "
  136 +"email in the message."
  137 +msgstr ""
  138 +
  139 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:16
  140 +msgid "Notifications Status"
  141 +msgstr ""
  142 +
  143 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:18
  144 +msgid "Notifications Color/Type"
  145 +msgstr ""
  146 +
  147 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:18
  148 +msgid "Blue - Information"
  149 +msgstr ""
  150 +
  151 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:18
  152 +msgid "Yellow - Warning"
  153 +msgstr ""
  154 +
  155 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:18
  156 +msgid "Green - Success"
  157 +msgstr ""
  158 +
  159 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:18
  160 +msgid "Red - Danger"
  161 +msgstr ""
  162 +
  163 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:21
  164 +msgid "Display only in the homepage"
  165 +msgstr ""
  166 +
  167 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:25
  168 +msgid "Display to not logged users too"
  169 +msgstr ""
  170 +
  171 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:29
  172 +msgid "Display popup until user close the notification"
  173 +msgstr ""
  174 +
  175 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:33
  176 +msgid "Save"
  177 +msgstr ""
... ...
plugins/environment_notification/po/pt/environment_notification.po 0 → 100644
... ... @@ -0,0 +1,178 @@
  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 +msgid ""
  7 +msgstr ""
  8 +"Project-Id-Version: 1.2-514-gbe9e36b\n"
  9 +"POT-Creation-Date: 2015-09-24 18:52-0000\n"
  10 +"PO-Revision-Date: 2015-09-14 12:12-0000\n"
  11 +"Last-Translator: FULL NAME <arthurmde@gmail.com>\n"
  12 +"Language-Team: Portuguese\n"
  13 +"Language: Portuguese\n"
  14 +"MIME-Version: 1.0\n"
  15 +"Content-Type: text/plain; charset=UTF-8\n"
  16 +"Content-Transfer-Encoding: 8bit\n"
  17 +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
  18 +
  19 +#: plugins/environment_notification/lib/environment_notification_plugin.rb:11
  20 +msgid "A plugin for environment notifications."
  21 +msgstr "Plugin para notificações do ambiente"
  22 +
  23 +#: plugins/environment_notification/lib/environment_notification_plugin.rb:29
  24 +msgid "Notification Manager"
  25 +msgstr "Gerenciador de Notificações"
  26 +
  27 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:14
  28 +msgid "Notification successfully created"
  29 +msgstr "Notificação criada com sucesso"
  30 +
  31 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:17
  32 +msgid "Notification couldn't be created"
  33 +msgstr "Não foi possível criar notificação"
  34 +
  35 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:26
  36 +msgid "The notification was deleted."
  37 +msgstr "A notificação foi removida"
  38 +
  39 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:28
  40 +msgid "Could not remove the notification"
  41 +msgstr "Não foi possível remover a notificação"
  42 +
  43 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:38
  44 +msgid "The notification was edited."
  45 +msgstr "A notificação foi editada."
  46 +
  47 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:40
  48 +msgid "Could not edit the notification."
  49 +msgstr "Não foi possível editar a notificação."
  50 +
  51 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:52
  52 +msgid "The status of the notification was changed."
  53 +msgstr "O status da notificação foi modificado"
  54 +
  55 +#: plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb:54
  56 +msgid "Could not change the status of the notification."
  57 +msgstr "Não foi possível alterar o status da notificação"
  58 +
  59 +#: plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb:8
  60 +msgid "There are active notifications in this environment! You can "
  61 +msgstr "Existem notificações ativas neste ambiente! Você pode "
  62 +
  63 +#: plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb:10
  64 +msgid "manage all notifications here."
  65 +msgstr "gerenciar todas as notificações aqui."
  66 +
  67 +#: plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb:28
  68 +msgid "Do not show anymore"
  69 +msgstr "Não mostrar mais"
  70 +
  71 +#: plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb:29
  72 +msgid "Hide for now"
  73 +msgstr "Ocultar momentaneamente"
  74 +
  75 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:3
  76 +msgid "Environment Notifications"
  77 +msgstr "Notificações do Ambiente"
  78 +
  79 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:7
  80 +msgid "New Notification"
  81 +msgstr "Nova Notificação"
  82 +
  83 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:10
  84 +msgid "Back to control panel"
  85 +msgstr "Voltar ao Painel de Controle"
  86 +
  87 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:16
  88 +msgid "Notifications"
  89 +msgstr "Notificações"
  90 +
  91 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:19
  92 +msgid "Actions"
  93 +msgstr "Ações"
  94 +
  95 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:30
  96 +msgid "Deactivate"
  97 +msgstr "Desativar"
  98 +
  99 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:30
  100 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:32
  101 +msgid "Do you want to change the status of this notification?"
  102 +msgstr "Você quer alterar o status dessa notificação?"
  103 +
  104 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:32
  105 +msgid "Activate"
  106 +msgstr "Ativar"
  107 +
  108 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:34
  109 +msgid "Edit"
  110 +msgstr "Editar"
  111 +
  112 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:35
  113 +msgid "Delete"
  114 +msgstr "Remover"
  115 +
  116 +#: plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb:35
  117 +msgid "Do you want to delete this notification?"
  118 +msgstr "Você quer remover essa notificação?"
  119 +
  120 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:3
  121 +msgid "Back"
  122 +msgstr "Voltar"
  123 +
  124 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:9
  125 +msgid "Optional Title:"
  126 +msgstr "Título Opcional:"
  127 +
  128 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:11
  129 +msgid "Enter your message here:"
  130 +msgstr "Entre com a sua mensagem aqui:"
  131 +
  132 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:13
  133 +msgid ""
  134 +"Obs: You can use %{name} and %{email} variables to put the user's name and "
  135 +"email in the message."
  136 +msgstr ""
  137 +"Obs: Você pode usar as variáveis %{name} e %{email} para inserir o nome e "
  138 +"email do usuário logado na mensagem."
  139 +
  140 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:16
  141 +msgid "Notifications Status"
  142 +msgstr "Status da Notificação"
  143 +
  144 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:18
  145 +msgid "Notifications Color/Type"
  146 +msgstr "Cor/Tipo de Notificação"
  147 +
  148 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:18
  149 +msgid "Blue - Information"
  150 +msgstr "Azul - Informação"
  151 +
  152 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:18
  153 +msgid "Yellow - Warning"
  154 +msgstr "Amarelo - Atenção"
  155 +
  156 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:18
  157 +msgid "Green - Success"
  158 +msgstr "Verde - Sucesso"
  159 +
  160 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:18
  161 +msgid "Red - Danger"
  162 +msgstr "Vermelho - Perigo"
  163 +
  164 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:21
  165 +msgid "Display only in the homepage"
  166 +msgstr "Apresentar apenas na página inicial"
  167 +
  168 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:25
  169 +msgid "Display to not logged users too"
  170 +msgstr "Apresentar notificação para usuários não logados também"
  171 +
  172 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:29
  173 +msgid "Display popup until user close the notification"
  174 +msgstr "Apresentar Popup da notificação até que o usuário a feche"
  175 +
  176 +#: plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb:33
  177 +msgid "Save"
  178 +msgstr "Salvar"
... ...
plugins/environment_notification/public/environment_notification_plugin.js 0 → 100644
... ... @@ -0,0 +1,95 @@
  1 +(function($) {
  2 + "use strict";
  3 +
  4 + function notificationBar() {
  5 + var completeMessage = $(".notification-bar").remove();
  6 + $("#content-inner").before(completeMessage);
  7 + }
  8 +
  9 + function closeNotification(){
  10 + var notification = $(this).parent();
  11 + var id = notification.attr("data-notification");
  12 +
  13 + $.ajax({
  14 + url: noosfero_root()+"/admin/plugin/environment_notification/close_notification",
  15 + type: "POST",
  16 + data: {notification_id: id},
  17 + success: function(response) {
  18 + notification.fadeOut();
  19 + }
  20 + });
  21 + }
  22 +
  23 + function hideNotification(){
  24 + var notification = $(this).parent();
  25 + var id = notification.attr("data-notification");
  26 +
  27 + $.ajax({
  28 + url: noosfero_root()+"/admin/plugin/environment_notification/hide_notification",
  29 + type: "POST",
  30 + data: {notification_id: id},
  31 + success: function(response) {
  32 + notification.fadeOut();
  33 + }
  34 + });
  35 + }
  36 +
  37 + function hideUserNotification(){
  38 + var ids = $.cookie('hide_notifications');
  39 + if(ids === null) {
  40 + return null;
  41 + }
  42 +
  43 + if(ids.startsWith('[') && ids.endsWith(']')){
  44 + ids = ids.substring(1, ids.length - 1);
  45 + ids = ids.split(",");
  46 +
  47 + for(var i = 0; i < ids.length; i++) {
  48 + $('[data-notification="' + ids[i] + '"]').fadeOut();
  49 + }
  50 + }
  51 + }
  52 +
  53 + function mceRestrict() {
  54 + tinyMCE.init({
  55 + menubar : false,
  56 + selector: "textarea",
  57 + plugins: [
  58 + "autolink link"
  59 + ],
  60 + toolbar: "bold italic underline | link"
  61 + });
  62 + }
  63 +
  64 + function showPopup() {
  65 + if($('.action-home-index').length > 0) {
  66 + jQuery(function($){
  67 + $.colorbox({href: noosfero_root()+'/plugin/environment_notification/public/notifications_with_popup?previous_path=home'});
  68 + });
  69 + }
  70 + else {
  71 + jQuery(function($){
  72 + $.colorbox({href: noosfero_root()+'/plugin/environment_notification/public/notifications_with_popup'});
  73 + });
  74 + }
  75 + }
  76 +
  77 + $(document).ready(function(){
  78 + notificationBar();
  79 + $(".notification-close").on("click", closeNotification);
  80 + $(".notification-hide").on("click", hideNotification);
  81 +
  82 + if($('.environment-notification-plugin-message').length > 0){
  83 + mceRestrict();
  84 + }
  85 +
  86 + if($('.notification-bar').length > 0){
  87 + hideUserNotification();
  88 + }
  89 +
  90 + if($('[notification-display-popup="true"]').length > 0){
  91 + showPopup();
  92 + }
  93 + });
  94 +
  95 +})($);
0 96 \ No newline at end of file
... ...
plugins/environment_notification/public/images/close.png 0 → 100644

240 Bytes

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

794 Bytes

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

389 Bytes

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

552 Bytes

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

364 Bytes

plugins/environment_notification/public/public 0 → 120000
... ... @@ -0,0 +1 @@
  1 +/home/arthurmde/Documentos/projects/noosfero/config/plugins/environment_notification/public
0 2 \ No newline at end of file
... ...
plugins/environment_notification/style.css 0 → 100644
... ... @@ -0,0 +1,224 @@
  1 +.notification-bar {
  2 + display: block;
  3 +}
  4 +
  5 +.notification:hover {
  6 + opacity: 0.8;
  7 +}
  8 +
  9 +#notification-manager {
  10 + overflow: auto;
  11 +}
  12 +
  13 +.notification .notification-close {
  14 + background: url(public/images/close.png) no-repeat;
  15 + background-position: center;
  16 + width: 20px;
  17 + height: 20px;
  18 +}
  19 +
  20 +.warningnotification,
  21 +.informationnotification,
  22 +.successnotification,
  23 +.dangernotification,
  24 +.adminnotification {
  25 + margin-bottom: 10px;
  26 + padding: 7px 10px;
  27 + border-radius: 5px;
  28 + border: 1px solid blue;
  29 + font-size: 16px;
  30 + color: white;
  31 + overflow: auto;
  32 +}
  33 +
  34 +.warningnotification p,
  35 +.informationnotification p,
  36 +.successnotification p,
  37 +.dangernotification p,
  38 +.adminnotification p {
  39 + margin: 0px;
  40 +}
  41 +
  42 +.warningnotification {
  43 + background: #fcf8e3;
  44 + border: 1px solid #faebcc;
  45 + color: #8a6d3b;
  46 +}
  47 +
  48 +.warningnotification p a{
  49 + font-weight: bold;
  50 + color: #8a6d3b;
  51 +}
  52 +
  53 +
  54 +.informationnotification {
  55 + background: #d9edf7;
  56 + border: 1px solid #bce8f1;
  57 + color: #31708f;
  58 +}
  59 +
  60 +.informationnotification p a{
  61 + font-weight: bold;
  62 + color: #31708f;
  63 +}
  64 +
  65 +.successnotification {
  66 + background: #dff0d8;
  67 + border: 1px solid #d6e9c6;
  68 + color: #3c763d;
  69 +}
  70 +
  71 +.successnotification p a{
  72 + font-weight: bold;
  73 + color: #3c763d;
  74 +}
  75 +
  76 +.dangernotification {
  77 + background: #f2dede;
  78 + border: 1px solid #ebccd1;
  79 + color: #a94442;
  80 +}
  81 +
  82 +.dangernotification p a{
  83 + font-weight: bold;
  84 + color: #a94442;
  85 +}
  86 +
  87 +.adminnotification {
  88 + background: #9a959a;
  89 + border: 1px solid #9a959a;
  90 +}
  91 +
  92 +.adminnotification p a{
  93 + font-weight: bold;
  94 + color: white;
  95 +}
  96 +
  97 +a.button.icon-deactivate {
  98 + background: url(public/images/hide.png) no-repeat;
  99 + background-position: center;
  100 +}
  101 +
  102 +a.button.icon-activate {
  103 + background: url(public/images/show.png) no-repeat;
  104 + background-position: center;
  105 +}
  106 +
  107 +.notification-line {
  108 + display: inline;
  109 + padding-top: 10px;
  110 + vertical-align: middle;
  111 + border-bottom: 1px solid #ccc;
  112 +}
  113 +
  114 +.notification-title-bar {
  115 + float: left;
  116 + width: 100%;
  117 + font-style: 14px;
  118 + font-weight: 700;
  119 + border-bottom: 2px solid black;
  120 + padding: 9px 0;
  121 +}
  122 +
  123 +.notification-title {
  124 + width: 80%;
  125 + float: left;
  126 + text-align: center;
  127 +}
  128 +
  129 +.notification-modal .notification-with-title {
  130 + margin-bottom: 0px;
  131 +}
  132 +
  133 +.notification-modal .notification .notification-title {
  134 + width: 100%;
  135 + float: left;
  136 + font-weight: bold;
  137 + text-align: left;
  138 +}
  139 +
  140 +.notification-modal .notification-with-title-message {
  141 + width: 100%;
  142 + float: left;
  143 + border-radius: 3px;
  144 + margin-bottom: 10px;
  145 + background-color: #f5f5f5;
  146 + font-size: 14px;
  147 + overflow: auto;
  148 +}
  149 +
  150 +.notification-modal .notification-with-title-message p{
  151 + padding: 0px 7px;
  152 +}
  153 +
  154 +.notification-modal .notification-with-title-message p a{
  155 + color: black;
  156 + font-weight: bold;
  157 +}
  158 +
  159 +
  160 +.action-title {
  161 + width: 20%;
  162 + float: left;
  163 + text-align: center;
  164 +}
  165 +
  166 +.notification-action {
  167 + width: 18%;
  168 + float: left;
  169 + height: 30px;
  170 + padding-top: 9px;
  171 +}
  172 +
  173 +.main-bar .button,
  174 +.notification-action .button {
  175 + border-radius: 3px;
  176 +}
  177 +
  178 +.notification-message {
  179 + width: 82%;
  180 + float: left;
  181 +}
  182 +
  183 +.new-notification {
  184 + float: right;
  185 + width: auto;
  186 +}
  187 +
  188 +.back-button {
  189 + float: left;
  190 +}
  191 +
  192 +.main-bar {
  193 + display: inline;
  194 + width: 100%;
  195 +}
  196 +
  197 +.notification-bar .notification .notification-message {
  198 + width: 90%;
  199 + float: left;
  200 +}
  201 +
  202 +.notification-bar .notification .notification-close {
  203 + background: url(public/images/redclose.png) no-repeat;
  204 + background-position: center;
  205 + width: 20px;
  206 + height: 20px;
  207 + float: right;
  208 + cursor: pointer;
  209 +}
  210 +
  211 +.notification-bar .notification .notification-hide {
  212 + background: url(public/images/greenhide.png) no-repeat;
  213 + background-position: center;
  214 + width: 20px;
  215 + height: 20px;
  216 + float: right;
  217 + cursor: pointer;
  218 +}
  219 +
  220 +.notification-modal {
  221 + display: block;
  222 + min-width: 400px;
  223 + max-width: 700px;
  224 +}
0 225 \ No newline at end of file
... ...
plugins/environment_notification/test/functional/account_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
  2 +require 'account_controller'
  3 +
  4 +class AccountController; def rescue_action(e) raise e end;
  5 +end
  6 +
  7 +class AccountControllerTest < ActionController::TestCase
  8 + def setup
  9 + @controller = AccountController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 + @person = create_user('person').person
  13 +
  14 + @environment = Environment.default
  15 + @environment.enable_plugin('EnvironmentNotificationPlugin')
  16 + @environment.save!
  17 +
  18 + login_as(@person.user.login)
  19 + end
  20 +
  21 + attr_accessor :person
  22 +
  23 + should 'clean hide_notifications cookie after logout' do
  24 + @request.cookies[:hide_notifications] = JSON.generate([1,2])
  25 + get :index
  26 + assert !@request.cookies[:hide_notifications].blank?
  27 +
  28 + @request.cookies[:hide_notifications] = nil
  29 + get :logout
  30 + assert_nil session[:user]
  31 + assert_response :redirect
  32 + assert_equal 1, @controller.hide_notifications.count
  33 + assert @controller.hide_notifications.include?(-1)
  34 + end
  35 +end
... ...
plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,186 @@
  1 +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
  2 +require(
  3 + File.expand_path(File.dirname(__FILE__)) +
  4 + '/../../controllers/environment_notification_plugin_admin_controller'
  5 +)
  6 +
  7 +class EnvironmentNotificationPluginAdminController; def rescue_action(e) raise e end;
  8 +end
  9 +
  10 +class EnvironmentNotificationPluginAdminControllerTest < ActionController::TestCase
  11 + def setup
  12 + @controller = EnvironmentNotificationPluginAdminController.new
  13 + @request = ActionController::TestRequest.new
  14 + @response = ActionController::TestResponse.new
  15 + @person = create_user('person').person
  16 +
  17 + @environment = Environment.default
  18 + @environment.enable_plugin('EnvironmentNotificationPlugin')
  19 + @environment.save!
  20 +
  21 + login_as(@person.user.login)
  22 + end
  23 +
  24 + attr_accessor :person
  25 +
  26 + should 'an admin be able to create a notification' do
  27 + @environment.add_admin(@person)
  28 + post :new, :notifications => {
  29 + :message => "Message",
  30 + :active => true,
  31 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  32 + }
  33 + assert_redirected_to :action => 'index'
  34 + notification = EnvironmentNotificationPlugin::EnvironmentNotification.last
  35 + assert_equal "Message", notification.message
  36 + assert notification.active
  37 + assert_equal "EnvironmentNotificationPlugin::DangerNotification", notification.type
  38 + end
  39 +
  40 + should 'an user not to be able to create a notification' do
  41 + post :new, :notifications => {
  42 + :message => "Message",
  43 + :active => true,
  44 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  45 + }
  46 + assert_redirected_to :root
  47 + assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.last
  48 + end
  49 +
  50 + should 'an admin be able to edit a notification' do
  51 + @environment.add_admin(@person)
  52 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  53 + :environment_id => @environment.id,
  54 + :message => "Message",
  55 + :active => true,
  56 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  57 + )
  58 + post :edit, :id => @notification.id, :notifications => {
  59 + :message => "Edited Message",
  60 + :active => false,
  61 + :type => "EnvironmentNotificationPlugin::WarningNotification"
  62 + }
  63 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.last
  64 + assert_redirected_to :action => 'index'
  65 + assert_equal "Edited Message", @notification.message
  66 + assert !@notification.active
  67 + assert_equal "EnvironmentNotificationPlugin::WarningNotification", @notification.type
  68 + end
  69 +
  70 + should 'an user not to be able to edit a notification' do
  71 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  72 + :environment_id => @environment.id,
  73 + :message => "Message",
  74 + :active => true,
  75 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  76 + )
  77 + post :edit, :notifications => {
  78 + :message => "Edited Message",
  79 + :active => false,
  80 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  81 + }
  82 + @notification.reload
  83 + assert_redirected_to :root
  84 + assert_equal "Message", @notification.message
  85 + assert @notification.active
  86 + end
  87 +
  88 + should 'an admin be able to destroy a notification' do
  89 + @environment.add_admin(@person)
  90 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  91 + :environment_id => @environment.id,
  92 + :message => "Message",
  93 + :active => true,
  94 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  95 + )
  96 + delete :destroy, :id => @notification.id
  97 + assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id)
  98 + end
  99 +
  100 + should 'an user not to be able to destroy a notification' do
  101 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  102 + :environment_id => @environment.id,
  103 + :message => "Message",
  104 + :active => true,
  105 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  106 + )
  107 + delete :destroy, :id => @notification.id
  108 +
  109 + assert_redirected_to :root
  110 + assert_not_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id)
  111 + end
  112 +
  113 + should 'an admin be able to change Notification status' do
  114 + @environment.add_admin(@person)
  115 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  116 + :environment_id => @environment.id,
  117 + :message => "Message",
  118 + :active => true,
  119 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  120 + )
  121 + post :change_status, :id => @notification.id
  122 + assert_redirected_to :action => 'index'
  123 +
  124 + @notification.reload
  125 + assert !@notification.active
  126 + end
  127 +
  128 + should 'an user not be able to change Notification status' do
  129 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  130 + :environment_id => @environment.id,
  131 + :message => "Message",
  132 + :active => true,
  133 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  134 + )
  135 + post :change_status, :id => @notification.id
  136 + assert_redirected_to :root
  137 +
  138 + @notification.reload
  139 + assert @notification.active
  140 + end
  141 +
  142 + should 'a logged in user be able to permanently hide notifications' do
  143 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  144 + :environment_id => @environment.id,
  145 + :message => "Message",
  146 + :active => true,
  147 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  148 + )
  149 + post :close_notification, :notification_id => @notification.id
  150 + assert_equal "true", @response.body
  151 + assert @notification.users.include?(@person.user)
  152 + end
  153 +
  154 + should 'a logged in user be able to momentarily hide notifications' do
  155 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  156 + :environment_id => @environment.id,
  157 + :message => "Message",
  158 + :active => true,
  159 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  160 + )
  161 +
  162 + @another_notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  163 + :environment_id => @environment.id,
  164 + :message => "Another Message",
  165 + :active => true,
  166 + :type => "EnvironmentNotificationPlugin::WarningNotification"
  167 + )
  168 + post :hide_notification, :notification_id => @notification.id
  169 + assert_equal "true", @response.body
  170 + assert @controller.hide_notifications.include?(@notification.id)
  171 + assert !@controller.hide_notifications.include?(@another_notification.id)
  172 + end
  173 +
  174 + should 'not momentarily hide any notification if its id is not found' do
  175 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  176 + :environment_id => @environment.id,
  177 + :message => "Message",
  178 + :active => true,
  179 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  180 + )
  181 +
  182 + post :hide_notification, :notification_id => nil
  183 + assert_equal "false", @response.body
  184 + assert !@controller.hide_notifications.include?(@notification.id)
  185 + end
  186 +end
... ...
plugins/environment_notification/test/functional/home_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,120 @@
  1 +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
  2 +require 'home_controller'
  3 +
  4 +class HomeController; def rescue_action(e) raise e end;
  5 +end
  6 +
  7 +class HomeControllerTest < ActionController::TestCase
  8 + def setup
  9 + @controller = HomeController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 + @person = create_user('person').person
  13 +
  14 + @environment = Environment.default
  15 + @environment.enable_plugin('EnvironmentNotificationPlugin')
  16 + @environment.save!
  17 + end
  18 +
  19 + attr_accessor :person
  20 +
  21 + should 'an active notification be displayed on home page for a logged in user' do
  22 + login_as(@person.user.login)
  23 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  24 + :environment_id => @environment.id,
  25 + :message => "Hello, this is a Notification Message",
  26 + :active => true,
  27 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  28 + )
  29 + get :index
  30 + assert_match /Hello, this is a Notification Message/, @response.body
  31 + end
  32 +
  33 +
  34 + should 'an active notification not be displayed on home page for unlogged user' do
  35 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  36 + :environment_id => @environment.id,
  37 + :message => "Hello, this is a Notification Message",
  38 + :active => true,
  39 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  40 + )
  41 + get :index
  42 + assert_no_match /Hello, this is a Notification Message/, @response.body
  43 + end
  44 +
  45 + should 'an active notification be displayed on home page for unlogged user' do
  46 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  47 + :environment_id => @environment.id,
  48 + :message => "Hello, this is a Notification Message",
  49 + :display_to_all_users => true,
  50 + :active => true,
  51 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  52 + )
  53 + get :index
  54 + assert_match /Hello, this is a Notification Message/, @response.body
  55 + end
  56 +
  57 + should 'only display the notification with display_to_all_users option for unlogged user ' do
  58 + @notification1 = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  59 + :environment_id => @environment.id,
  60 + :message => "Hello, this is an old Notification Message",
  61 + :active => true,
  62 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  63 + )
  64 +
  65 + @notification2 = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  66 + :environment_id => @environment.id,
  67 + :message => "Hello, this is a new Notification Message",
  68 + :display_to_all_users => true,
  69 + :active => true,
  70 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  71 + )
  72 +
  73 +
  74 + get :index
  75 + assert_no_match /Hello, this is a Notification Message/, @response.body
  76 + assert_match /Hello, this is a new Notification Message/, @response.body
  77 + end
  78 +
  79 + should 'an inactive notification not be displayed on home page' do
  80 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  81 + :environment_id => @environment.id,
  82 + :message => "Hello, this is a Notification Message",
  83 + :active => false,
  84 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  85 + )
  86 + get :index
  87 + assert_no_match /Hello, this is a Notification Message/, @response.body
  88 + end
  89 +
  90 +
  91 + should 'an active notification not be displayed to a logged in user after been closed by him' do
  92 + login_as(@person.user.login)
  93 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  94 + :environment_id => @environment.id,
  95 + :message => "Hello, this is a Notification Message",
  96 + :active => true,
  97 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  98 + )
  99 + @notification.users << @person.user
  100 + @notification.save!
  101 + assert_equal true, @notification.users.include?(@person.user)
  102 + get :index
  103 + assert_no_match /Hello, this is a Notification Message/, @response.body
  104 + end
  105 +
  106 + should 'a notification be displayed with a Popup' do
  107 + login_as(@person.user.login)
  108 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  109 + :environment_id => @environment.id,
  110 + :message => "Message",
  111 + :display_popup => true,
  112 + :active => true,
  113 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  114 + )
  115 + assert_equal true, @notification.display_popup?
  116 +
  117 + get :index
  118 + assert_no_match /div id="cboxWrapper"/, @response.body
  119 + end
  120 +end
... ...
plugins/environment_notification/test/unit/environment_notification_helper_test.rb 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +require_relative '../../../../test/test_helper'
  2 +
  3 +class EnvironmentNotificationHelperTest < ActiveSupport::TestCase
  4 + def setup
  5 + @env = Environment.default
  6 + @env.enable_plugin('EnvironmentNotificationPlugin')
  7 +
  8 + @user = User.create!(:environment_id => @env.id, :email => "user@domain.com", :login => "new_user", :password => "test", :password_confirmation => "test", :name => "UserName")
  9 + end
  10 +
  11 + should 'substitute all email variables to the current user email' do
  12 + message = "Hello user with email %{email}! please, update your current email (%{email})."
  13 +
  14 + new_message = EnvironmentNotificationHelper.substitute_variables(message, @user)
  15 +
  16 + assert message != new_message
  17 + assert_equal new_message, "Hello user with email user@domain.com! please, update your current email (user@domain.com)."
  18 + end
  19 +
  20 + should 'not substitute emails variables if there is no current user' do
  21 + message = "Hello user with email %{email}! please, update your current email (%{email})."
  22 +
  23 + new_message = EnvironmentNotificationHelper.substitute_variables(message, nil)
  24 +
  25 + assert_equal message, new_message
  26 + assert_not_include new_message, "user@domain.com"
  27 + end
  28 +
  29 + should 'substitute all name variables to the current user name' do
  30 + message = "Hello %{name}! is %{name} your real name?."
  31 +
  32 + new_message = EnvironmentNotificationHelper.substitute_variables(message, @user)
  33 +
  34 + assert message != new_message
  35 + assert_equal new_message, "Hello UserName! is UserName your real name?."
  36 + end
  37 +
  38 + should 'not substitute name variables if there is no current user' do
  39 + message = "Hello %{name}! is %{name} your real name?."
  40 +
  41 + new_message = EnvironmentNotificationHelper.substitute_variables(message, nil)
  42 +
  43 + assert_equal message, new_message
  44 + assert_not_include new_message, "UserName"
  45 + end
  46 +end
0 47 \ No newline at end of file
... ...
plugins/environment_notification/test/unit/environment_notification_test.rb 0 → 100644
... ... @@ -0,0 +1,162 @@
  1 +require_relative '../../../../test/test_helper'
  2 +
  3 +class EnvironmentNotificationTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @env = Environment.default
  7 + @env.enable_plugin('EnvironmentNotificationPlugin')
  8 +
  9 + User.destroy_all
  10 + EnvironmentNotificationPlugin::EnvironmentNotification.destroy_all
  11 + EnvironmentNotificationsUser.destroy_all
  12 +
  13 + @user = User.create!(:environment_id => @env.id, :email => "user@domain.com", :login => "new_user", :password => "test", :password_confirmation => "test")
  14 + @danger_notification = EnvironmentNotificationPlugin::DangerNotification.create!(
  15 + :environment_id => @env.id,
  16 + :message => "Danger Message",
  17 + :active => true,
  18 + )
  19 +
  20 + @warning_notification = EnvironmentNotificationPlugin::WarningNotification.create!(
  21 + :environment_id => @env.id,
  22 + :message => "Warning Message",
  23 + :active => true,
  24 + )
  25 +
  26 + @information_notification = EnvironmentNotificationPlugin::InformationNotification.create!(
  27 + :environment_id => @env.id,
  28 + :message => "Information Message",
  29 + :active => true,
  30 + )
  31 + end
  32 +
  33 + should 'get all notifications that a user did not closed' do
  34 + @information_notification.users << @user
  35 +
  36 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, nil)
  37 +
  38 + assert notifications.include?(@danger_notification)
  39 + assert notifications.include?(@warning_notification)
  40 + assert !notifications.include?(@information_notification)
  41 + end
  42 +
  43 + should 'get only notifications configured to be displayed to all users' do
  44 + @information_notification.display_to_all_users = true
  45 + @information_notification.save!
  46 +
  47 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, nil, nil)
  48 +
  49 + assert !notifications.include?(@danger_notification)
  50 + assert !notifications.include?(@warning_notification)
  51 + assert notifications.include?(@information_notification)
  52 + end
  53 +
  54 + should 'get only notifications configured to be displayed to all users and in all pages' do
  55 + @information_notification.display_to_all_users = true
  56 + @information_notification.display_only_in_homepage = true
  57 + @information_notification.save!
  58 +
  59 + @danger_notification.display_to_all_users = true
  60 + @danger_notification.save!
  61 +
  62 + @warning_notification.display_only_in_homepage = true
  63 + @warning_notification.save!
  64 +
  65 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, nil, 'not_home')
  66 +
  67 + assert notifications.include?(@danger_notification)
  68 + assert !notifications.include?(@warning_notification)
  69 + assert !notifications.include?(@information_notification)
  70 + end
  71 +
  72 + should 'get only notifications configured to be displayed in all pages' do
  73 + @danger_notification.display_to_all_users = true
  74 + @danger_notification.display_only_in_homepage = true
  75 + @danger_notification.save!
  76 +
  77 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, "not_home")
  78 +
  79 + assert !notifications.include?(@danger_notification)
  80 + assert notifications.include?(@warning_notification)
  81 + assert notifications.include?(@information_notification)
  82 +
  83 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, nil, "home")
  84 +
  85 + assert notifications.include?(@danger_notification)
  86 + assert !notifications.include?(@warning_notification)
  87 + assert !notifications.include?(@information_notification)
  88 + end
  89 +
  90 + should 'get only notifications configured to be displayed to all users and in all pages and not closed by an user' do
  91 + @information_notification.display_to_all_users = true
  92 + @information_notification.save!
  93 +
  94 + @danger_notification.display_to_all_users = true
  95 + @danger_notification.display_only_in_homepage = true
  96 + @danger_notification.save!
  97 +
  98 + @warning_notification.display_to_all_users = true
  99 + @warning_notification.save!
  100 +
  101 + @warning_notification.users << @user
  102 +
  103 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, 'not_home')
  104 +
  105 + assert !notifications.include?(@danger_notification)
  106 + assert !notifications.include?(@warning_notification)
  107 + assert notifications.include?(@information_notification)
  108 + end
  109 +
  110 + should 'get only active notifications' do
  111 + @information_notification.active = false
  112 + @information_notification.save!
  113 +
  114 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(@env, @user, 'home')
  115 +
  116 + assert notifications.include?(@danger_notification)
  117 + assert notifications.include?(@warning_notification)
  118 + assert !notifications.include?(@information_notification)
  119 + end
  120 +
  121 + should 'get only notifications with popup' do
  122 + @information_notification.display_popup = true
  123 + @information_notification.display_to_all_users = true
  124 + @information_notification.save!
  125 +
  126 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, @user, 'home')
  127 +
  128 + assert !notifications.include?(@danger_notification)
  129 + assert !notifications.include?(@warning_notification)
  130 + assert notifications.include?(@information_notification)
  131 +
  132 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, nil, nil)
  133 +
  134 + assert !notifications.include?(@danger_notification)
  135 + assert !notifications.include?(@warning_notification)
  136 + assert notifications.include?(@information_notification)
  137 + end
  138 +
  139 + should 'get only notifications with popup not closed by an user' do
  140 + @information_notification.display_popup = true
  141 + @information_notification.display_to_all_users = true
  142 + @information_notification.save!
  143 +
  144 + @danger_notification.display_popup = true
  145 + @danger_notification.display_to_all_users = true
  146 + @danger_notification.save!
  147 +
  148 + @danger_notification.users << @user
  149 +
  150 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, @user, 'home')
  151 +
  152 + assert !notifications.include?(@danger_notification)
  153 + assert !notifications.include?(@warning_notification)
  154 + assert notifications.include?(@information_notification)
  155 +
  156 + notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(@env, nil, nil)
  157 +
  158 + assert notifications.include?(@danger_notification)
  159 + assert !notifications.include?(@warning_notification)
  160 + assert notifications.include?(@information_notification)
  161 + end
  162 +end
... ...
plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +<% abstract_options = {:value => @notification.message, :style => 'width: 100%; height: 200px;', :class => "environment-notification-plugin-message" } %>
  2 +
  3 +<%= button :back, _('Back'), :controller => 'environment_notification_plugin_admin' %>
  4 +
  5 +<%= form_for :notifications do |f| %>
  6 +
  7 + <%= render :file => 'shared/tiny_mce' %>
  8 +
  9 + <%= labelled_form_field(_("Optional Title:"), f.text_field(:title, value: @notification.title)) %>
  10 +
  11 + <%= labelled_form_field(_("Enter your message here:"), f.text_area(:message, abstract_options)) %>
  12 + <small>
  13 + <%= _("Obs: You can use %{name} and %{email} variables to put the user's name and email in the message.") %>
  14 + </small>
  15 +
  16 + <%= labelled_form_field(_('Notifications Status'), select(:notifications, :active, options_for_select_with_title({"Active" => true, "Inactive" => false}, @notification.active))) %>
  17 +
  18 + <%= 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))) %>
  19 +
  20 + <div>
  21 + <%= labelled_check_box(_("Display only in the homepage"), 'notifications[display_only_in_homepage]', '1', @notification.display_only_in_homepage?) %>
  22 + </div>
  23 +
  24 + <div>
  25 + <%= labelled_check_box(_("Display to not logged users too"), 'notifications[display_to_all_users]', '1', @notification.display_to_all_users?) %>
  26 + </div>
  27 +
  28 + <div>
  29 + <%= labelled_check_box(_("Display popup until user close the notification"), 'notifications[display_popup]', '1', @notification.display_popup?) %>
  30 + </div>
  31 +
  32 + <% button_bar do %>
  33 + <%= submit_button 'save', _('Save'), :cancel => { :action => 'index' } %>
  34 + <% end %>
  35 +
  36 +<% end %>
... ...
plugins/environment_notification/views/environment_notification_plugin_admin/edit.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= render :partial => "form" %>
... ...
plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +<div id="notification-manager">
  2 + <div class="notification-manager-title">
  3 + <h1><%= _("Environment Notifications") %></h1>
  4 + </div>
  5 + <div class="buttons-bar">
  6 + <div class="new-notification">
  7 + <%= button :new, _('New Notification'), {:action => :new}, :method => :get %>
  8 + </div>
  9 + <div class="back-button">
  10 + <%= button :back, _('Back to control panel'), {:controller => 'admin_panel', :action => :index}, :method => :get %>
  11 + </div>
  12 + </div>
  13 +
  14 + <div class="notification-title-bar">
  15 + <div class="notification-title">
  16 + <%= _('Notifications') %>
  17 + </div>
  18 + <div class="action-title">
  19 + <%= _('Actions') %>
  20 + </div>
  21 + </div>
  22 +
  23 + <% @notifications.each do |notification| %>
  24 + <div class="notification-line">
  25 + <div class="notification-message">
  26 + <%= truncate(notification.message, length: 50) %>
  27 + </div>
  28 + <div class="notification-action">
  29 + <% if notification.active? %>
  30 + <%= button_without_text :deactivate, _('Deactivate'), {:action => :change_status, :id => notification}, :method => :post, :confirm => _("Do you want to change the status of this notification?") %>
  31 + <% else %>
  32 + <%= button_without_text :activate, _('Activate'), {:action => :change_status, :id => notification}, :method => :post, :confirm => _("Do you want to change the status of this notification?") %>
  33 + <% end %>
  34 + <%= button_without_text :edit, _('Edit'), {:action => 'edit', :id => notification.id} if !remove_content_button(:edit, notification) %>
  35 + <%= button_without_text :delete, _('Delete'), {:action => :destroy, :id => notification}, :method => :delete, :confirm => _("Do you want to delete this notification?") %>
  36 + </div>
  37 + </div>
  38 + <% end %>
  39 +</div>
  40 +
... ...
plugins/environment_notification/views/environment_notification_plugin_admin/new.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= render :partial => "form" %>
... ...
plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +<% if current_user && current_user.person.is_admin? %>
  2 + <% active_notifications = EnvironmentNotificationPlugin::EnvironmentNotification.active(environment) %>
  3 + <% unless active_notifications.blank? %>
  4 + <div class="notification-bar">
  5 + <div class="adminnotification notification">
  6 + <div class="notification-message">
  7 + <p>
  8 + <%= _("There are active notifications in this environment! You can ") %>
  9 + <a href="/admin/plugin/environment_notification">
  10 + <%= _("manage all notifications here.") %>
  11 + </a>
  12 + </p>
  13 + </div>
  14 + </div>
  15 + </div>
  16 + <% end %>
  17 +<% end %>
  18 +
  19 +<% @notifications = EnvironmentNotificationPlugin::EnvironmentNotification.visibles(environment, current_user, controller_path).where("id NOT IN (?)", hide_notifications) %>
  20 +
  21 +<div class="notification-bar">
  22 + <% @notifications.each do |notification| %>
  23 + <div class="<%= notification.type.gsub("EnvironmentNotificationPlugin::", "").downcase %> notification" data-notification="<%=notification.id%>" notification-display-popup="<%=notification.display_popup?%>">
  24 + <div class="notification-message">
  25 + <%= EnvironmentNotificationHelper.substitute_variables(notification.message, current_user) %>
  26 + </div>
  27 + <% if logged_in? %>
  28 + <div class="notification-close" title="<%= _('Do not show anymore') %>"></div>
  29 + <div class="notification-hide" title="<%= _('Hide for now') %>"></div>
  30 + <% end %>
  31 + </div>
  32 + <% end %>
  33 +</div>
... ...
plugins/environment_notification/views/environment_notification_plugin_public/notifications_with_popup.html.erb 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +<% @notifications = EnvironmentNotificationPlugin::EnvironmentNotification.with_popup(environment, current_user, @previous_path).where("id NOT IN (?)", @hide_notifications) %>
  2 +
  3 +<div class="notification-modal">
  4 + <% @notifications.each do |notification| %>
  5 + <% if !notification.title.blank? %>
  6 + <div class="<%= notification.type.gsub("EnvironmentNotificationPlugin::", "").downcase %> notification notification-with-title" data-notification="<%=notification.id%>">
  7 + <div class="notification-title">
  8 + <%= notification.title %>
  9 + </div>
  10 + </div>
  11 + <div class="notification-message notification-with-title-message">
  12 + <%= EnvironmentNotificationHelper.substitute_variables(notification.message, current_user) %>
  13 + </div>
  14 + <% else %>
  15 + <div class="<%= notification.type.gsub("EnvironmentNotificationPlugin::", "").downcase %> notification notification-without-title" data-notification="<%=notification.id%>">
  16 + <div class="notification-message">
  17 + <%= EnvironmentNotificationHelper.substitute_variables(notification.message, current_user) %>
  18 + </div>
  19 + </div>
  20 + <% end %>
  21 + <% end %>
  22 +</div>
... ...