Validate new parent id

pull/2077/head
Hagen Schink 10 years ago
parent 53b46d1c0e
commit 9fa1efe266
  1. 2
      lib/api/errors/validation.rb
  2. 6
      lib/api/v3/work_packages/work_packages_api.rb

@ -41,7 +41,7 @@ module API
end
def errors
@obj.errors.full_messages
@obj.nil? ? '' : @obj.errors.full_messages
end
def to_json

@ -45,6 +45,12 @@ module API
attributes = JSON.parse(env['api.request.input'])
authorize(:manage_subtasks, context: @work_package.project) if attributes.include? 'parentId'
parent_id = attributes['parentId'].blank? ? nil : attributes['parentId'].to_i
if parent_id && !WorkPackage.visible(current_user).exists?(parent_id)
fail Errors::Validation.new(nil, { message: "Parent work package does not exist!" } )
end
end
end

Loading…
Cancel
Save