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
use helper instead of a service to get open url for file_links
Christophe Bliard9e968c4752b2
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.rbindex 7c31574c018..0ba53c49c40 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@@ -33,6 +33,7 @@ module APIinclude API::Decorators::LinkedResourceinclude API::Decorators::DatePropertyinclude ::API::Caching::CachedRepresenter+ include API::V3::FileLinks::StorageUrlHelperproperty :id@@ -67,7 +68,7 @@ module APIlink :originOpen do{- href: ::Storages::StorageUrlService.new(represented).call('open').result+ href: storage_url_open(represented)}enddiff --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.rbindex 158b51b07fa..a6d1c7d9a45 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@@ -30,13 +30,11 @@ module APImodule V3module FileLinksclass FileLinksOpenAPI < ::API::OpenProjectAPI+ helpers API::V3::FileLinks::StorageUrlHelper+resources :open doget do- service_call = ::Storages::StorageUrlService.new(@file_link).call('open')-- raise StandardError, 'Cannot create opening url for linked file.' if service_call.failure?-- url = service_call.result+ url = storage_url_open(@file_link)redirect url, body: "The requested resource can be viewed at #{url}"status 303 # The follow-up request to the resource must be GETenddiff --git a/modules/storages/app/services/storages/storage_url_service.rb b/modules/storages/lib/api/v3/file_links/storage_url_helper.rbsimilarity index 74%rename from modules/storages/app/services/storages/storage_url_service.rbrename to modules/storages/lib/api/v3/file_links/storage_url_helper.rbindex 500ffce1f90..c001ffba47d 100644--- a/modules/storages/app/services/storages/storage_url_service.rb+++ b/modules/storages/lib/api/v3/file_links/storage_url_helper.rb@@ -26,20 +26,9 @@# See COPYRIGHT and LICENSE files for more details.#++-module Storages- class StorageUrlService- attr_reader :file_link-- ACTION_TYPES = %w[open].freeze-- def initialize(file_link)- @file_link = file_link- end-- def call(action)- return ServiceResult.new(success: false, message: 'invalid action type') unless ACTION_TYPES.include?(action)-- ServiceResult.new(success: true, result: "#{@file_link.storage.host}/f/#{@file_link.origin_id}")- end+# 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}"endenddiff --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.rbindex 6ae4fc934cc..4206f669c70 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@@ -40,10 +40,6 @@ describe ::API::V3::FileLinks::FileLinkRepresenter, 'rendering' dosubject(:generated) { representer.to_json }- before do- allow(::Storages::StorageUrlService).to receive(:find).and_return creator- end-describe '_links' dodescribe 'self' doit_behaves_like 'has a titled link' do