diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb index 1ca2ebd3c0c9..30a194b19cd9 100644 --- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb +++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud.rb @@ -43,7 +43,8 @@ module Nextcloud register(:propfind, Internal::PropfindQuery) register(:group_users, GroupUsersQuery) register(:upload_link, UploadLinkQuery) - register(:open_link, OpenLinkQuery) + register(:open_file_link, OpenFileLinkQuery) + register(:open_storage, OpenStorageQuery) end end diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query.rb similarity index 98% rename from modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_link_query.rb rename to modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query.rb index 6c0b64c2ad3a..6565de958f46 100644 --- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_link_query.rb +++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query.rb @@ -32,7 +32,7 @@ module Storages module Peripherals module StorageInteraction module Nextcloud - class OpenLinkQuery + class OpenFileLinkQuery def initialize(storage) @uri = storage.uri end diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_storage_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_storage_query.rb new file mode 100644 index 000000000000..a1fdd5803c68 --- /dev/null +++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/open_storage_query.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +#-- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2012-2023 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 Storages + module Peripherals + module StorageInteraction + module Nextcloud + class OpenStorageQuery + def initialize(storage) + @uri = storage.uri + end + + def self.call(storage:, user:) + new(storage).call(user:) + end + + # rubocop:disable Lint/UnusedMethodArgument + def call(user:) + ServiceResult.success(result: File.join(@uri.to_s, 'index.php/apps/files')) + end + + # rubocop:enable Lint/UnusedMethodArgument + end + end + end + end +end diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rb index 1d05a7b59d03..2b7d449e7453 100644 --- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rb +++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rb @@ -38,8 +38,8 @@ module OneDrive register(:files, FilesQuery) register(:file_info, FileInfoQuery) register(:files_info, FilesInfoQuery) - register(:open_link, OpenLinkQuery) - register(:open_drive_link, OpenDriveLinkQuery) + register(:open_file_link, OpenFileLinkQuery) + register(:open_storage, OpenStorageQuery) register(:upload_link, UploadLinkQuery) end end diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rb index 4726eb267a75..acdaa8c3e547 100644 --- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rb +++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/files_info_query.rb @@ -33,8 +33,6 @@ module Peripherals module StorageInteraction module OneDrive class FilesInfoQuery - include StorageErrorHelper - using ServiceResultRefinements def self.call(storage:, user:, file_ids: []) diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_file_link_query.rb similarity index 98% rename from modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_link_query.rb rename to modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_file_link_query.rb index 6c4c6413370f..1c539ce39e7f 100644 --- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_link_query.rb +++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_file_link_query.rb @@ -32,7 +32,7 @@ module Storages module Peripherals module StorageInteraction module OneDrive - class OpenLinkQuery + class OpenFileLinkQuery using ::Storages::Peripherals::ServiceResultRefinements def self.call(storage:, user:, file_id:, open_location: false) diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_drive_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb similarity index 88% rename from modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_drive_link_query.rb rename to modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb index 68d48ad46e9c..57b6be0c4196 100644 --- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_drive_link_query.rb +++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/open_storage_query.rb @@ -32,7 +32,7 @@ module Storages module Peripherals module StorageInteraction module OneDrive - class OpenDriveLinkQuery + class OpenStorageQuery def self.call(storage:, user:) new(storage).call(user:) end @@ -44,13 +44,13 @@ def initialize(storage) def call(user:) Util.using_user_token(@storage, user) do |token| - make_request(token).map(&web_url) + request_drive(token).map(&web_url) end end private - def make_request(token) + def request_drive(token) response_data = Net::HTTP.start(@uri.host, @uri.port, use_ssl: true) do |http| http.get(drive_uri_path, { 'Authorization' => "Bearer #{token.access_token}" }) end @@ -60,22 +60,23 @@ def make_request(token) def handle_responses(response) json = MultiJson.load(response.body, symbolize_keys: true) + error_data = ::Storages::StorageErrorData.new(source: self, payload: json) case response when Net::HTTPSuccess ServiceResult.success(result: json) when Net::HTTPNotFound ServiceResult.failure(result: :not_found, - errors: ::Storages::StorageError.new(code: :not_found, data: json)) + errors: ::Storages::StorageError.new(code: :not_found, data: error_data)) when Net::HTTPForbidden ServiceResult.failure(result: :forbidden, - errors: ::Storages::StorageError.new(code: :forbidden, data: json)) + errors: ::Storages::StorageError.new(code: :forbidden, data: error_data)) when Net::HTTPUnauthorized ServiceResult.failure(result: :unauthorized, - errors: ::Storages::StorageError.new(code: :unauthorized, data: json)) + errors: ::Storages::StorageError.new(code: :unauthorized, data: error_data)) else ServiceResult.failure(result: :error, - errors: ::Storages::StorageError.new(code: :error, data: json)) + errors: ::Storages::StorageError.new(code: :error, data: error_data)) end end diff --git a/modules/storages/app/models/storages/nextcloud_storage.rb b/modules/storages/app/models/storages/nextcloud_storage.rb index c31f8810bbad..06451b2beb78 100644 --- a/modules/storages/app/models/storages/nextcloud_storage.rb +++ b/modules/storages/app/models/storages/nextcloud_storage.rb @@ -60,10 +60,6 @@ def oauth_configuration Peripherals::OAuthConfigurations::NextcloudConfiguration.new(self) end - def open_link - File.join(uri.to_s, 'index.php/apps/files') - end - def automatic_management_unspecified? automatically_managed.nil? end diff --git a/modules/storages/app/models/storages/one_drive_storage.rb b/modules/storages/app/models/storages/one_drive_storage.rb index 7209f71061b4..1d2e116cc328 100644 --- a/modules/storages/app/models/storages/one_drive_storage.rb +++ b/modules/storages/app/models/storages/one_drive_storage.rb @@ -50,14 +50,5 @@ def uri def connect_src %w[https://*.sharepoint.com https://*.up.1drv.com] end - - def open_link - ::Storages::Peripherals::Registry.resolve("queries.one_drive.open_drive_link") - .call(storage: self, user: User.current) - .match( - on_success: ->(web_url) { web_url }, - on_failure: ->(*) { '' } - ) - end end end diff --git a/modules/storages/app/models/storages/project_storage.rb b/modules/storages/app/models/storages/project_storage.rb index 24b544dccf52..b2405f97eb3b 100644 --- a/modules/storages/app/models/storages/project_storage.rb +++ b/modules/storages/app/models/storages/project_storage.rb @@ -64,19 +64,6 @@ def file_inside_project_folder?(escaped_file_path) escaped_file_path.match?(%r|^/#{project_folder_path_escaped}|) end - def open_link - if project_folder_inactive? - storage.open_link - else - call = ::Storages::Peripherals::Registry.resolve("queries.#{storage.short_provider_type}.open_link") - .call(storage:, user: User.current, file_id: project_folder_id) - call.match( - on_success: ->(url) { url }, - on_failure: ->(*) { storage.open_link } - ) - end - end - private def escape_path(path) diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rb index 72bd1f37f862..42c345a7736f 100644 --- a/modules/storages/app/models/storages/storage.rb +++ b/modules/storages/app/models/storages/storage.rb @@ -116,10 +116,6 @@ def connect_src ["#{uri.scheme}://#{uri.host}"] end - def open_link - raise Errors::SubclassResponsibility - end - def oauth_configuration raise Errors::SubclassResponsibility end 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 e721ac5d4bef..8b4a6d2f2fa4 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 @@ -27,12 +27,14 @@ #++ class API::V3::FileLinks::FileLinksOpenAPI < API::OpenProjectAPI + helpers Storages::Peripherals::StorageErrorHelper + using Storages::Peripherals::ServiceResultRefinements resources :open do get do Storages::Peripherals::Registry - .resolve("queries.#{@file_link.storage.short_provider_type}.open_link") + .resolve("queries.#{@file_link.storage.short_provider_type}.open_file_link") .call( storage: @file_link.storage, user: current_user, diff --git a/modules/storages/lib/api/v3/project_storages/project_storage_open_api.rb b/modules/storages/lib/api/v3/project_storages/project_storage_open_api.rb new file mode 100644 index 000000000000..b48d22f1bd9f --- /dev/null +++ b/modules/storages/lib/api/v3/project_storages/project_storage_open_api.rb @@ -0,0 +1,62 @@ +#-- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2012-2023 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. +#++ + +class API::V3::ProjectStorages::ProjectStorageOpenAPI < API::OpenProjectAPI + helpers Storages::Peripherals::StorageErrorHelper + + using Storages::Peripherals::ServiceResultRefinements + + resources :open do + get do + query_result = if @project_storage.project_folder_inactive? + Storages::Peripherals::Registry + .resolve("queries.#{@project_storage.storage.short_provider_type}.open_storage") + .call( + storage: @project_storage.storage, + user: current_user + ) + else + Storages::Peripherals::Registry + .resolve("queries.#{@project_storage.storage.short_provider_type}.open_file_link") + .call( + storage: @project_storage.storage, + user: current_user, + file_id: @project_storage.project_folder_id + ) + end + + query_result.match( + on_success: ->(url) do + redirect url, body: "The requested resource can be viewed at #{url}" + status 303 + end, + on_failure: ->(error) { raise_error(error) } + ) + end + end +end diff --git a/modules/storages/lib/api/v3/project_storages/project_storage_representer.rb b/modules/storages/lib/api/v3/project_storages/project_storage_representer.rb index 3582a75628e5..8795408722a9 100644 --- a/modules/storages/lib/api/v3/project_storages/project_storage_representer.rb +++ b/modules/storages/lib/api/v3/project_storages/project_storage_representer.rb @@ -46,6 +46,10 @@ class ProjectStorageRepresenter < ::API::Decorators::Single { href: api_v3_paths.storage_file(represented.storage.id, represented.project_folder_id) } end + link :open do + { href: api_v3_paths.project_storage_open(represented.id) } + end + associated_resource :storage, skip_render: ->(*) { true }, skip_link: ->(*) { false } associated_resource :project, skip_render: ->(*) { true }, skip_link: ->(*) { false } associated_resource :creator, diff --git a/modules/storages/lib/api/v3/project_storages/project_storages_api.rb b/modules/storages/lib/api/v3/project_storages/project_storages_api.rb index a7393998e781..126461dc3e93 100644 --- a/modules/storages/lib/api/v3/project_storages/project_storages_api.rb +++ b/modules/storages/lib/api/v3/project_storages/project_storages_api.rb @@ -63,6 +63,8 @@ class ProjectStoragesAPI < API::OpenProjectAPI end get &API::V3::Utilities::Endpoints::Show.new(model: Storages::ProjectStorage).mount + + mount API::V3::ProjectStorages::ProjectStorageOpenAPI end end end diff --git a/modules/storages/lib/api/v3/storages/storage_open_api.rb b/modules/storages/lib/api/v3/storages/storage_open_api.rb new file mode 100644 index 000000000000..be0d7d2c34c7 --- /dev/null +++ b/modules/storages/lib/api/v3/storages/storage_open_api.rb @@ -0,0 +1,48 @@ +#-- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2012-2023 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. +#++ + +class API::V3::Storages::StorageOpenAPI < API::OpenProjectAPI + helpers Storages::Peripherals::StorageErrorHelper + + using Storages::Peripherals::ServiceResultRefinements + + resources :open do + get do + Storages::Peripherals::Registry + .resolve("queries.#{@storage.short_provider_type}.open_storage") + .call(storage: @storage, user: current_user, file_id: nil) + .match( + on_success: ->(url) do + redirect url, body: "The requested resource can be viewed at #{url}" + status 303 + end, + on_failure: ->(error) { raise_error(error) } + ) + end + end +end diff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rb index f4877fc26b25..ebdd3886f9de 100644 --- a/modules/storages/lib/api/v3/storages/storage_representer.rb +++ b/modules/storages/lib/api/v3/storages/storage_representer.rb @@ -151,7 +151,7 @@ def initialize(model, current_user:, embed_links: nil) end link :open do - { href: represented.open_link } + { href: api_v3_paths.storage_open(represented.id) } end link :authorizationState do diff --git a/modules/storages/lib/api/v3/storages/storages_api.rb b/modules/storages/lib/api/v3/storages/storages_api.rb index 80e676100960..1032ca3ae8da 100644 --- a/modules/storages/lib/api/v3/storages/storages_api.rb +++ b/modules/storages/lib/api/v3/storages/storages_api.rb @@ -49,6 +49,7 @@ class API::V3::Storages::StoragesAPI < API::OpenProjectAPI mount API::V3::StorageFiles::StorageFilesAPI mount API::V3::OAuthClient::OAuthClientCredentialsAPI + mount API::V3::Storages::StorageOpenAPI end end end diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb index 653bce0582e8..b078b5748e94 100644 --- a/modules/storages/lib/open_project/storages/engine.rb +++ b/modules/storages/lib/open_project/storages/engine.rb @@ -159,7 +159,7 @@ def self.permissions User.current.allowed_to?(:view_file_links, project) project.project_storages.each do |project_storage| storage = project_storage.storage - href = project_storage.open_link + href = "/api/v3/project_storages/#{project_storage.id}/open" icon = if storage.provider_type_nextcloud? 'nextcloud-circle' else @@ -228,13 +228,21 @@ def self.permissions end add_api_path :project_storage do |id| - "#{root}/project_storages/#{id}" + "#{project_storages}/#{id}" + end + + add_api_path :project_storage_open do |id| + "#{project_storage(id)}/open" end add_api_path :storage do |storage_id| "#{storages}/#{storage_id}" end + add_api_path :storage_open do |storage_id| + "#{storage(storage_id)}/open" + end + add_api_path :storage_files do |storage_id| "#{storage(storage_id)}/files" end diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/open_link_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query_spec.rb similarity index 91% rename from modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/open_link_query_spec.rb rename to modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query_spec.rb index 365182befbbf..a45f8d92193a 100644 --- a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/open_link_query_spec.rb +++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/open_file_link_query_spec.rb @@ -31,9 +31,7 @@ require 'spec_helper' require_module_spec_helper -RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::OpenLinkQuery do - include JsonResponseHelper - +RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::OpenFileLinkQuery do let(:storage) { create(:nextcloud_storage, host: 'https://example.com') } let(:user) { create(:user) } let(:file_id) { '1337' } @@ -45,6 +43,11 @@ expect(method.parameters).to contain_exactly(%i[keyreq storage], %i[keyreq user], %i[keyreq file_id], %i[key open_location]) end + it 'returns the url for opening the storage if no file id is provided' do + url = described_class.call(storage:, user:, file_id: nil).result + expect(url).to eq("#{storage.host}/index.php/apps/files") + end + it 'returns the url for opening the file on storage' do url = described_class.call(storage:, user:, file_id:).result expect(url).to eq("#{storage.host}/index.php/f/#{file_id}?openfile=1") diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/download_link_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/download_link_query_spec.rb index 5ecb40ba05b5..034560550e9b 100644 --- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/download_link_query_spec.rb +++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/download_link_query_spec.rb @@ -56,7 +56,7 @@ it 'return an error if any other response is received' do stub_request(:get, "https://graph.microsoft.com/v1.0/drives/#{storage.drive_id}/items/#{file_link.origin_id}/content") .with(headers: { 'Authorization' => "Bearer #{token.access_token}" }) - .and_return(status: 200, body: "") + .and_return(status: 200, body: '') download_link = download_link_query.call(user:, file_link:) diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_link_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_file_link_query_spec.rb similarity index 99% rename from modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_link_query_spec.rb rename to modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_file_link_query_spec.rb index 0c0786e52d5c..943649571fde 100644 --- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_link_query_spec.rb +++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_file_link_query_spec.rb @@ -31,7 +31,7 @@ require 'spec_helper' require_module_spec_helper -RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::OpenLinkQuery, :webmock do +RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::OpenFileLinkQuery, :webmock do include JsonResponseHelper let(:storage) do diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_drive_link_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_storage_query_spec.rb similarity index 93% rename from modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_drive_link_query_spec.rb rename to modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_storage_query_spec.rb index 5dfaf831295a..e1011ba9f7f4 100644 --- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_drive_link_query_spec.rb +++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/open_storage_query_spec.rb @@ -31,9 +31,11 @@ require 'spec_helper' require_module_spec_helper -RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::OpenDriveLinkQuery, :webmock do +RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::OpenStorageQuery, :webmock do include JsonResponseHelper + using Storages::Peripherals::ServiceResultRefinements + let(:storage) do create(:one_drive_storage, :with_oauth_client, @@ -70,7 +72,7 @@ expect(open_drive_link_result).to be_failure expect(open_drive_link_result.result).to eq(:not_found) - expect(open_drive_link_result.errors.data.to_json).to eq(not_found_json) + expect(open_drive_link_result.error_payload.to_json).to eq(not_found_json) end it 'returns a forbidden error if the API call returns a 403' do @@ -82,7 +84,7 @@ expect(open_drive_link_result).to be_failure expect(open_drive_link_result.result).to eq(:forbidden) - expect(open_drive_link_result.errors.data.to_json).to eq(forbidden_json) + expect(open_drive_link_result.error_payload.to_json).to eq(forbidden_json) end end end diff --git a/modules/storages/spec/features/storages_menu_links_spec.rb b/modules/storages/spec/features/storages_menu_links_spec.rb index fc21cfa2d083..48a8bd89c569 100644 --- a/modules/storages/spec/features/storages_menu_links_spec.rb +++ b/modules/storages/spec/features/storages_menu_links_spec.rb @@ -56,10 +56,10 @@ it 'has links to enabled storages' do visit(project_path(id: project.id)) - expect(page).to have_link(storage.name, href: storage.open_link) - project_folder_id = project_storage_with_manual_folder.project_folder_id - folder_href = "#{another_storage.host}/index.php/f/#{project_folder_id}?openfile=1" - expect(page).to have_link(another_storage.name, href: folder_href) + expect(page).to have_link(storage.name, + href: api_v3_paths.project_storage_open(project_storage_without_folder.id)) + expect(page).to have_link(another_storage.name, + href: api_v3_paths.project_storage_open(project_storage_with_manual_folder.id)) expect(page).not_to have_link(unlinked_storage.name) end @@ -69,11 +69,10 @@ it 'has no links to enabled storage' do visit(project_path(id: project.id)) - expect(page).not_to have_link(storage.name, href: storage.open_link) - project_folder_id = project_storage_with_manual_folder.project_folder_id - folder_href = "#{another_storage.host}/index.php/f/#{project_folder_id}?openfile=1" - expect(page).not_to have_link(another_storage.name, href: folder_href) - expect(page).not_to have_link(another_storage.name, href: another_storage.open_link) + expect(page).not_to have_link(storage.name, + href: api_v3_paths.project_storage_open(project_storage_without_folder.id)) + expect(page).not_to have_link(another_storage.name, + href: api_v3_paths.project_storage_open(project_storage_with_manual_folder.id)) expect(page).not_to have_link(unlinked_storage.name) end end diff --git a/modules/storages/spec/lib/api/v3/storages/storages_representer_rendering_spec.rb b/modules/storages/spec/lib/api/v3/storages/storages_representer_rendering_spec.rb index b3961557933f..4217000cc11c 100644 --- a/modules/storages/spec/lib/api/v3/storages/storages_representer_rendering_spec.rb +++ b/modules/storages/spec/lib/api/v3/storages/storages_representer_rendering_spec.rb @@ -276,7 +276,7 @@ end before do - Storages::Peripherals::Registry.stub('queries.one_drive.open_drive_link', ->(_) do + Storages::Peripherals::Registry.stub('queries.one_drive.open_storage', ->(_) do ServiceResult.success(result: 'https://my.sharepoint.com/sites/DeathStar/Documents') end) end