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

Improve readability.

Pavel Balashou2c3dcdf9d538
diff --git a/modules/storages/app/controllers/storages/project_storages_controller.rb b/modules/storages/app/controllers/storages/project_storages_controller.rb
index 9229c593deb..4fb19650d23 100644
--- a/modules/storages/app/controllers/storages/project_storages_controller.rb
+++ b/modules/storages/app/controllers/storages/project_storages_controller.rb
@@ -45,60 +45,66 @@ class Storages::ProjectStoragesController < ApplicationController
if @object.project_folder_automatic?
storage = @object.storage
# check if user "see" project_folder
- result = ::Storages::Peripherals::Registry
- .resolve("queries.#{storage.short_provider_type}.file_info")
- .call(storage:,
- user: current_user,
- file_id: @object.project_folder_id)
- result.match(
- on_success: ->(_) do
- respond_to do |format|
- format.turbo_stream do
- render(
- turbo_stream: OpTurbo::StreamComponent.new(
- action: :update,
- target: Storages::OpenProjectStorageModalComponent.dialog_body_id,
- template: Storages::OpenProjectStorageModalComponent::Body.new(:success).render_in(view_context)
- ).render_in(view_context)
- )
- end
- format.html { redirect_to storage_open_url }
- end
- end,
- on_failure: ->(result) do
- respond_to do |format|
- format.turbo_stream { head :no_content }
- format.html do
- case result.code
- when :unauthorized
- redirect_to(
- oauth_clients_ensure_connection_url(
- oauth_client_id: storage.oauth_client.client_id,
- storage_id: storage.id,
- destination_url: request.url
- )
- )
- when :forbidden
- redirect_to(
- project_overview_path(project_id: @project.identifier),
- flash: {
- modal: {
- type: 'Storages::OpenProjectStorageModalComponent',
- parameters: {
- project_storage_open_url: request.path,
- redirect_url: storage_open_url,
- state: :waiting
- }
- }
- }
- )
- end
- end
- end
- end
- )
+ ::Storages::Peripherals::Registry
+ .resolve("queries.#{storage.short_provider_type}.file_info")
+ .call(storage:,
+ user: current_user,
+ file_id: @object.project_folder_id)
+ .match(
+ on_success: ->(_) { user_can_read_project_folder },
+ on_failure: ->(result) { user_can_not_read_project_folder(result.code) }
+ )
else
redirect_to storage_open_url
end
end
+
+ private
+
+ def user_can_read_project_folder
+ respond_to do |format|
+ format.turbo_stream do
+ render(
+ turbo_stream: OpTurbo::StreamComponent.new(
+ action: :update,
+ target: Storages::OpenProjectStorageModalComponent.dialog_body_id,
+ template: Storages::OpenProjectStorageModalComponent::Body.new(:success).render_in(view_context)
+ ).render_in(view_context)
+ )
+ end
+ format.html { redirect_to storage_open_url }
+ end
+ end
+
+ def user_can_not_read_project_folder(reason_code)
+ respond_to do |format|
+ format.turbo_stream { head :no_content }
+ format.html do
+ case reason_code
+ when :unauthorized
+ redirect_to(
+ oauth_clients_ensure_connection_url(
+ oauth_client_id: storage.oauth_client.client_id,
+ storage_id: storage.id,
+ destination_url: request.url
+ )
+ )
+ when :forbidden
+ redirect_to(
+ project_overview_path(project_id: @project.identifier),
+ flash: {
+ modal: {
+ type: 'Storages::OpenProjectStorageModalComponent',
+ parameters: {
+ project_storage_open_url: request.path,
+ redirect_url: storage_open_url,
+ state: :waiting
+ }
+ }
+ }
+ )
+ end
+ end
+ end
+ end
end