Skip to content

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

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

Eric Schubert06a75b9261fd
diff --git a/modules/storages/lib/api/v3/file_links/file_link_representer.rb b/modules/storages/lib/api/v3/file_links/file_link_representer.rb
index c7c07e2ae50..7a2b89e6ff7 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
@@ -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,
diff --git a/modules/storages/lib/api/v3/file_links/file_links_open_api.rb b/modules/storages/lib/api/v3/file_links/file_links_open_api.rb
index a6d1c7d9a45..68ed37fa957 100644
--- a/modules/storages/lib/api/v3/file_links/file_links_open_api.rb
+++ b/modules/storages/lib/api/v3/file_links/file_links_open_api.rb
@@ -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
diff --git a/modules/storages/lib/api/v3/file_links/storage_url_helper.rb b/modules/storages/lib/api/v3/file_links/storage_url_helper.rb
index c001ffba47d..b4f88e6d328 100644
--- a/modules/storages/lib/api/v3/file_links/storage_url_helper.rb
+++ b/modules/storages/lib/api/v3/file_links/storage_url_helper.rb
@@ -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
diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb
index 5089130e405..fcc2bdd4b27 100644
--- a/modules/storages/lib/open_project/storages/engine.rb
+++ b/modules/storages/lib/open_project/storages/engine.rb
@@ -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
diff --git a/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb b/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb
index 4206f669c70..44fd6331d25 100644
--- a/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb
+++ b/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb
@@ -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
diff --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.rb
index 4e2a1bc136c..460c9749e7b 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
@@ -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