Defect #44152 ยป 0001-Return-visible-roles-for-all-role-aware-custom-field.patch
| app/controllers/custom_fields_controller.rb | ||
|---|---|---|
|
IssueCustomField.where(is_for_all: false).joins(:projects).group(:custom_field_id).count
|
||
|
end
|
||
|
format.api do
|
||
|
@custom_fields = CustomField.all
|
||
|
@custom_fields = CustomField.includes(:roles).all
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| app/views/custom_fields/index.api.rsb | ||
|---|---|---|
|
api.tracker :id => tracker.id, :name => tracker.name
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
if %w(IssueCustomField TimeEntryCustomField ProjectCustomField VersionCustomField).include?(field.class.name)
|
||
|
api.array :roles do
|
||
|
field.roles.each do |role|
|
||
|
api.role :id => role.id, :name => role.name
|
||
| test/integration/api_test/custom_fields_test.rb | ||
|---|---|---|
|
assert_select "value:contains(?) + label:contains(?)", bar.id.to_s, 'Bar'
|
||
|
end
|
||
|
end
|
||
|
test "GET /custom_fields.xml should include roles for custom fields visible by role" do
|
||
|
custom_fields = [
|
||
|
IssueCustomField.generate!(:visible => false, :role_ids => [1, 2]),
|
||
|
TimeEntryCustomField.generate!(:visible => false, :role_ids => [1, 2]),
|
||
|
ProjectCustomField.generate!(:visible => false, :role_ids => [1, 2]),
|
||
|
VersionCustomField.generate!(:visible => false, :role_ids => [1, 2])
|
||
|
]
|
||
|
get '/custom_fields.xml', :headers => credentials('admin')
|
||
|
assert_response :success
|
||
|
xml = Hash.from_xml(response.body)
|
||
|
fields = xml['custom_fields']
|
||
|
custom_fields.each do |custom_field|
|
||
|
field = fields.detect {|f| f['id'] == custom_field.id.to_s}
|
||
|
assert_kind_of Hash, field
|
||
|
assert_kind_of Array, field['roles']
|
||
|
roles = field['roles'].sort_by {|role| role['id'].to_i}
|
||
|
assert_equal({'id' => '1', 'name' => 'Manager'}, roles[0])
|
||
|
assert_equal({'id' => '2', 'name' => 'Developer'}, roles[1])
|
||
|
end
|
||
|
end
|
||
|
test "GET /custom_fields.json should not include roles for custom fields that do not support role visibility" do
|
||
|
custom_field = UserCustomField.generate!(:visible => false, :role_ids => [1, 2])
|
||
|
get '/custom_fields.json', :headers => credentials('admin')
|
||
|
assert_response :success
|
||
|
json = ActiveSupport::JSON.decode(response.body)
|
||
|
field = json['custom_fields'].detect {|f| f['id'] == custom_field.id}
|
||
|
assert_kind_of Hash, field
|
||
|
assert_not field.has_key?('roles')
|
||
|
end
|
||
|
end
|
||