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
turn scope and label unwritable
ulfertse003ad0af788
diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 4ea70c7863b..12d6a8a1ef4 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -497,7 +497,7 @@ en:could_not_be_copied: "could not be (fully) copied."does_not_exist: "does not exist."error_unauthorized: "may not be accessed."- error_readonly: "is not writable."+ error_readonly: "was attempted to be written but is not writable."empty: "can't be empty."even: "must be even."exclusion: "is reserved."@@ -2652,7 +2652,6 @@ en:estimated_hours: "Estimated hours cannot be set on parent work packages."invalid_user_assigned_to_work_package: "The chosen user is not allowed to be '%{property}' for this work package."start_date: "Start date cannot be set on parent work packages."- writing_read_only_attributes: "You must not write a read-only attribute."resources:schema: 'Schema'diff --git a/lib/api/errors/error_base.rb b/lib/api/errors/error_base.rbindex 404cc2e6a1b..5827ec5946c 100644--- a/lib/api/errors/error_base.rb+++ b/lib/api/errors/error_base.rb@@ -89,7 +89,7 @@ module APIapi_attribute_name = ::API::Utilities::PropertyNameConverter.from_ar_name(attribute)errors.symbols_and_messages_for(attribute).each do |symbol, full_message, _|api_errors << if symbol == :error_readonly- ::API::Errors::UnwritableProperty.new(api_attribute_name)+ ::API::Errors::UnwritableProperty.new(api_attribute_name, full_message)else::API::Errors::Validation.new(api_attribute_name, full_message)enddiff --git a/lib/api/errors/unwritable_property.rb b/lib/api/errors/unwritable_property.rbindex ea90f2737f1..21a423d33ac 100644--- a/lib/api/errors/unwritable_property.rb+++ b/lib/api/errors/unwritable_property.rb@@ -33,8 +33,8 @@ module APIidentifier 'urn:openproject-org:api:v3:errors:PropertyIsReadOnly'code 422- def initialize(property)- super I18n.t('api_v3.errors.writing_read_only_attributes')+ def initialize(property, message)+ super message@property = property@details = { attribute: property }diff --git a/modules/bcf/app/contracts/bcf/issues/base_contract.rb b/modules/bcf/app/contracts/bcf/issues/base_contract.rbindex a4862671cf4..76a0e696de7 100644--- a/modules/bcf/app/contracts/bcf/issues/base_contract.rb+++ b/modules/bcf/app/contracts/bcf/issues/base_contract.rb@@ -32,8 +32,6 @@ module Bcf::Issuesclass BaseContract < ::ModelContractattribute :uuidattribute :work_package- attribute :stage- attribute :labelsattribute :indexdef validatediff --git a/modules/bcf/spec/contracts/bcf/issues/shared_contract_examples.rb b/modules/bcf/spec/contracts/bcf/issues/shared_contract_examples.rbindex 0545f15d934..d44560ac17f 100644--- a/modules/bcf/spec/contracts/bcf/issues/shared_contract_examples.rb+++ b/modules/bcf/spec/contracts/bcf/issues/shared_contract_examples.rb@@ -51,8 +51,8 @@ shared_examples_for 'issues contract' doidend- let(:issue_stage) { 'some stage' }- let(:issue_labels) { %w(some labels) }+ let(:issue_stage) { nil }+ let(:issue_labels) { [] }let(:issue_index) { 8 }before do@@ -105,10 +105,20 @@ shared_examples_for 'issues contract' doit_behaves_like 'is valid'end- context 'if labels is nil' do- let(:issue_labels) { nil }+ context 'if the stage is written' do+ let(:issue_stage) { 'some stage' }- it_behaves_like 'is valid'+ it 'is invalid' do+ expect_valid(false, stage: %i(error_readonly))+ end+ end++ context 'if labels is written' do+ let(:issue_labels) { %w(some labels) }++ it 'is invalid' do+ expect_valid(false, labels: %i(error_readonly))+ endendcontext 'if index is nil' dodiff --git a/modules/bcf/spec/requests/api/bcf/v2_1/projects_api_spec.rb b/modules/bcf/spec/requests/api/bcf/v2_1/projects_api_spec.rbindex 405fe340610..57ae5e2edcd 100644--- a/modules/bcf/spec/requests/api/bcf/v2_1/projects_api_spec.rb+++ b/modules/bcf/spec/requests/api/bcf/v2_1/projects_api_spec.rb@@ -119,7 +119,7 @@ describe 'BCF 2.1 projects resource', type: :request, content_type: :json doendit_behaves_like 'bcf api unprocessable response' do- let(:message) { 'You must not write a read-only attribute.' }+ let(:message) { 'ID was attempted to be written but is not writable.' }endendenddiff --git a/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rb b/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rbindex 4d539479288..f949708d8d9 100644--- a/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rb+++ b/modules/bcf/spec/requests/api/bcf/v2_1/topics_api_spec.rb@@ -199,8 +199,8 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_maFactoryBot.create(:default_priority)endlet(:description) { 'some description' }- let(:stage) { 'current stage' }- let(:labels) { %w(some labels) }+ let(:stage) { nil }+ let(:labels) { [] }let(:index) { 5 }let(:params) do{@@ -237,15 +237,15 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_malabels: labels,index: index,reference_links: [- api_v3_paths.work_package(work_package.id)+ api_v3_paths.work_package(work_package&.id)],assigned_to: view_only_user.mail,due_date: Date.today.iso8601,stage: stage,creation_author: edit_member_user.mail,- creation_date: work_package.created_at.iso8601,+ creation_date: work_package&.created_at&.iso8601,modified_author: edit_member_user.mail,- modified_date: work_package.updated_at.iso8601,+ modified_date: work_package&.updated_at&.iso8601,description: description}end@@ -273,15 +273,15 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_malabels: [],index: nil,reference_links: [- api_v3_paths.work_package(work_package.id)+ api_v3_paths.work_package(work_package&.id)],assigned_to: nil,due_date: nil,stage: nil,creation_author: edit_member_user.mail,- creation_date: work_package.created_at.iso8601,+ creation_date: work_package&.created_at&.iso8601,modified_author: edit_member_user.mail,- modified_date: work_package.updated_at.iso8601,+ modified_date: work_package&.updated_at&.iso8601,description: nil}end@@ -376,5 +376,35 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_maendendend++ context 'with a label' do+ let(:params) do+ {+ title: 'Some title',+ labels: ['some label']+ }+ end++ it_behaves_like 'bcf api unprocessable response' do+ let(:message) do+ "Labels was attempted to be written but is not writable."+ end+ end+ end++ context 'with a stage' do+ let(:params) do+ {+ title: 'Some title',+ stage: 'some stage'+ }+ end++ it_behaves_like 'bcf api unprocessable response' do+ let(:message) do+ "Stage was attempted to be written but is not writable."+ end+ end+ endendenddiff --git a/modules/boards/spec/requests/api/v3/grids/grids_resource_spec.rb b/modules/boards/spec/requests/api/v3/grids/grids_resource_spec.rbindex c453a2e7a1a..1d9d0567e08 100644--- a/modules/boards/spec/requests/api/v3/grids/grids_resource_spec.rb+++ b/modules/boards/spec/requests/api/v3/grids/grids_resource_spec.rb@@ -288,21 +288,7 @@ describe 'API v3 Grids resource for Board Grids', type: :request, content_type:}.with_indifferent_accessend- it 'responds with 422 and mentions the error' do- expect(subject.status).to eq 422-- expect(subject.body)- .to be_json_eql('Error'.to_json)- .at_path('_type')-- expect(subject.body)- .to be_json_eql("You must not write a read-only attribute.".to_json)- .at_path('message')-- expect(subject.body)- .to be_json_eql("scope".to_json)- .at_path('_embedded/details/attribute')- end+ it_behaves_like 'read-only violation', 'scope', Boards::Gridendcontext 'with the grid not existing' dodiff --git a/modules/boards/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb b/modules/boards/spec/requests/api/v3/grids/grids_update_form_resource_spec.rbindex acb3870450a..52d9d576ef8 100644--- a/modules/boards/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb+++ b/modules/boards/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb@@ -121,7 +121,7 @@ describe "PATCH /api/v3/grids/:id/form for Board Grids", type: :request, contentit 'has a validation error on scope as the value is not writeable' doexpect(subject.body)- .to be_json_eql("You must not write a read-only attribute.".to_json)+ .to be_json_eql("Scope was attempted to be written but is not writable.".to_json).at_path('_embedded/validationErrors/scope/message')endenddiff --git a/modules/my_page/spec/requests/api/v3/grids/grids_resource_spec.rb b/modules/my_page/spec/requests/api/v3/grids/grids_resource_spec.rbindex 959e55b5a85..5948901d069 100644--- a/modules/my_page/spec/requests/api/v3/grids/grids_resource_spec.rb+++ b/modules/my_page/spec/requests/api/v3/grids/grids_resource_spec.rb@@ -277,21 +277,7 @@ describe 'API v3 Grids resource', type: :request, content_type: :json do}.with_indifferent_accessend- it 'responds with 422 and mentions the error' do- expect(subject.status).to eq 422-- expect(subject.body)- .to be_json_eql('Error'.to_json)- .at_path('_type')-- expect(subject.body)- .to be_json_eql("You must not write a read-only attribute.".to_json)- .at_path('message')-- expect(subject.body)- .to be_json_eql("scope".to_json)- .at_path('_embedded/details/attribute')- end+ it_behaves_like 'read-only violation', 'scope', Grids::Gridendcontext 'with the page not existing' dodiff --git a/modules/my_page/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb b/modules/my_page/spec/requests/api/v3/grids/grids_update_form_resource_spec.rbindex 7311008a47a..28a61287356 100644--- a/modules/my_page/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb+++ b/modules/my_page/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb@@ -132,7 +132,7 @@ describe "PATCH /api/v3/grids/:id/form", type: :request, content_type: :json doit 'has a validation error on scope as the value is not writeable' doexpect(subject.body)- .to be_json_eql("You must not write a read-only attribute.".to_json)+ .to be_json_eql("Scope was attempted to be written but is not writable.".to_json).at_path('_embedded/validationErrors/scope/message')endenddiff --git a/spec/requests/api/v3/membership_resources_spec.rb b/spec/requests/api/v3/membership_resources_spec.rbindex 8308783cc49..100c767cb35 100644--- a/spec/requests/api/v3/membership_resources_spec.rb+++ b/spec/requests/api/v3/membership_resources_spec.rb@@ -576,14 +576,7 @@ describe 'API v3 memberhips resource', type: :request, content_type: :json do}.to_jsonend- it 'returns 422' do- expect(last_response.status)- .to eql(422)-- expect(last_response.body)- .to be_json_eql("You must not write a read-only attribute.".to_json)- .at_path('message')- end+ it_behaves_like 'read-only violation', 'project', Memberendcontext 'if attempting to switch the principal' do@@ -602,18 +595,7 @@ describe 'API v3 memberhips resource', type: :request, content_type: :json do}.to_jsonend- it 'returns 422' do- expect(last_response.status)- .to eql(422)-- expect(last_response.body)- .to be_json_eql("You must not write a read-only attribute.".to_json)- .at_path('message')-- expect(last_response.body)- .to be_json_eql("user".to_json)- .at_path('_embedded/details/attribute')- end+ it_behaves_like 'read-only violation', 'user', Memberendcontext 'if lacking the manage permissions' dodiff --git a/spec/requests/api/v3/support/response_examples.rb b/spec/requests/api/v3/support/response_examples.rbindex ea7026db442..cda20d2cce2 100644--- a/spec/requests/api/v3/support/response_examples.rb+++ b/spec/requests/api/v3/support/response_examples.rb@@ -150,7 +150,7 @@ shared_examples_for 'format error' do |message|messageend-shared_examples_for 'read-only violation' do |attribute|+shared_examples_for 'read-only violation' do |attribute, model|describe 'details' dosubject { JSON.parse(last_response.body)['_embedded']['details'] }@@ -160,7 +160,7 @@ shared_examples_for 'read-only violation' do |attribute|it_behaves_like 'error response',422,'PropertyIsReadOnly',- I18n.t('api_v3.errors.writing_read_only_attributes')+ "#{model.human_attribute_name(attribute)} #{I18n.t('activerecord.errors.messages.error_readonly')}"endshared_examples_for 'multiple errors' do |code, _message|diff --git a/spec/requests/api/v3/version_resource_spec.rb b/spec/requests/api/v3/version_resource_spec.rbindex 541db826083..9a8f021ad6e 100644--- a/spec/requests/api/v3/version_resource_spec.rb+++ b/spec/requests/api/v3/version_resource_spec.rb@@ -236,14 +236,7 @@ describe 'API v3 Version resource', content_type: :json do}.to_jsonend- it 'returns 422' do- expect(last_response.status)- .to eql(422)-- expect(last_response.body)- .to be_json_eql("You must not write a read-only attribute.".to_json)- .at_path('message')- end+ it_behaves_like 'read-only violation', 'project', Versionendcontext 'if lacking the manage permissions' dodiff --git a/spec/requests/api/v3/work_package_resource_spec.rb b/spec/requests/api/v3/work_package_resource_spec.rbindex 2532f6a5db0..c58eef42c16 100644--- a/spec/requests/api/v3/work_package_resource_spec.rb+++ b/spec/requests/api/v3/work_package_resource_spec.rb@@ -856,13 +856,13 @@ describe 'API v3 Work package resource',context 'created_at' dolet(:params) { valid_params.merge(createdAt: tomorrow) }- it_behaves_like 'read-only violation', 'createdAt'+ it_behaves_like 'read-only violation', 'createdAt', WorkPackageendcontext 'updated_at' dolet(:params) { valid_params.merge(updatedAt: tomorrow) }- it_behaves_like 'read-only violation', 'updatedAt'+ it_behaves_like 'read-only violation', 'updatedAt', WorkPackageendendend