Project

General

Profile

Actions

Defect #38668

closed

Unable to retrieve custom fields set as "For all projects" via Projects API

Added by Hirokazu Onozato 11 months ago. Updated 10 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
REST API
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Create a custom field for the Issue and check "For all projects".

When retrieving Issue custom fields in the Projects API, those with "For all projects" checked will not be retrieved.

<projects total_count="2" offset="0" limit="25" type="array">
  <project>
    <id>1</id>
    <name>a</name>
    <identifier>a</identifier>
    <description/>
    <status>1</status>
    <is_public>true</is_public>
    <inherit_members>false</inherit_members>
    <issue_custom_fields type="array">
      <custom_field id="2" name="Per Projects"/>
    </issue_custom_fields>
    <created_on>2023-06-07T09:45:45Z</created_on>
    <updated_on>2023-06-07T09:45:45Z</updated_on>
  </project>
  <project>
    <id>2</id>
    <name>b</name>
    <identifier>b</identifier>
    <description/>
    <status>1</status>
    <is_public>false</is_public>
    <inherit_members>false</inherit_members>
    <issue_custom_fields type="array"/>
    <created_on>2023-06-07T09:45:57Z</created_on>
    <updated_on>2023-06-07T09:45:57Z</updated_on>
  </project>
</projects>

I thought it should also be possible to retrieve those specified in "For all projects."
I have confirmed that the following modification will result in the intended behavior.


Files

clipboard-202306071920-mez0o.png (32.6 KB) clipboard-202306071920-mez0o.png Hirokazu Onozato, 2023-06-07 12:20
clipboard-202306071923-sjvfc.png (13.2 KB) clipboard-202306071923-sjvfc.png Hirokazu Onozato, 2023-06-07 12:23
projects_helper.rb.diff (594 Bytes) projects_helper.rb.diff Hirokazu Onozato, 2023-06-07 12:28

Related issues

Related to Redmine - Feature #33301: Add option to include enabled issue custom fields in projects#show API responseClosedGo MAEDA

Actions
Actions #1

Updated by Go MAEDA 10 months ago

  • Related to Feature #33301: Add option to include enabled issue custom fields in projects#show API response added
Actions #2

Updated by Go MAEDA 10 months ago

  • Status changed from New to Confirmed
  • Target version set to Candidate for next major release
Actions #3

Updated by Go MAEDA 10 months ago

  • Target version changed from Candidate for next major release to 5.1.0

The code below is a test for the suggested fix. Setting the target version to 5.1.0.

diff --git a/test/integration/api_test/projects_test.rb b/test/integration/api_test/projects_test.rb
index f0c1973cb..c32f7679b 100644
--- a/test/integration/api_test/projects_test.rb
+++ b/test/integration/api_test/projects_test.rb
@@ -86,11 +86,16 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
   end

   test "GET /projects.xml with include=issue_custom_fields should return custom fields" do
+    IssueCustomField.find(6).update_attribute :is_for_all, true
+    IssueCustomField.find(8).update_attribute :is_for_all, false
     get '/projects.xml?include=issue_custom_fields'
     assert_response :success
     assert_equal 'application/xml', @response.media_type

     assert_select 'issue_custom_fields[type=array] custom_field[name="Project 1 cf"]'
+    # Custom field for all projects
+    assert_select 'issue_custom_fields[type=array] custom_field[id="6"]'
+    assert_select 'issue_custom_fields[type=array] custom_field[id="8"]', 0
   end

   test "GET /projects/:id.xml should return the project" do
Actions #4

Updated by Go MAEDA 10 months ago

  • Subject changed from Custom field set in "For all projects" cannot be retrieved by the projects API to Unable to retrieve custom fields set as "For all projects" via Projects API
  • Status changed from Confirmed to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch. Thank you for your contribution.

Actions

Also available in: Atom PDF