OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#40228] migrated some file links endpoint
Eric Schubertf82f355c0369
diff --git a/lib/api/v3/root.rb b/lib/api/v3/root.rbindex 3edce98d608..f64a3021b71 100644--- a/lib/api/v3/root.rb+++ b/lib/api/v3/root.rb@@ -70,6 +70,7 @@ module APImount ::API::V3::Roles::RolesAPImount ::API::V3::Statuses::StatusesAPImount ::API::V3::Storages::StoragesAPI+ mount ::API::V3::FileLinks::FileLinksAPImount ::API::V3::StringObjects::StringObjectsAPImount ::API::V3::Types::TypesAPImount ::API::V3::Users::UsersAPIdiff --git a/lib/api/v3/work_packages/work_packages_api.rb b/lib/api/v3/work_packages/work_packages_api.rbindex 515bc0afdd9..46bb2cbc5ce 100644--- a/lib/api/v3/work_packages/work_packages_api.rb+++ b/lib/api/v3/work_packages/work_packages_api.rb@@ -102,7 +102,7 @@ module APImount ::API::V3::WorkPackages::AvailableProjectsOnEditAPImount ::API::V3::WorkPackages::AvailableRelationCandidatesAPImount ::API::V3::WorkPackages::WorkPackageRelationsAPI- mount ::API::V3::FileLinks::FileLinksAPI+ mount ::API::V3::FileLinks::WorkPackagesFileLinksAPIendmount ::API::V3::WorkPackages::CreateFormAPIdiff --git a/modules/storages/lib/api/v3/file_links/file_link_representer.rb b/modules/storages/lib/api/v3/file_links/file_link_representer.rbindex 64876346c85..32133ce0e2d 100644--- a/modules/storages/lib/api/v3/file_links/file_link_representer.rb+++ b/modules/storages/lib/api/v3/file_links/file_link_representer.rb@@ -51,13 +51,13 @@ module APIlink :self do{- href: api_v3_paths.file_link(represented.container_id, represented.id)+ href: api_v3_paths.file_link(represented.id)}endlink :delete, cache_if: -> { user_allowed_to_manage?(represented) } do{- href: api_v3_paths.file_link(represented.container_id, represented.id),+ href: api_v3_paths.file_link(represented.id),method: :delete}end@@ -77,7 +77,7 @@ module APIlink :staticOriginOpen do{- href: api_v3_paths.file_link_open(represented.container_id, represented.id)+ href: api_v3_paths.file_link_open(represented.id)}enddiff --git a/modules/storages/lib/api/v3/file_links/file_links_api.rb b/modules/storages/lib/api/v3/file_links/file_links_api.rbindex 6cc31bf96bc..ff19c4d479e 100644--- a/modules/storages/lib/api/v3/file_links/file_links_api.rb+++ b/modules/storages/lib/api/v3/file_links/file_links_api.rb@@ -27,9 +27,8 @@#++# This class provides definitions for API routes and endpoints for the file_links namespace. It inherits the-# functionality from the Grape REST API framework. It is mounted in lib/api/v3/work_packages/work_packages_api.rb,-# which puts the file_links namespace behind the provided namespace of the work packages api-# -> /api/v3/work_packages/:id/file_links/...+# functionality from the Grape REST API framework. It is mounted in lib/api/v3/root.rb.+# -> /api/v3/file_links/...module APImodule V3module FileLinks@@ -42,26 +41,8 @@ module APIendend- # The `:resources` keyword defines the API namespace -> /api/v3/work_packages/:id/file_links/...+ # The `:resources` keyword defines the API namespace -> /api/v3/file_links/...resources :file_links do- # A helper is used to define the behaviour at GET /api/v3/work_packages/:id/file_links- get &::API::V3::Utilities::Endpoints::Index- .new(model: ::Storages::FileLink,- scope: -> { visible_file_links_scope.where(container_id: @work_package.id) },- self_path: -> { api_v3_paths.file_links(params[:id]) })- .mount-- # A helper is used to define the behaviour at POST /api/v3/work_packages/:id/file_links.- # Additional classes are provided, that overwrite standard behaviour for parsing request parameters or- # rendering the response.- post &CreateEndpoint- .new(- model: ::Storages::FileLink,- parse_service: ParseCreateParamsService,- render_representer: FileLinkCollectionRepresenter- )- .mount-# `route_param` extends the route by a route parameter of the endpoint.# The input parameter value is parsed into the `:file_link_id` symbol.route_param :file_link_id, type: Integer, desc: 'File link id' do@@ -71,17 +52,16 @@ module API@file_link = visible_file_links_scope.find(params[:file_link_id])end- # A helper is used to define the behaviour at GET /api/v3/work_packages/:id/file_links/:file_link_id+ # A helper is used to define the behaviour at GET /api/v3/file_links/:file_link_idget &::API::V3::Utilities::Endpoints::Show.new(model: ::Storages::FileLink).mount- # A helper is used to define the behaviour at DELETE /api/v3/work_packages/:id/file_links/:file_link_id+ # A helper is used to define the behaviour at DELETE /api/v3/file_links/:file_link_iddelete &::API::V3::Utilities::Endpoints::Delete.new(model: ::Storages::FileLink,process_service: ::Storages::FileLinks::DeleteService).mount# Additional API definitions are mounted under the current namespace, hence they are- # appended to /api/v3/work_packages/:id/file_links/:file_link_id/...- mount ::API::V3::FileLinks::FileLinksDownloadAPI+ # appended to /api/v3/file_links/:file_link_id/...mount ::API::V3::FileLinks::FileLinksOpenAPIendenddiff --git a/modules/storages/lib/api/v3/file_links/file_links_download_api.rb b/modules/storages/lib/api/v3/file_links/file_links_download_api.rbdeleted file mode 100644index a01b0dfef35..00000000000--- a/modules/storages/lib/api/v3/file_links/file_links_download_api.rb+++ /dev/null@@ -1,41 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2022 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 FileLinks- class FileLinksDownloadAPI < ::API::OpenProjectAPI- resources :download do- get do- raise ::API::Errors::NotImplemented- end- end- end- end- end-enddiff --git a/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb b/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rbnew file mode 100644index 00000000000..a06a9dbf8ac--- /dev/null+++ b/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb@@ -0,0 +1,68 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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.+#++++# This class provides definitions for API routes and endpoints for the file_links namespace. It inherits the+# functionality from the Grape REST API framework. It is mounted in lib/api/v3/work_packages/work_packages_api.rb,+# which puts the file_links namespace behind the provided namespace of the work packages api+# -> /api/v3/work_packages/:id/file_links/...+module API+ module V3+ module FileLinks+ class WorkPackagesFileLinksAPI < ::API::OpenProjectAPI+ # helpers are defined by the grape framework. They provide methods that can be called from within the+ # endpoint context.+ helpers do+ def visible_file_links_scope+ ::Storages::FileLink.visible(current_user)+ end+ end++ # The `:resources` keyword defines the API namespace -> /api/v3/work_packages/:id/file_links/...+ resources :file_links do+ # A helper is used to define the behaviour at GET /api/v3/work_packages/:id/file_links+ get &::API::V3::Utilities::Endpoints::Index+ .new(model: ::Storages::FileLink,+ scope: -> { visible_file_links_scope.where(container_id: @work_package.id) },+ self_path: -> { api_v3_paths.file_links(params[:id]) })+ .mount++ # A helper is used to define the behaviour at POST /api/v3/work_packages/:id/file_links.+ # Additional classes are provided, that overwrite standard behaviour for parsing request parameters or+ # rendering the response.+ post &CreateEndpoint+ .new(+ model: ::Storages::FileLink,+ parse_service: ParseCreateParamsService,+ render_representer: FileLinkCollectionRepresenter+ )+ .mount+ end+ end+ end+ end+enddiff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rbindex 353919612e8..33409f99348 100644--- a/modules/storages/lib/open_project/storages/engine.rb+++ b/modules/storages/lib/open_project/storages/engine.rb@@ -96,16 +96,16 @@ module OpenProject::Storages"#{work_package(work_package_id)}/file_links"end- add_api_path :file_link do |work_package_id, file_link_id|- "#{work_package(work_package_id)}/file_links/#{file_link_id}"+ add_api_path :file_link do |file_link_id|+ "#{root}/file_links/#{file_link_id}"end- add_api_path :file_link_download do |work_package_id, file_link_id|- "#{work_package(work_package_id)}/file_links/#{file_link_id}/download"+ add_api_path :file_link_download do |file_link_id|+ "#{root}/file_links/#{file_link_id}/download"end- add_api_path :file_link_open do |work_package_id, file_link_id|- "#{work_package(work_package_id)}/file_links/#{file_link_id}/open"+ add_api_path :file_link_open do |file_link_id|+ "#{root}/file_links/#{file_link_id}/open"endendenddiff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rbindex 9851abfae38..0244e71c7b6 100644--- a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb@@ -183,8 +183,8 @@ describe 'API v3 file links resource', type: :request doendend- describe 'GET /api/v3/work_packages/:work_package_id/file_links/:file_link_id' do- let(:path) { api_v3_paths.file_link(work_package.id, file_link.id) }+ describe 'GET /api/v3/file_links/:file_link_id' do+ let(:path) { api_v3_paths.file_link(file_link.id) }before doget path@@ -195,21 +195,21 @@ describe 'API v3 file links resource', type: :request doendcontext 'if user has not sufficient permissions' do- let(:permissions) { %i(view_work_packages) }+ let(:permissions) { [] }it_behaves_like 'not found'endcontext 'if no storage with that id exists' do- let(:path) { api_v3_paths.file_link(work_package.id, 1337) }+ let(:path) { api_v3_paths.file_link(1337) }it_behaves_like 'not found'endend- describe 'DELETE /api/v3/work_packages/:work_package_id/file_links/:file_link_id' do- let(:path) { api_v3_paths.file_link(work_package.id, file_link.id) }- let(:permissions) { %i(view_work_packages view_file_links manage_file_links) }+ describe 'DELETE /api/v3/file_links/:file_link_id' do+ let(:path) { api_v3_paths.file_link(file_link.id) }+ let(:permissions) { %i(view_file_links manage_file_links) }before doheader 'Content-Type', 'application/json'@@ -222,26 +222,26 @@ describe 'API v3 file links resource', type: :request doendcontext 'if user has no view permissions' do- let(:permissions) { %i(view_work_packages) }+ let(:permissions) { [] }it_behaves_like 'not found'endcontext 'if user has no manage permissions' do- let(:permissions) { %i(view_work_packages view_file_links) }+ let(:permissions) { %i(view_file_links) }it_behaves_like 'unauthorized access'endcontext 'if no storage with that id exists' do- let(:path) { api_v3_paths.file_link(work_package.id, 1337) }+ let(:path) { api_v3_paths.file_link(1337) }it_behaves_like 'not found'endend- describe 'GET /api/v3/work_packages/:work_package_id/file_links/:file_link_id/open' do- let(:path) { api_v3_paths.file_link_open(work_package.id, file_link.id) }+ describe 'GET /api/v3/file_links/:file_link_id/open' do+ let(:path) { api_v3_paths.file_link_open(file_link.id) }before doget path@@ -252,13 +252,13 @@ describe 'API v3 file links resource', type: :request doendcontext 'if user has no view permissions' do- let(:permissions) { %i(view_work_packages) }+ let(:permissions) { [] }it_behaves_like 'not found'endcontext 'if no storage with that id exists' do- let(:path) { api_v3_paths.file_link(work_package.id, 1337) }+ let(:path) { api_v3_paths.file_link(1337) }it_behaves_like 'not found'end