Project

General

Profile

Feature #44153 ยป 0001-Add-projects-to-issue-custom-fields-API-response.patch

Go MAEDA, 2026-06-07 10:25

View differences:

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.includes(:roles).all
@custom_fields = CustomField.includes(:roles).all.to_a
issue_custom_fields = @custom_fields.grep(IssueCustomField)
ActiveRecord::Associations::Preloader.new(
records: issue_custom_fields,
associations: [:projects, :trackers]
).call
end
end
end
app/views/custom_fields/index.api.rsb
api.min_length field.min_length
api.max_length field.max_length
api.is_required field.is_required?
api.is_for_all field.is_for_all?
api.is_filter field.is_filter?
api.searchable field.searchable
api.multiple field.multiple?
......
end
if field.is_a?(IssueCustomField)
api.array :projects do
field.projects.each do |project|
api.project :id => project.id, :name => project.name
end
end
api.array :trackers do
field.trackers.each do |tracker|
api.tracker :id => tracker.id, :name => tracker.name
test/integration/api_test/custom_fields_test.rb
assert_select 'description', :text => 'Select one of the databases'
assert_select 'id', :text => '2'
assert_select 'customized_type', :text => 'issue'
assert_select 'is_for_all', :text => 'true'
assert_select 'possible_values[type=array]' do
assert_select 'possible_value>value', :text => 'PostgreSQL'
assert_select 'possible_value>label', :text => 'PostgreSQL'
end
assert_select 'projects[type=array]'
assert_select 'trackers[type=array]'
assert_select 'roles[type=array]'
assert_select 'visible', :text => 'true'
......
end
end
test "GET /custom_fields.xml should include projects for issue custom fields limited to projects" do
get '/custom_fields.xml', :headers => credentials('admin')
assert_response :success
xml = Hash.from_xml(response.body)
field = xml['custom_fields'].detect {|f| f['id'] == '9'}
assert_kind_of Hash, field
assert_equal 'false', field['is_for_all']
assert_kind_of Array, field['projects']
assert_equal [{'id' => '1', 'name' => 'eCookbook'}], field['projects']
end
test "GET /custom_fields.xml should include empty projects for issue custom fields for all projects" do
get '/custom_fields.xml', :headers => credentials('admin')
assert_response :success
xml = Hash.from_xml(response.body)
field = xml['custom_fields'].detect {|f| f['id'] == '1'}
assert_kind_of Hash, field
assert_equal 'true', field['is_for_all']
assert_equal [], field['projects']
end
test "GET /custom_fields.xml should not include projects for custom fields that are not issue custom fields" do
get '/custom_fields.xml', :headers => credentials('admin')
assert_response :success
xml = Hash.from_xml(response.body)
field = xml['custom_fields'].detect {|f| f['id'] == '3'}
assert_kind_of Hash, field
assert_not field.has_key?('projects')
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]),
    (1-1/1)