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

Restrict Project#all_available_custom_fields by the visible scope to apply the view_project_attributes permission on the Project schema api.

Dombi Attilad1560336cf0d
diff --git a/app/contracts/base_contract.rb b/app/contracts/base_contract.rb
index ba90a7b2eeb..e92d1326aae 100644
--- a/app/contracts/base_contract.rb
+++ b/app/contracts/base_contract.rb
@@ -234,7 +234,7 @@ class BaseContract < Disposable::Twin
# as the disabled custom fields would be treated as not-writable
#
# relevant especially for the project API
- model.all_available_custom_fields.map(&:attribute_name)
+ model.all_available_custom_fields.visible.map(&:attribute_name)
else
model.available_custom_fields.map(&:attribute_name)
end
diff --git a/app/models/project_custom_field.rb b/app/models/project_custom_field.rb
index f971d3381a7..1edccb4a227 100644
--- a/app/models/project_custom_field.rb
+++ b/app/models/project_custom_field.rb
@@ -52,14 +52,13 @@ class ProjectCustomField < CustomField
private
def mappings_with_view_project_attributes_permission(user)
- allowed_project_ids = Project.allowed_to(user, :view_project_attributes)
- .or(Project.public_projects)
- .select(:id).arel
+ allowed_projects = Project.allowed_to(user, :view_project_attributes)
+ .or(Project.public_projects)
mapping_table = ProjectCustomFieldProjectMapping.arel_table
mapping_table.project(Arel.star)
.where(
mapping_table[:custom_field_id].eq(arel_table[:id])
- .and(mapping_table[:project_id].in(allowed_project_ids))
+ .and(mapping_table[:project_id].in(allowed_projects.select(:id).arel))
)
end
end
diff --git a/app/models/projects/custom_fields.rb b/app/models/projects/custom_fields.rb
index 2bbac410817..7c042adb540 100644
--- a/app/models/projects/custom_fields.rb
+++ b/app/models/projects/custom_fields.rb
@@ -32,9 +32,11 @@ module Projects::CustomFields
attr_accessor :_limit_custom_fields_validation_to_section_id
included do
- has_many :project_custom_field_project_mappings, class_name: "ProjectCustomFieldProjectMapping", foreign_key: :project_id,
- dependent: :destroy, inverse_of: :project
- has_many :project_custom_fields, through: :project_custom_field_project_mappings, class_name: "ProjectCustomField"
+ has_many :project_custom_field_project_mappings, class_name: "ProjectCustomFieldProjectMapping",
+ foreign_key: :project_id, dependent: :destroy,
+ inverse_of: :project
+ has_many :project_custom_fields, through: :project_custom_field_project_mappings,
+ class_name: "ProjectCustomField"
def available_custom_fields
visible_fields = all_available_custom_fields.visible