include dedicated error message for readonly work packages

pull/9993/head
ulferts 3 years ago
parent 786a4dbd0c
commit 38fb6a4a3e
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 19
      app/contracts/work_packages/base_contract.rb
  2. 1
      config/locales/en.yml
  3. 32
      spec/contracts/work_packages/update_contract_spec.rb

@ -304,10 +304,18 @@ module WorkPackages
end
end
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)
else
super
@ -420,5 +428,10 @@ module WorkPackages
def users_roles_in_project
user.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
end
end
end

@ -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:

@ -42,7 +42,8 @@ describe WorkPackages::UpdateContract do
let(:work_package) do
FactoryBot.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 do
end
let(: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 do
end
end
end
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
end
end

Loading…
Cancel
Save