Skip to content

Commit

Permalink
Merge pull request #16293 from opf/feature/56045-add-link-to-storage-…
Browse files Browse the repository at this point in the history
…provider-in-storage-edit-view

Feature/56045 add link to storage provider in storage edit view
  • Loading branch information
apfohl authored Jul 31, 2024
2 parents 4923e0f + b497062 commit ca76746
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
end

grid.with_area(:description, tag: :div, color: :subtle, test_selector: 'storage-description') do
render(Primer::Beta::Text.new) { storage_description }
concat(render(Primer::Beta::Text.new) { storage_description })

if open_link_was_generated
concat(render(Primer::Beta::Text.new) { " - " })
concat(render(Primer::Beta::Link.new(href: open_href)) do
concat(render(Primer::Beta::Text.new) { "Open storage " })
concat(render(Primer::Beta::Octicon.new(icon: "link-external", size: :small)))
end)
end
end

if editable_storage?
Expand All @@ -20,7 +28,7 @@
tag: :a,
scheme: :invisible,
href: edit_host_admin_settings_storage_path(storage),
aria: { label: I18n.t('storages.label_edit_storage_host') } ,
aria: { label: I18n.t('storages.label_edit_storage_host') },
test_selector: 'storage-edit-host-button',
data: { turbo_stream: true }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,26 @@ class GeneralInfoComponent < ApplicationComponent
alias_method :storage, :model

def self.wrapper_key = :storage_general_info_section

def initialize(model = nil, **options)
auth_strategy = ::Storages::Peripherals::StorageInteraction::AuthenticationStrategies::OAuthUserToken
.strategy
.with_user(User.current)

@href_result = ::Storages::Peripherals::Registry
.resolve("#{model.short_provider_type}.queries.open_storage")
.call(storage: model, auth_strategy:)

super
end

def open_link_was_generated
@href_result.on_success { return true }
@href_result.on_failure { return false }
end

def open_href
@href_result.result
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-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.
#++

require "spec_helper"
require_module_spec_helper

RSpec.describe Storages::Admin::GeneralInfoComponent, type: :component do
describe "#description" do
context "with storage configured" do
it "must show a link to the storage" do
storage = create(:nextcloud_storage)
component = described_class.new(storage)
expect(component.open_link_was_generated).to be_truthy
expect(component.open_href).not_to be_nil
end
end
end
end

0 comments on commit ca76746

Please sign in to comment.