Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
source "https://rubygems.org"

gem 'faye'

group :test do
gem "factory_girl", "~> 4.0"
end
gem "factory_bot", "~> 6.0"
end
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
29 changes: 18 additions & 11 deletions app/controllers/app_notifications_controller.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -18,37 +18,44 @@ 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

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

2 changes: 1 addition & 1 deletion db/migrate/001_create_app_notifications.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/002_update_users.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/003_update_users2.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions init.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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'
24 changes: 7 additions & 17 deletions lib/app_notifications_account_patch.rb
Original file line number Diff line number Diff line change
@@ -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)