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
Change storage links in a project menu.
Pavel Balashou18d607a6fd20
diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rbindex 8dcba806c85..1a1cda0b3b0 100644--- a/modules/storages/lib/open_project/storages/engine.rb+++ b/modules/storages/lib/open_project/storages/engine.rb@@ -159,17 +159,22 @@ module OpenProject::StoragesUser.current.allowed_in_project?(:view_file_links, project)project.project_storages.each do |project_storage|storage = project_storage.storage- href = Rails- .application- .routes- .url_helpers- .open_project_storage_path(project_id: project_storage.project.identifier,- id: project_storage.id)- icon = if storage.provider_type_nextcloud?- 'nextcloud-circle'- else- 'hosting'- end+ next unless storage.configured?++ # consider moving to the model+ url_helpers = Rails.application.routes.url_helpers+ open_project_storage_url = url_helpers.open_project_storage_url(+ host: Setting.host_name,+ protocol: 'https',+ project_id: project_storage.project.identifier,+ id: project_storage.id+ )+ href = url_helpers.oauth_clients_ensure_connection_path(+ oauth_client_id: storage.oauth_client.client_id,+ storage_id: storage.id,+ destination_url: open_project_storage_url+ )+ icon = storage.provider_type_nextcloud? ? 'nextcloud-circle' : 'hosting'menu.push(:"storage_#{storage.id}",diff --git a/modules/storages/spec/factories/storage_factory.rb b/modules/storages/spec/factories/storage_factory.rbindex 7e1b1e445a8..15e0a80f604 100644--- a/modules/storages/spec/factories/storage_factory.rb+++ b/modules/storages/spec/factories/storage_factory.rb@@ -66,6 +66,13 @@ FactoryBot.define doendend+ factory :nextcloud_storage_configured, parent: :nextcloud_storage do+ after(:create) do |storage, _evaluator|+ create(:oauth_client, integration: storage)+ create(:oauth_application, integration: storage)+ end+ end+factory :nextcloud_storage_with_local_connection,parent: :nextcloud_storage,traits: [:as_not_automatically_managed] dodiff --git a/modules/storages/spec/features/storages_menu_links_spec.rb b/modules/storages/spec/features/storages_menu_links_spec.rbindex 81f00395f61..7994c264be7 100644--- a/modules/storages/spec/features/storages_menu_links_spec.rb+++ b/modules/storages/spec/features/storages_menu_links_spec.rb@@ -31,38 +31,45 @@require 'spec_helper'require_module_spec_helper-RSpec.describe 'Project menu', :js, :with_cuprite do+RSpec.describe 'Storage links in project menu', :js doinclude API::V3::Utilities::PathHelper- let(:storage) { create(:nextcloud_storage, name: "Storage 1") }- let(:another_storage) { create(:nextcloud_storage, name: "Storage 2") }- let(:unlinked_storage) { create(:nextcloud_storage, name: "Storage 3") }- let(:project) { create(:project, enabled_module_names: %i[storages]) }- let(:project_storage_without_folder) { create(:project_storage, project:, storage:) }- let(:project_storage_with_manual_folder) do- create(:project_storage, project:, storage: another_storage, project_folder_mode: 'manual', project_folder_id: '42')- end+ let!(:storage_configured_linked1) { create(:nextcloud_storage_configured, name: "Storage 1") }+ let!(:project_storage1) { create(:project_storage, project:, storage: storage_configured_linked1) }+ let!(:storage_configured_linked2) { create(:nextcloud_storage_configured, name: "Storage 2") }+ let!(:project_storage2) { create(:project_storage, project:, storage: storage_configured_linked2) }+ let!(:storage_configured_unlinked) { create(:nextcloud_storage_configured, name: "Storage 3") }+ let!(:storage_unconfigured_linked) { create(:nextcloud_storage, name: "Storage 4") }+ let!(:project_storage4) { create(:project_storage, project:, storage: storage_unconfigured_linked) }+ let!(:project) { create(:project, enabled_module_names: %i[storages]) }let(:permissions) { %i[view_file_links] }let(:user) { create(:user, member_with_permissions: { project => permissions }) }before do- project_storage_without_folder- project_storage_with_manual_folder- unlinked_storage-login_as(user)visit(project_path(project))end+ def href(project_storage)+ oauth_clients_ensure_connection_path(+ oauth_client_id: project_storage.storage.oauth_client.client_id,+ storage_id: project_storage.storage.id,+ destination_url: open_project_storage_url(+ protocol: 'https',+ project_id: project_storage.project.identifier,+ id: project_storage.id+ )+ )+ end+context 'if user has permission to see storage links' doit 'has links to enabled storages' dovisit(project_path(id: project.id))- expect(page).to have_link(storage.name,- href: api_v3_paths.project_storage_open(project_storage_without_folder.id))- expect(page).to have_link(another_storage.name,- href: api_v3_paths.project_storage_open(project_storage_with_manual_folder.id))- expect(page).not_to have_link(unlinked_storage.name)+ expect(page).to have_link(storage_configured_linked1.name, href: href(project_storage1))+ expect(page).to have_link(storage_configured_linked2.name, href: href(project_storage2))+ expect(page).not_to have_link(storage_configured_unlinked.name)+ expect(page).not_to have_link(storage_unconfigured_linked.name)endcontext 'if user is an admin but not a member of the project' do@@ -71,11 +78,10 @@ RSpec.describe 'Project menu', :js, :with_cuprite doit 'has no links to enabled storage' dovisit(project_path(id: project.id))- expect(page).not_to have_link(storage.name,- href: api_v3_paths.project_storage_open(project_storage_without_folder.id))- expect(page).not_to have_link(another_storage.name,- href: api_v3_paths.project_storage_open(project_storage_with_manual_folder.id))- expect(page).not_to have_link(unlinked_storage.name)+ expect(page).not_to have_link(storage_configured_linked1.name)+ expect(page).not_to have_link(storage_configured_linked2.name)+ expect(page).not_to have_link(storage_configured_unlinked.name)+ expect(page).not_to have_link(storage_unconfigured_linked.name)endendend@@ -86,8 +92,10 @@ RSpec.describe 'Project menu', :js, :with_cuprite doit 'has no links to enabled storages' dovisit(project_path(id: project.id))- expect(page).not_to have_link(storage.name)- expect(page).not_to have_link(another_storage.name)+ expect(page).not_to have_link(storage_configured_linked1.name)+ expect(page).not_to have_link(storage_configured_linked2.name)+ expect(page).not_to have_link(storage_configured_unlinked.name)+ expect(page).not_to have_link(storage_unconfigured_linked.name)endendenddiff --git a/spec/factories/oauth_application_factory.rb b/spec/factories/oauth_application_factory.rbindex 59d2733c000..e12a142c058 100644--- a/spec/factories/oauth_application_factory.rb+++ b/spec/factories/oauth_application_factory.rb@@ -32,7 +32,7 @@ FactoryBot.define doconfidential { true }owner factory: :adminowner_type { 'User' }- uid { '12345' }+ sequence(:uid) { |n| "1234567890#{n}" }redirect_uri { 'urn:ietf:wg:oauth:2.0:oob' }scopes { 'api_v3' }enddiff --git a/spec/requests/oauth_clients/ensure_connection_flow_spec.rb b/spec/requests/oauth_clients/ensure_connection_flow_spec.rbindex 25dfcf571ad..bcaea46d4c7 100644--- a/spec/requests/oauth_clients/ensure_connection_flow_spec.rb+++ b/spec/requests/oauth_clients/ensure_connection_flow_spec.rb@@ -80,8 +80,8 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :wecontext 'when destination_url is the same origin as OP' doit 'redirects to storage authorization_uri with oauth_state_* cookie set' doget oauth_clients_ensure_connection_url(oauth_client_id: storage.oauth_client.client_id,- storage_id: storage.id,- destination_url: "#{root_url}123")+ storage_id: storage.id,+ destination_url: "#{root_url}123")oauth_client = storage.oauth_clientexpect(last_response.status).to eq(302)@@ -98,8 +98,8 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :wecontext 'when destination_url is not the same origin as OP' doit 'redirects to storage authorization_uri with oauth_state_* cookie set' doget oauth_clients_ensure_connection_url(oauth_client_id: storage.oauth_client.client_id,- storage_id: storage.id,- destination_url: "#{storage.host}/index.php")+ storage_id: storage.id,+ destination_url: "#{storage.host}/index.php")oauth_client = storage.oauth_clientexpect(last_response.status).to eq(302)@@ -149,8 +149,8 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :wecontext 'when destination_url is the same origin as OP' doit 'redirects to destination_url' doget oauth_clients_ensure_connection_url(oauth_client_id: storage.oauth_client.client_id,- storage_id: storage.id,- destination_url: "#{root_url}123")+ storage_id: storage.id,+ destination_url: "#{root_url}123")storage.oauth_clientexpect(last_response.status).to eq(302)@@ -164,8 +164,8 @@ RSpec.describe "/oauth_clients/:oauth_client_id/ensure_connection endpoint", :wecontext 'when destination_url is not the same origin as OP' doit 'redirects to root_url' doget oauth_clients_ensure_connection_url(oauth_client_id: storage.oauth_client.client_id,- storage_id: storage.id,- destination_url: "#{storage.host}/index.php")+ storage_id: storage.id,+ destination_url: "#{storage.host}/index.php")storage.oauth_clientexpect(last_response.status).to eq(302)