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
[#64192] add open file link query for sharepoint
Eric Schubert0bf9a30e27b7
diff --git a/modules/storages/app/common/storages/adapters/providers/share_point/queries/open_file_link_query.rb b/modules/storages/app/common/storages/adapters/providers/share_point/queries/open_file_link_query.rbnew file mode 100644index 00000000000..7c8117cdaa2--- /dev/null+++ b/modules/storages/app/common/storages/adapters/providers/share_point/queries/open_file_link_query.rb@@ -0,0 +1,68 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 Adapters+ module Providers+ module SharePoint+ module Queries+ class OpenFileLinkQuery < Base+ def call(auth_strategy:, input_data:)+ Authentication[auth_strategy].call(storage: @storage) do |http|+ split_identifier(input_data.file_id) => { drive_id:, location: item_id }++ if input_data.open_location+ request_parent_id(http, drive_id, item_id).bind { request_web_url(http, drive_id, it) }+ else+ request_web_url(http, drive_id, item_id)+ end+ end+ end++ private++ def drive_item_query+ @drive_item_query ||= Internal::DriveItemQuery.new(@storage)+ end++ def request_web_url(http, drive_id, item_id)+ drive_item_query.call(http:, drive_id:, item_id:, fields: %w[webUrl]).fmap { it[:webUrl] }+ end++ def request_parent_id(http, drive_id, item_id)+ drive_item_query.call(http:, drive_id:, item_id:, fields: %w[parentReference])+ .fmap { Peripherals::ParentFolder.new(it.dig(:parentReference, :id) || "/") }+ end+ end+ end+ end+ end+ end+enddiff --git a/modules/storages/app/common/storages/adapters/providers/share_point/share_point_registry.rb b/modules/storages/app/common/storages/adapters/providers/share_point/share_point_registry.rbindex e813c5205f5..2e2e9176663 100644--- a/modules/storages/app/common/storages/adapters/providers/share_point/share_point_registry.rb+++ b/modules/storages/app/common/storages/adapters/providers/share_point/share_point_registry.rb@@ -73,6 +73,7 @@ module Storagesregister(:file_info, Queries::FileInfoQuery)register(:files_info, Queries::FilesInfoQuery)register(:files, Queries::FilesQuery)+ register(:open_file_link, Queries::OpenFileLinkQuery)register(:open_storage, Queries::OpenStorageQuery)register(:upload_link, Queries::UploadLinkQuery)register(:user, OneDrive::Queries::UserQuery)diff --git a/modules/storages/spec/common/storages/adapters/providers/nextcloud/queries/open_file_link_query_spec.rb b/modules/storages/spec/common/storages/adapters/providers/nextcloud/queries/open_file_link_query_spec.rbindex 35ed75b4412..0454f8151ac 100644--- a/modules/storages/spec/common/storages/adapters/providers/nextcloud/queries/open_file_link_query_spec.rb+++ b/modules/storages/spec/common/storages/adapters/providers/nextcloud/queries/open_file_link_query_spec.rb@@ -38,37 +38,28 @@ module Storagesmodule QueriesRSpec.describe OpenFileLinkQuery dolet(:storage) { create(:nextcloud_storage, host: "https://example.com") }- let(:file_id) { "1337" }let(:auth_strategy) { Registry["nextcloud.authentication.userless"].call }- let(:input_data) { Input::OpenFileLink.build(file_id:).value! }+ let(:file_id) { "1337" }+ let(:open_location) { false }+ let(:input_data) { Input::OpenFileLink.build(file_id:, open_location:).value! }+ let(:open_file_link) { "#{storage.host}/index.php/f/#{file_id}?openfile=#{open_location ? '0' : '1'}" }- it "responds to .call" do- expect(described_class).to respond_to(:call)+ it_behaves_like "adapter open_file_link_query: basic query setup"- method = described_class.method(:call)- expect(method.parameters).to contain_exactly(%i[keyreq storage],- %i[keyreq auth_strategy],- %i[keyreq input_data])+ context "with open location flag not set" do+ it_behaves_like "adapter open_file_link_query: successful link response"end- it "returns the url for opening the file on storage" do- url = described_class.call(storage:, auth_strategy:, input_data:).value!- expect(url).to eq("#{storage.host}/index.php/f/#{file_id}?openfile=1")- end+ context "with open location flag set" do+ let(:open_location) { true }- it "returns the url for opening the file's location on storage" do- input_data = Input::OpenFileLink.build(file_id:, open_location: true).value!- url = described_class.call(storage:, auth_strategy:, input_data:).value!- expect(url).to eq("#{storage.host}/index.php/f/#{file_id}?openfile=0")+ it_behaves_like "adapter open_file_link_query: successful link response"endcontext "with a storage with host url with a sub path" dolet(:storage) { create(:nextcloud_storage, host: "https://example.com/html") }- it "returns the url for opening the file on storage" do- url = described_class.call(storage:, auth_strategy:, input_data:).value!- expect(url).to eq("#{storage.host}/index.php/f/#{file_id}?openfile=1")- end+ it_behaves_like "adapter open_file_link_query: successful link response"endendenddiff --git a/modules/storages/spec/common/storages/adapters/providers/one_drive/queries/open_file_link_query_spec.rb b/modules/storages/spec/common/storages/adapters/providers/one_drive/queries/open_file_link_query_spec.rbindex 3ed72b6c613..72ae6338493 100644--- a/modules/storages/spec/common/storages/adapters/providers/one_drive/queries/open_file_link_query_spec.rb+++ b/modules/storages/spec/common/storages/adapters/providers/one_drive/queries/open_file_link_query_spec.rb@@ -39,50 +39,38 @@ module StoragesRSpec.describe OpenFileLinkQuery, :vcr, :webmock dolet(:user) { create(:user) }let(:storage) { create(:one_drive_sandbox_storage, oauth_client_token_user: user) }- let(:file_id) { "01AZJL5PJTICED3C5YSVAY6NWTBNA2XERU" }let(:auth_strategy) { Registry.resolve("one_drive.authentication.user_bound").call(user, storage) }- let(:input_data) { Input::OpenFileLink.build(file_id:).value! }- subject { described_class.new(storage) }+ it_behaves_like "adapter open_file_link_query: basic query setup"- describe "#call" do- it "responds with correct parameters" do- expect(described_class).to respond_to(:call)+ context "with outbound requests successful" do+ context "with open location flag not set", vcr: "one_drive/open_file_link_query_success" do+ let(:file_id) { "01AZJL5PJTICED3C5YSVAY6NWTBNA2XERU" }+ let(:input_data) { Input::OpenFileLink.build(file_id:).value! }+ let(:open_file_link) do+ "https://finn.sharepoint.com/sites/openprojectfilestoragetests/_layouts/15/Doc.aspx" \+ "?sourcedoc=%7B3D884033-B88B-4195-8F36-D30B41AB9234%7D&file=Document.docx" \+ "&action=default&mobileredirect=true"+ end- method = described_class.method(:call)- expect(method.parameters).to contain_exactly(%i[keyreq storage],- %i[keyreq auth_strategy],- %i[keyreq input_data])+ it_behaves_like "adapter open_file_link_query: successful link response"end- context "with outbound requests successful" do- context "with open location flag not set", vcr: "one_drive/open_file_link_query_success" do- it "returns the url for opening the file on storage" do- call = subject.call(auth_strategy:, input_data:)- expect(call).to be_success- expect(call.value!).to eq("https://finn.sharepoint.com/sites/openprojectfilestoragetests/_layouts/15/Doc.aspx?sourcedoc=%7B3D884033-B88B-4195-8F36-D30B41AB9234%7D&file=Document.docx&action=default&mobileredirect=true")- end- end+ context "with open location flag set", vcr: "one_drive/open_file_link_location_query_success" do+ let(:file_id) { "01AZJL5PJTICED3C5YSVAY6NWTBNA2XERU" }+ let(:input_data) { Input::OpenFileLink.build(file_id:, open_location: true).value! }+ let(:open_file_link) { "https://finn.sharepoint.com/sites/openprojectfilestoragetests/VCR/Folder" }- context "with open location flag set", vcr: "one_drive/open_file_link_location_query_success" do- it "returns the url for opening the file on storage" do- call = subject.call(auth_strategy:, input_data: input_data.with(open_location: true))- expect(call).to be_success- expect(call.value!).to eq("https://finn.sharepoint.com/sites/openprojectfilestoragetests/VCR/Folder")- end- end+ it_behaves_like "adapter open_file_link_query: successful link response"end+ end- context "with not existent file id", vcr: "one_drive/open_file_link_query_missing_file_id" do- let(:file_id) { "iamnotexistent" }+ context "with not existent file id", vcr: "one_drive/open_file_link_query_missing_file_id" do+ let(:file_id) { "iamnotexistent" }+ let(:input_data) { Input::OpenFileLink.build(file_id:).value! }+ let(:error_source) { Internal::DriveItemQuery }- it "must return not found" do- result = subject.call(auth_strategy:, input_data:)- expect(result).to be_failure- expect(result.failure.source).to be(Internal::DriveItemQuery)- expect(result.failure.code).to eq(:not_found)- end- end+ it_behaves_like "adapter open_file_link_query: not found"endendenddiff --git a/modules/storages/spec/common/storages/adapters/providers/share_point/queries/open_file_link_query_spec.rb b/modules/storages/spec/common/storages/adapters/providers/share_point/queries/open_file_link_query_spec.rbnew file mode 100644index 00000000000..28fb668d590--- /dev/null+++ b/modules/storages/spec/common/storages/adapters/providers/share_point/queries/open_file_link_query_spec.rb@@ -0,0 +1,85 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++require "spec_helper"+require_module_spec_helper++module Storages+ module Adapters+ module Providers+ module SharePoint+ module Queries+ RSpec.describe OpenFileLinkQuery, :vcr, :webmock do+ let(:user) { create(:user) }+ let(:storage) { create(:share_point_storage, :sandbox, oauth_client_token_user: user) }+ let(:auth_strategy) { Registry.resolve("share_point.authentication.user_bound").call(user, storage) }+ let(:drive_id) { "b!FeOZEMfQx0eGQKqVBLcP__BG8mq-4-9FuRqOyk3MXY87vnZ6fgfvQanZHX-XCAyw" }+ let(:separator) { SharePointStorage::IDENTIFIER_SEPARATOR }++ it_behaves_like "adapter open_file_link_query: basic query setup"++ context "with outbound requests successful" do+ context "with open location flag not set", vcr: "share_point/open_file_link_query_success" do+ let(:file_id) { "#{drive_id}#{separator}01ANJ53WYLXAJW5PXSCJB2CFCD42UPDKMI" }+ let(:input_data) { Input::OpenFileLink.build(file_id:).value! }+ let(:open_file_link) { "https://ymt6d.sharepoint.com/sites/OPTest/Shared%20Documents/Folder" }++ it_behaves_like "adapter open_file_link_query: successful link response"+ end++ context "with open location flag set", vcr: "share_point/open_file_link_location_query_success" do+ let(:file_id) { "#{drive_id}#{separator}01ANJ53WYLXAJW5PXSCJB2CFCD42UPDKMI" }+ let(:input_data) { Input::OpenFileLink.build(file_id:, open_location: true).value! }+ let(:open_file_link) { "https://ymt6d.sharepoint.com/sites/OPTest/Shared%20Documents" }++ it_behaves_like "adapter open_file_link_query: successful link response"++ context "if file id already points at root element",+ vcr: "share_point/open_file_link_location_on_root_query_success" do+ let(:file_id) { "#{drive_id}#{separator}01ANJ53W56Y2GOVW7725BZO354PWSELRRZ" }++ it_behaves_like "adapter open_file_link_query: successful link response"+ end+ end+ end++ context "with not existent file id", vcr: "share_point/open_file_link_query_not_found" do+ let(:file_id) { "#{drive_id}#{separator}YouShallNotPass" }+ let(:input_data) { Input::OpenFileLink.build(file_id:).value! }+ let(:error_source) { Internal::DriveItemQuery }++ it_behaves_like "adapter open_file_link_query: not found"+ end+ end+ end+ end+ end+ end+enddiff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_location_on_root_query_success.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_location_on_root_query_success.ymlnew file mode 100644index 00000000000..7998058a4d9--- /dev/null+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_location_on_root_query_success.yml@@ -0,0 +1,89 @@+---+http_interactions:+- request:+ method: get+ uri: https://graph.microsoft.com/v1.0/drives/b!FeOZEMfQx0eGQKqVBLcP__BG8mq-4-9FuRqOyk3MXY87vnZ6fgfvQanZHX-XCAyw/items/01ANJ53W56Y2GOVW7725BZO354PWSELRRZ?$select=parentReference+ body:+ encoding: US-ASCII+ string: ''+ headers:+ Authorization:+ - Bearer <BEARER TOKEN>+ User-Agent:+ - httpx.rb/1.3.4+ Accept:+ - "*/*"+ Accept-Encoding:+ - gzip, deflate+ response:+ status:+ code: 200+ message: OK+ headers:+ Cache-Control:+ - no-store, no-cache+ Content-Type:+ - application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false;+ charset=utf-8+ Content-Encoding:+ - gzip+ Strict-Transport-Security:+ - max-age=31536000+ Request-Id:+ - 7563ecee-7556-4fa3-8776-5eb2b10c2c22+ Client-Request-Id:+ - 7563ecee-7556-4fa3-8776-5eb2b10c2c22+ X-Ms-Ags-Diagnostic:+ - '{"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"4","ScaleUnit":"002","RoleInstance":"FR3PEPF0000036E"}}'+ Splogid:+ - e6fdbba1-9050-0000-7bb8-a1935b862cfb+ Date:+ - Fri, 15 Aug 2025 12:25:51 GMT+ body:+ encoding: UTF-8+ string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)/$entity","parentReference":{"driveType":"documentLibrary","driveId":"b!FeOZEMfQx0eGQKqVBLcP__BG8mq-4-9FuRqOyk3MXY87vnZ6fgfvQanZHX-XCAyw"}}'+ recorded_at: Fri, 15 Aug 2025 12:25:51 GMT+- request:+ method: get+ uri: https://graph.microsoft.com/v1.0/drives/b!FeOZEMfQx0eGQKqVBLcP__BG8mq-4-9FuRqOyk3MXY87vnZ6fgfvQanZHX-XCAyw/root?$select=webUrl+ body:+ encoding: US-ASCII+ string: ''+ headers:+ Authorization:+ - Bearer <BEARER TOKEN>+ User-Agent:+ - httpx.rb/1.3.4+ Accept:+ - "*/*"+ Accept-Encoding:+ - gzip, deflate+ response:+ status:+ code: 200+ message: OK+ headers:+ Cache-Control:+ - no-store, no-cache+ Content-Type:+ - application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false;+ charset=utf-8+ Content-Encoding:+ - gzip+ Strict-Transport-Security:+ - max-age=31536000+ Request-Id:+ - e3d484d6-0151-4fe2-9df5-af5745933bf3+ Client-Request-Id:+ - e3d484d6-0151-4fe2-9df5-af5745933bf3+ X-Ms-Ags-Diagnostic:+ - '{"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"4","ScaleUnit":"002","RoleInstance":"FR3PEPF0000036E"}}'+ Splogid:+ - e6fdbba1-2057-0000-7534-cbf0a98aeb0c+ Date:+ - Fri, 15 Aug 2025 12:25:51 GMT+ body:+ encoding: UTF-8+ string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)/$entity","webUrl":"https://ymt6d.sharepoint.com/sites/OPTest/Shared%20Documents"}'+ recorded_at: Fri, 15 Aug 2025 12:25:51 GMT+recorded_with: VCR 6.3.1diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_location_query_success.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_location_query_success.ymlnew file mode 100644index 00000000000..4d442fed182--- /dev/null+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_location_query_success.yml@@ -0,0 +1,90 @@+---+http_interactions:+- request:+ method: get+ uri: https://graph.microsoft.com/v1.0/drives/b!FeOZEMfQx0eGQKqVBLcP__BG8mq-4-9FuRqOyk3MXY87vnZ6fgfvQanZHX-XCAyw/items/01ANJ53WYLXAJW5PXSCJB2CFCD42UPDKMI?$select=parentReference+ body:+ encoding: US-ASCII+ string: ''+ headers:+ Authorization:+ - Bearer <BEARER TOKEN>+ User-Agent:+ - httpx.rb/1.3.4+ Accept:+ - "*/*"+ Accept-Encoding:+ - gzip, deflate+ response:+ status:+ code: 200+ message: OK+ headers:+ Cache-Control:+ - no-cache+ Content-Type:+ - application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false;+ charset=utf-8+ Content-Encoding:+ - gzip+ Strict-Transport-Security:+ - max-age=31536000+ Request-Id:+ - e7a4716f-67e7-4500-ac13-d82c9f32180a+ Client-Request-Id:+ - e7a4716f-67e7-4500-ac13-d82c9f32180a+ X-Ms-Ags-Diagnostic:+ - '{"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"4","ScaleUnit":"002","RoleInstance":"FR3PEPF00000165"}}'+ Splogid:+ - e6fdbba1-106f-0000-7534-cf31b43a0fa1+ Date:+ - Fri, 15 Aug 2025 12:25:51 GMT+ body:+ encoding: UTF-8+ string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)/$entity","@odata.etag":"\"{6E13B80B-F2BE-4312-A114-43E6A8F1A988},1\"","parentReference":{"driveType":"documentLibrary","driveId":"b!FeOZEMfQx0eGQKqVBLcP__BG8mq-4-9FuRqOyk3MXY87vnZ6fgfvQanZHX-XCAyw","id":"01ANJ53W56Y2GOVW7725BZO354PWSELRRZ","name":"Shared+ Documents","path":"/drives/b!FeOZEMfQx0eGQKqVBLcP__BG8mq-4-9FuRqOyk3MXY87vnZ6fgfvQanZHX-XCAyw/root:","siteId":"1099e315-d0c7-47c7-8640-aa9504b70fff"}}'+ recorded_at: Fri, 15 Aug 2025 12:25:51 GMT+- request:+ method: get+ uri: https://graph.microsoft.com/v1.0/drives/b!FeOZEMfQx0eGQKqVBLcP__BG8mq-4-9FuRqOyk3MXY87vnZ6fgfvQanZHX-XCAyw/items/01ANJ53W56Y2GOVW7725BZO354PWSELRRZ?$select=webUrl+ body:+ encoding: US-ASCII+ string: ''+ headers:+ Authorization:+ - Bearer <BEARER TOKEN>+ User-Agent:+ - httpx.rb/1.3.4+ Accept:+ - "*/*"+ Accept-Encoding:+ - gzip, deflate+ response:+ status:+ code: 200+ message: OK+ headers:+ Cache-Control:+ - no-store, no-cache+ Content-Type:+ - application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false;+ charset=utf-8+ Content-Encoding:+ - gzip+ Strict-Transport-Security:+ - max-age=31536000+ Request-Id:+ - 4f7c9d66-ff7b-4f82-af8a-03bc5f61a347+ Client-Request-Id:+ - 4f7c9d66-ff7b-4f82-af8a-03bc5f61a347+ X-Ms-Ags-Diagnostic:+ - '{"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"4","ScaleUnit":"002","RoleInstance":"FR3PEPF00000165"}}'+ Splogid:+ - e6fdbba1-e076-0000-7534-c426bf0fd973+ Date:+ - Fri, 15 Aug 2025 12:25:51 GMT+ body:+ encoding: UTF-8+ string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)/$entity","webUrl":"https://ymt6d.sharepoint.com/sites/OPTest/Shared%20Documents"}'+ recorded_at: Fri, 15 Aug 2025 12:25:51 GMT+recorded_with: VCR 6.3.1diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_query_not_found.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_query_not_found.ymlnew file mode 100644index 00000000000..dc33d2da148--- /dev/null+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_query_not_found.yml@@ -0,0 +1,47 @@+---+http_interactions:+- request:+ method: get+ uri: https://graph.microsoft.com/v1.0/drives/b!FeOZEMfQx0eGQKqVBLcP__BG8mq-4-9FuRqOyk3MXY87vnZ6fgfvQanZHX-XCAyw/items/YouShallNotPass?$select=webUrl+ body:+ encoding: US-ASCII+ string: ''+ headers:+ Authorization:+ - Bearer <BEARER TOKEN>+ User-Agent:+ - httpx.rb/1.3.4+ Accept:+ - "*/*"+ Accept-Encoding:+ - gzip, deflate+ response:+ status:+ code: 404+ message: Not Found+ headers:+ Cache-Control:+ - no-store, no-cache+ Content-Type:+ - application/json; charset=utf-8+ Content-Encoding:+ - gzip+ Vary:+ - Accept-Encoding+ Strict-Transport-Security:+ - max-age=31536000+ Request-Id:+ - 79eeb634-d7af-4f0a-af0f-9d959d32532f+ Client-Request-Id:+ - 79eeb634-d7af-4f0a-af0f-9d959d32532f+ X-Ms-Ags-Diagnostic:+ - '{"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"4","ScaleUnit":"008","RoleInstance":"FR3PEPF00000CC0"}}'+ Splogid:+ - ecfdbba1-40cb-0000-7534-cd3fef3f5674+ Date:+ - Fri, 15 Aug 2025 12:26:17 GMT+ body:+ encoding: UTF-8+ string: '{"error":{"code":"itemNotFound","message":"Item not found"}}'+ recorded_at: Fri, 15 Aug 2025 12:26:17 GMT+recorded_with: VCR 6.3.1diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_query_success.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_query_success.ymlnew file mode 100644index 00000000000..2621abdebad--- /dev/null+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/share_point/open_file_link_query_success.yml@@ -0,0 +1,46 @@+---+http_interactions:+- request:+ method: get+ uri: https://graph.microsoft.com/v1.0/drives/b!FeOZEMfQx0eGQKqVBLcP__BG8mq-4-9FuRqOyk3MXY87vnZ6fgfvQanZHX-XCAyw/items/01ANJ53WYLXAJW5PXSCJB2CFCD42UPDKMI?$select=webUrl+ body:+ encoding: US-ASCII+ string: ''+ headers:+ Authorization:+ - Bearer <BEARER TOKEN>+ User-Agent:+ - httpx.rb/1.3.4+ Accept:+ - "*/*"+ Accept-Encoding:+ - gzip, deflate+ response:+ status:+ code: 200+ message: OK+ headers:+ Cache-Control:+ - no-cache+ Content-Type:+ - application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false;+ charset=utf-8+ Content-Encoding:+ - gzip+ Strict-Transport-Security:+ - max-age=31536000+ Request-Id:+ - bb714ee9-e99c-4d2b-b494-2858acf7a0fb+ Client-Request-Id:+ - bb714ee9-e99c-4d2b-b494-2858acf7a0fb+ X-Ms-Ags-Diagnostic:+ - '{"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"4","ScaleUnit":"002","RoleInstance":"FR3PEPF00000E37"}}'+ Splogid:+ - e6fdbba1-c035-0000-7bb8-af64dd94fc1d+ Date:+ - Fri, 15 Aug 2025 12:25:50 GMT+ body:+ encoding: UTF-8+ string: '{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)/$entity","@odata.etag":"\"{6E13B80B-F2BE-4312-A114-43E6A8F1A988},1\"","webUrl":"https://ymt6d.sharepoint.com/sites/OPTest/Shared%20Documents/Folder"}'+ recorded_at: Fri, 15 Aug 2025 12:25:50 GMT+recorded_with: VCR 6.3.1diff --git a/modules/storages/spec/support/shared_examples_for_storage_providers/open_file_link_query_examples.rb b/modules/storages/spec/support/shared_examples_for_storage_providers/open_file_link_query_examples.rbnew file mode 100644index 00000000000..7feeb4dd992--- /dev/null+++ b/modules/storages/spec/support/shared_examples_for_storage_providers/open_file_link_query_examples.rb@@ -0,0 +1,80 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++RSpec.shared_examples_for "adapter open_file_link_query: basic query setup" do+ it "is registered as queries.open_file_link" do+ expect(Storages::Adapters::Registry+ .resolve("#{storage}.queries.open_file_link")).to eq(described_class)+ end++ it "responds to #call with correct parameters" do+ expect(described_class).to respond_to(:call)++ method = described_class.method(:call)+ expect(method.parameters).to contain_exactly(%i[keyreq storage],+ %i[keyreq auth_strategy],+ %i[keyreq input_data])+ end+end++RSpec.shared_examples_for "adapter open_file_link_query: successful link response" do+ it "returns a link result object" do+ result = described_class.call(storage:, auth_strategy:, input_data:)++ expect(result).to be_success++ response = result.value!+ expect(response).to eq(open_file_link)+ end+end++RSpec.shared_examples_for "adapter open_file_link_query: not found" do+ it "returns a failure" do+ result = described_class.call(storage:, auth_strategy:, input_data:)++ expect(result).to be_failure++ error = result.failure+ expect(error.code).to eq(:not_found)+ expect(error.source).to eq(error_source)+ end+end++RSpec.shared_examples_for "adapter open_file_link_query: error" do+ it "returns a failure" do+ result = described_class.call(storage:, auth_strategy:, input_data:)++ expect(result).to be_failure++ error = result.failure+ expect(error.code).to eq(:error)+ expect(error.source).to eq(described_class)+ end+end