OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/lib/api/v3/relations/relations_api.rb

43 lines
1.4 KiB

module API
module V3
module Relations
class RelationsAPI < Grape::API
resources :relations do
params do
optional :to_id, desc: 'Id of related work package'
optional :relation_type, desc: 'Type of relationship'
optional :delay
end
post do
authorize(:manage_work_package_relations, context: @work_package.project)
declared_params = declared(params).reject{ |key, value| key.to_sym == :id || value.nil? }
relation = @work_package.new_relation.tap do |r|
r.to = WorkPackage.visible.find_by_id(declared_params[:to_id].match(/\d+/).to_s)
r.relation_type = declared_params[:relation_type]
r.delay = declared_params[:delay_id]
end
if relation.valid? && relation.save
model = ::API::V3::WorkPackages::RelationModel.new(relation)
representer = ::API::V3::WorkPackages::RelationRepresenter.new(model, work_package: relation.to)
representer
else
fail Errors::Validation.new(relation)
end
end
namespace ':relation_id' do
delete do
authorize(:manage_work_package_relations, context: @work_package.project)
Relation.destroy(params[:relation_id])
status 204
end
end
end
end
end
end
end