]> source.dussan.org Git - redmine.git/commitdiff
Merged r19975 from trunk to 4.0-stable (#33689).
authorGo MAEDA <maeda@farend.jp>
Sat, 15 Aug 2020 07:49:52 +0000 (07:49 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 15 Aug 2020 07:49:52 +0000 (07:49 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/4.0-stable@19979 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/functional/issues_controller_test.rb
test/unit/issue_test.rb

index dad03e39b6560b1ddd77d30601a0b24208ba4339..4e0c7a4923aadc07890a6922509e95ce0594b926 100644 (file)
@@ -465,7 +465,6 @@ class Issue < ActiveRecord::Base
     'custom_field_values',
     'custom_fields',
     'lock_version',
-    'notes',
     :if => lambda {|issue, user| issue.new_record? || issue.attributes_editable?(user) }
 
   safe_attributes 'notes',
index 81312123c07cfe00298493f64586510152f79fa6..38bf87ce3d9e790d1bb294ce3c731e10e7154268 100644 (file)
@@ -4917,6 +4917,24 @@ class IssuesControllerTest < Redmine::ControllerTest
     assert_equal spent_hours_before + 2.5, issue.spent_hours
   end
 
+  def test_put_update_should_check_add_issue_notes_permission
+    role = Role.find(1)
+    role.remove_permission! :add_issue_notes
+    @request.session[:user_id] = 2
+
+    assert_no_difference 'Journal.count' do
+      put(
+        :update,
+        :params => {
+          :id => 1,
+          :issue => {
+            :notes => 'New note'
+          }
+        }
+      )
+    end
+  end
+
   def test_put_update_should_preserve_parent_issue_even_if_not_visible
     parent = Issue.generate!(:project_id => 1, :is_private => true)
     issue = Issue.generate!(:parent_issue_id => parent.id)
index 432dd8745c6964cd45756d3565cb07bee26de8ed..f6a945f12fe31e59182e81384cd541d58845f707 100644 (file)
@@ -873,6 +873,23 @@ class IssueTest < ActiveSupport::TestCase
     assert_equal Date.parse('2012-07-14'), issue.due_date
   end
 
+  def test_safe_attributes_notes_should_check_add_issue_notes_permission
+    # With add_issue_notes permission
+    user = User.find(2)
+    issue = Issue.new(:project => Project.find(1))
+    issue.init_journal(user)
+    issue.send :safe_attributes=, {'notes' => 'note'}, user
+    assert_equal 'note', issue.notes
+
+    # Without add_issue_notes permission
+    Role.find(1).remove_permission!(:add_issue_notes)
+    issue = Issue.new(:project => Project.find(1))
+    user.reload
+    issue.init_journal(user)
+    issue.send :safe_attributes=, {'notes' => 'note'}, user
+    assert_equal '', issue.notes
+  end
+
   def test_safe_attributes_should_accept_target_tracker_enabled_fields
     source = Tracker.find(1)
     source.core_fields = []