diff --git a/Gemfile b/Gemfile index 319dfe8..0ee4366 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,7 @@ +source "https://rubygems.org" + gem 'faye' group :test do - gem "factory_girl", "~> 4.0" -end \ No newline at end of file + gem "factory_bot", "~> 6.0" +end diff --git a/README.md b/README.md index d4132af..b465879 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,15 @@ # Redmine App Notifications App notifications plugin provides simple in application notifications for Redmine. It can replace default e-mail notifications. +Updated for Redmine 5.0. Tested on docker containers, maybe require create a secret key: + +> rake secret + +The aded to the compose file or declare the env variable + +> environment: +> SECRET_KEY_BASE: "tu_valor_generado" + ## Installation and Setup diff --git a/app/controllers/app_notifications_controller.rb b/app/controllers/app_notifications_controller.rb index a782975..e13d93f 100644 --- a/app/controllers/app_notifications_controller.rb +++ b/app/controllers/app_notifications_controller.rb @@ -1,10 +1,10 @@ class AppNotificationsController < ApplicationController unloadable - # helper :app_notifications - # include AppNotificationsHelper def index - @app_notifications = AppNotification.includes(:issue, :author, :journal).where(recipient_id: User.current.id).order("created_on desc") + @app_notifications = AppNotification.includes(:issue, :author, :journal) + .where(recipient_id: User.current.id) + .order("created_on desc") if request.xhr? @app_notifications = @app_notifications.limit(5) render :partial => "ajax" @@ -18,15 +18,17 @@ def index params.has_key?(:new) ? @new = params['new'] : @new = false end - if(!@viewed && !@new) + if (!@viewed && !@new) return @app_notifications = [] end - if(@viewed != @new) + + if (@viewed != @new) @app_notifications = @app_notifications.where(viewed: true) if @viewed @app_notifications = @app_notifications.where(viewed: false) if @new end + @limit = 10 - @app_notifications_pages = Paginator.new @app_notifications.count, @limit, params['page'] + @app_notifications_pages = Paginator.new(@app_notifications.count, @limit, params['page']) @offset ||= @app_notifications_pages.offset @app_notifications = @app_notifications.limit(@limit).offset(@offset) end @@ -34,21 +36,26 @@ def index def view @notification = AppNotification.find(params[:id]) if @notification.recipient == User.current - AppNotification.update(@notification, :viewed => true) + @notification.update(viewed: true) if request.xhr? if @notification.is_edited? - render :partial => 'issues/issue_edit', :formats => [:html], :locals => { :notification => @notification, :journal => @notification.journal } + render :partial => 'issues/issue_edit', :formats => [:html], + :locals => { :notification => @notification, :journal => @notification.journal } else - render :partial => 'issues/issue_add', :formats => [:html], :locals => { :notification => @notification } + render :partial => 'issues/issue_add', :formats => [:html], + :locals => { :notification => @notification } end else - redirect_to :controller => 'issues', :action => 'show', :id => params[:issue_id], :anchor => params[:anchor] + redirect_to :controller => 'issues', :action => 'show', + :id => params[:issue_id], :anchor => params[:anchor] end end end def view_all - AppNotification.where(:recipient_id => User.current.id, :viewed => false).update_all( :viewed => true ) + AppNotification.where(recipient_id: User.current.id, viewed: false) + .update_all(viewed: true) redirect_to :action => 'index' end end + diff --git a/db/migrate/001_create_app_notifications.rb b/db/migrate/001_create_app_notifications.rb index d0aaf1f..59569a2 100644 --- a/db/migrate/001_create_app_notifications.rb +++ b/db/migrate/001_create_app_notifications.rb @@ -1,4 +1,4 @@ -class CreateAppNotifications < ActiveRecord::Migration +class CreateAppNotifications < ActiveRecord::Migration[4.2] def change create_table :app_notifications do |t| t.datetime :created_on diff --git a/db/migrate/002_update_users.rb b/db/migrate/002_update_users.rb index 792d7a5..ef2c96c 100644 --- a/db/migrate/002_update_users.rb +++ b/db/migrate/002_update_users.rb @@ -1,4 +1,4 @@ -class UpdateUsers < ActiveRecord::Migration +class UpdateUsers < ActiveRecord::Migration[4.2] def self.up change_table :users do |t| t.column :app_notification, :boolean, :default => false diff --git a/db/migrate/003_update_users2.rb b/db/migrate/003_update_users2.rb index 614f655..539ff41 100644 --- a/db/migrate/003_update_users2.rb +++ b/db/migrate/003_update_users2.rb @@ -1,4 +1,4 @@ -class UpdateUsers2 < ActiveRecord::Migration +class UpdateUsers2 < ActiveRecord::Migration[4.2] def self.up change_table :users do |t| t.column :app_notification_desktop, :boolean, :default => false diff --git a/init.rb b/init.rb index 45ce22a..6dfa7cd 100644 --- a/init.rb +++ b/init.rb @@ -1,8 +1,8 @@ Redmine::Plugin.register :redmine_app_notifications do name 'Redmine App Notifications plugin' - author 'Michal Vanzura' + author 'Michal Vanzura / Emiliano A. Baum' description 'App notifications plugin provides simple in application notifications. It can replace default e-mail notifications.' - version '1.0' + version '1.1' url 'https://github.com/MichalVanzura/redmine_app_notifications' author_url 'https://github.com/MichalVanzura/redmine_app_notifications' @@ -30,8 +30,8 @@ 'faye_server_adress' => 'http://ip_address_or_name_of_your_server:9292/faye' }, :partial => 'settings/app_notifications_settings' end +require_dependency File.expand_path('lib/app_notifications_hook_listener', __dir__) +require_dependency File.expand_path('lib/app_notifications_account_patch', __dir__) +require_dependency File.expand_path('lib/app_notifications_issues_patch', __dir__) +require_dependency File.expand_path('lib/app_notifications_journals_patch', __dir__) -require_dependency 'app_notifications_hook_listener' -require_dependency 'app_notifications_account_patch' -require_dependency 'app_notifications_issues_patch' -require_dependency 'app_notifications_journals_patch' diff --git a/lib/app_notifications_account_patch.rb b/lib/app_notifications_account_patch.rb index 3bac0e6..da802b5 100644 --- a/lib/app_notifications_account_patch.rb +++ b/lib/app_notifications_account_patch.rb @@ -1,23 +1,13 @@ require_dependency 'my_controller' module AppNotificationsAccountPatch - def self.included(base) # :nodoc: - base.send(:include, InstanceMethods) - - base.class_eval do - unloadable # Send unloadable so it will not be unloaded in development - - alias_method_chain :account, :in_app_option - end - end - - module InstanceMethods - def account_with_in_app_option - account = account_without_in_app_option - User.safe_attributes 'app_notification', 'app_notification_desktop' - return account - end + # Sobrescribe el método account para extender su comportamiento. + def account + result = super # Llama a la implementación original. + User.safe_attributes 'app_notification', 'app_notification_desktop' + result end end -MyController.send(:include, AppNotificationsAccountPatch) +# En lugar de include, usamos prepend para que este módulo tenga prioridad. +MyController.prepend(AppNotificationsAccountPatch)