This commit is contained in:
Karel.Picman 2022-01-28 13:36:28 +01:00
parent aa0574de37
commit 172904428e
8 changed files with 145 additions and 104 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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? %>
<div id="watchers">
<% if @folder %>
<%= render partial: 'watchers/watchers', locals: { watched: @folder } %>

View File

@ -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 %>

View File

@ -25,7 +25,7 @@
<% html_title(l(:dmsf)) %>
<div class="contextual">
<% 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)),

View File

@ -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

View File

@ -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