Skip to content

Commit

Permalink
Merge pull request #16748 from opf/impl/add-storage-missing-services
Browse files Browse the repository at this point in the history
Adds some missing services to Storages along with logging.
  • Loading branch information
Kharonus authored Sep 25, 2024
2 parents 2ac078f + bddf831 commit 063b652
Show file tree
Hide file tree
Showing 58 changed files with 298 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def validate

def capabilities
@capabilities ||= Peripherals::Registry
.resolve("#{@storage.short_provider_type}.queries.capabilities")
.resolve("#{@storage}.queries.capabilities")
.call(storage: @storage, auth_strategy: noop)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def validate

def query
@query ||= Peripherals::Registry
.resolve("#{@storage.short_provider_type}.queries.files")
.resolve("#{@storage}.queries.files")
.call(storage: @storage, auth_strategy:, folder: root_folder)
end

Expand Down Expand Up @@ -173,7 +173,7 @@ def root_folder
end

def auth_strategy
Peripherals::Registry.resolve("#{@storage.short_provider_type}.authentication.userless")
Peripherals::Registry.resolve("#{@storage}.authentication.userless")
.call
.with_cache(false)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def self.authorization_state(storage:, user:)
auth_strategy = AuthenticationStrategies::OAuthUserToken.strategy.with_user(user)

Registry
.resolve("#{storage.short_provider_type}.queries.auth_check")
.resolve("#{storage}.queries.auth_check")
.call(storage:, auth_strategy:)
.match(
on_success: ->(*) { :connected },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
) do |form|
flex_layout do |oauth_client_row|
oauth_client_row.with_row(mb: 3) do
render(Primer::Beta::Text.new(font_weight: :bold)) { I18n.t("storages.file_storage_view.#{storage.short_provider_type}_oauth") }
render(Primer::Beta::Text.new(font_weight: :bold)) { I18n.t("storages.file_storage_view.#{storage}_oauth") }
end

oauth_client_row.with_row(mb: 3) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def cancel_button_path
end

def storage_provider_credentials_instructions
I18n.t("storages.instructions.#{storage.short_provider_type}.oauth_configuration",
application_link_text: send(:"#{storage.short_provider_type}_integration_link")).html_safe
I18n.t("storages.instructions.#{storage}.oauth_configuration",
application_link_text: send(:"#{storage}_integration_link")).html_safe
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
concat(
render(
Primer::Beta::Text.new(font_weight: :bold, mr: 1, test_selector: 'storage-oauth-client-label')
) { I18n.t("storages.file_storage_view.#{storage.short_provider_type}_oauth") }
) { I18n.t("storages.file_storage_view.#{storage}_oauth") }
)
concat(configuration_check_label_for(:storage_oauth_client_configured))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def self.wrapper_key = :storage_oauth_client_section

def edit_icon_button_options
label = I18n.t("storages.buttons.replace_oauth_client",
provider_type: I18n.t("storages.provider_types.#{storage.short_provider_type}.name"))
provider_type: I18n.t("storages.provider_types.#{storage}.name"))

