diff --git a/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb b/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb index b5645fa7a4ed..8ea89f531d38 100644 --- a/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb +++ b/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb @@ -45,6 +45,7 @@ def validate .or { missing_dependencies } .or { version_mismatch } .or { request_failed_with_unknown_error } + .or { with_unexpected_content } .value_or(ConnectionValidation.new(type: :healthy, error_code: :none, timestamp: Time.current, @@ -59,6 +60,17 @@ def query .call(storage: @storage, auth_strategy:) end + def files + @files ||= Peripherals::Registry + .resolve("#{@storage.short_provider_type}.queries.files") + .call( + storage: @storage, + auth_strategy: Peripherals::Registry + .resolve("#{@storage.short_provider_type}.authentication.userless").call, + folder: ParentFolder.new(@storage.group_folder) + ) + end + def maybe_is_not_configured return None() if @storage.configured? @@ -147,10 +159,12 @@ def version_mismatch def request_failed_with_unknown_error return None() if query.success? - Rails.logger.error("Connection validation failed with unknown error:\n\t" \ - "storage: ##{@storage.id} #{@storage.name}\n\t" \ - "status: #{query.result}\n\t" \ - "response: #{query.error_payload}") + Rails.logger.error( + "Connection validation failed with unknown error:\n\t" \ + "storage: ##{@storage.id} #{@storage.name}\n\t" \ + "status: #{query.result}\n\t" \ + "response: #{query.error_payload}" + ) Some(ConnectionValidation.new(type: :error, error_code: :err_unknown, @@ -158,6 +172,26 @@ def request_failed_with_unknown_error description: I18n.t("storages.health.connection_validation.unknown_error"))) end + # rubocop:disable Metrics/AbcSize + def with_unexpected_content + return None() unless @storage.automatic_management_enabled? + return None() if files.failure? + + expected_folder_ids = @storage.project_storages + .where(project_folder_mode: "automatic") + .map(&:project_folder_id) + + unexpected_files = files.result.files.reject { |file| expected_folder_ids.include?(file.id) } + return None() if unexpected_files.empty? + + Some(ConnectionValidation.new(type: :warning, + error_code: :wrn_unexpected_content, + timestamp: Time.current, + description: I18n.t("storages.health.connection_validation.unexpected_content"))) + end + + # rubocop:enable Metrics/AbcSize + def auth_strategy = StorageInteraction::AuthenticationStrategies::Noop.strategy def path_to_config diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb index 848f06e3cf53..a80dc489d77d 100644 --- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb +++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb @@ -42,7 +42,7 @@ def initialize(storage) end def call(auth_strategy:, folder:) - validate_input_data(auth_strategy, folder).on_failure { return _1 } + validate_input_data(folder).on_failure { return _1 } origin_user = Util.origin_user_id(caller: self.class, storage: @storage, auth_strategy:) .on_failure { return _1 } @@ -56,12 +56,10 @@ def call(auth_strategy:, folder:) private - def validate_input_data(auth_strategy, folder) + def validate_input_data(folder) error_data = StorageErrorData.new(source: self.class) - if auth_strategy.user.nil? - Util.error(:error, "Cannot execute query without user context.", error_data) - elsif folder.is_a?(ParentFolder) + if folder.is_a?(ParentFolder) ServiceResult.success else Util.error(:error, "Folder input is not a ParentFolder object.", error_data)