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
feat[Op#49396]: Use session instead to flash modal
Kabiru Mwenja75a0047c820f
diff --git a/app/controllers/oauth_clients_controller.rb b/app/controllers/oauth_clients_controller.rbindex abecfac759b..dafe94fbfd7 100644--- a/app/controllers/oauth_clients_controller.rb+++ b/app/controllers/oauth_clients_controller.rb@@ -54,9 +54,10 @@ class OAuthClientsController < ApplicationControllerservice_result = @connection_manager.code_to_token(@code)if service_result.success?+ flash[:modal] = session[:oauth_callback_flash_modal] if session[:oauth_callback_flash_modal].present?# Redirect the user to the page that initially wanted to access the OAuth2 resource.# "state" is a nonce that identifies a cookie which holds that page's URL.- redirect_to @redirect_uri, @redirect_uri_params+ redirect_to @redirect_urielse# We got a list of errors from ::OAuthClients::ConnectionManagerset_oauth_errors(service_result)@@ -154,8 +155,7 @@ class OAuthClientsController < ApplicationController.callif service_result.success?- @redirect_uri = service_result.result[:redirect_uri]- @redirect_uri_params = service_result.result[:redirect_uri_params]+ @redirect_uri = service_result.resultelse# To protect against CSRF we cancel this request. There was either no# state parameter given, or there was no corresponding cookie present.diff --git a/app/services/oauth_clients/redirect_uri_from_state_service.rb b/app/services/oauth_clients/redirect_uri_from_state_service.rbindex f0d31ef1ca0..29803390d4f 100644--- a/app/services/oauth_clients/redirect_uri_from_state_service.rb+++ b/app/services/oauth_clients/redirect_uri_from_state_service.rb@@ -26,6 +26,9 @@# See COPYRIGHT and LICENSE files for more details.#+++require "rack/oauth2"+require "uri/http"+module OAuthClientsclass RedirectUriFromStateServicedef initialize(state:, cookies:)@@ -34,13 +37,10 @@ module OAuthClientsenddef call- return ServiceResult.failure if @state.blank?-- redirect_uri = oauth_state_cookie[:href]- redirect_uri_params = oauth_state_cookie.fetch(:href_params, {})+ redirect_uri = oauth_state_cookieif redirect_uri.present? && ::API::V3::Utilities::PathHelper::ApiV3Path::same_origin?(redirect_uri)- ServiceResult.success(result: { redirect_uri:, redirect_uri_params: })+ ServiceResult.success(result: redirect_uri)elseServiceResult.failureend@@ -49,13 +49,13 @@ module OAuthClientsprivatedef oauth_state_cookie- @oauth_state_cookie ||= load_oauth_state_cookie- end+ return nil if @state.blank?- def load_oauth_state_cookie- return if (cookie = @cookies["oauth_state_#{@state}"]).blank?+ state_cookie = @cookies["oauth_state_#{@state}"]+ return nil if state_cookie.blank?- MultiJson.load(cookie, symbolize_keys: true)+ state_value = MultiJson.load(@cookies["oauth_state_#{@state}"], symbolize_keys: true)+ state_value[:href]endendenddiff --git a/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.html.erb b/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.html.erbindex e59265a76e6..f5135907cdb 100644--- a/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.html.erb+++ b/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.html.erb@@ -23,7 +23,7 @@) { cancel_button_text })- if waiting?+ unless authorized?concat(render(Primer::Beta::Button.new(diff --git a/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.rb b/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.rbindex 12614630991..68ed128ab0d 100644--- a/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.rb+++ b/modules/storages/app/components/storages/admin/oauth_access_grant_nudge_modal_component.rb@@ -33,7 +33,7 @@ module Storages::Adminoptions dialog_id: 'storages--oauth-grant-nudge-modal-component',dialog_body_id: 'storages--oauth-grant-nudge-modal-body-component',confirm_button_text: I18n.t('storages.oauth_grant_nudge_modal.confirm_button_label'),- state: :waiting+ authorized: falseattr_reader :project_storage@@ -45,30 +45,29 @@ module Storages::Adminprivatedef title- return unless waiting?+ return if authorized?I18n.t('storages.oauth_grant_nudge_modal.title')enddef cancel_button_text- if waiting?- I18n.t('storages.oauth_grant_nudge_modal.cancel_button_label')- else+ if authorized?I18n.t('button_close')+ else+ I18n.t('storages.oauth_grant_nudge_modal.cancel_button_label')endenddef body_text- case options[:state].to_sym- when :waiting- I18n.t('storages.oauth_grant_nudge_modal.body')- when :success+ if authorized?concat(render(Storages::OpenProjectStorageModalComponent::Body.new(:success, success_subtitle_notice: :ready)))+ else+ I18n.t('storages.oauth_grant_nudge_modal.body')endend- def waiting?- options[:state] == :waiting+ def authorized?+ authorized.present?enddef confirm_button_urldiff --git a/modules/storages/app/controllers/storages/admin/project_storages_controller.rb b/modules/storages/app/controllers/storages/admin/project_storages_controller.rbindex 9a5d19aeb77..5a2eee4c7a0 100644--- a/modules/storages/app/controllers/storages/admin/project_storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/project_storages_controller.rb@@ -106,10 +106,10 @@ class Storages::Admin::ProjectStoragesController < Projects::SettingsControllernonce = SecureRandom.uuidcookies["oauth_state_#{nonce}"] = {value: { href: project_settings_project_storages_url(project_id: @project_storage.project_id),- storageId: @project_storage.storage_id,- href_params: oauth_access_grant_nudge_modal(:success) }.to_json,+ storageId: @project_storage.storage_id }.to_json,expires: 1.hour}+ session[:oauth_callback_flash_modal] = oauth_access_grant_nudge_modal(authorized: true).dig(:flash, :modal)redirect_to(connection_manager.get_authorization_uri(state: nonce))endend@@ -207,18 +207,18 @@ class Storages::Admin::ProjectStoragesController < Projects::SettingsControllerdef redirect_to_project_storages_path_with_nudge_modalredirect_to(project_settings_project_storages_path,- oauth_access_grant_nudge_modal(:waiting)+ oauth_access_grant_nudge_modal)end- def oauth_access_grant_nudge_modal(state)+ def oauth_access_grant_nudge_modal(authorized: false){flash: {modal: {type: 'Storages::Admin::OAuthAccessGrantNudgeModalComponent',parameters: {project_storage_id: @project_storage.id,- state:+ authorized:}}}