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,6 +37,7 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
end
def test_dmsf_file
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)
@ -47,8 +48,10 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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
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)
@ -58,6 +61,7 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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
User.current = @jsmith
@ -87,14 +91,17 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
def test_dmsf_file_notification_on
@file1.notify_activate
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
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)
@ -102,8 +109,10 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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
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)
@ -111,6 +120,7 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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
@role_manager.remove_permission! :email_documents
@ -163,6 +173,7 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
end
def test_dmsf_file_link
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
@ -174,9 +185,11 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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?
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
@ -186,6 +199,7 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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
get :dmsf, params: { id: @url_link5.project.id, ids: ["url-link-#{@url_link5.id}"] }
@ -194,6 +208,7 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
end
def test_dmsf_folder
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)
@ -204,9 +219,11 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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?
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)
@ -215,6 +232,7 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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
@request.session[:user_id] = @dlopper.id
@ -235,14 +253,17 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
def test_dmsf_folder_notification_on
@folder5.notify_activate
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
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)
@ -250,8 +271,10 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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
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)
@ -259,6 +282,7 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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
@role_manager.remove_permission! :email_documents
@ -274,6 +298,7 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
end
def test_dmsf_folder_link
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)
@ -283,9 +308,11 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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!
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)
@ -294,6 +321,7 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase
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
get :dmsf, params: { id: @project1.id, ids: ["folder-#{@folder1.id}", "file-#{@file1.id}"] }

View File

@ -94,9 +94,15 @@ class DmsfMailerTest < RedmineDmsf::Test::UnitTest
end
def test_get_notify_users
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
@file1.notify_deactivate