From f48972d5707140b72e659784b2b417faaca3ec84 Mon Sep 17 00:00:00 2001 From: Alexander Bach Date: Fri, 13 Mar 2015 11:35:57 +0100 Subject: [PATCH] Added schema indications for writability of start & due date --- .../schema/work_package_schema.rb | 8 ++++++ .../schema/work_package_schema_representer.rb | 26 ++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) 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,