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
[#64182] Sharepoint Storage Setup Wizard (#19712)
Yauheni Suhakou7ea1f3ff5fe9
diff --git a/config/static_links.yml b/config/static_links.ymlindex ea4aea50a98..bb2fe894bc6 100644--- a/config/static_links.yml+++ b/config/static_links.yml@@ -149,6 +149,12 @@ storage_docs:href: https://portal.azure.com/one_drive_setup:href: https://www.openproject.org/docs/system-admin-guide/integrations/one-drive/+ share_point_drive_id_guide:+ href: https://www.openproject.org/docs/system-admin-guide/integrations/one-drive/drive-guide/+ share_point_oauth_application:+ href: https://portal.azure.com/+ share_point_setup:+ href: https://www.openproject.org/docs/system-admin-guide/integrations/one-drive/troubleshooting:href: https://www.openproject.org/docs/user-guide/file-management/nextcloud-integration/#possible-errors-and-troubleshootingsysadmin_docs:diff --git a/modules/storages/app/common/storages/adapters/providers/share_point/share_point_contract.rb b/modules/storages/app/common/storages/adapters/providers/share_point/share_point_contract.rbindex 17deae142ca..47b6362add3 100644--- a/modules/storages/app/common/storages/adapters/providers/share_point/share_point_contract.rb+++ b/modules/storages/app/common/storages/adapters/providers/share_point/share_point_contract.rb@@ -36,6 +36,9 @@ module Storagesattribute :namevalidates :name, presence: true, length: { maximum: 255 }+ attribute :tenant_id+ validates :tenant_id,+ format: { with: /\A(?:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}|consumers)\z/i }attribute :hostvalidates :host, presence: true, format: { with: URI::DEFAULT_PARSER.make_regexp }validates :host,diff --git a/modules/storages/app/common/storages/adapters/providers/share_point/share_point_registry.rb b/modules/storages/app/common/storages/adapters/providers/share_point/share_point_registry.rbindex 618b55a6ec2..b1802c10b24 100644--- a/modules/storages/app/common/storages/adapters/providers/share_point/share_point_registry.rb+++ b/modules/storages/app/common/storages/adapters/providers/share_point/share_point_registry.rb@@ -40,6 +40,27 @@ module Storagesnamespace("contracts") doregister(:storage, SharePointContract)+ register(:general_information, SharePointContract)+ end++ namespace("components") do+ namespace("forms") do+ register(:access_management, Admin::Forms::AccessManagementFormComponent)+ register(:general_information, Admin::Forms::GeneralInfoFormComponent)+ register(:oauth_client, Admin::Forms::OAuthClientFormComponent)+ register(:redirect_uri, Admin::Forms::RedirectUriFormComponent)+ end++ register(:setup_wizard, StorageWizard)++ register(:access_management, Admin::AccessManagementComponent)+ register(:general_information, Admin::GeneralInfoComponent)+ register(:oauth_client, Admin::OAuthClientInfoComponent)+ register(:redirect_uri, Admin::RedirectUriComponent)+ end++ namespace("validators") do+ register(:connection, Validators::ConnectionValidator)endendenddiff --git a/modules/storages/app/common/storages/adapters/providers/share_point/storage_wizard.rb b/modules/storages/app/common/storages/adapters/providers/share_point/storage_wizard.rbnew file mode 100644index 00000000000..38c490e2cc7--- /dev/null+++ b/modules/storages/app/common/storages/adapters/providers/share_point/storage_wizard.rb@@ -0,0 +1,76 @@+# 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+ module Adapters+ module Providers+ module SharePoint+ class StorageWizard < Wizard+ step :general_information, completed_if: ->(storage) { storage.name.present? }++ step :access_management,+ section: :access_management_section,+ completed_if: ->(storage) { !storage.automatic_management_unspecified? },+ preparation: :prepare_storage_for_access_management_form++ step :oauth_client,+ section: :oauth_configuration,+ completed_if: ->(storage) { storage.oauth_client.present? },+ preparation: ->(storage) { storage.build_oauth_client }++ step :redirect_uri,+ section: :oauth_configuration,+ completed_if: ->(storage) {+ storage.oauth_client&.persisted? && storage.oauth_client.created_at < 10.seconds.ago+ }++ private++ def prepare_storage_for_access_management_form(storage)+ ::Storages::Storages::SetProviderFieldsAttributesService+ .new(user:, model: storage, contract_class: EmptyContract)+ .call+ end++ def prepare_oauth_application(storage)+ persist_service_result = ::Storages::OAuthApplications::CreateService.new(storage:, user:).call+ storage.oauth_application = persist_service_result.result if persist_service_result.success?+ end++ def prepare_storage_for_automatic_management_form(storage)+ ::Storages::Storages::SetProviderFieldsAttributesService+ .new(user:, model: storage, contract_class: EmptyContract)+ .call+ end+ end+ end+ end+ end+enddiff --git a/modules/storages/app/common/storages/adapters/providers/share_point/validators/connection_validator.rb b/modules/storages/app/common/storages/adapters/providers/share_point/validators/connection_validator.rbnew file mode 100644index 00000000000..bfc511bdf34--- /dev/null+++ b/modules/storages/app/common/storages/adapters/providers/share_point/validators/connection_validator.rb@@ -0,0 +1,43 @@+# 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+ module Adapters+ module Providers+ module SharePoint+ module Validators+ class ConnectionValidator < ConnectionValidators::BaseConnectionValidator+ # TODO: #64183 Implement the connection validation logic for SharePoint+ end+ end+ end+ end+ end+enddiff --git a/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erbindex d5aa6ddfbd3..2bcfb0414d0 100644--- a/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb+++ b/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb@@ -56,6 +56,16 @@endend+ if storage.provider_type_share_point?+ general_info_row.with_row(mb: 3) do+ render(Storages::Admin::ProviderTenantIdInputForm.new(form))+ end++ general_info_row.with_row(mb: 3) do+ render(Storages::Admin::ProviderHostInputForm.new(form))+ end+ end+general_info_row.with_row dorender(Storages::Admin::SubmitOrCancelForm.new(diff --git a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rbindex e7b9dc7e13a..a56d225480b 100644--- a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb+++ b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb@@ -61,6 +61,11 @@ module Storages::Admin::Formsrender(Primer::Beta::Link.new(href:, underline: true, target:)) { I18n.t("storages.instructions.one_drive.application_link_text") }end+ def share_point_integration_link(target: "_blank")+ href = ::OpenProject::Static::Links[:storage_docs][:share_point_oauth_application][:href]+ render(Primer::Beta::Link.new(href:, underline: true, target:)) { I18n.t("storages.instructions.share_point.application_link_text") }+ end+def nextcloud_integration_link(target: "_blank")href = Storages::UrlBuilder.url(storage.uri, "settings/admin/openproject")render(Primer::Beta::Link.new(href:, underline: true, target:)) { I18n.t("storages.instructions.nextcloud.integration") }diff --git a/modules/storages/app/controllers/storages/admin/access_management_controller.rb b/modules/storages/app/controllers/storages/admin/access_management_controller.rbindex 73920f5d4c9..94e27d06de9 100644--- a/modules/storages/app/controllers/storages/admin/access_management_controller.rb+++ b/modules/storages/app/controllers/storages/admin/access_management_controller.rb@@ -31,11 +31,13 @@class Storages::Admin::AccessManagementController < ApplicationControllerinclude OpTurbo::ComponentStream+ ALLOWED_STORAGES = %i[storages_one_drive_storage storages_share_point_storage].freeze+layout "admin"before_action :require_admin- model_object Storages::OneDriveStorage+ model_object Storages::Storagebefore_action :find_model_object, only: %i[new create edit update]# menu_item is defined in the Redmine::MenuManager::MenuController@@ -54,6 +56,11 @@ class Storages::Admin::AccessManagementController < ApplicationControllerendend+ def edit+ update_via_turbo_stream(component: Storages::Admin::Forms::AccessManagementFormComponent.new(@storage))+ respond_with_turbo_streams+ end+def createservice_result = call_update_service@@ -81,11 +88,6 @@ class Storages::Admin::AccessManagementController < ApplicationControllerrespond_with_turbo_streamsend- def edit- update_via_turbo_stream(component: Storages::Admin::Forms::AccessManagementFormComponent.new(@storage))- respond_with_turbo_streams- end-privatedef find_model_object(object_id = :storage_id)@@ -100,8 +102,7 @@ class Storages::Admin::AccessManagementController < ApplicationControllerenddef permitted_storage_params- params- .require(:storages_one_drive_storage)- .permit("automatic_management_enabled")+ key = params.keys.find { |k| ALLOWED_STORAGES.include?(k.to_sym) }+ params.expect(key => ["automatic_management_enabled"])endenddiff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex 5738b477170..563173f4839 100644--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb@@ -263,6 +263,8 @@ class Storages::Admin::StoragesController < ApplicationController:storages_nextcloud_storageelsif params.key?(:storages_one_drive_storage):storages_one_drive_storage+ elsif params.key?(:storages_share_point_storage)+ :storages_share_point_storageelse:storages_storageenddiff --git a/modules/storages/app/models/storages/share_point_storage.rb b/modules/storages/app/models/storages/share_point_storage.rbindex ce6b700c79d..62989206fab 100644--- a/modules/storages/app/models/storages/share_point_storage.rb+++ b/modules/storages/app/models/storages/share_point_storage.rb@@ -30,10 +30,17 @@module Storagesclass SharePointStorage < Storage- # For now SharePoint is visible only in tests.+ PROVIDER_FIELDS_DEFAULTS = {+ automatically_managed: false,+ automatic_management_enabled: false+ }.freeze++ store_attribute :provider_fields, :tenant_id, :string++ # For now SharePoint is visible only for development and tests.# This is to prevent it from being shown in the UI, as it is not ready yet.def self.visible?- Rails.env.test?+ Rails.env.local?enddef self.short_provider_name = :share_point@@ -53,9 +60,27 @@ module Storagesdef oauth_configuration = Adapters::Providers::SharePoint::OAuthConfiguration.new(self)- # To implement- # configuration_checks- # automatic_management_new_record?- # provider_fields_defaults+ def provider_fields_defaults+ PROVIDER_FIELDS_DEFAULTS+ end++ def automatic_management_new_record?+ if provider_fields_changed?+ previous_configuration = provider_fields_change.first+ previous_configuration.values_at("automatically_managed").compact.empty?+ else+ automatic_management_unspecified?+ end+ end++ def configuration_checks+ {+ storage_oauth_client_configured: oauth_client.present?,+ storage_redirect_uri_configured: oauth_client&.persisted?,+ storage_tenant_drive_configured: tenant_id.present?,+ access_management_configured: !automatic_management_unspecified?,+ name_configured: name.present?+ }+ endendenddiff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex 86570c64803..2d07c894523 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -178,6 +178,10 @@ module Storagesis_a?(OneDriveStorage)end+ def provider_type_share_point?+ is_a?(SharePointStorage)+ end+def health_reason_identifier@health_reason_identifier ||= self.class.extract_part_from_piped_string(health_reason, 0)enddiff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex d67b9dd1320..12b682841e8 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -196,8 +196,10 @@ en:oauth_client_incomplete:nextcloud: Allow OpenProject to access Nextcloud data using OAuth.one_drive: Allow OpenProject to access Azure data using OAuth to connect OneDrive.+ share_point: Allow OpenProject to access SharePoint data using OAuth.redirect_uri_incomplete:one_drive: Complete the setup with the correct URI redirection.+ share_point: Complete the setup with the correct URI redirection.confirm_replace_oauth_application: This action will reset the current OAuth credentials. After confirming you will have to reenter the credentials at the storage provider and all remote users will have to authorize against OpenProject again. Are you sure you want to proceed?confirm_replace_oauth_client: This action will reset the current OAuth credentials. After confirming you will have to enter new credentials from the storage provider and all users will have to authorize against %{provider_type} again. Are you sure you want to proceed?delete_warning:@@ -387,6 +389,11 @@ en:setting_up_additional_storages_non_admin: Administrators can set up additional file storages in Administration / File storages.setting_up_storages: For setting up file storages, please visitsetting_up_storages_non_admin: Administrators can set up file storages in Administration / File storages.+ share_point:+ application_link_text: SharePoint site+ integration: SharePoint Administration / OpenProject+ oauth_configuration: Copy these values from the desired application in the %{application_link_text}.+ provider_configuration: Please make sure you have administration privileges in your SharePoint instance and the OpenProject integration app is installed before doing the setup.type: 'Please make sure you have administration privileges in your Nextcloud instance and have the following application installed before doing the setup:'type_link_text: "“Integration OpenProject”"label_active: Activediff --git a/modules/storages/spec/common/storages/adapters/providers/share_point/share_point_contract_spec.rb b/modules/storages/spec/common/storages/adapters/providers/share_point/share_point_contract_spec.rbindex 66e4f4de8e2..413aaa4263e 100644--- a/modules/storages/spec/common/storages/adapters/providers/share_point/share_point_contract_spec.rb+++ b/modules/storages/spec/common/storages/adapters/providers/share_point/share_point_contract_spec.rb@@ -37,7 +37,7 @@ module Storagesmodule SharePointRSpec.describe SharePointContract, :storage_server_helpers, :webmock dolet(:current_user) { create(:admin) }- let(:storage) { build(:share_point_storage) }+ let(:storage) { build(:share_point_storage, :with_tenant_id) }# As the SharePointContract is selected by the BaseContract to make writable attributes available,# the BaseContract needs to be instantiated here.diff --git a/modules/storages/spec/common/storages/adapters/providers/share_point/storage_wizard_spec.rb b/modules/storages/spec/common/storages/adapters/providers/share_point/storage_wizard_spec.rbnew file mode 100644index 00000000000..074b2215275--- /dev/null+++ b/modules/storages/spec/common/storages/adapters/providers/share_point/storage_wizard_spec.rb@@ -0,0 +1,121 @@+# 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.+#++++require "spec_helper"++RSpec.describe Storages::Adapters::Providers::SharePoint::StorageWizard do+ subject(:wizard) { described_class.new(model:, user:) }++ let(:model) { Storages::SharePointStorage.new }+ let(:user) { create(:admin) }++ before do+ Storages::Storages::SetAttributesService.new(user:, model:, contract_class: EmptyContract).call+ end++ it "has no completed steps" do+ expect(wizard.completed_steps).to be_empty+ end++ it "has all steps pending in correct order" do+ expect(wizard.pending_steps).to eq(%i[general_information+ access_management+ oauth_client+ redirect_uri])+ end++ context "when name was set" do+ before do+ model.name = "Karl"+ model.save!+ end++ it "has general_information step completed" do+ expect(wizard.completed_steps).to eq([:general_information])+ end++ it "still didn't specify how to manage folders" do+ expect(model).to be_automatic_management_unspecified+ end++ context "and the next step was prepared" do+ before do+ wizard.prepare_next_step+ end++ it "automatically finished the access_management step" do+ expect(wizard.completed_steps).to eq(%i[general_information access_management])+ end++ it "disabled automatic storage management, and didn't persist it" do+ expect(model).not_to be_automatic_management_enabled+ before, after = model.changes["provider_fields"]+ expect(before.keys).not_to include("automatically_managed")+ expect(after.keys).to include("automatically_managed")+ end++ it "has no oauth_client yet" do+ expect(model.oauth_client).to be_nil+ end++ context "and the next step was prepared" do+ before do+ wizard.prepare_next_step+ end++ it "finishes the oauth_client step" do+ expect(wizard.completed_steps).to eq(%i[general_information access_management oauth_client])+ end++ it "now has an unsaved oauth_client" do+ expect(model.oauth_client).to be_present+ expect(model.oauth_client).not_to be_persisted+ end++ context "when the client was saved" do+ before do+ model.oauth_client.assign_attributes(client_id: "Foo", client_secret: "Bar")+ model.oauth_client.save!+ end++ it "did not finish the final step immediately" do+ expect(wizard.pending_steps).to eq(%i[redirect_uri])+ end++ it "after some time, the final step is completed" do+ Timecop.travel(15.seconds.from_now) do+ expect(wizard.completed_steps).to eq(%i[general_information access_management oauth_client redirect_uri])+ end+ end+ end+ end+ end+ end+enddiff --git a/modules/storages/spec/factories/storage_factory.rb b/modules/storages/spec/factories/storage_factory.rbindex 6be6b0dea7f..eef7959d215 100644--- a/modules/storages/spec/factories/storage_factory.rb+++ b/modules/storages/spec/factories/storage_factory.rb@@ -230,10 +230,6 @@ FactoryBot.define dohost { "https://openproject.sharepoint.com/sites/ProjectX" }automatically_managed { false }- trait :as_automatically_managed do- automatically_managed { true }- end-trait :with_tenant_id dotenant_id { SecureRandom.uuid }end