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
[#57707] rework group users query
Eric Schubert33b028234249
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rbindex 8ab9d8b9bcc..19cf94f9bf3 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/group_users_query.rb@@ -34,47 +34,51 @@ module Storagesmodule Nextcloudclass GroupUsersQueryinclude TaggedLogging- using ServiceResultRefinements- def self.call(storage:, group: storage.group)- new(storage).call(group:)+ def self.call(storage:, auth_strategy:, group:)+ new(storage).call(auth_strategy:, group:)enddef initialize(storage)@storage = storage- @username = storage.username- @password = storage.passwordend- # rubocop:disable Metrics/AbcSize- def call(group:)+ def call(auth_strategy:, group:)with_tagged_logger do- url = UrlBuilder.url(@storage.uri, "ocs/v1.php/cloud/groups", CGI.escapeURIComponent(group))+ Authentication[auth_strategy].call(storage: @storage, http_options:) do |http|+ url = UrlBuilder.url(@storage.uri, "ocs/v1.php/cloud/groups", group)+ info "Requesting user list for group #{group} via url #{url} "- info "Requesting user list for group #{group} via url #{url} "- response = OpenProject.httpx- .basic_auth(@username, @password)- .with(headers: { "OCS-APIRequest" => "true" })- .get(url)+ handle_response(http.get(url))+ end+ end+ end- error_data = StorageErrorData.new(source: self.class, payload: response)+ private- case response- in { status: 200..299 }- group_users = Nokogiri::XML(response.body.to_s).xpath("/ocs/data/users/element").map(&:text)- info "#{group_users.size} users found"- ServiceResult.success(result: group_users)- in { status: 405 }- Util.error(:not_allowed, "Outbound request method not allowed", error_data)- in { status: 401 }- Util.error(:unauthorized, "Outbound request not authorized", error_data)- in { status: 404 }- Util.error(:not_found, "Outbound request destination not found", error_data)- in { status: 409 }- Util.error(:conflict, error_text_from_response(response), error_data)- else- Util.error(:error, "Outbound request failed", error_data)- end+ def http_options+ Util.ocs_api_request+ end++ # rubocop:disable Metrics/AbcSize+ def handle_response(response)+ error_data = StorageErrorData.new(source: self.class, payload: response)++ case response+ in { status: 200..299 }+ group_users = Nokogiri::XML(response.body.to_s).xpath("/ocs/data/users/element").map(&:text)+ info "#{group_users.size} users found"+ ServiceResult.success(result: group_users)+ in { status: 405 }+ Util.error(:not_allowed, "Outbound request method not allowed", error_data)+ in { status: 401 }+ Util.error(:unauthorized, "Outbound request not authorized", error_data)+ in { status: 404 }+ Util.error(:not_found, "Outbound request destination not found", error_data)+ in { status: 409 }+ Util.error(:conflict, error_text_from_response(response), error_data)+ else+ Util.error(:error, "Outbound request failed", error_data)endenddiff --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 d12de30e0fa..4ea4c380974 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@@ -62,20 +62,6 @@ module Storages)end- def token(user:, configuration:, &)- connection_manager = OAuthClients::ConnectionManager.new(user:, configuration:)- connection_manager.get_access_token.match(- on_success: lambda do |token|- connection_manager.request_with_token_refresh(token) { yield token }- end,- on_failure: lambda do |_|- error(:unauthorized,- "Query could not be created! No access token found!",- StorageErrorData.new(source: connection_manager))- end- )- end-def error_text_from_response(response)response.xml.xpath("//s:message").textenddiff --git a/modules/storages/app/services/storages/nextcloud_managed_folder_sync_service.rb b/modules/storages/app/services/storages/nextcloud_managed_folder_sync_service.rbindex 9a6554009f8..78e27cc34ae 100644--- a/modules/storages/app/services/storages/nextcloud_managed_folder_sync_service.rb+++ b/modules/storages/app/services/storages/nextcloud_managed_folder_sync_service.rb@@ -308,7 +308,7 @@ module Storagesdef remote_group_usersinfo "Retrieving users that a part of the #{@storage.group} group"- group_users.call(storage: @storage, group: @storage.group)+ group_users.call(storage: @storage, auth_strategy:, group: @storage.group)end### Model Scopesdiff --git a/modules/storages/spec/services/storages/nextcloud_managed_folder_sync_service_spec.rb b/modules/storages/spec/services/storages/nextcloud_managed_folder_sync_service_spec.rbindex cce5b7cb51a..37b15f03ee8 100644--- a/modules/storages/spec/services/storages/nextcloud_managed_folder_sync_service_spec.rb+++ b/modules/storages/spec/services/storages/nextcloud_managed_folder_sync_service_spec.rb@@ -185,7 +185,10 @@ module Storagesend# No AuthStrategy on GroupUsers- allow(group_users).to receive(:call).with(storage:, group: storage.group).and_return(group_users_result)+ allow(group_users).to receive(:call).with(storage:,+ auth_strategy:,+ group: storage.group)+ .and_return(group_users_result)# Updating the group usersallow(add_user).to receive(:call).with(storage:,auth_strategy:,