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

restrict writability of ignore_non_working_days if parent

ulferts7be7ede6b5ab
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rb
index 45d2fa9cefb..92903fc3da2 100644
--- a/app/contracts/work_packages/base_contract.rb
+++ b/app/contracts/work_packages/base_contract.rb
@@ -80,18 +80,21 @@ module WorkPackages
end
attribute :schedule_manually
- attribute :ignore_non_working_days
+ attribute :ignore_non_working_days,
+ writable: ->(*) {
+ !automatically_scheduled_parent?
+ }
attribute :start_date,
writable: ->(*) {
- model.leaf? || model.schedule_manually?
+ !automatically_scheduled_parent?
} do
validate_after_soonest_start(:start_date)
end
attribute :due_date,
writable: ->(*) {
- model.leaf? || model.schedule_manually?
+ !automatically_scheduled_parent?
} do
validate_after_soonest_start(:due_date)
end
@@ -473,5 +476,9 @@ module WorkPackages
def calculated_duration
@calculated_duration ||= WorkPackages::Shared::Days.for(model).duration(model.start_date, model.due_date)
end
+
+ def automatically_scheduled_parent?
+ !model.leaf? && !model.schedule_manually?
+ end
end
end
diff --git a/docs/api/apiv3/tags/work_packages.yml b/docs/api/apiv3/tags/work_packages.yml
index 44747dfe869..d795677310a 100644
--- a/docs/api/apiv3/tags/work_packages.yml
+++ b/docs/api/apiv3/tags/work_packages.yml
@@ -45,28 +45,28 @@ description: |-
## Local Properties
- | Property | Description | Type | Constraints | Supported operations | Condition |
- | :--------------: | ------------------------------------------------------ | ----------- | ------------------------------------------------------------------------------------------------------ | -------------------- | -------------------------------- |
- | id | Work package id | Integer | x > 0 | READ | |
- | lockVersion | The version of the item as used for optimistic locking | Integer | | READ | |
- | subject | Work package subject | String | not null; 1 <= length <= 255 | READ / WRITE | |
- | type | Name of the work package's type | String | not null | READ | |
- | description | The work package description | Formattable | | READ / WRITE | |
- | scheduleManually | If false (default) schedule automatically. | Boolean | | READ / WRITE | |
- | startDate | Scheduled beginning of a work package | Date | Cannot be set for parent work packages; must be equal or greater than the earliest possible start date; Exists only on work packages of a non milestone type | READ / WRITE | |
- | dueDate | Scheduled end of a work package | Date | Cannot be set for parent work packages; must be greater than or equal to the start date; Exists only on work packages of a non milestone type | READ / WRITE | |
- | date | Date on which a milestone is achieved | Date | Exists only on work packages of a milestone type | READ / WRITE | |
- | derivedStartDate | Similar to start date but is not set by a client but rather deduced by the work packages' descendants. If manual scheduleManually is active, the two dates can deviate. | Date | | READ | |
- | derivedDueDate | Similar to due date but is not set by a client but rather deduced by the work packages' descendants. If manual scheduleManually is active, the two dates can deviate. | Date | | READ | |
- | duration | The amount of time in hours the work package needs to be completed. | Duration | **(NOT IMPLEMENTED YET)** Not available for milestone type of work packages. | READ | |
- | estimatedTime | Time a work package likely needs to be completed excluding its descendants | Duration | | READ / WRITE | |
- | derivedEstimatedTime | Time a work package likely needs to be completed including its descendants | Duration | | READ | |
- | ignoreNonWorkingDays | When scheduling, whether or not to ignore the non working days being defined. A work package with the flag set to true will be allowed to be scheduled to a non working day. | Boolean | **(NOT IMPLEMENTED YET)** | READ | |
- | spentTime | The time booked for this work package by users working on it | Duration | | READ | **Permission** view time entries |
- | percentageDone | Amount of total completion for a work package | Integer | 0 <= x <= 100; Cannot be set for parent work packages | READ / WRITE | |
- | readonly | If true, the work package is in a readonly status so with the exception of the status, no other property can be altered. | Boolean | | READ | Enterprise edition only |
- | createdAt | Time of creation | DateTime | | READ | |
- | updatedAt | Time of the most recent change to the work package | DateTime | | READ | |
+ | Property | Description | Type | Constraints | Supported operations | Condition |
+ | :--------------: | ------------------------------------------------------ | ----------- | ------------------------------------------------------------------------------------------------------ | -------------------- | -------------------------------- |
+ | id | Work package id | Integer | x > 0 | READ | |
+ | lockVersion | The version of the item as used for optimistic locking | Integer | | READ | |
+ | subject | Work package subject | String | not null; 1 <= length <= 255 | READ / WRITE | |
+ | type | Name of the work package's type | String | not null | READ | |
+ | description | The work package description | Formattable | | READ / WRITE | |
+ | scheduleManually | If false (default) schedule automatically. | Boolean | | READ / WRITE | |
+ | startDate | Scheduled beginning of a work package | Date | Cannot be set for parent work packages unless it is scheduled manually; must be equal or greater than the earliest possible start date; Exists only on work packages of a non milestone type | READ / WRITE | |
+ | dueDate | Scheduled end of a work package | Date | Cannot be set for parent work packages unless it is scheduled manually; must be greater than or equal to the start date; Exists only on work packages of a non milestone type | READ / WRITE | |
+ | date | Date on which a milestone is achieved | Date | Exists only on work packages of a milestone type | READ / WRITE | |
+ | derivedStartDate | Similar to start date but is not set by a client but rather deduced by the work packages' descendants. If manual scheduleManually is active, the two dates can deviate. | Date | | READ | |
+ | derivedDueDate | Similar to due date but is not set by a client but rather deduced by the work packages' descendants. If manual scheduleManually is active, the two dates can deviate. | Date | | READ | |
+ | duration | The amount of time in hours the work package needs to be completed. | Duration | Not available for milestone type of work packages. | READ / WRITE | |
+ | estimatedTime | Time a work package likely needs to be completed excluding its descendants | Duration | | READ / WRITE | |
+ | derivedEstimatedTime | Time a work package likely needs to be completed including its descendants | Duration | | READ | |
+ | ignoreNonWorkingDays | When scheduling, whether or not to ignore the non working days being defined. A work package with the flag set to true will be allowed to be scheduled to a non working day. | Boolean | Cannot be set for parent work packages unless it is scheduled manually | READ | |
+ | spentTime | The time booked for this work package by users working on it | Duration | | READ | **Permission** view time entries |
+ | percentageDone | Amount of total completion for a work package | Integer | 0 <= x <= 100; Cannot be set for parent work packages | READ / WRITE | |
+ | readonly | If true, the work package is in a readonly status so with the exception of the status, no other property can be altered. | Boolean | | READ | Enterprise edition only |
+ | createdAt | Time of creation | DateTime | | READ | |
+ | updatedAt | Time of the most recent change to the work package | DateTime | | READ | |
Note that the properties listed here only cover the built-in properties of the OpenProject Core.
Using plug-ins and custom fields a work package might contain various additional properties.
diff --git a/spec/contracts/work_packages/update_contract_spec.rb b/spec/contracts/work_packages/update_contract_spec.rb
index 74d301a724b..66c6813c473 100644
--- a/spec/contracts/work_packages/update_contract_spec.rb
+++ b/spec/contracts/work_packages/update_contract_spec.rb
@@ -243,6 +243,43 @@ describe WorkPackages::UpdateContract do
end
end
+ describe 'ignore_non_working_days' do
+ context 'when having children and not being scheduled manually' do
+ before do
+ allow(work_package)
+ .to receive(:leaf?)
+ .and_return(false)
+
+ work_package.ignore_non_working_days = !work_package.ignore_non_working_days
+ work_package.schedule_manually = false
+
+ contract.validate
+ end
+
+ it 'is invalid' do
+ expect(contract.errors.symbols_for(:ignore_non_working_days))
+ .to match_array([:error_readonly])
+ end
+ end
+
+ context 'when having children and being scheduled manually' do
+ before do
+ allow(work_package)
+ .to receive(:leaf?)
+ .and_return(false)
+
+ work_package.ignore_non_working_days = !work_package.ignore_non_working_days
+ work_package.schedule_manually = true
+
+ contract.validate
+ end
+
+ it 'is valid' do
+ expect(contract.errors).to be_empty
+ end
+ end
+ end
+
describe 'with children' do
context 'changing to milestone' do
let(:milestone) { build_stubbed :type, is_milestone: true }
diff --git a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
index 180793edde9..ac627c67b46 100644
--- a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
@@ -331,12 +331,35 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do
end
describe 'ignoreNonWorkingDays' do
- it_behaves_like 'has basic schema properties' do
- let(:path) { 'ignoreNonWorkingDays' }
- let(:type) { 'Boolean' }
- let(:name) { I18n.t('activerecord.attributes.work_package.ignore_non_working_days') }
- let(:required) { false }
+ before do
+ allow(schema)
+ .to receive(:writable?)
+ .with(:ignore_non_working_days)
+ .and_return writable
+ end
+
+ context 'when writable' do
let(:writable) { true }
+
+ it_behaves_like 'has basic schema properties' do
+ let(:path) { 'ignoreNonWorkingDays' }
+ let(:type) { 'Boolean' }
+ let(:name) { I18n.t('activerecord.attributes.work_package.ignore_non_working_days') }
+ let(:required) { false }
+ let(:writable) { true }
+ end
+ end
+
+ context 'when not writable' do
+ let(:writable) { false }
+
+ it_behaves_like 'has basic schema properties' do
+ let(:path) { 'ignoreNonWorkingDays' }
+ let(:type) { 'Boolean' }
+ let(:name) { I18n.t('activerecord.attributes.work_package.ignore_non_working_days') }
+ let(:required) { false }
+ let(:writable) { false }
+ end
end
end