diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb
index d0811a46..53a3bf3d 100644
--- a/app/controllers/dmsf_controller.rb
+++ b/app/controllers/dmsf_controller.rb
@@ -238,6 +238,11 @@ class DmsfController < ApplicationController
@pathfolder = copy_folder(@folder)
@force_file_unlock_allowed = User.current.allowed_to?(:force_file_unlock, @project)
@redirect_to_folder_id = params[:redirect_to_folder_id]
+ @notifications = Setting.notified_events.include?('dmsf_legacy_notifications')
+ end
+
+ def edit_root
+ @notifications = Setting.notified_events.include?('dmsf_legacy_notifications')
end
def create
diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb
index 04232bbf..a7c69ec6 100644
--- a/app/models/dmsf_file.rb
+++ b/app/models/dmsf_file.rb
@@ -215,7 +215,7 @@ class DmsfFile < ActiveRecord::Base
end
def notify?
- notification dmsf_folder&.notify? || (!dmsf_folder && project.dmsf_notification)
+ notification || dmsf_folder&.notify? || (!dmsf_folder && project.dmsf_notification)
end
def get_all_watchers(watchers)
diff --git a/app/models/dmsf_mailer.rb b/app/models/dmsf_mailer.rb
index 4cc16e9e..f9273204 100644
--- a/app/models/dmsf_mailer.rb
+++ b/app/models/dmsf_mailer.rb
@@ -47,7 +47,7 @@ class DmsfMailer < Mailer
end
def self.deliver_files_deleted(project, files)
- users = get_notify_users(project, file.first)
+ users = get_notify_users(project, files.first)
users.each do |user|
files_deleted(user, project, files).deliver_later
end
diff --git a/app/views/dmsf/_main.html.erb b/app/views/dmsf/_main.html.erb
index dde8d48b..33b78283 100644
--- a/app/views/dmsf/_main.html.erb
+++ b/app/views/dmsf/_main.html.erb
@@ -95,7 +95,7 @@
<%= render partial: 'dmsf/sidebar' %>
<% project_or_folder = @folder? @folder : @project %>
- <% if project_or_folder.watchers.present? %>
+ <% if project_or_folder&.watchers.present? %>
<% if @folder %>
<%= render partial: 'watchers/watchers', locals: { watched: @folder } %>
diff --git a/app/views/dmsf/edit.html.erb b/app/views/dmsf/edit.html.erb
index 34796a47..2ae10ebd 100644
--- a/app/views/dmsf/edit.html.erb
+++ b/app/views/dmsf/edit.html.erb
@@ -46,6 +46,7 @@
edit: true,
unlockable: @folder.unlockable? && (!@folder.locked_for_user? || User.current.allowed_to?(:force_file_unlock, @project)),
email_allowed: User.current.allowed_to?(:email_documents, @project),
+ notifications: @notifications,
back_url: edit_dmsf_url(id: @project, folder_id: @folder)
} %>
<% else %>
@@ -60,6 +61,7 @@
edit: true,
unlockable: @folder.unlockable? && (!@folder.locked_for_user? || User.current.allowed_to?(:force_file_unlock, @project)),
email_allowed: User.current.allowed_to?(:email_documents, @project),
+ notifications: @notifications,
back_url: edit_dmsf_url(id: @project, folder_id: @folder)
} %>
<% end %>
diff --git a/app/views/dmsf/edit_root.html.erb b/app/views/dmsf/edit_root.html.erb
index 9ef5f72f..c6cd495c 100644
--- a/app/views/dmsf/edit_root.html.erb
+++ b/app/views/dmsf/edit_root.html.erb
@@ -25,7 +25,7 @@
<% html_title(l(:dmsf)) %>
- <% if User.current.allowed_to?(:folder_manipulation, @project) %>
+ <% if @notifications && User.current.allowed_to?(:folder_manipulation, @project) %>
<% if @project.dmsf_notification %>
<%= link_to l(:label_notifications_off),
notify_deactivate_dmsf_path(id: @project, back_url: edit_root_dmsf_path(id: @project)),
diff --git a/test/functional/dmsf_context_menus_controller_test.rb b/test/functional/dmsf_context_menus_controller_test.rb
index 5a110709..78b145e2 100644
--- a/test/functional/dmsf_context_menus_controller_test.rb
+++ b/test/functional/dmsf_context_menus_controller_test.rb
@@ -37,26 +37,30 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
end
def test_dmsf_file
- get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] }
- assert_response :success
- assert_select 'a.icon-edit', text: l(:button_edit)
- assert_select 'a.icon-lock', text: l(:button_lock)
- assert_select 'a.icon-email-add', text: l(:label_notifications_on)
- assert_select 'a.icon-del', text: l(:button_delete)
- assert_select 'a.icon-download', text: l(:button_download)
- assert_select 'a.icon-email', text: l(:field_mail)
- assert_select 'a.icon-file', text: l(:button_edit_content)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] }
+ assert_response :success
+ assert_select 'a.icon-edit', text: l(:button_edit)
+ assert_select 'a.icon-lock', text: l(:button_lock)
+ assert_select 'a.icon-email-add', text: l(:label_notifications_on)
+ assert_select 'a.icon-del', text: l(:button_delete)
+ assert_select 'a.icon-download', text: l(:button_download)
+ assert_select 'a.icon-email', text: l(:field_mail)
+ assert_select 'a.icon-file', text: l(:button_edit_content)
+ end
end
def test_dmsf_file_locked
- get :dmsf, params: { id: @file2.project.id, ids: ["file-#{@file2.id}"] }
- assert_response :success
- assert_select 'a.icon-edit.disabled', text: l(:button_edit)
- assert_select 'a.icon-unlock', text: l(:button_unlock)
- assert_select 'a.icon-lock', text: l(:button_lock), count: 0
- assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
- assert_select 'a.icon-del.disabled', text: l(:button_delete)
- assert_select 'a.icon-file.disabled', text: l(:button_edit_content)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @file2.project.id, ids: ["file-#{@file2.id}"] }
+ assert_response :success
+ assert_select 'a.icon-edit.disabled', text: l(:button_edit)
+ assert_select 'a.icon-unlock', text: l(:button_unlock)
+ assert_select 'a.icon-lock', text: l(:button_lock), count: 0
+ assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
+ assert_select 'a.icon-del.disabled', text: l(:button_delete)
+ assert_select 'a.icon-file.disabled', text: l(:button_edit_content)
+ end
end
def test_dmsf_edit_file_locked_by_myself
@@ -87,29 +91,35 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
def test_dmsf_file_notification_on
@file1.notify_activate
- get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] }
- assert_response :success
- assert_select 'a.icon-email', text: l(:label_notifications_off)
- assert_select 'a.icon-email-add', text: l(:label_notifications_on), count: 0
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] }
+ assert_response :success
+ assert_select 'a.icon-email', text: l(:label_notifications_off)
+ assert_select 'a.icon-email-add', text: l(:label_notifications_on), count: 0
+ end
end
def test_dmsf_file_manipulation_permission_off
@role_manager.remove_permission! :file_manipulation
- get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] }
- assert_response :success
- assert_select 'a.icon-edit.disabled', text: l(:button_edit)
- assert_select 'a.icon-lock.disabled', text: l(:button_lock)
- assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
- assert_select 'a.icon-del.disabled', text: l(:button_delete)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] }
+ assert_response :success
+ assert_select 'a.icon-edit.disabled', text: l(:button_edit)
+ assert_select 'a.icon-lock.disabled', text: l(:button_lock)
+ assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
+ assert_select 'a.icon-del.disabled', text: l(:button_delete)
+ end
end
def test_dmsf_file_manipulation_permission_on
- get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] }
- assert_response :success
- assert_select 'a:not(icon-edit.disabled)', text: l(:button_edit)
- assert_select 'a:not(icon-lock.disabled)', text: l(:button_lock)
- assert_select 'a:not(icon-email-add.disabled)', text: l(:label_notifications_on)
- assert_select 'a:not(icon-del.disabled)', text: l(:button_delete)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] }
+ assert_response :success
+ assert_select 'a:not(icon-edit.disabled)', text: l(:button_edit)
+ assert_select 'a:not(icon-lock.disabled)', text: l(:button_lock)
+ assert_select 'a:not(icon-email-add.disabled)', text: l(:label_notifications_on)
+ assert_select 'a:not(icon-del.disabled)', text: l(:button_delete)
+ end
end
def test_dmsf_file_email_permission_off
@@ -163,28 +173,32 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
end
def test_dmsf_file_link
- get :dmsf, params: {
- id: @file_link6.project.id, folder_id: @file_link6.dmsf_folder, ids: ["file-link-#{@file_link6.id}"] }
- assert_response :success
- assert_select 'a.icon-edit', text: l(:button_edit)
- assert_select 'a.icon-lock', text: l(:button_lock)
- assert_select 'a.icon-email-add', text: l(:label_notifications_on)
- assert_select 'a.icon-del', text: l(:button_delete)
- assert_select 'a.icon-download', text: l(:button_download)
- assert_select 'a.icon-email', text: l(:field_mail)
- assert_select 'a.icon-file', text: l(:button_edit_content)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: {
+ id: @file_link6.project.id, folder_id: @file_link6.dmsf_folder, ids: ["file-link-#{@file_link6.id}"] }
+ assert_response :success
+ assert_select 'a.icon-edit', text: l(:button_edit)
+ assert_select 'a.icon-lock', text: l(:button_lock)
+ assert_select 'a.icon-email-add', text: l(:label_notifications_on)
+ assert_select 'a.icon-del', text: l(:button_delete)
+ assert_select 'a.icon-download', text: l(:button_download)
+ assert_select 'a.icon-email', text: l(:field_mail)
+ assert_select 'a.icon-file', text: l(:button_edit_content)
+ end
end
def test_dmsf_file_link_locked
assert @file_link2.target_file.locked?
- get :dmsf, params: {
- id: @file_link2.project.id, folder_id: @file_link2.dmsf_folder.id, ids: ["file-link-#{@file_link2.id}"] }
- assert_response :success
- assert_select 'a.icon-edit.disabled', text: l(:button_edit)
- assert_select 'a.icon-unlock', text: l(:button_unlock)
- assert_select 'a.icon-lock', text: l(:button_lock), count: 0
- assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
- assert_select 'a.icon-del', text: l(:button_delete)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: {
+ id: @file_link2.project.id, folder_id: @file_link2.dmsf_folder.id, ids: ["file-link-#{@file_link2.id}"] }
+ assert_response :success
+ assert_select 'a.icon-edit.disabled', text: l(:button_edit)
+ assert_select 'a.icon-unlock', text: l(:button_unlock)
+ assert_select 'a.icon-lock', text: l(:button_lock), count: 0
+ assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
+ assert_select 'a.icon-del', text: l(:button_delete)
+ end
end
def test_dmsf_url_link
@@ -194,26 +208,30 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
end
def test_dmsf_folder
- get :dmsf, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] }
- assert_response :success
- assert_select 'a.icon-edit', text: l(:button_edit)
- assert_select 'a.icon-lock', text: l(:button_lock)
- assert_select 'a.icon-email-add', text: l(:label_notifications_on)
- assert_select 'a.icon-del', text: l(:button_delete)
- assert_select 'a:not(icon-del.disabled)', text: l(:button_delete)
- assert_select 'a.icon-download', text: l(:button_download)
- assert_select 'a.icon-email', text: l(:field_mail)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] }
+ assert_response :success
+ assert_select 'a.icon-edit', text: l(:button_edit)
+ assert_select 'a.icon-lock', text: l(:button_lock)
+ assert_select 'a.icon-email-add', text: l(:label_notifications_on)
+ assert_select 'a.icon-del', text: l(:button_delete)
+ assert_select 'a:not(icon-del.disabled)', text: l(:button_delete)
+ assert_select 'a.icon-download', text: l(:button_download)
+ assert_select 'a.icon-email', text: l(:field_mail)
+ end
end
def test_dmsf_folder_locked
assert @folder5.locked?
- get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] }
- assert_response :success
- assert_select 'a.icon-edit.disabled', text: l(:button_edit)
- assert_select 'a.icon-unlock', text: l(:button_unlock)
- assert_select 'a.icon-lock', text: l(:button_lock), count: 0
- assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
- assert_select 'a.icon-del.disabled', text: l(:button_delete)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] }
+ assert_response :success
+ assert_select 'a.icon-edit.disabled', text: l(:button_edit)
+ assert_select 'a.icon-unlock', text: l(:button_unlock)
+ assert_select 'a.icon-lock', text: l(:button_lock), count: 0
+ assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
+ assert_select 'a.icon-del.disabled', text: l(:button_delete)
+ end
end
def test_dmsf_folder_locked_force_unlock_permission_off
@@ -235,29 +253,35 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
def test_dmsf_folder_notification_on
@folder5.notify_activate
- get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] }
- assert_response :success
- assert_select 'a.icon-email', text: l(:label_notifications_off)
- assert_select 'a.icon-email-add', text: l(:label_notifications_on), count: 0
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] }
+ assert_response :success
+ assert_select 'a.icon-email', text: l(:label_notifications_off)
+ assert_select 'a.icon-email-add', text: l(:label_notifications_on), count: 0
+ end
end
def test_dmsf_folder_manipulation_permmissions_off
@role_manager.remove_permission! :folder_manipulation
- get :dmsf, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] }
- assert_response :success
- assert_select 'a.icon-edit.disabled', text: l(:button_edit)
- assert_select 'a.icon-lock.disabled', text: l(:button_lock)
- assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
- assert_select 'a.icon-del.disabled', text: l(:button_delete)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] }
+ assert_response :success
+ assert_select 'a.icon-edit.disabled', text: l(:button_edit)
+ assert_select 'a.icon-lock.disabled', text: l(:button_lock)
+ assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
+ assert_select 'a.icon-del.disabled', text: l(:button_delete)
+ end
end
def test_dmsf_folder_manipulation_permmissions_on
- get :dmsf, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] }
- assert_response :success
- assert_select 'a:not(icon-edit.disabled)', text: l(:button_edit)
- assert_select 'a:not(icon-lock.disabled)', text: l(:button_lock)
- assert_select 'a:not(icon-email-add.disabled)', text: l(:label_notifications_on)
- assert_select 'a:not(icon-del.disabled)', text: l(:button_delete)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] }
+ assert_response :success
+ assert_select 'a:not(icon-edit.disabled)', text: l(:button_edit)
+ assert_select 'a:not(icon-lock.disabled)', text: l(:button_lock)
+ assert_select 'a:not(icon-email-add.disabled)', text: l(:label_notifications_on)
+ assert_select 'a:not(icon-del.disabled)', text: l(:button_delete)
+ end
end
def test_dmsf_folder_email_permmissions_off
@@ -274,25 +298,29 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
end
def test_dmsf_folder_link
- get :dmsf, params: { id: @folder_link1.project.id, ids: ["folder-#{@folder_link1.id}"] }
- assert_response :success
- assert_select 'a.icon-edit', text: l(:button_edit)
- assert_select 'a.icon-lock', text: l(:button_lock)
- assert_select 'a.icon-email-add', text: l(:label_notifications_on)
- assert_select 'a.icon-del', text: l(:button_delete)
- assert_select 'a.icon-download', text: l(:button_download)
- assert_select 'a.icon-email', text: l(:field_mail)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @folder_link1.project.id, ids: ["folder-#{@folder_link1.id}"] }
+ assert_response :success
+ assert_select 'a.icon-edit', text: l(:button_edit)
+ assert_select 'a.icon-lock', text: l(:button_lock)
+ assert_select 'a.icon-email-add', text: l(:label_notifications_on)
+ assert_select 'a.icon-del', text: l(:button_delete)
+ assert_select 'a.icon-download', text: l(:button_download)
+ assert_select 'a.icon-email', text: l(:field_mail)
+ end
end
def test_dmsf_folder_link_locked
@folder_link1.target_folder.lock!
- get :dmsf, params: { id: @folder_link1.project.id, ids: ["folder-#{@folder_link1.id}"] }
- assert_response :success
- assert_select 'a.icon-edit.disabled', text: l(:button_edit)
- assert_select 'a.icon-unlock', text: l(:button_unlock)
- assert_select 'a.icon-lock', text: l(:button_lock), count: 0
- assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
- assert_select 'a.icon-del.disabled', text: l(:button_delete)
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ get :dmsf, params: { id: @folder_link1.project.id, ids: ["folder-#{@folder_link1.id}"] }
+ assert_response :success
+ assert_select 'a.icon-edit.disabled', text: l(:button_edit)
+ assert_select 'a.icon-unlock', text: l(:button_unlock)
+ assert_select 'a.icon-lock', text: l(:button_lock), count: 0
+ assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on)
+ assert_select 'a.icon-del.disabled', text: l(:button_delete)
+ end
end
def test_dmsf_multiple
diff --git a/test/unit/dmsf_mailer_test.rb b/test/unit/dmsf_mailer_test.rb
index b3dab515..be8af00e 100644
--- a/test/unit/dmsf_mailer_test.rb
+++ b/test/unit/dmsf_mailer_test.rb
@@ -94,8 +94,14 @@ class DmsfMailerTest < RedmineDmsf::Test::UnitTest
end
def test_get_notify_users
- users = DmsfMailer.get_notify_users(@project1, @file1)
- assert users.present?
+ with_settings :notified_events => ['dmsf_legacy_notifications'] do
+ users = DmsfMailer.get_notify_users(@project1, @file1)
+ assert users.present?
+ end
+ with_settings :notified_events => [] do
+ users = DmsfMailer.get_notify_users(@project1, @file1)
+ assert users.empty?
+ end
end
def test_get_notify_users_notification_switched_off