[#42161] added new open file location link to api v3

pull/10571/head
Eric Schubert 3 years ago
parent 4e43a4d6c2
commit 06a75b9261
No known key found for this signature in database
GPG Key ID: 1D346C019BD4BAA2
  1. 12
      modules/storages/lib/api/v3/file_links/file_link_representer.rb
  2. 2
      modules/storages/lib/api/v3/file_links/file_links_open_api.rb
  3. 6
      modules/storages/lib/api/v3/file_links/storage_url_helper.rb
  4. 4
      modules/storages/lib/open_project/storages/engine.rb
  5. 16
      modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb
  6. 10
      modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb

@ -78,6 +78,18 @@ module API
}
end
link :originOpenLocation do
{
href: storage_url_open(represented, true)
}
end
link :staticOriginOpenLocation do
{
href: api_v3_paths.file_link_open(represented.id, true)
}
end
associated_resource :storage
associated_resource :storageUrl,

@ -34,7 +34,7 @@ module API
resources :open do
get do
url = storage_url_open(@file_link)
url = storage_url_open(@file_link, params[:location])
redirect url, body: "The requested resource can be viewed at #{url}"
status 303 # The follow-up request to the resource must be GET
end

@ -28,7 +28,9 @@
# Helper for open and download links for a file link object.
module API::V3::FileLinks::StorageUrlHelper
def storage_url_open(file_link)
"#{file_link.storage.host}/f/#{file_link.origin_id}"
def storage_url_open(file_link, open_location: false)
location_flag = ActiveModel::Type::Boolean.new.cast(open_location) ? 0 : 1
"#{file_link.storage.host}/f/#{file_link.origin_id}?openfile=#{location_flag}"
end
end

@ -120,8 +120,8 @@ module OpenProject::Storages
"#{root}/file_links/#{file_link_id}/download"
end
add_api_path :file_link_open do |file_link_id|
"#{root}/file_links/#{file_link_id}/open"
add_api_path :file_link_open do |file_link_id, location = false|
"#{root}/file_links/#{file_link_id}/open#{location ? '?location=true' : ''}"
end
# Add api endpoints specific to this module

@ -86,7 +86,7 @@ describe ::API::V3::FileLinks::FileLinkRepresenter, 'rendering' do
describe 'originOpen' do
it_behaves_like 'has an untitled link' do
let(:link) { 'originOpen' }
let(:href) { "#{storage.host}/f/#{file_link.origin_id}" }
let(:href) { "#{storage.host}/f/#{file_link.origin_id}?openfile=1" }
end
end
@ -96,6 +96,20 @@ describe ::API::V3::FileLinks::FileLinkRepresenter, 'rendering' do
let(:href) { "/api/v3/file_links/#{file_link.id}/open" }
end
end
describe 'originOpenLocation' do
it_behaves_like 'has an untitled link' do
let(:link) { 'originOpenLocation' }
let(:href) { "#{storage.host}/f/#{file_link.origin_id}?openfile=0" }
end
end
describe 'staticOriginOpenLocation' do
it_behaves_like 'has an untitled link' do
let(:link) { 'staticOriginOpenLocation' }
let(:href) { "/api/v3/file_links/#{file_link.id}/open?location=true" }
end
end
end
describe 'properties' do

@ -29,7 +29,6 @@
require 'spec_helper'
require_module_spec_helper
# rubocop:disable RSpec/MultipleMemoizedHelpers
describe 'API v3 file links resource', :enable_storages, type: :request do
include API::V3::Utilities::PathHelper
@ -408,6 +407,14 @@ describe 'API v3 file links resource', :enable_storages, type: :request do
expect(subject.status).to be 303
end
context 'with location flag' do
let(:path) { api_v3_paths.file_link_open(file_link.id, true) }
it 'is successful' do
expect(subject.status).to be 303
end
end
context 'if user has no view permissions' do
let(:permissions) { [] }
@ -425,4 +432,3 @@ describe 'API v3 file links resource', :enable_storages, type: :request do
end
end
end
# rubocop:enable RSpec/MultipleMemoizedHelpers

Loading…
Cancel
Save