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

99 lines
3.5 KiB

#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'api/v3/relations/relation_representer'
require 'api/v3/relations/relation_collection_representer'
8 years ago
require 'relations/create_relation_service'
require 'relations/update_relation_service'
module API
module V3
module Relations
class RelationsAPI < ::API::OpenProjectAPI
8 years ago
helpers ::API::V3::Relations::RelationsHelper
8 years ago
resources :relations do
get do
query = ::API::V3::ParamsToQueryService.new(Relation, current_user).call(params)
if query.valid?
RelationCollectionRepresenter.new(
query.results.includes(::API::V3::Relations::RelationRepresenter.to_eager_load),
api_v3_paths.relations,
current_user: current_user
)
else
raise ::API::Errors::InvalidQuery.new(query.errors.full_messages)
end
end
params do
8 years ago
requires :id, type: Integer, desc: 'Relation id'
end
8 years ago
route_param :id do
get do
representer.new(
Relation.find_by_id!(params[:id]),
current_user: current_user,
embed_links: true
)
end
8 years ago
patch do
rep = representer.new Relation.new, current_user: current_user
relation = rep.from_json request.body.read
attributes = filter_attributes relation
service = ::UpdateRelationService.new relation: Relation.find_by_id!(params[:id]),
user: current_user
call = service.call attributes: attributes,
send_notifications: !(params[:notify] == 'false')
if call.success?
representer.new call.result, current_user: current_user, embed_links: true
else
fail ::API::Errors::ErrorBase.create_and_merge_errors(call.errors)
end
end
delete do
8 years ago
project_id = project_id_for_relation params[:id]
project = Project.find project_id
authorize :manage_work_package_relations, context: project
Relation.destroy params[:id]
status 204
end
end
end
end
end
end
end