From 69a0251bc24a898db6724e88b3a7a3ff3d232e09 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Fri, 6 Aug 2021 06:59:45 +0000 Subject: [PATCH] Merged r21142 to 4.2-stable (#35634). git-svn-id: http://svn.redmine.org/redmine/branches/4.2-stable@21144 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 5 +++++ .../functional/attachments_controller_test.rb | 21 +++++++++++++++++++ test/functional/issues_controller_test.rb | 13 ++++++++++++ 3 files changed, 39 insertions(+) diff --git a/app/models/issue.rb b/app/models/issue.rb index e5bb30e25..c258065b2 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -209,6 +209,11 @@ class Issue < ActiveRecord::Base user_tracker_permission?(user, :delete_issues) end + # Overrides Redmine::Acts::Attachable::InstanceMethods#attachments_deletable? + def attachments_deletable?(user=User.current) + attributes_editable?(user) + end + def initialize(attributes=nil, *args) super if new_record? diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index e7f6d3a2f..08ebe25bf 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -744,4 +744,25 @@ class AttachmentsControllerTest < Redmine::ControllerTest assert_response 302 assert Attachment.find_by_id(3) end + + def test_destroy_issue_attachment_by_user_without_edit_issue_permission_on_tracker + role = Role.find(2) + role.set_permission_trackers 'edit_issues', [2, 3] + role.save! + + @request.session[:user_id] = 2 + + set_tmp_attachments_directory + assert_no_difference 'Attachment.count' do + delete( + :destroy, + :params => { + :id => 7 + } + ) + end + + assert_response 403 + assert Attachment.find_by_id(7) + end end diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 618454005..686c617a2 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -3161,6 +3161,19 @@ class IssuesControllerTest < Redmine::ControllerTest assert_select 'div.attachments .icon-edit', 0 end + def test_show_should_not_display_delete_attachment_icon_for_user_without_edit_issue_permission_on_tracker + role = Role.find(2) + role.set_permission_trackers 'edit_issues', [2, 3] + role.save! + + @request.session[:user_id] = 2 + + get :show, params: {id: 4} + + assert_response :success + assert_select 'div.attachments .icon-del', 0 + end + def test_get_new @request.session[:user_id] = 2 get( -- 2.39.5