@@ -548,13 +548,27 class Issue < ActiveRecord::Base | |||
|
548 | 548 | workflow_permissions = WorkflowPermission.where(:tracker_id => tracker_id, :old_status_id => status_id, :role_id => roles.map(&:id)).to_a |
|
549 | 549 | if workflow_permissions.any? |
|
550 | 550 | workflow_rules = workflow_permissions.inject({}) do |h, wp| |
|
551 |
h[wp.field_name] ||= |
|
|
552 |
h[wp.field_name] |
|
|
551 | h[wp.field_name] ||= {} | |
|
552 | h[wp.field_name][wp.role_id] = wp.rule | |
|
553 | 553 | h |
|
554 | 554 | end |
|
555 | fields_with_roles = {} | |
|
556 | IssueCustomField.where(:visible => false).joins(:roles).pluck(:id, "role_id").each do |field_id, role_id| | |
|
557 | fields_with_roles[field_id] ||= [] | |
|
558 | fields_with_roles[field_id] << role_id | |
|
559 | end | |
|
560 | roles.each do |role| | |
|
561 | fields_with_roles.each do |field_id, role_ids| | |
|
562 | unless role_ids.include?(role.id) | |
|
563 | field_name = field_id.to_s | |
|
564 | workflow_rules[field_name] ||= {} | |
|
565 | workflow_rules[field_name][role.id] = 'readonly' | |
|
566 | end | |
|
567 | end | |
|
568 | end | |
|
555 | 569 | workflow_rules.each do |attr, rules| |
|
556 | 570 | next if rules.size < roles.size |
|
557 | uniq_rules = rules.uniq | |
|
571 | uniq_rules = rules.values.uniq | |
|
558 | 572 | if uniq_rules.size == 1 |
|
559 | 573 | result[attr] = uniq_rules.first |
|
560 | 574 | else |
@@ -911,7 +911,7 class IssueTest < ActiveSupport::TestCase | |||
|
911 | 911 | assert_equal [], issue.required_attribute_names(user.reload) |
|
912 | 912 | |
|
913 | 913 | WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, |
|
914 |
:role_id => |
|
|
914 | :role_id => 3, :field_name => 'due_date', | |
|
915 | 915 | :rule => 'readonly') |
|
916 | 916 | # required + readonly => required |
|
917 | 917 | assert_equal %w(due_date), issue.required_attribute_names(user) |
@@ -941,6 +941,23 class IssueTest < ActiveSupport::TestCase | |||
|
941 | 941 | assert_equal %w(due_date), issue.read_only_attribute_names(user) |
|
942 | 942 | end |
|
943 | 943 | |
|
944 | # A field that is not visible by role 2 and readonly by role 1 should be readonly for user with role 1 and 2 | |
|
945 | def test_read_only_attribute_names_should_include_custom_fields_that_combine_readonly_and_not_visible_for_roles | |
|
946 | field = IssueCustomField.generate!( | |
|
947 | :is_for_all => true, :trackers => Tracker.all, :visible => false, :role_ids => [1] | |
|
948 | ) | |
|
949 | WorkflowPermission.delete_all | |
|
950 | WorkflowPermission.create!( | |
|
951 | :old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => field.id, :rule => 'readonly' | |
|
952 | ) | |
|
953 | user = User.generate! | |
|
954 | project = Project.find(1) | |
|
955 | User.add_to_project(user, project, Role.where(:id => [1, 2])) | |
|
956 | ||
|
957 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1) | |
|
958 | assert_equal [field.id.to_s], issue.read_only_attribute_names(user) | |
|
959 | end | |
|
960 | ||
|
944 | 961 | def test_workflow_rules_should_ignore_roles_without_issue_permissions |
|
945 | 962 | role = Role.generate! :permissions => [:view_issues, :edit_issues] |
|
946 | 963 | ignored_role = Role.generate! :permissions => [:view_issues] |
General Comments 0
You need to be logged in to leave comments.
Login now