[#40228] migrated some file links endpoint

- following endpoint under own file links namespace
  - GET file link
  - DELETE file link
  - GET static file link open url
pull/10279/head
Eric Schubert 3 years ago
parent 070369427a
commit f82f355c03
No known key found for this signature in database
GPG Key ID: 1D346C019BD4BAA2
  1. 1
      lib/api/v3/root.rb
  2. 2
      lib/api/v3/work_packages/work_packages_api.rb
  3. 6
      modules/storages/lib/api/v3/file_links/file_link_representer.rb
  4. 32
      modules/storages/lib/api/v3/file_links/file_links_api.rb
  5. 41
      modules/storages/lib/api/v3/file_links/file_links_download_api.rb
  6. 68
      modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb
  7. 12
      modules/storages/lib/open_project/storages/engine.rb
  8. 28
      modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb

@ -70,6 +70,7 @@ module API
mount ::API::V3::Roles::RolesAPI
mount ::API::V3::Statuses::StatusesAPI
mount ::API::V3::Storages::StoragesAPI
mount ::API::V3::FileLinks::FileLinksAPI
mount ::API::V3::StringObjects::StringObjectsAPI
mount ::API::V3::Types::TypesAPI
mount ::API::V3::Users::UsersAPI

@ -102,7 +102,7 @@ module API
mount ::API::V3::WorkPackages::AvailableProjectsOnEditAPI
mount ::API::V3::WorkPackages::AvailableRelationCandidatesAPI
mount ::API::V3::WorkPackages::WorkPackageRelationsAPI
mount ::API::V3::FileLinks::FileLinksAPI
mount ::API::V3::FileLinks::WorkPackagesFileLinksAPI
end
mount ::API::V3::WorkPackages::CreateFormAPI

@ -51,13 +51,13 @@ module API
link :self do
{
href: api_v3_paths.file_link(represented.container_id, represented.id)
href: api_v3_paths.file_link(represented.id)
}
end
link :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 API
link :staticOriginOpen do
{
href: api_v3_paths.file_link_open(represented.container_id, represented.id)
href: api_v3_paths.file_link_open(represented.id)
}
end

@ -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 API
module V3
module FileLinks
@ -42,26 +41,8 @@ module API
end
end
# 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_id
get &::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_id
delete &::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::FileLinksOpenAPI
end
end

@ -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
end

@ -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
end

@ -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"
end
end
end

@ -183,8 +183,8 @@ describe 'API v3 file links resource', type: :request do
end
end
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 do
get path
@ -195,21 +195,21 @@ describe 'API v3 file links resource', type: :request do
end
context 'if user has not sufficient permissions' do
let(:permissions) { %i(view_work_packages) }
let(:permissions) { [] }
it_behaves_like 'not found'
end
context '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
end
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 do
header 'Content-Type', 'application/json'
@ -222,26 +222,26 @@ describe 'API v3 file links resource', type: :request do
end
context 'if user has no view permissions' do
let(:permissions) { %i(view_work_packages) }
let(:permissions) { [] }
it_behaves_like 'not found'
end
context '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'
end
context '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
end
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 do
get path
@ -252,13 +252,13 @@ describe 'API v3 file links resource', type: :request do
end
context 'if user has no view permissions' do
let(:permissions) { %i(view_work_packages) }
let(:permissions) { [] }
it_behaves_like 'not found'
end
context '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

Loading…
Cancel
Save