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
include dedicated error message for readonly work packages
ulferts38fb6a4a3ea3
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rbindex 1c121661e75..b4cd766d2cc 100644--- a/app/contracts/work_packages/base_contract.rb+++ b/app/contracts/work_packages/base_contract.rb@@ -304,10 +304,18 @@ module WorkPackagesendend+ def readonly_attributes_unchanged+ super.tap do+ if already_in_readonly_status? && unauthenticated_changed.any?+ # Better documentation on why a property is readonly.+ errors.add :base, :readonly_status+ end+ end+ end+def reduce_by_writable_permissions(attributes)- # If we're in a readonly status and did not move into that status right now- # only allow other status transitions. But also prevent that if the associated version is closed.- if model.readonly_status? && !model.status_id_change+ # If we're in a readonly status only allow other status transitions.+ if already_in_readonly_status?super & %w(status status_id)elsesuper@@ -420,5 +428,10 @@ module WorkPackagesdef users_roles_in_projectuser.roles_for_project(model.project)end++ # We're in a readonly status and did not move into that status right now.+ def already_in_readonly_status?+ model.readonly_status? && !model.status_id_change+ endendenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex dcbaf300774..410ca6a2eb7 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -801,6 +801,7 @@ en:does_not_exist: "The specified category does not exist."estimated_hours:only_values_greater_or_equal_zeroes_allowed: "must be >= 0."+ readonly_status: 'The work package is in a readonly status so its attributes cannot be changed.'type:attributes:attribute_groups:diff --git a/spec/contracts/work_packages/update_contract_spec.rb b/spec/contracts/work_packages/update_contract_spec.rbindex 62b508cbe26..44dc22960cb 100644--- a/spec/contracts/work_packages/update_contract_spec.rb+++ b/spec/contracts/work_packages/update_contract_spec.rb@@ -42,7 +42,8 @@ describe WorkPackages::UpdateContract dolet(:work_package) doFactoryBot.build_stubbed(:work_package,project: work_package_project,- type: type).tap do |wp|+ type: type,+ status: status).tap do |wp|wp_scope = double('wp scope')allow(WorkPackage)@@ -58,6 +59,7 @@ describe WorkPackages::UpdateContract doendlet(:user) { FactoryBot.build_stubbed(:user) }let(:type) { FactoryBot.build_stubbed(:type) }+ let(:status) { FactoryBot.build_stubbed(:status) }let(:permissions) { %i[view_work_packages edit_work_packages assign_versions] }before do@@ -337,4 +339,32 @@ describe WorkPackages::UpdateContract doendendend++ describe 'readonly status' do+ context 'with the status being readonly', with_ee: %i[readonly_work_packages] do+ let(:status) { FactoryBot.build_stubbed(:status, is_readonly: true) }+ let(:new_priority) { FactoryBot.build_stubbed(:priority) }++ before do+ work_package.priority = new_priority++ contract.validate+ end++ it 'is invalid' do+ expect(contract)+ .not_to be_valid+ end++ it 'adds an error to the written to attribute' do+ expect(contract.errors.symbols_for(:priority_id))+ .to include(:error_readonly)+ end++ it 'adds an error to base to better explain' do+ expect(contract.errors.symbols_for(:base))+ .to include(:readonly_status)+ end+ end+ endend