From 68c7f4ef208524e0c9f866cebac4ba349b944b23 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 16 Dec 2016 08:32:35 +0000 Subject: [PATCH] Workflow editing shows statuses of irrelevant roles (#24281). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@16081 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/workflows_controller.rb | 6 +++++- test/functional/workflows_controller_test.rb | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/controllers/workflows_controller.rb b/app/controllers/workflows_controller.rb index e825171bf..dd75860ff 100644 --- a/app/controllers/workflows_controller.rb +++ b/app/controllers/workflows_controller.rb @@ -138,7 +138,11 @@ class WorkflowsController < ApplicationController def find_statuses @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) if @trackers && @used_statuses_only - @statuses = @trackers.map(&:issue_statuses).flatten.uniq.sort.presence + role_ids = Role.all.select(&:consider_workflow?).map(&:id) + status_ids = WorkflowTransition.where( + :tracker_id => @trackers.map(&:id), :role_id => role_ids + ).uniq.pluck(:old_status_id, :new_status_id).flatten.uniq + @statuses = IssueStatus.where(:id => status_ids).sorted.to_a.presence end @statuses ||= IssueStatus.sorted.to_a end diff --git a/test/functional/workflows_controller_test.rb b/test/functional/workflows_controller_test.rb index d70a79896..c22224e3b 100644 --- a/test/functional/workflows_controller_test.rb +++ b/test/functional/workflows_controller_test.rb @@ -59,6 +59,25 @@ class WorkflowsControllerTest < Redmine::ControllerTest assert_select 'input[type=checkbox][name=?]', 'transitions[1][1][always]', 0 end + def test_get_edit_with_role_and_tracker_should_not_include_statuses_from_roles_without_workflow_permissions + WorkflowTransition.delete_all + WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) + + reporter = Role.find(3) + reporter.remove_permission! :edit_issues + reporter.remove_permission! :add_issues + assert !reporter.consider_workflow? + WorkflowTransition.create!(:role_id => 3, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5) + + get :edit, :params => {:role_id => 2, :tracker_id => 1} + assert_response :success + + # statuses 1 and 5 not displayed + statuses = IssueStatus.where(:id => [2, 3]).sorted.pluck(:name) + assert_equal ["New issue"] + statuses, + css_select('table.workflows.transitions-always tbody tr td:first').map(&:text).map(&:strip) + end + def test_get_edit_should_include_allowed_statuses_for_new_issues WorkflowTransition.delete_all WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 0, :new_status_id => 1) -- 2.39.5