{
icon: oauth_client_configured? ? :sync : :pencil,
Expand All @@ -64,7 +64,7 @@ def edit_icon_button_options
def edit_icon_button_data_options
{}.tap do |data_h|
if oauth_client_configured?
provider_type = I18n.t("storages.provider_types.#{storage.short_provider_type}.name")
provider_type = I18n.t("storages.provider_types.#{storage}.name")
data_h[:turbo_confirm] = I18n.t("storages.confirm_replace_oauth_client", provider_type:)
end
data_h[:turbo_stream] = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
end

grid.with_area(:provider, tag: :div, color: :subtle, mr: 3, hide: :sm, data: { 'test-selector': 'storage-provider' }) do
render(Primer::Beta::Truncate.new(font_weight: :light)) { I18n.t("storages.provider_types.#{storage.short_provider_type}.name") }
render(Primer::Beta::Truncate.new(font_weight: :light)) { I18n.t("storages.provider_types.#{storage}.name") }
end

grid.with_area(:time, tag: :div, color: :subtle) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 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 Storages::Admin
module StorageViewInformation
private
Expand All @@ -9,7 +37,7 @@ def editable_storage?
end

def storage_description
[I18n.t("storages.provider_types.#{storage.short_provider_type}.name"),
[I18n.t("storages.provider_types.#{storage}.name"),
storage.name,
storage.host].compact.join(" - ")
end
Expand Down Expand Up @@ -62,15 +90,15 @@ def provider_oauth_client_description
if storage.oauth_client
"#{I18n.t('storages.label_oauth_client_id')}: #{storage.oauth_client.client_id}"
else
I18n.t("storages.configuration_checks.oauth_client_incomplete.#{storage.short_provider_type}")
I18n.t("storages.configuration_checks.oauth_client_incomplete.#{storage}")
end
end

def provider_redirect_uri_description
if storage.oauth_client
"#{I18n.t('storages.label_uri')}: #{storage.oauth_client.redirect_uri}"
else
I18n.t("storages.configuration_checks.redirect_uri_incomplete.#{storage.short_provider_type}")
I18n.t("storages.configuration_checks.redirect_uri_incomplete.#{storage}")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def heading_text = I18n.t("storages.oauth_grant_nudge_modal.heading", provider_t
def waiting_title = I18n.t("storages.oauth_grant_nudge_modal.requesting_access_to", storage: storage.name)
def cancel_button_text = I18n.t(:button_close)
def body_text = I18n.t("storages.oauth_grant_nudge_modal.storage_admin.description", provider_type:)
def provider_type = I18n.t("storages.provider_types.#{storage.short_provider_type}.name")
def provider_type = I18n.t("storages.provider_types.#{storage}.name")

def login_button_aria_label
I18n.t("storages.oauth_grant_nudge_modal.login_button_aria_label", storage: storage.name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
Expand All @@ -24,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class Storages::OpenProjectStorageModalComponent::Body < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
class Storages::OpenProjectStorageModalComponent::Body < ApplicationComponent
options success_title: I18n.t("storages.open_project_storage_modal.success.title"),
success_subtitle: I18n.t("storages.open_project_storage_modal.success.subtitle"),
waiting_title: I18n.t("storages.open_project_storage_modal.waiting.title"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# -- copyright
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# -- copyright
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# -- copyright
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# -- copyright
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# -- copyright
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
Expand Down Expand Up @@ -45,7 +47,7 @@ def open
# check if user "see" project_folder
if @object.project_folder_id.present?
::Storages::Peripherals::Registry
.resolve("#{@storage.short_provider_type}.queries.file_info")
.resolve("#{@storage}.queries.file_info")
.call(storage: @storage, auth_strategy:, file_id: @object.project_folder_id)
.match(
on_success: user_can_read_project_folder,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
Expand Down Expand Up @@ -58,7 +60,7 @@ def provider_type_link
href: Storages::UrlBuilder.url(@storage.uri, "settings/admin/openproject"),
target: "_blank"
)
) { I18n.t("storages.instructions.#{@storage.short_provider_type}.integration") }
) { I18n.t("storages.instructions.#{@storage}.integration") }
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
Expand Down Expand Up @@ -69,11 +71,11 @@ def provider_default_client_secret_input_options
end

def label_client_id
I18n.t("storages.provider_types.#{@storage.short_provider_type}.label_oauth_client_id")
I18n.t("storages.provider_types.#{@storage}.label_oauth_client_id")
end

def label_client_secret
I18n.t("storages.provider_types.#{@storage.short_provider_type}.label_oauth_client_secret")
I18n.t("storages.provider_types.#{@storage}.label_oauth_client_secret")
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# -- copyright
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
Expand All @@ -26,7 +26,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
# ++
#++
#

# This filter is used to find projects (including archived projects) that use one
Expand Down
6 changes: 3 additions & 3 deletions modules/storages/app/models/storages/project_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ def open(user)

if project_folder_not_accessible?(user)
Peripherals::Registry
.resolve("#{storage.short_provider_type}.queries.open_storage")
.resolve("#{storage}.queries.open_storage")
.call(storage:, auth_strategy:)
else
Peripherals::Registry
.resolve("#{storage.short_provider_type}.queries.open_file_link")
.resolve("#{storage}.queries.open_file_link")
.call(storage:, auth_strategy:, file_id: project_folder_id)
end
end
Expand All @@ -118,7 +118,7 @@ def open_with_connection_ensured

def managed_folder_identifier
@managed_folder_identifier ||=
Peripherals::Registry.resolve("#{storage.short_provider_type}.models.managed_folder_identifier").new(self)
Peripherals::Registry.resolve("#{storage}.models.managed_folder_identifier").new(self)
end

def project_folder_not_accessible?(user)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
Expand Down Expand Up @@ -45,7 +47,7 @@ def call
::OAuth::Applications::CreateService
.new(user:)
.call(
name: "#{storage.name} (#{I18n.t("storages.provider_types.#{storage.short_provider_type}.name")})",
name: "#{storage.name} (#{I18n.t("storages.provider_types.#{storage}.name")})",
redirect_uri: File.join(storage.host, "index.php/apps/integration_openproject/oauth-redirect"),
scopes: "api_v3",
confidential: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def manually_managed_source?(source)

def initiate_copy(storage, source_path, destination_path)
Peripherals::Registry
.resolve("#{storage.short_provider_type}.commands.copy_template_folder")
.resolve("#{storage}.commands.copy_template_folder")
.call(auth_strategy: auth_strategy(storage.short_provider_type),
storage:,
source_path:,
Expand Down
50 changes: 50 additions & 0 deletions modules/storages/app/services/storages/storage_file_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 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 Storages
class StorageFileService < BaseService
def self.call(storage:, user:, file_id:)
new.call(storage:, user:, file_id:)
end

def call(user:, storage:, file_id:)
auth_strategy = strategy(storage, user)

info "Requesting file #{file_id} information on #{storage.name}"
Peripherals::Registry.resolve("#{storage}.queries.file_info").call(storage:, auth_strategy:, file_id:)
end

private

def strategy(storage, user)
Peripherals::Registry.resolve("#{storage}.authentication.user_bound").call(user:)
end
end
end
Loading

0 comments on commit 063b652

Please sign in to comment.