diff --git a/lib/api/decorators/schema.rb b/lib/api/decorators/schema.rb index a50050c509..d2a17b2958 100644 --- a/lib/api/decorators/schema.rb +++ b/lib/api/decorators/schema.rb @@ -35,7 +35,7 @@ module API type:, name_source: property, required: true, - writable: true, + writable: -> { represented.writable?(property) }, min_length: nil, max_length: nil, regular_expression: nil, 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 a5a5a45f04..a0dedf88cb 100644 --- a/lib/api/v3/work_packages/schema/work_package_schema.rb +++ b/lib/api/v3/work_packages/schema/work_package_schema.rb @@ -84,23 +84,39 @@ module API project.all_work_package_custom_fields.to_a & type.custom_fields.to_a end - def percentage_done_writable? - if Setting.work_package_done_ratio == 'status' || - Setting.work_package_done_ratio == 'disabled' - return false + def writable?(property) + case property + when :percentage_done + percentage_done_writable? + when :estimated_time, :start_date, :due_date + nil_or_leaf?(@work_package) + else + writable_properties.include? property end - nil_or_leaf?(@work_package) - end - - def estimated_time_writable? - nil_or_leaf?(@work_package) end - def start_date_writable? - nil_or_leaf?(@work_package) + private + + def writable_properties + [ + :subject, + :description, + :estimated_time, + :assignee, + :responsible, + :type, + :status, + :category, + :version, + :priority + ] end - def due_date_writable? + def percentage_done_writable? + if Setting.work_package_done_ratio == 'status' || + Setting.work_package_done_ratio == 'disabled' + return false + end nil_or_leaf?(@work_package) 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 8368a4a1df..6897639d72 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 @@ -60,12 +60,10 @@ module API schema :lock_version, type: 'Integer', - name_source: -> (*) { I18n.t('api_v3.attributes.lock_version') }, - writable: false + name_source: -> (*) { I18n.t('api_v3.attributes.lock_version') } schema :id, - type: 'Integer', - writable: false + type: 'Integer' schema :subject, type: 'String', @@ -77,22 +75,18 @@ module API schema :start_date, type: 'Date', - required: false, - writable: -> { represented.start_date_writable? } + required: false schema :due_date, type: 'Date', - required: false, - writable: -> { represented.due_date_writable? } + required: false schema :estimated_time, type: 'Duration', - required: false, - writable: -> { represented.estimated_time_writable? } + required: false schema :spent_time, type: 'Duration', - writable: false, show_if: -> (_) do current_user_allowed_to(:view_time_entries, context: represented.project) end @@ -100,24 +94,19 @@ module API schema :percentage_done, type: 'Integer', name_source: :done_ratio, - writable: -> { represented.percentage_done_writable? }, show_if: -> (*) { Setting.work_package_done_ratio != 'disabled' } schema :created_at, - type: 'DateTime', - writable: false + type: 'DateTime' schema :updated_at, - type: 'DateTime', - writable: false + type: 'DateTime' schema :author, - type: 'User', - writable: false + type: 'User' schema :project, - type: 'Project', - writable: false + type: 'Project' schema_with_allowed_link :assignee, type: 'User',