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

Ensure to select auth strategy via storage registry

Jan Sandbrinkf71f0dd930e2
diff --git a/modules/storages/app/controllers/storages/project_storages_controller.rb b/modules/storages/app/controllers/storages/project_storages_controller.rb
index 70e53c650c3..9ea8acaef94 100644
--- a/modules/storages/app/controllers/storages/project_storages_controller.rb
+++ b/modules/storages/app/controllers/storages/project_storages_controller.rb
@@ -71,9 +71,7 @@ class Storages::ProjectStoragesController < ApplicationController
private
def auth_strategy
- Storages::Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken
- .strategy
- .with_user(current_user)
+ Storages::Peripherals::Registry.resolve("#{@storage}.authentication.user_bound").call(user: current_user, storage: @storage)
end
def user_can_read_project_folder
diff --git a/modules/storages/app/models/storages/project_storage.rb b/modules/storages/app/models/storages/project_storage.rb
index 6d33c1b2942..f57f43fe9e8 100644
--- a/modules/storages/app/models/storages/project_storage.rb
+++ b/modules/storages/app/models/storages/project_storage.rb
@@ -82,9 +82,7 @@ module Storages
end
def open(user)
- auth_strategy = Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken
- .strategy
- .with_user(user)
+ auth_strategy = Peripherals::Registry.resolve("#{storage}.authentication.user_bound").call(user:, storage:)
if project_folder_not_accessible?(user)
Peripherals::Registry
diff --git a/modules/storages/lib/api/v3/file_links/file_links_download_api.rb b/modules/storages/lib/api/v3/file_links/file_links_download_api.rb
index a269302ed78..788fbddd9f1 100644
--- a/modules/storages/lib/api/v3/file_links/file_links_download_api.rb
+++ b/modules/storages/lib/api/v3/file_links/file_links_download_api.rb
@@ -34,16 +34,15 @@ class API::V3::FileLinks::FileLinksDownloadAPI < API::OpenProjectAPI
helpers do
def auth_strategy
- Storages::Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken
- .strategy
- .with_user(User.current)
+ storage = @file_link.storage
+ Storages::Peripherals::Registry.resolve("#{storage}.authentication.user_bound").call(user: User.current, storage:)
end
end
resources :download do
get do
Storages::Peripherals::Registry
- .resolve("#{@file_link.storage.short_provider_type}.queries.download_link")
+ .resolve("#{@file_link.storage}.queries.download_link")
.call(storage: @file_link.storage, auth_strategy:, file_link: @file_link)
.match(
on_success: ->(url) do
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 1980073a9ae..e7ab0bc4a86 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
@@ -31,14 +31,17 @@ class API::V3::FileLinks::FileLinksOpenAPI < API::OpenProjectAPI
using Storages::Peripherals::ServiceResultRefinements
+ helpers do
+ def auth_strategy
+ storage = @file_link.storage
+ Storages::Peripherals::Registry.resolve("#{storage}.authentication.user_bound").call(user: current_user, storage:)
+ end
+ end
+
resources :open do
get do
- auth_strategy = Storages::Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken
- .strategy
- .with_user(current_user)
-
Storages::Peripherals::Registry
- .resolve("#{@file_link.storage.short_provider_type}.queries.open_file_link")
+ .resolve("#{@file_link.storage}.queries.open_file_link")
.call(
storage: @file_link.storage,
auth_strategy:,
diff --git a/modules/storages/lib/api/v3/storages/storage_open_api.rb b/modules/storages/lib/api/v3/storages/storage_open_api.rb
index 937c33ba601..588f09bfe92 100644
--- a/modules/storages/lib/api/v3/storages/storage_open_api.rb
+++ b/modules/storages/lib/api/v3/storages/storage_open_api.rb
@@ -33,12 +33,14 @@ class API::V3::Storages::StorageOpenAPI < API::OpenProjectAPI
using Storages::Peripherals::ServiceResultRefinements
+ helpers do
+ def auth_strategy
+ Storages::Peripherals::Registry.resolve("#{@storage}.authentication.user_bound").call(user: current_user, storage: @storage)
+ end
+ end
+
resources :open do
get do
- auth_strategy = Storages::Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken
- .strategy
- .with_user(current_user)
-
Storages::Peripherals::Registry
.resolve("#{@storage}.queries.open_storage")
.call(storage: @storage, auth_strategy:)