Moved lock_version validation enforcement

pull/3125/head
Alexander Bach 10 years ago committed by Jens Ulferts
parent d67d016db0
commit cccfcd9652
  1. 2
      lib/api/v3/work_packages/form/form_api.rb
  2. 11
      lib/api/v3/work_packages/form/work_package_payload_representer.rb
  3. 2
      lib/api/v3/work_packages/work_packages_api.rb
  4. 7
      lib/api/v3/work_packages/work_packages_shared_helpers.rb

@ -34,7 +34,7 @@ module API
module Form
class FormAPI < ::API::OpenProjectAPI
post '/form' do
write_work_package_attributes
write_work_package_attributes(reset_lock_version: true)
write_request_valid?
error = ::API::Errors::ErrorBase.create(@work_package.errors)

@ -45,19 +45,14 @@ module API
WorkPackagePayloadRepresenter)
end
def create(work_package, options = {})
create_class(work_package).new(work_package, options)
def create(work_package)
create_class(work_package).new(work_package)
end
end
self.as_strategy = ::API::Utilities::CamelCasingStrategy.new
def initialize(represented, options = {})
if options[:enforce_lock_version_validation]
# enforces availibility validation of lock_version
represented.lock_version = nil
end
def initialize(represented)
super(represented)
end

@ -61,7 +61,7 @@ module API
end
patch do
write_work_package_attributes
write_work_package_attributes(reset_lock_version: true)
send_notifications = !(params.has_key?(:notify) && params[:notify] == 'false')
update_service = UpdateWorkPackageService.new(current_user,

@ -40,15 +40,14 @@ module API
# merges the given JSON representation into @work_package
def merge_json_into_work_package!(json)
payload = Form::WorkPackagePayloadRepresenter.create(
@work_package,
enforce_lock_version_validation: true)
payload = Form::WorkPackagePayloadRepresenter.create(@work_package)
payload.from_json(json)
end
def write_work_package_attributes
def write_work_package_attributes(reset_lock_version: false)
if request_body
begin
@work_package.lock_version = nil if reset_lock_version
# we need to merge the JSON two times:
# In Pass 1 the representer only has custom fields for the current WP type
# After Pass 1 the correct type information is merged into the WP

Loading…
Cancel
Save