Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
2.2 KiB
Ruby
Raw Permalink Normal View History

2014-06-11 19:26:31 +02:00
#-- copyright
2020-01-15 11:31:26 +01:00
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
2014-06-11 19:26:31 +02:00
#
# 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:
2021-01-13 17:47:45 +01:00
# Copyright (C) 2006-2013 Jean-Philippe Lang
2014-06-11 19:26:31 +02:00
# 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 COPYRIGHT and LICENSE files for more details.
2014-06-11 19:26:31 +02:00
#++
module API
2019-11-08 11:37:18 +01:00
class Root < ::API::RootAPI
2022-05-31 13:47:40 +02:00
include ::API::AppsignalAPI
2019-11-11 10:22:52 +01:00
content_type "hal+json", "application/hal+json; charset=utf-8"
2014-06-11 19:26:31 +02:00
format "hal+json"
2019-11-08 11:37:18 +01:00
formatter "hal+json", API::Formatter.new
parser "hal+json", Grape::Parser::Json
2019-11-11 10:22:52 +01:00
default_format "hal+json"
2019-11-08 11:37:18 +01:00
parser :json, API::V3::Parser.new
2014-06-11 19:26:31 +02:00
2024-06-25 17:40:53 +02:00
error_representer ::API::V3::Errors::ErrorRepresenter, "application/hal+json; charset=utf-8"
2019-11-11 16:49:22 +01:00
authentication_scope OpenProject::Authentication::Scope::API_V3
2019-11-11 10:22:52 +01:00
OpenProject::Authentication.handle_failure(scope: API_V3) do |warden, opts|
e = grape_error_for(warden.env, self)
2019-11-13 09:18:58 +01:00
error_message = I18n.t("api_v3.errors.code_401_wrong_credentials")
api_error = ::API::Errors::Unauthenticated.new(error_message)
representer = ::API::V3::Errors::ErrorRepresenter.new(api_error)
status = opts[:message] == "insufficient_scope" ? 403 : 401
2019-11-13 09:18:58 +01:00
e.error!(representer.to_json, status, warden.headers)
2019-11-13 09:18:58 +01:00
end
2015-03-17 17:18:04 +01:00
version "v3", using: :path do
mount API::V3::Root
end
2014-06-11 19:26:31 +02:00
end
end