Skip to content

Commit

Permalink
[#61936] Can't associate storage to project via storage admin view
Browse files Browse the repository at this point in the history
  • Loading branch information
ba1ash committed Mar 6, 2025
1 parent cdedf93 commit ced2f2d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= render(Primer::BaseComponent.new(tag: :div, data: @wrapper_data_attributes, classes: @wrapper_classes)) do %>
<%= render(Primer::BaseComponent.new(tag: :div, display: :inline_flex, direction: :row, align_items: :center)) do %>
<% if storage_oauth_access_granted? %>
<% if @storage.oauth_access_granted?(User.current) %>
<%=
render(
Primer::Beta::Button.new(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# frozen_string_literal: true

# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2024 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 Primer
module OpenProject
module Forms
Expand All @@ -12,7 +42,7 @@ def initialize(input:, project_storage:, last_project_folders: {},
super()
@input = input

@project_storage = project_storage
@storage = project_storage.storage
@last_project_folders = last_project_folders

@storage_login_button_options = storage_login_button_options
Expand All @@ -22,13 +52,6 @@ def initialize(input:, project_storage:, last_project_folders: {},
@wrapper_data_attributes = wrapper_arguments.delete(:data) { {} }
@wrapper_classes = wrapper_arguments.delete(:classes) { [] }
end

private

def storage_oauth_access_granted?
OAuthClientToken
.exists?(user: User.current, oauth_client: @project_storage.storage.oauth_client)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ def open_redirect_to_storage_authorization_with(callback_url:, storage:, callbac
redirect_to(storage.oauth_configuration.authorization_uri(state: nonce), allow_other_host: true)
end

def storage_oauth_access_granted?(storage:)
OAuthClientToken.exists?(user: User.current, oauth_client: storage.oauth_client)
end

def project_storage_oauth_access_grant_nudge_modal(project_storage:)
{
component: ::Storages::ProjectStorages::OAuthAccessGrantNudgeModalComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def available_storages
end

def redirect_to_project_storages_path_with_oauth_access_grant_confirmation
if storage_oauth_access_granted?(storage: @project_storage.storage)
if storage.oauth_access_granted?(User.current)
redirect_to external_file_storages_project_settings_project_storages_path
else
redirect_to_project_storages_path_with_nudge_modal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def index; end

def new
respond_with_dialog(
if storage_oauth_access_granted?(storage: @storage)
if @project_storage.storage.oauth_access_granted?(User.current)
::Storages::Admin::Storages::ProjectsStorageModalComponent.new(
project_storage: @project_storage, last_project_folders: {}
)
Expand Down
13 changes: 13 additions & 0 deletions modules/storages/app/models/storages/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ def self.extract_part_from_piped_string(text, index)
end
end

def oauth_access_granted?(user)
selector = Peripherals::StorageInteraction::AuthenticationMethodSelector.new(
storage: self,
user:
)
case selector.authentication_method
when :sso
true
when :storage_oauth
OAuthClientToken.exists?(user:, oauth_client: oauth_client)
end
end

def health_notifications_should_be_sent?
# it is a fallback for already created storages without health_notifications_enabled configured.
(health_notifications_enabled.nil? && automatic_management_enabled?) || health_notifications_enabled?
Expand Down

0 comments on commit ced2f2d

Please sign in to comment.