diff --git a/docs/api/apiv3/paths/custom_field_item.yml b/docs/api/apiv3/paths/custom_field_item.yml index 9fd0aa9022e0..c1ac90dda38b 100644 --- a/docs/api/apiv3/paths/custom_field_item.yml +++ b/docs/api/apiv3/paths/custom_field_item.yml @@ -23,6 +23,18 @@ get: examples: 'simple response': $ref: '../components/examples/hierarchy_item_response.yml' + '403': + description: Returned if the user is not logged in. + content: + application/hal+json: + schema: + $ref: '../components/schemas/error_response.yml' + examples: + response: + value: + _type: Error + errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission + message: You are not authorized to access this resource. '404': description: Returned if the custom field item does not exist or the user is not logged in. content: diff --git a/lib/api/v3/custom_fields/hierarchy/item_api.rb b/lib/api/v3/custom_fields/hierarchy/item_api.rb new file mode 100644 index 000000000000..d0ce2d51b6ae --- /dev/null +++ b/lib/api/v3/custom_fields/hierarchy/item_api.rb @@ -0,0 +1,53 @@ +#-- copyright +# OpenProject is an open source project management software. +# Copyright (C) the OpenProject GmbH +# +# 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-2013 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 COPYRIGHT and LICENSE files for more details. +#++ + +module API + module V3 + module CustomFields + module Hierarchy + class ItemAPI < ::API::OpenProjectAPI + resource :custom_field_items do + route_param :id, type: Integer, desc: "Custom Field Item ID" do + after_validation do + authorize_logged_in + + @custom_field_item = CustomField::Hierarchy::Item.find(params[:id]) + end + + get &::API::V3::Utilities::Endpoints::Show + .new(model: CustomField::Hierarchy::Item, + render_representer: HierarchyItemRepresenter, + instance_generator: ->(*) { @custom_field_item }) + .mount + end + end + end + end + end + end +end diff --git a/lib/api/v3/root.rb b/lib/api/v3/root.rb index 8360051a5d35..a30041f486f1 100644 --- a/lib/api/v3/root.rb +++ b/lib/api/v3/root.rb @@ -52,6 +52,7 @@ class Root < ::API::OpenProjectAPI mount ::API::V3::Configuration::ConfigurationAPI mount ::API::V3::CustomActions::CustomActionsAPI mount ::API::V3::CustomFields::CustomFieldsAPI + mount ::API::V3::CustomFields::Hierarchy::ItemAPI mount ::API::V3::CustomOptions::CustomOptionsAPI mount ::API::V3::Days::DaysAPI mount ::API::V3::Grids::GridsAPI