Implement response to write access to read-only attribute

pull/2081/head
Hagen Schink 10 years ago
parent bdc0efd510
commit 3f8522238d
  1. 22
      lib/api/errors/unwritable_property.rb
  2. 2
      lib/api/v3/work_packages/work_packages_api.rb

@ -29,23 +29,13 @@
module API
module Errors
class UnwritableProperty < Grape::Exceptions::Base
attr_reader :code, :title, :description, :headers
class UnwritableProperty < ErrorBase
IDENTIFIER = 'urn:openproject-org:api:v3:errors:PropertyIsReadOnly'
def initialize(property, args = { })
@property = property
@code = args[:code] || 422
@title = args[:title] || 'unwriteable_property_error'
@description = args[:description] || 'You tried to write read-only property.'
@headers = { 'Content-Type' => 'application/hal+json' }.merge(args[:headers] || { })
end
def errors
[{ key: @property, messages: ['is read-only'] }]
end
def to_json
{ title: @title, description: @description, errors: errors }.to_json
def initialize(invalid_attributes)
super 422,
IDENTIFIER,
"You must not write the following attributes: #{invalid_attributes.keys.join(', ')}"
end
end
end

@ -48,7 +48,7 @@ module API
attributes = JSON.parse(env['api.request.input'])
invalid_attributes = invalid_work_package_update_attributes(attributes)
fail ::API::Errors::Validation.new(nil) unless invalid_attributes.empty?
fail ::API::Errors::UnwritableProperty.new(invalid_attributes) unless invalid_attributes.empty?
end
def invalid_work_package_update_attributes(attributes)

Loading…
Cancel
Save