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

fix[Op#57579]: stick to `select_custom_fields` perm check

Kabiru Mwenja179829e4df43
diff --git a/app/contracts/custom_fields/custom_field_projects/base_contract.rb b/app/contracts/custom_fields/custom_field_projects/base_contract.rb
index e2994ab423c..d2d260d1111 100644
--- a/app/contracts/custom_fields/custom_field_projects/base_contract.rb
+++ b/app/contracts/custom_fields/custom_field_projects/base_contract.rb
@@ -29,8 +29,6 @@
module CustomFields
module CustomFieldProjects
class BaseContract < ::ModelContract
- include RequiresAdminGuard
-
attribute :project_id
attribute :custom_field_id
@@ -47,7 +45,7 @@ module CustomFields
# Only mappings of custom fields which are not enabled for all projects can be manipulated by the user
return if model.custom_field.nil? || !model.custom_field.is_for_all?
- errors.add :custom_field_id, :cannot_delete_mapping
+ errors.add :custom_field_id, :is_for_all_cannot_modify
end
end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 558a0f7da02..97c02d8aeb1 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -884,6 +884,7 @@ en:
blank: "can't be blank."
blank_nested: "needs to have the property '%{property}' set."
cannot_delete_mapping: "is required. Cannot be deleted."
+ is_for_all_cannot_modify: "is for all. Cannot be modified."
cant_link_a_work_package_with_a_descendant: "A work package cannot be linked to one of its subtasks."
circular_dependency: "This relation would create a circular dependency."
confirmation: "doesn't match %{attribute}."
diff --git a/spec/contracts/custom_fields/custom_field_projects/base_contract_spec.rb b/spec/contracts/custom_fields/custom_field_projects/base_contract_spec.rb
index a63f7428635..56d18778163 100644
--- a/spec/contracts/custom_fields/custom_field_projects/base_contract_spec.rb
+++ b/spec/contracts/custom_fields/custom_field_projects/base_contract_spec.rb
@@ -42,13 +42,25 @@ RSpec.describe CustomFields::CustomFieldProjects::BaseContract do
let(:custom_field) { build_stubbed(:custom_field, is_for_all: true) }
let(:custom_field_project) { build_stubbed(:custom_fields_project, custom_field:) }
- it_behaves_like "contract is invalid"
+ it_behaves_like "contract is invalid", custom_field_id: :is_for_all_cannot_modify
end
- context "with non-admin user" do
+ context "with authorised user" do
let(:user) { build_stubbed(:user) }
- it_behaves_like "contract is invalid", base: %i[error_unauthorized error_unauthorized]
+ before do
+ mock_permissions_for(user) do |mock|
+ mock.allow_in_project(:select_custom_fields, project: custom_field_project.project)
+ end
+ end
+
+ it_behaves_like "contract is valid"
+ end
+
+ context "with unauthorised user" do
+ let(:user) { build_stubbed(:user) }
+
+ it_behaves_like "contract is invalid", base: :error_unauthorized
end
include_examples "contract reuses the model errors"