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
[#48609] Fix issues with nextcloud permissions synchronization.
Pavel Balashou39b10342a7da
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rbindex e6e24e13d56..86f27eaab27 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/util.rb@@ -36,7 +36,7 @@ module Storages::Peripherals::StorageInteraction::Nextcloud::Utildef basic_auth_header(username, password){- 'Authorization' => "Basic #{Base64::encode64("#{username}:#{password}")}"+ 'Authorization' => "Basic #{Base64::strict_encode64("#{username}:#{password}")}"}enddiff --git a/modules/storages/app/workers/cleanup_uncontainered_file_links_job.rb b/modules/storages/app/workers/storages/cleanup_uncontainered_file_links_job.rbsimilarity index 95%rename from modules/storages/app/workers/cleanup_uncontainered_file_links_job.rbrename to modules/storages/app/workers/storages/cleanup_uncontainered_file_links_job.rbindex 96f27af0f2c..0f46560e0d8 100644--- a/modules/storages/app/workers/cleanup_uncontainered_file_links_job.rb+++ b/modules/storages/app/workers/storages/cleanup_uncontainered_file_links_job.rb@@ -26,7 +26,7 @@# See COPYRIGHT and LICENSE files for more details.#++-class CleanupUncontaineredFileLinksJob < Cron::CronJob+class Storages::CleanupUncontaineredFileLinksJob < Cron::CronJobqueue_with_priority :lowself.cron_expression = '06 22 * * *'diff --git a/modules/storages/app/workers/manage_nextcloud_integration_job.rb b/modules/storages/app/workers/storages/manage_nextcloud_integration_job.rbsimilarity index 98%rename from modules/storages/app/workers/manage_nextcloud_integration_job.rbrename to modules/storages/app/workers/storages/manage_nextcloud_integration_job.rbindex dd36c3617f5..e8c0d93a8b4 100644--- a/modules/storages/app/workers/manage_nextcloud_integration_job.rb+++ b/modules/storages/app/workers/storages/manage_nextcloud_integration_job.rb@@ -26,7 +26,7 @@# See COPYRIGHT and LICENSE files for more details.#++-class ManageNextcloudIntegrationJob < Cron::CronJob+class Storages::ManageNextcloudIntegrationJob < Cron::CronJobusing ::Storages::Peripherals::ServiceResultRefinementsqueue_with_priority :low@@ -105,7 +105,7 @@ class ManageNextcloudIntegrationJob < Cron::CronJobenddef project_folder_path(project)- "#{@group_folder}/#{project.name.gsub('/', '|')}(#{project.id})/"+ "#{@group_folder}/#{project.name.gsub('/', '|')} (#{project.id})/"end# rubocop:disable Metrics/AbcSize@@ -223,7 +223,7 @@ class ManageNextcloudIntegrationJob < Cron::CronJobenddef remove_inactive_users_from_group- (group_users - @nextcloud_usernames_used_in_openproject.to_a).each do |user|+ (group_users - @nextcloud_usernames_used_in_openproject.to_a - [@nextcloud_system_user]).each do |user|remove_user_from_group(user)endenddiff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rbindex 28c2e54bfdc..fc61a44ee02 100644--- a/modules/storages/lib/open_project/storages/engine.rb+++ b/modules/storages/lib/open_project/storages/engine.rb@@ -227,10 +227,10 @@ module OpenProject::Storagesadd_cron_jobs do[- CleanupUncontaineredFileLinksJob,+ Storages::CleanupUncontaineredFileLinksJob].tap do |cron_jobs|if OpenProject::FeatureDecisions.managed_project_folders_active?- cron_jobs << ManageNextcloudIntegrationJob+ cron_jobs << Storages::ManageNextcloudIntegrationJobendendenddiff --git a/modules/storages/spec/common/peripherals/util_spec.rb b/modules/storages/spec/common/peripherals/util_spec.rbnew file mode 100644index 00000000000..6196cd4e06f--- /dev/null+++ b/modules/storages/spec/common/peripherals/util_spec.rb@@ -0,0 +1,51 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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::Peripherals::StorageInteraction::Nextcloud::Util do+ describe '.basic_auth_header' do+ subject { described_class.basic_auth_header(username, password) }++ context 'when password is more than 60 symbols' do+ let(:username) { 'Dart Scuadron' }+ let(:password) { "#{'StarWars' * 10}Forever!" }++ it 'has no newline characters in encoded string' do+ expect(subject['Authorization']).not_to match(/\n/)+ expect(subject).to eq(+ {+ "Authorization" => "Basic RGFydCBTY3VhZHJvbjpTdGFyV2Fyc1N0YXJXYXJzU3Rhcl" \+ "dhcnNTdGFyV2Fyc1N0YXJXYXJzU3RhcldhcnNTdGFyV2Fyc1N0YX" \+ "JXYXJzU3RhcldhcnNTdGFyV2Fyc0ZvcmV2ZXIh"+ }+ )+ end+ end+ end+enddiff --git a/modules/storages/spec/workers/cleanup_uncontainered_file_links_job_spec.rb b/modules/storages/spec/workers/storages/cleanup_uncontainered_file_links_job_spec.rbsimilarity index 97%rename from modules/storages/spec/workers/cleanup_uncontainered_file_links_job_spec.rbrename to modules/storages/spec/workers/storages/cleanup_uncontainered_file_links_job_spec.rbindex 6123afd5ab5..1b2c038291a 100644--- a/modules/storages/spec/workers/cleanup_uncontainered_file_links_job_spec.rb+++ b/modules/storages/spec/workers/storages/cleanup_uncontainered_file_links_job_spec.rb@@ -28,7 +28,7 @@require 'spec_helper'-RSpec.describe CleanupUncontaineredFileLinksJob, type: :job do+RSpec.describe Storages::CleanupUncontaineredFileLinksJob, type: :job doit 'has a schedule set' doexpect(described_class.cron_expression).to eq('06 22 * * *')enddiff --git a/modules/storages/spec/workers/manage_nextcloud_integration_job_spec.rb b/modules/storages/spec/workers/storages/manage_nextcloud_integration_job_spec.rbsimilarity index 80%rename from modules/storages/spec/workers/manage_nextcloud_integration_job_spec.rbrename to modules/storages/spec/workers/storages/manage_nextcloud_integration_job_spec.rbindex d0dc348a286..46dd5649c27 100644--- a/modules/storages/spec/workers/manage_nextcloud_integration_job_spec.rb+++ b/modules/storages/spec/workers/storages/manage_nextcloud_integration_job_spec.rb@@ -28,7 +28,7 @@require 'spec_helper'-RSpec.describe ManageNextcloudIntegrationJob, type: :job, webmock: true do+RSpec.describe Storages::ManageNextcloudIntegrationJob, type: :job, webmock: true do# rubocop:disable RSpec/IndexedLetlet(:group_users_response_body) do<<~XML@@ -44,6 +44,7 @@ RSpec.describe ManageNextcloudIntegrationJob, type: :job, webmock: true do<data><users><element>Darth Maul</element>+ <element>OpenProject</element></users></data></ocs>@@ -151,7 +152,7 @@ RSpec.describe ManageNextcloudIntegrationJob, type: :job, webmock: true doxmlns:oc="http://owncloud.org/ns"xmlns:nc="http://nextcloud.org/ns"><d:response>- <d:href>/remote.php/dav/files/OpenProject/OpenProject/%5bSample%5d%20Project%20Name%20%7c%20Ehuu(#{project1.id})/</d:href>+ <d:href>/remote.php/dav/files/OpenProject/OpenProject/%5bSample%5d%20Project%20Name%20%7c%20Ehuu%20(#{project1.id})/</d:href><d:propstat><d:prop><oc:fileid>819</oc:fileid>@@ -350,40 +351,44 @@ RSpec.describe ManageNextcloudIntegrationJob, type: :job, webmock: true do'OCS-APIRequest' => 'true'}).to_return(status: 200, body: group_users_response_body, headers: {})- request_stubs << stub_request(:proppatch, "https://example.com/remote.php/dav/files/OpenProject/OpenProject")- .with(- body: set_permissions_request_body1,- headers: {- 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg='- }- )- .to_return(status: 207, body: set_permissions_response_body1, headers: {})- request_stubs << stub_request(:propfind, "https://example.com/remote.php/dav/files/OpenProject/OpenProject")- .with(- body: propfind_request_body,- headers: {- 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',- 'Depth' => '1'- }- )- .to_return(status: 207, body: propfind_response_body1, headers: {})+ request_stubs << stub_request(+ :proppatch,+ "https://example.com/remote.php/dav/files/OpenProject/OpenProject"+ ).with(+ body: set_permissions_request_body1,+ headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg='+ }+ ).to_return(status: 207, body: set_permissions_response_body1, headers: {})+ request_stubs << stub_request(+ :propfind,+ "https://example.com/remote.php/dav/files/OpenProject/OpenProject"+ ).with(+ body: propfind_request_body,+ headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',+ 'Depth' => '1'+ }+ ).to_return(status: 207, body: propfind_response_body1, headers: {})request_stubs << stub_request(:mkcol,- "https://example.com/remote.php/dav/files/OpenProject/OpenProject/%5BSample%5D%20Project%20Name%20%7C%20Ehuu(#{project1.id})"+ "https://example.com/remote.php/dav/files/OpenProject/OpenProject/%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})").with(headers: {'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg='}).to_return(status: 201, body: "", headers: {})- request_stubs << stub_request(:propfind, "https://example.com/remote.php/dav/files/OpenProject/OpenProject/%5BSample%5D%20Project%20Name%20%7C%20Ehuu(#{project1.id})")- .with(- body: propfind_request_body,- headers: {- 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',- 'Depth' => '0'- }- )- .to_return(status: 207, body: propfind_response_body2, headers: {})+ request_stubs << stub_request(+ :propfind,+ "https://example.com/remote.php/dav/files/OpenProject/OpenProject/" \+ "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})"+ ).with(+ body: propfind_request_body,+ headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',+ 'Depth' => '0'+ }+ ).to_return(status: 207, body: propfind_response_body2, headers: {})request_stubs << stub_request(:post, "https://example.com/ocs/v1.php/cloud/users/Obi-Wan/groups").with(body: "groupid=OpenProject",@@ -392,58 +397,65 @@ RSpec.describe ManageNextcloudIntegrationJob, type: :job, webmock: true do'Ocs-Apirequest' => 'true'}).to_return(status: 200, body: add_user_to_group_response_body, headers: {})- request_stubs << stub_request(:proppatch, "https://example.com/remote.php/dav/files/OpenProject/OpenProject/%5BSample%5D%20Project%20Name%20%7C%20Ehuu(#{project1.id})")- .with(- body: set_permissions_request_body2,- headers: {- 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg='- }- )- .to_return(status: 207, body: set_permissions_response_body2, headers: {})- request_stubs << stub_request(:move, "https://example.com/remote.php/dav/files/OpenProject/OpenProject/Lost%20Jedi%20Project%20Folder%20%233")- .with(- headers: {- 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',- 'Destination' => "/remote.php/dav/files/OpenProject/OpenProject/Jedi%20Project%20Folder%20%7C%7C%7C%28#{project2.id}%29"- }- )- .to_return(status: 201, body: "", headers: {})- request_stubs << stub_request(:proppatch, "https://example.com/remote.php/dav/files/OpenProject/OpenProject/Jedi%20Project%20Folder%20%7C%7C%7C%28#{project2.id}%29")- .with(- body: set_permissions_request_body2,- headers: {- 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg='- }- )- .to_return(status: 207, body: set_permissions_response_body4, headers: {})+ request_stubs << stub_request(+ :proppatch,+ "https://example.com/remote.php/dav/files/OpenProject/OpenProject/" \+ "%5BSample%5D%20Project%20Name%20%7C%20Ehuu%20(#{project1.id})"+ ).with(+ body: set_permissions_request_body2,+ headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg='+ }+ ).to_return(status: 207, body: set_permissions_response_body2, headers: {})+ request_stubs << stub_request(+ :move,+ "https://example.com/remote.php/dav/files/OpenProject/OpenProject/" \+ "Lost%20Jedi%20Project%20Folder%20%233"+ ).with(+ headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=',+ 'Destination' => "/remote.php/dav/files/OpenProject/OpenProject/" \+ "Jedi%20Project%20Folder%20%7C%7C%7C%20%28#{project2.id}%29"+ }+ ).to_return(status: 201, body: "", headers: {})+ request_stubs << stub_request(+ :proppatch,+ "https://example.com/remote.php/dav/files/OpenProject/OpenProject/" \+ "Jedi%20Project%20Folder%20%7C%7C%7C%20%28#{project2.id}%29"+ ).with(+ body: set_permissions_request_body2,+ headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg='+ }+ ).to_return(status: 207, body: set_permissions_response_body4, headers: {})request_stubs << stub_request(:delete, "https://example.com/ocs/v1.php/cloud/users/Darth%20Maul/groups?groupid=OpenProject").with(headers: {'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg=','Ocs-Apirequest' => 'true'}- )- .to_return(status: 200, body: remove_user_from_group_response, headers: {})- request_stubs << stub_request(:proppatch, "https://example.com/remote.php/dav/files/OpenProject/OpenProject/Lost%20Jedi%20Project%20Folder%20%232")- .with(- body: set_permissions_request_body3,- headers: {- 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg='- }- )- .to_return(status: 207, body: set_permissions_response_body3, headers: {})+ ).to_return(status: 200, body: remove_user_from_group_response, headers: {})+ request_stubs << stub_request(+ :proppatch,+ "https://example.com/remote.php/dav/files/OpenProject/OpenProject/" \+ "Lost%20Jedi%20Project%20Folder%20%232"+ ).with(+ body: set_permissions_request_body3,+ headers: {+ 'Authorization' => 'Basic T3BlblByb2plY3Q6MTIzNDU2Nzg='+ }+ ).to_return(status: 207, body: set_permissions_response_body3, headers: {})expect(projects_storage1.project_folder_id).to be_nilexpect(projects_storage2.project_folder_id).to eq('123')described_class.new.perform+ expect(request_stubs).to all have_been_requestedprojects_storage1.reloadprojects_storage2.reloadexpect(projects_storage1.project_folder_id).to eq('819')expect(projects_storage2.project_folder_id).to eq('123')-- expect(request_stubs).to all have_been_requestedend# rubocop:enable RSpec/ExampleLengthend