]> source.dussan.org Git - redmine.git/commitdiff
Merged r21937 from trunk to 4.2-stable (#37685).
authorGo MAEDA <maeda@farend.jp>
Mon, 7 Nov 2022 02:43:15 +0000 (02:43 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 7 Nov 2022 02:43:15 +0000 (02:43 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/4.2-stable@21954 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/issues_helper.rb
test/functional/issues_controller_test.rb

index b8e1dd4140a1559c158f30db879c0fc022578f33..4ca0cbbd18e510a19a6e48e0b3b86ac15a40b6df 100644 (file)
@@ -750,12 +750,18 @@ module IssuesHelper
   end
 
   def projects_for_select(issue)
-    if issue.parent_issue_id.present?
-      issue.allowed_target_projects_for_subtask(User.current)
-    elsif @project && issue.new_record? && !issue.copy?
-      issue.allowed_target_projects(User.current, 'tree')
+    projects =
+      if issue.parent_issue_id.present?
+        issue.allowed_target_projects_for_subtask(User.current)
+      elsif @project && issue.new_record? && !issue.copy?
+        issue.allowed_target_projects(User.current, 'tree')
+      else
+        issue.allowed_target_projects(User.current)
+      end
+    if issue.read_only_attribute_names(User.current).include?('project_id')
+      params['project_id'].present? ? Project.where(identifier: params['project_id']) : projects
     else
-      issue.allowed_target_projects(User.current)
+      projects
     end
   end
 end
index 59d071b0a43a6318b556e4a9749666dc21072d21..3e454ffd272a9729afcd9f08649a113b490a5079 100644 (file)
@@ -5586,6 +5586,26 @@ class IssuesControllerTest < Redmine::ControllerTest
     assert_select 'select[name=?]', 'issue[project_id]', 0
   end
 
+  def test_new_should_hide_project_if_user_is_not_allowed_to_change_project_in_hierarchy_projects
+    WorkflowPermission.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1,
+                               :field_name => 'project_id', :rule => 'readonly')
+
+    @request.session[:user_id] = 2
+    get(:new, :params => { :tracker_id => 1, :project_id => 1 })
+    assert_response :success
+    assert_select 'select[name=?]', 'issue[project_id]', 0
+  end
+
+  def test_new_should_show_project_if_user_is_not_allowed_to_change_project_global_new_issue
+    WorkflowPermission.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1,
+                               :field_name => 'project_id', :rule => 'readonly')
+
+    @request.session[:user_id] = 2
+    get(:new, :params => { :tracker_id => 1})
+    assert_response :success
+    assert_select 'select[name=?]', 'issue[project_id]'
+  end
+
   def test_edit_should_not_hide_project_when_user_changes_the_project_even_if_project_is_readonly_on_target_project
     WorkflowPermission.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1,
                                :field_name => 'project_id', :rule => 'readonly')