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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Update project eagerloading wrapper custom field loading to check view_project_attributes permission
Dombi Attilae818d543d6d2
diff --git a/lib/api/v3/projects/project_eager_loading_wrapper.rb b/lib/api/v3/projects/project_eager_loading_wrapper.rbindex c096b34a413..f9f5379f484 100644--- a/lib/api/v3/projects/project_eager_loading_wrapper.rb+++ b/lib/api/v3/projects/project_eager_loading_wrapper.rb@@ -65,9 +65,11 @@ module APIdef custom_fields_from_projectsProjectCustomFieldProjectMapping- .eager_load(:project_custom_field)+ .eager_load(:project_custom_field, :project).merge(ProjectCustomField.visible).each_with_object(Hash.new { |h, k| h[k] = [] }) do |mapping, acc|+ next unless User.current.allowed_in_project?(:view_project_attributes, mapping.project)+acc[mapping.project_id] << mapping.project_custom_fieldendenddiff --git a/spec/requests/api/v3/projects/index_resource_spec.rb b/spec/requests/api/v3/projects/index_resource_spec.rbindex 479b229612b..a9cfc103f63 100644--- a/spec/requests/api/v3/projects/index_resource_spec.rb+++ b/spec/requests/api/v3/projects/index_resource_spec.rb@@ -408,10 +408,13 @@ RSpec.describe "API v3 Project resource index", content_type: :json docreate(:work_package, project: public_wp_share_project)endshared_let(:project_cf) do- create(:project_custom_field_project_mapping, project:).project_custom_field- end- shared_let(:other_cf) do- create(:project_custom_field_project_mapping, project: other_project).project_custom_field+ # This custom field is enabled in both project and other_project to test enabled+ # custom field state overflow between 2 projects.+ pcf = create(:project_custom_field_project_mapping, project:).project_custom_field+ create(:project_custom_field_project_mapping,+ project: other_project,+ project_custom_field: pcf)+ pcfendshared_let(:public_cf) docreate(:project_custom_field_project_mapping, project: public_project).project_custom_field@@ -468,7 +471,8 @@ RSpec.describe "API v3 Project resource index", content_type: :json do)end- it "does not return the project attributes for a private project without view_project_attributes" do+ it "does not return the project attributes for a private project without view_project_attributes " \+ "even if the same custom field is active in other_project" doexpect(subject).to be_json_eql(project.name.to_json).at_path("_embedded/elements/3/name")@@ -478,13 +482,14 @@ RSpec.describe "API v3 Project resource index", content_type: :json do)end- it "returns project attributes for other project with view_project_attributes" do+ it "returns project attributes for other project with view_project_attributes for the same " \+ "custom field enabled in the project too" doexpect(subject).to be_json_eql(other_project.name.to_json).at_path("_embedded/elements/4/name")expect(subject).to have_json_path(- "_embedded/elements/4/#{other_cf.attribute_name(:camel_case)}"+ "_embedded/elements/4/#{project_cf.attribute_name(:camel_case)}")endend