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

Check projects available custom fields for view_project_attributes permission

Dombi Attila308cc4a26904
diff --git a/app/models/project_custom_field.rb b/app/models/project_custom_field.rb
index b8ccfe02ce6..b8aa73aba1b 100644
--- a/app/models/project_custom_field.rb
+++ b/app/models/project_custom_field.rb
@@ -42,25 +42,11 @@ class ProjectCustomField < CustomField
def visible(user = User.current)
if user.admin?
all
- elsif user.allowed_in_any_project?(:select_project_custom_fields) || user.allowed_globally?(:add_project)
- where(visible: true)
else
- where(visible: true).where(mappings_with_view_project_attributes_permission(user).exists)
+ where(visible: true)
end
end
- private
-
- def mappings_with_view_project_attributes_permission(user)
- allowed_projects = Project.allowed_to(user, :view_project_attributes)
-
- 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_projects.select(:id).arel))
- )
- end
end
def type_name
diff --git a/app/models/projects/custom_fields.rb b/app/models/projects/custom_fields.rb
index 92be68bbd5c..4b9161175a6 100644
--- a/app/models/projects/custom_fields.rb
+++ b/app/models/projects/custom_fields.rb
@@ -41,8 +41,12 @@ module Projects::CustomFields
def available_custom_fields
return all_visible_custom_fields if new_record?
- all_visible_custom_fields.where(id: project_custom_field_project_mappings.select(:custom_field_id))
- .or(ProjectCustomField.required)
+ if User.current.allowed_in_project?(:view_project_attributes, self)
+ all_visible_custom_fields.where(id: project_custom_field_project_mappings.select(:custom_field_id))
+ .or(ProjectCustomField.required)
+ else
+ all_visible_custom_fields.none
+ end
end
# Note: