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

Revert "Remove duration from the work package form configuration"

ulfertsbb60882b31fb
diff --git a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
index 1cda6e9c543..ff36ecf4216 100644
--- a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
+++ b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
@@ -117,6 +117,18 @@ module API
type: 'Formattable',
required: false
+ schema :duration,
+ type: 'Duration',
+ required: false,
+ writable: false,
+ show_if: ->(*) { !represented.milestone? && OpenProject::FeatureDecisions.work_packages_duration_field_active? }
+
+ # TODO: Remove this, once the duration feature is complete
+ # This enables hiding the duration field on the form_configuration
+ ::Type.add_constraint :duration, ->(*) {
+ OpenProject::FeatureDecisions.work_packages_duration_field_active?
+ }
+
schema :schedule_manually,
type: 'Boolean',
required: false,
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 77066b3e90a..1e6382424ce 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
@@ -293,6 +293,50 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do
end
end
+ describe 'duration' do
+ before do
+ # TODO: remove feature flag once the implementation is complete
+ allow(OpenProject::FeatureDecisions)
+ .to receive(:work_packages_duration_field_active?)
+ .and_return(true)
+ allow(schema)
+ .to receive(:milestone?)
+ .and_return(false)
+ end
+
+ it_behaves_like 'has basic schema properties' do
+ let(:path) { 'duration' }
+ let(:type) { 'Duration' }
+ let(:name) { I18n.t('activerecord.attributes.work_package.duration') }
+ let(:required) { false }
+ let(:writable) { false }
+ end
+
+ context 'when the work package is a milestone' do
+ before do
+ allow(schema)
+ .to receive(:milestone?)
+ .and_return(true)
+ end
+
+ it 'has no duration attribute' do
+ expect(subject).not_to have_json_path('duration')
+ end
+ end
+
+ context 'when the feature flag is off' do
+ before do
+ allow(OpenProject::FeatureDecisions)
+ .to receive(:work_packages_duration_field_active?)
+ .and_return(false)
+ end
+
+ it 'has no duration attribute' do
+ expect(subject).not_to have_json_path('duration')
+ end
+ end
+ end
+
describe 'scheduleManually' do
it_behaves_like 'has basic schema properties' do
let(:path) { 'scheduleManually' }