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
[#55939] OneDrive/SharePoint storage with AMPF should not be addable as manual folder
Judith Roth48d9f3b0907b
diff --git a/modules/storages/app/models/storages/one_drive_storage.rb b/modules/storages/app/models/storages/one_drive_storage.rbindex 76d20c4aac3..f8915cd4225 100644--- a/modules/storages/app/models/storages/one_drive_storage.rb+++ b/modules/storages/app/models/storages/one_drive_storage.rb@@ -57,6 +57,10 @@ module Storagesendend+ def manual_management_possible?+ !automatic_management_enabled?+ end+def oauth_configurationPeripherals::OAuthConfigurations::OneDriveConfiguration.new(self)enddiff --git a/modules/storages/app/models/storages/project_storage.rb b/modules/storages/app/models/storages/project_storage.rbindex a1fe8fa686b..fc27e233066 100644--- a/modules/storages/app/models/storages/project_storage.rb+++ b/modules/storages/app/models/storages/project_storage.rb@@ -61,6 +61,10 @@ module Storagesstorage.present? && storage.automatic_management_enabled?end+ def manual_management_possible?+ storage&.manual_management_possible?+ end+def managed_project_folder_pathmanaged_folder_identifier.pathenddiff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex 07e02e575ab..832d8eb452f 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -149,6 +149,10 @@ module Storagesalias automatic_management_enabled automatically_managed+ def manual_management_possible?+ true+ end+def configured?configuration_checks.values.all?enddiff --git a/modules/storages/app/views/storages/project_settings/_project_folder_form.html.erb b/modules/storages/app/views/storages/project_settings/_project_folder_form.html.erbindex c136a0db048..c15d97310be 100644--- a/modules/storages/app/views/storages/project_settings/_project_folder_form.html.erb+++ b/modules/storages/app/views/storages/project_settings/_project_folder_form.html.erb@@ -103,18 +103,20 @@ See COPYRIGHT and LICENSE files for more details.</span><% end %>- <div class="form--field-container">- <%= f.label :project_folder_mode, value: 'manual', class: "form--label-with-radio-button" do %>- <%= f.radio_button :project_folder_mode,- 'manual',- no_label: true,- data: { action: 'project-storage-form#updateForm' } %>- <%= t(:"storages.label_existing_manual_folder") %>- <% end %>- </div>- <span class="form--field-instructions -xwide -with-bottom-spacing">- <%= t(:"storages.instructions.existing_manual_folder") %>- </span>+ <% if @project_storage.manual_management_possible? %>+ <div class="form--field-container">+ <%= f.label :project_folder_mode, value: 'manual', class: "form--label-with-radio-button" do %>+ <%= f.radio_button :project_folder_mode,+ 'manual',+ no_label: true,+ data: { action: 'project-storage-form#updateForm' } %>+ <%= t(:"storages.label_existing_manual_folder") %>+ <% end %>+ </div>+ <span class="form--field-instructions -xwide -with-bottom-spacing">+ <%= t(:"storages.instructions.existing_manual_folder") %>+ </span>+ <% end %><divstyle="display: none;"diff --git a/modules/storages/spec/features/manage_project_storage_spec.rb b/modules/storages/spec/features/manage_project_storage_spec.rbindex df11ab2e070..961bab1a55b 100644--- a/modules/storages/spec/features/manage_project_storage_spec.rb+++ b/modules/storages/spec/features/manage_project_storage_spec.rb@@ -38,7 +38,8 @@ require_module_spec_helper# We decrease the notification polling interval because some portions of the JS code rely on something triggering# the Angular change detection. This is usually done by the notification polling, but we don't want to waitRSpec.describe("Activation of storages in projects",- :js, :webmock, :with_cuprite, with_settings: { notifications_polling_interval: 1_000 }) do+ :js, :oauth_connection_helpers, :webmock, :with_cuprite,+ with_settings: { notifications_polling_interval: 1_000 }) dolet(:user) { create(:user) }# The first page is the Project -> Settings -> General page, so we need# to provide the user with the edit_project permission in the role.@@ -227,6 +228,38 @@ RSpec.describe("Activation of storages in projects",endend+ describe "manual project folder mode" do+ context "when the storage is automatically managed" do+ context "when the storage is a nextcloud storage" do+ let(:oauth_application) { create(:oauth_application) }+ let(:storage) { create(:nextcloud_storage, :as_automatically_managed, oauth_application:) }+ let(:project_storage) { create(:project_storage, storage:, project:) }++ it "shows the option for manually managed permissions" do+ visit edit_project_settings_project_storage_path(project_id: project, id: project_storage)++ expect(page).to have_content("Existing folder with manually managed permissions")+ end+ end++ context "when the storage is a one drive storage" do+ let(:oauth_application) { create(:oauth_application) }+ let(:storage) { create(:one_drive_storage, :as_automatically_managed, oauth_application:) }+ let(:project_storage) { create(:project_storage, storage:, project:) }++ before do+ mock_one_drive_authorization_validation+ end++ it "shows no option for manually managed permissions" do+ visit edit_project_settings_project_storage_path(project_id: project, id: project_storage)++ expect(page).to have_no_content("Existing folder with manually managed permissions")+ end+ end+ end+ end+describe "configuration checks" dolet(:configured_storage) { storage }let!(:unconfigured_storage) { create(:nextcloud_storage) }diff --git a/modules/storages/spec/models/storages/project_storage_spec.rb b/modules/storages/spec/models/storages/project_storage_spec.rbindex 61ef1f8d33e..06dc13d3ea6 100644--- a/modules/storages/spec/models/storages/project_storage_spec.rb+++ b/modules/storages/spec/models/storages/project_storage_spec.rb@@ -113,6 +113,38 @@ RSpec.describe Storages::ProjectStorage doendend+ describe "#manual_management_possible?" do+ let(:project_storage) { build_stubbed(:project_storage, storage:) }++ context "when the storage is not a OneDriveStorage" do+ let(:storage) { build_stubbed(:storage, :as_generic) }++ it "returns true" do+ expect(project_storage.manual_management_possible?).to be true+ end+ end++ context "when the storage is a OneDriveStorage" do+ let(:storage) { build_stubbed(:one_drive_storage) }++ context "when the storage is not automatically managed" do+ it "returns true" do+ expect(project_storage.manual_management_possible?).to be true+ end+ end++ context "when the storage is automatically managed" do+ before do+ storage.automatically_managed = true+ end++ it "returns false" do+ expect(project_storage.manual_management_possible?).to be false+ end+ end+ end+ end+describe "#project_folder_mode" dolet(:project_storage) { build(:project_storage) }diff --git a/spec/services/oauth_clients/one_drive_connection_manager_spec.rb b/spec/services/oauth_clients/connection_manager_one_drive_spec.rbsimilarity index 81%rename from spec/services/oauth_clients/one_drive_connection_manager_spec.rbrename to spec/services/oauth_clients/connection_manager_one_drive_spec.rbindex b04fa5de908..96408d97d8a 100644--- a/spec/services/oauth_clients/one_drive_connection_manager_spec.rb+++ b/spec/services/oauth_clients/connection_manager_one_drive_spec.rb@@ -30,7 +30,7 @@require "spec_helper"-RSpec.describe OAuthClients::ConnectionManager, :webmock, type: :model do+RSpec.describe OAuthClients::ConnectionManager, :oauth_connection_helpers, :webmock, type: :model dolet(:user) { create(:user) }let(:storage) { create(:one_drive_storage, :with_oauth_client, tenant_id: "consumers") }let(:token) { create(:oauth_client_token, oauth_client: storage.oauth_client, user:) }@@ -50,31 +50,14 @@ RSpec.describe OAuthClients::ConnectionManager, :webmock, type: :model dorefresh_token: "AwABAAAAvPM1KaPlrEqdFSBzjqfTGAMxZGUTdM0t4B4..."}.to_jsonend- let(:me_response) do- {- businessPhones: [- "+45 123 4567 8901"- ],- displayName: "Sheev Palpatine ",- givenName: "Sheev",- jobTitle: "Galatic Senator",- mail: "[email protected]",- mobilePhone: "+45 123 4567 8901",- officeLocation: "500 Republica",- preferredLanguage: "en-US",- surname: "Palpatine",- userPrincipalName: "[email protected]",- id: "87d349ed-44d7-43e1-9a83-5f2406dee5bd"- }.to_json- endbefore dostub_request(:post, "https://login.microsoftonline.com/consumers/oauth2/v2.0/token").to_return(status: 200, body: code_to_token_response, headers: { "Content-Type" => "application/json" })- stub_request(:get, "https://graph.microsoft.com/v1.0/me")- .with(headers: { Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5HVEZ2ZEstZnl0aEV1Q..." })- .to_return(status: 200, body: me_response, headers: { "Content-Type" => "application/json" })+ mock_one_drive_authorization_validation(+ with: { headers: { Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5HVEZ2ZEstZnl0aEV1Q..." } }+ )endit "fills in the origin_user_id" dodiff --git a/spec/support/oauth_connections_helpers.rb b/spec/support/oauth_connections_helpers.rbnew file mode 100644index 00000000000..34370bed68c--- /dev/null+++ b/spec/support/oauth_connections_helpers.rb@@ -0,0 +1,30 @@+module OAuthConnectionsHelpers+ def mock_one_drive_authorization_validation(with: {})+ me_response = {+ businessPhones: [+ "+45 123 4567 8901"+ ],+ displayName: "Sheev Palpatine ",+ givenName: "Sheev",+ jobTitle: "Galactic Senator",+ mail: "[email protected]",+ mobilePhone: "+45 123 4567 8901",+ officeLocation: "500 Republica",+ preferredLanguage: "en-US",+ surname: "Palpatine",+ userPrincipalName: "[email protected]",+ id: "87d349ed-44d7-43e1-9a83-5f2406dee5bd"+ }.to_json++ stub = stub_request(:get, "https://graph.microsoft.com/v1.0/me")+ .to_return(status: 200, body: me_response, headers: { "Content-Type" => "application/json" })++ if with.present?+ stub.with(with)+ end+ end+end++RSpec.configure do |c|+ c.include OAuthConnectionsHelpers, :oauth_connection_helpers+end