Project

General

Profile

Defect #44152 ยป 0001-Return-visible-roles-for-all-role-aware-custom-field.patch

Go MAEDA, 2026-06-07 04:50

View differences:

app/controllers/custom_fields_controller.rb
34 34
          IssueCustomField.where(is_for_all: false).joins(:projects).group(:custom_field_id).count
35 35
      end
36 36
      format.api do
37
        @custom_fields = CustomField.all
37
        @custom_fields = CustomField.includes(:roles).all
38 38
      end
39 39
    end
40 40
  end
app/views/custom_fields/index.api.rsb
35 35
            api.tracker :id => tracker.id, :name => tracker.name
36 36
          end
37 37
        end
38
      end
39

  
40
      if %w(IssueCustomField TimeEntryCustomField ProjectCustomField VersionCustomField).include?(field.class.name)
38 41
        api.array :roles do
39 42
          field.roles.each do |role|
40 43
            api.role :id => role.id, :name => role.name
test/integration/api_test/custom_fields_test.rb
56 56
      assert_select "value:contains(?) + label:contains(?)", bar.id.to_s, 'Bar'
57 57
    end
58 58
  end
59

  
60
  test "GET /custom_fields.xml should include roles for custom fields visible by role" do
61
    custom_fields = [
62
      IssueCustomField.generate!(:visible => false, :role_ids => [1, 2]),
63
      TimeEntryCustomField.generate!(:visible => false, :role_ids => [1, 2]),
64
      ProjectCustomField.generate!(:visible => false, :role_ids => [1, 2]),
65
      VersionCustomField.generate!(:visible => false, :role_ids => [1, 2])
66
    ]
67

  
68
    get '/custom_fields.xml', :headers => credentials('admin')
69
    assert_response :success
70

  
71
    xml = Hash.from_xml(response.body)
72
    fields = xml['custom_fields']
73
    custom_fields.each do |custom_field|
74
      field = fields.detect {|f| f['id'] == custom_field.id.to_s}
75
      assert_kind_of Hash, field
76
      assert_kind_of Array, field['roles']
77
      roles = field['roles'].sort_by {|role| role['id'].to_i}
78
      assert_equal({'id' => '1', 'name' => 'Manager'}, roles[0])
79
      assert_equal({'id' => '2', 'name' => 'Developer'}, roles[1])
80
    end
81
  end
82

  
83
  test "GET /custom_fields.json should not include roles for custom fields that do not support role visibility" do
84
    custom_field = UserCustomField.generate!(:visible => false, :role_ids => [1, 2])
85

  
86
    get '/custom_fields.json', :headers => credentials('admin')
87
    assert_response :success
88

  
89
    json = ActiveSupport::JSON.decode(response.body)
90
    field = json['custom_fields'].detect {|f| f['id'] == custom_field.id}
91
    assert_kind_of Hash, field
92
    assert_not field.has_key?('roles')
93
  end
59 94
end
    (1-1/1)