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

let writability of duration and ignore_non_working_days be govered by feature flag

ulferts122b56332e76
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rb
index b03bda4f1c3..2dd08b1c573 100644
--- a/app/contracts/work_packages/base_contract.rb
+++ b/app/contracts/work_packages/base_contract.rb
@@ -80,7 +80,10 @@ module WorkPackages
end
attribute :schedule_manually
- attribute :ignore_non_working_days
+ attribute :ignore_non_working_days,
+ writeable: ->(*) {
+ OpenProject::FeatureDecisions.work_packages_duration_field_active?
+ }
attribute :start_date,
writeable: ->(*) {
@@ -99,7 +102,10 @@ module WorkPackages
model.leaf? || model.schedule_manually?
}
- attribute :duration
+ attribute :duration,
+ writeable: ->(*) {
+ OpenProject::FeatureDecisions.work_packages_duration_field_active?
+ }
attribute :budget
diff --git a/lib/api/v3/work_packages/work_package_payload_representer.rb b/lib/api/v3/work_packages/work_package_payload_representer.rb
index 8293edf578f..df9edd8149b 100644
--- a/lib/api/v3/work_packages/work_package_payload_representer.rb
+++ b/lib/api/v3/work_packages/work_package_payload_representer.rb
@@ -36,13 +36,7 @@ module API
cached_representer disabled: true
def writeable_attributes
- attributes = super
- # TODO: Remove this, once the duration feature is complete
- # We have to remove the duration field as it is not being accepted yet.
- if OpenProject::FeatureDecisions.work_packages_duration_field_active?
- attributes -= %w[duration]
- end
- attributes + %w[date]
+ super + %w[date]
end
def load_complete_model(model)
diff --git a/spec/contracts/work_packages/base_contract_spec.rb b/spec/contracts/work_packages/base_contract_spec.rb
index c9122ee3076..4b765aa4c31 100644
--- a/spec/contracts/work_packages/base_contract_spec.rb
+++ b/spec/contracts/work_packages/base_contract_spec.rb
@@ -476,7 +476,7 @@ describe WorkPackages::BaseContract do
end
end
- describe 'duration' do
+ describe 'duration', with_flag: { work_packages_duration_field_active: true } do
context 'when setting the duration' do
before do
work_package.duration = 5
@@ -485,6 +485,14 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is valid'
end
+ context 'when setting the duration with the feature disabled', with_flag: { work_packages_duration_field_active: false } do
+ before do
+ work_package.duration = 5
+ end
+
+ it_behaves_like 'contract is invalid', duration: :error_readonly
+ end
+
context 'when setting the duration to 0' do
before do
work_package.duration = 0
@@ -551,7 +559,7 @@ describe WorkPackages::BaseContract do
end
describe 'ignore_non_working_days' do
- context 'when setting the value to true' do
+ context 'when setting the value to true', with_flag: { work_packages_duration_field_active: true } do
before do
work_package.ignore_non_working_days = true
end
@@ -559,13 +567,22 @@ describe WorkPackages::BaseContract do
it_behaves_like 'contract is valid'
end
- context 'when setting the value to false' do
+ context 'when setting the value to false', with_flag: { work_packages_duration_field_active: true } do
before do
work_package.ignore_non_working_days = false
end
it_behaves_like 'contract is valid'
end
+
+ context 'when setting the value to false and with the feature disabled',
+ with_flag: { work_packages_duration_field_active: false } do
+ before do
+ work_package.ignore_non_working_days = false
+ end
+
+ it_behaves_like 'contract is invalid', ignore_non_working_days: :error_readonly
+ end
end
describe 'percentage done' do