]> source.dussan.org Git - redmine.git/commitdiff
Merged r21142 to 4.1-stable (#35634).
authorMarius Balteanu <marius.balteanu@zitec.com>
Fri, 6 Aug 2021 07:00:56 +0000 (07:00 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Fri, 6 Aug 2021 07:00:56 +0000 (07:00 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/4.1-stable@21146 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/functional/attachments_controller_test.rb
test/functional/issues_controller_test.rb

index 12277b9ba1aa355b40368e7ce163e1c0c55d51ba..edd77b4cf127e25acbe9575ad5d1e371ca28255f 100644 (file)
@@ -201,6 +201,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?
index 7ffe2042339e0c951212ba3085c750daa2e164d4..ffd4ed954962dc15f623c9f832cba935b009b6c8 100644 (file)
@@ -676,4 +676,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
index 3491e0c2dfe5c086a67fed43ccad6782e15e3ec6..2e663c1c3a0e71e10fbafab9fbb121f509c0a791 100644 (file)
@@ -2687,6 +2687,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 :new, :params => {