diff --git a/lib/api/v3/work_packages/schema/work_package_schema.rb b/lib/api/v3/work_packages/schema/work_package_schema.rb index 61b6e63876..2fdf365378 100644 --- a/lib/api/v3/work_packages/schema/work_package_schema.rb +++ b/lib/api/v3/work_packages/schema/work_package_schema.rb @@ -96,6 +96,14 @@ module API nil_or_leaf?(@work_package) end + def start_date_writable? + nil_or_leaf?(@work_package) + end + + def due_date_writable? + nil_or_leaf?(@work_package) + end + def nil_or_leaf?(work_package) work_package.nil? || work_package.leaf? end 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 1025606ce4..09fe836d38 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 @@ -76,13 +76,27 @@ module API schema :description, type: 'Formattable' - schema :start_date, - type: 'Date', - required: false + property :start_date, + exec_context: :decorator, + getter: -> (*) do + representer = ::API::Decorators::PropertySchemaRepresenter + .new(type: 'Date', + name: WorkPackage.human_attribute_name(:start_date)) + representer.writable = represented.due_date_writable? + representer.required = false + representer + end - schema :due_date, - type: 'Date', - required: false + property :due_date, + exec_context: :decorator, + getter: -> (*) do + representer = ::API::Decorators::PropertySchemaRepresenter + .new(type: 'Date', + name: WorkPackage.human_attribute_name(:due_date)) + representer.writable = represented.due_date_writable? + representer.required = false + representer + end property :estimated_time, exec_context: :decorator,