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
Ensure SSO users do not fallback to ensure_connection
Jan Sandbrinkb75c171b4378
diff --git a/modules/storages/app/controllers/storages/project_storages_controller.rb b/modules/storages/app/controllers/storages/project_storages_controller.rbindex 9ea8acaef94..201aefd73b6 100644--- a/modules/storages/app/controllers/storages/project_storages_controller.rb+++ b/modules/storages/app/controllers/storages/project_storages_controller.rb@@ -98,13 +98,7 @@ class Storages::ProjectStoragesController < ApplicationControllerformat.html docase result.codewhen :unauthorized- redirect_to(- oauth_clients_ensure_connection_url(- oauth_client_id: @storage.oauth_client.client_id,- storage_id: @storage.id,- destination_url: request.url- )- )+ redirect_to(storage_fallback_url, allow_other_host: true)when :forbiddenredirect_to_project_overview_with_modalend@@ -113,6 +107,28 @@ class Storages::ProjectStoragesController < ApplicationControllerendend+ def storage_fallback_url+ selector = Storages::Peripherals::StorageInteraction::AuthenticationMethodSelector.new(user: current_user, storage: @storage)+ if selector.sso?+ # Maybe the user just can't read folder because they are not provisioned in (Nextcloud) storage. We redirect them+ # to the storage and leave error handling up to storage. Ideally they will login to the storage and thus prevent+ # the same error in the future.+ # This would not work for OneDrive, but for OneDrive we don't have SSO (yet).+ res = Storages::Peripherals::Registry.resolve("#{@storage}.queries.open_file_link").call(+ storage: @storage,+ auth_strategy:,+ file_id: @object.project_folder_id+ )+ res.result_or { |errors| raise "Could not redirect SSO user to storage: #{errors}" }+ else+ oauth_clients_ensure_connection_url(+ oauth_client_id: @storage.oauth_client.client_id,+ storage_id: @storage.id,+ destination_url: request.url+ )+ end+ end+def redirect_to_project_overview_with_modalredirect_to(project_overview_path(project_id: @project.identifier),diff --git a/modules/storages/spec/requests/project_storages_open_spec.rb b/modules/storages/spec/requests/project_storages_open_spec.rbindex c4e5099e7e3..6db1620d020 100644--- a/modules/storages/spec/requests/project_storages_open_spec.rb+++ b/modules/storages/spec/requests/project_storages_open_spec.rb@@ -94,14 +94,33 @@ RSpec.describe "projects/:project_id/project_storages/:id/open" docontext "when error code is unauthorized" dolet(:code) { :unauthorized }- it "redirects to ensure_connection url with current request url as a destination_url" do- get route, {}, { "HTTP_ACCEPT" => "text/html" }+ context "when user authenticates at storage via SSO" do+ shared_let(:storage) { create(:nextcloud_storage, :oidc_sso_enabled) }+ let(:provider) { create(:oidc_provider) }- expect(last_response).to have_http_status(:found)- expect(last_response.headers["Location"])- .to eq("http://#{Setting.host_name}/oauth_clients/#{storage.oauth_client.client_id}/ensure_connection?" \- "destination_url=http%3A%2F%2F#{CGI.escape(Setting.host_name)}%2Fprojects%2F#{project.identifier}" \- "%2Fproject_storages%2F#{project_storage.id}%2Fopen&storage_id=#{storage.id}")+ current_user do+ create(:user, identity_url: "#{provider.slug}:cheese", member_with_permissions: { project => permissions })+ end++ it "redirects to the storage directly" do+ get route, {}, { "HTTP_ACCEPT" => "text/html" }++ expect(last_response).to have_http_status(:found)+ expect(last_response.headers["Location"])+ .to eq("#{storage.host}index.php/f/123?openfile=1")+ end+ end++ context "when user authenticates at storage via oauth2" do+ it "redirects to ensure_connection url with current request url as a destination_url" do+ get route, {}, { "HTTP_ACCEPT" => "text/html" }++ expect(last_response).to have_http_status(:found)+ expect(last_response.headers["Location"])+ .to eq("http://#{Setting.host_name}/oauth_clients/#{storage.oauth_client.client_id}/ensure_connection?" \+ "destination_url=http%3A%2F%2F#{CGI.escape(Setting.host_name)}%2Fprojects%2F#{project.identifier}" \+ "%2Fproject_storages%2F#{project_storage.id}%2Fopen&storage_id=#{storage.id}")+ endendend