Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Address CR comments.

Dombi Attila43f612f1d119
diff --git a/docs/api/apiv3/components/schemas/projects_schema_model.yml b/docs/api/apiv3/components/schemas/projects_schema_model.yml
index f920c6e9ea4..4e2cf39eaa7 100644
--- a/docs/api/apiv3/components/schemas/projects_schema_model.yml
+++ b/docs/api/apiv3/components/schemas/projects_schema_model.yml
@@ -21,6 +21,9 @@ properties:
type: string
enum: [ProjectFormCustomFieldSection]
description: The type identifier for this resource
+ id:
+ type: integer
+ description: The unique identifier of the custom field section
name:
type: string
description: The human-readable name of the custom field section
diff --git a/docs/development/concepts/resource-schemas/README.md b/docs/development/concepts/resource-schemas/README.md
index fb3fe11f487..b430db4831f 100644
--- a/docs/development/concepts/resource-schemas/README.md
+++ b/docs/development/concepts/resource-schemas/README.md
@@ -72,10 +72,10 @@ This results in work package schemas being defined per project and type combinat
An exemplary schema response on the Community for the OpenProject project (`ID=14`) and the Bug type (`ID=1`) is [community.openproject.org/api/v3/work_packages/schemas/14-1](https://community.openproject.org/api/v3/work_packages/schemas/14-1)
-The work package schema also contains the reference to the attribute groups from the form configuration in the `_attributeGroups` property.
-
-The project schema also contains the reference the project attribute sections and their project attributes in the `_attributeGroups` property.
+Work package and project schemas contain references to their respective attribute groups in the `_attributeGroups` property:
+- Work package schemas reference attribute groups from the form configuration
+- Project schemas reference project attribute sections and their project attributes
## Frontend usage
diff --git a/lib/api/v3/projects/schemas/project_custom_field_section_representer.rb b/lib/api/v3/projects/schemas/project_custom_field_section_representer.rb
index c73a92e6b5c..0f86302c85b 100644
--- a/lib/api/v3/projects/schemas/project_custom_field_section_representer.rb
+++ b/lib/api/v3/projects/schemas/project_custom_field_section_representer.rb
@@ -33,6 +33,9 @@ module API
module Projects
module Schemas
class ProjectCustomFieldSectionRepresenter < ::API::Decorators::Single
+ property :id,
+ exec_context: :decorator
+
property :name,
exec_context: :decorator
@@ -43,7 +46,7 @@ module API
"ProjectFormCustomFieldSection"
end
- delegate :name, to: :represented
+ delegate :id, :name, to: :represented
def attributes
represented.custom_fields.map do |cf|
@@ -51,8 +54,8 @@ module API
end
end
- def convert_property(attribute)
- ::API::Utilities::PropertyNameConverter.from_ar_name(attribute)
+ def convert_property(attribute_name)
+ ::API::Utilities::PropertyNameConverter.from_ar_name(attribute_name)
end
end
end
diff --git a/lib/api/v3/projects/schemas/project_schema_representer.rb b/lib/api/v3/projects/schemas/project_schema_representer.rb
index d2744a762c6..b9e412d592c 100644
--- a/lib/api/v3/projects/schemas/project_schema_representer.rb
+++ b/lib/api/v3/projects/schemas/project_schema_representer.rb
@@ -113,7 +113,6 @@ module API
# However caching is still applied further down in the `section_representation` method.
property :attribute_groups,
name_source: ->(*) { I18n.t("activerecord.attributes.project.attribute_groups") },
- type: "[]String",
as: "_attributeGroups",
exec_context: :decorator,
uncacheable: true
@@ -122,13 +121,6 @@ module API
def represented_class
::Project
end
-
- def attribute_group(property)
- lambda do
- key = property.to_s
- attribute_group_map key
- end
- end
end
def attribute_groups
@@ -137,20 +129,6 @@ module API
end
end
- ##
- # Return a map of attribute => group name
- def attribute_group_map(key)
- return nil if project_custom_field_sections.empty?
-
- @attribute_group_map ||= project_custom_field_sections.each_with_object({}) do |section, hash|
- section.custom_fields.each do |cf|
- hash[cf.attribute_name(:camel_case)] = section.name
- end
- end
-
- @attribute_group_map[key]
- end
-
private
def project_custom_field_sections
@@ -164,9 +142,8 @@ module API
def section_representation(section)
OpenProject::Cache.fetch(*section_cache_key(section)) do
- ::JSON::parse(::API::V3::Projects::Schemas::ProjectCustomFieldSectionRepresenter
- .new(section, current_user:, embed_links: true)
- .to_json)
+ ::API::V3::Projects::Schemas::ProjectCustomFieldSectionRepresenter
+ .new(section, current_user:)
end
end
diff --git a/spec/lib/api/v3/projects/schemas/project_schema_representer_spec.rb b/spec/lib/api/v3/projects/schemas/project_schema_representer_spec.rb
index 287e076df1a..498d9cbdc85 100644
--- a/spec/lib/api/v3/projects/schemas/project_schema_representer_spec.rb
+++ b/spec/lib/api/v3/projects/schemas/project_schema_representer_spec.rb
@@ -131,13 +131,16 @@ RSpec.describe API::V3::Projects::Schemas::ProjectSchemaRepresenter do
it "renders section attribute group elements of the schema" do
expect(subject)
.to be_json_eql(
- {
- _type: "ProjectFormCustomFieldSection",
- name: "Common Project Attributes",
- attributes: ["customField#{user_custom_field.id}"]
- }.to_json
+ [
+ {
+ _type: "ProjectFormCustomFieldSection",
+ id: user_section.id,
+ name: "Common Project Attributes",
+ attributes: ["customField#{user_custom_field.id}"]
+ }
+ ].to_json
)
- .at_path("_attributeGroups/0")
+ .at_path("_attributeGroups")
end
end
@@ -147,23 +150,22 @@ RSpec.describe API::V3::Projects::Schemas::ProjectSchemaRepresenter do
it "renders section attribute group elements of the schema" do
expect(subject)
.to be_json_eql(
- {
- _type: "ProjectFormCustomFieldSection",
- name: "Common Project Attributes",
- attributes: ["customField#{user_custom_field.id}"]
- }.to_json
+ [
+ {
+ _type: "ProjectFormCustomFieldSection",
+ id: user_section.id,
+ name: "Common Project Attributes",
+ attributes: ["customField#{user_custom_field.id}"]
+ },
+ {
+ _type: "ProjectFormCustomFieldSection",
+ id: admin_section.id,
+ name: "Admin Project Attributes",
+ attributes: ["customField#{admin_custom_field.id}"]
+ }
+ ].to_json
)
- .at_path("_attributeGroups/0")
-
- expect(subject)
- .to be_json_eql(
- {
- _type: "ProjectFormCustomFieldSection",
- name: "Admin Project Attributes",
- attributes: ["customField#{admin_custom_field.id}"]
- }.to_json
- )
- .at_path("_attributeGroups/1")
+ .at_path("_attributeGroups")
end
end
end