Skip to content

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

Initial Mess

Marcello Rocha81e11bd54f26
diff --git a/Gemfile b/Gemfile
index 0dada9c507b..2b632665a43 100644
--- a/Gemfile
+++ b/Gemfile
@@ -211,6 +211,7 @@ gem "validate_url"
# Storages support code
gem "dry-container"
gem "dry-monads"
+gem "dry-auto_inject"
# ActiveRecord extension which adds typecasting to store accessors
gem "store_attribute", "~> 1.0"
diff --git a/Gemfile.lock b/Gemfile.lock
index 1f8c83711d9..a219bbd8c67 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -466,6 +466,9 @@ GEM
dotenv (= 3.1.2)
railties (>= 6.1)
drb (2.2.1)
+ dry-auto_inject (1.0.1)
+ dry-core (~> 1.0)
+ zeitwerk (~> 2.6)
dry-container (0.11.0)
concurrent-ruby (~> 1.0)
dry-core (1.0.1)
@@ -1200,6 +1203,7 @@ DEPENDENCIES
disposable (~> 0.6.2)
doorkeeper (~> 5.7.0)
dotenv-rails
+ dry-auto_inject
dry-container
dry-monads
email_validator (~> 2.2.3)
diff --git a/modules/storages/app/common/storages/injector.rb b/modules/storages/app/common/storages/injector.rb
new file mode 100644
index 00000000000..d8d5b6dce41
--- /dev/null
+++ b/modules/storages/app/common/storages/injector.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+require "dry/auto_inject"
+
+module Storages
+ Injector = Dry::AutoInject(Peripherals::Registry)
+end
diff --git a/modules/storages/app/common/storages/peripherals/registry.rb b/modules/storages/app/common/storages/peripherals/registry.rb
index 4912485a9fc..3e067f0315c 100644
--- a/modules/storages/app/common/storages/peripherals/registry.rb
+++ b/modules/storages/app/common/storages/peripherals/registry.rb
@@ -28,6 +28,8 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+require "dry/auto_inject"
+
module Storages
module Peripherals
class Registry
@@ -35,6 +37,7 @@ module Storages
class Resolver < Dry::Container::Resolver
def call(container, key)
+ Rails.logger.tagged("Registry").info("Resolving #{key}")
super
rescue Dry::Container::KeyError
raise Errors.registry_error_for(key)
diff --git a/modules/storages/app/common/storages/peripherals/service_result_refinements.rb b/modules/storages/app/common/storages/peripherals/service_result_refinements.rb
index c071701434c..7cbb9dd381a 100644
--- a/modules/storages/app/common/storages/peripherals/service_result_refinements.rb
+++ b/modules/storages/app/common/storages/peripherals/service_result_refinements.rb
@@ -86,6 +86,11 @@ module Storages
end
alias_method :error_or, :result_and
+
+ def fail!
+ self.success = false
+ self
+ end
end
end
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_ids_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_ids_query.rb
index 0335b6b6126..87851fc3f5c 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_ids_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_ids_query.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 the OpenProject GmbH
@@ -26,24 +28,26 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Storages::Peripherals::StorageInteraction::Nextcloud
- class FileIdsQuery
- def initialize(storage)
- @query = ::Storages::Peripherals::StorageInteraction::Nextcloud::Internal::PropfindQueryLegacy.new(storage)
- end
-
- def self.call(storage:, path:)
- new(storage).call(path:)
- end
+module Storages
+ module Peripherals
+ module StorageInteraction
+ module Nextcloud
+ class FileIdsQuery
+ def self.call(storage:, path:)
+ new(storage).call(path:)
+ end
- def call(path:)
- query_params = {
- depth: "1",
- path:,
- props: %w[oc:fileid]
- }
+ def initialize(storage)
+ @query = Internal::PropfindQueryLegacy.new(storage)
+ end
- @query.call(**query_params)
+ def call(path:)
+ query_params = { depth: "1", path:, props: %w[oc:fileid] }
+ Rails.logger.tagged(self.class).info "Requesting File Ids with the following args: #{query_params.inspect}"
+ @query.call(**query_params)
+ end
+ end
+ end
end
end
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query_legacy.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query_legacy.rb
index a080512170f..32cce7b819b 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query_legacy.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/internal/propfind_query_legacy.rb
@@ -77,20 +77,21 @@ module Storages
# rubocop:disable Metrics/AbcSize
def call(depth:, path:, props:)
- body = Nokogiri::XML::Builder.new do |xml|
- xml["d"].propfind(
- "xmlns:d" => "DAV:",
- "xmlns:oc" => "http://owncloud.org/ns",
- "xmlns:nc" => "http://nextcloud.org/ns"
- ) do
- xml["d"].prop do
- props.each do |prop|
- namespace, property = prop.split(":")
- xml[namespace].send(property)
+ Rails.logger.tagged(self.class) do
+ body = Nokogiri::XML::Builder.new do |xml|
+ xml["d"].propfind(
+ "xmlns:d" => "DAV:",
+ "xmlns:oc" => "http://owncloud.org/ns",
+ "xmlns:nc" => "http://nextcloud.org/ns"
+ ) do
+ xml["d"].prop do
+ props.each do |prop|
+ namespace, property = prop.split(":")
+ xml[namespace].send(property)
+ end
end
end
- end
- end.to_xml
+ end.to_xml
response = OpenProject
.httpx
@@ -102,38 +103,47 @@ module Storages
xml: body
)
- error_data = StorageErrorData.new(source: self.class, payload: response)
+ error_data = StorageErrorData.new(source: self.class, payload: response)
case response
in { status: 200..299 }
+ log_response(response)
doc = Nokogiri::XML(response.body.to_s)
- result = {}
- doc.xpath("/d:multistatus/d:response").each do |resource_section|
+ Rails.logger.info "Parsing response body"
+ result = doc.xpath("/d:multistatus/d:response").each_with_object({}) do |resource_section, hash|
source_path = UrlBuilder.path(@storage.uri.path, "/remote.php/dav/files", @username)
resource = CGI.unescape(resource_section.xpath("d:href").text.strip).gsub!(source_path, "")
- result[resource] = {}
+ hash[resource] = {}
- # In future it could be useful to respond not only with found, but not found props as well
- # resource_section.xpath("d:propstat[d:status[text() = 'HTTP/1.1 404 Not Found']]/d:prop/*")
- resource_section.xpath("d:propstat[d:status[text() = 'HTTP/1.1 200 OK']]/d:prop/*").each do |node|
- result[resource][node.name.to_s] = node.text.strip
+ # In future it could be useful to respond not only with found, but not found props as well
+ # resource_section.xpath("d:propstat[d:status[text() = 'HTTP/1.1 404 Not Found']]/d:prop/*")
+ resource_section.xpath("d:propstat[d:status[text() = 'HTTP/1.1 200 OK']]/d:prop/*").each do |node|
+ hash[resource][node.name.to_s] = node.text.strip
+ end
end
- end
- ServiceResult.success(result:)
- 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)
- else
- Util.error(:error, "Outbound request failed", error_data)
+ Rails.logger.info "Response parsed found: #{result.inspect}"
+ ServiceResult.success(result:)
+ in { status: 405 }
+ log_response(response)
+ Util.error(:not_allowed, "Outbound request method not allowed", error_data)
+ in { status: 401 }
+ log_response(response)
+ Util.error(:unauthorized, "Outbound request not authorized", error_data)
+ in { status: 404 }
+ log_response(response)
+ Util.error(:not_found, "Outbound request destination not found", error_data)
+ else
+ Util.error(:error, "Outbound request failed", error_data)
+ end
end
end
-
# rubocop:enable Metrics/AbcSize
+
+ def log_response(response)
+ Rails.logger.info "Storage responded with a #{response.status} code."
+ end
end
end
end
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rb
index b22d01c36b0..4dfa1910af7 100644
--- a/modules/storages/app/models/storages/storage.rb
+++ b/modules/storages/app/models/storages/storage.rb
@@ -54,6 +54,7 @@ module Storages
store_attribute :provider_fields, :automatically_managed, :boolean
store_attribute :provider_fields, :health_notifications_enabled, :boolean, default: true
+ store_attribute :provider_fields, :detailed_logging_enabled, :boolean, default: false
has_many :file_links, class_name: "Storages::FileLink"
belongs_to :creator, class_name: "User"
@@ -118,11 +119,7 @@ module Storages
def health_notifications_should_be_sent?
# it is a fallback for already created storages without health_notifications_enabled configured.
- if health_notifications_enabled.nil?
- automatic_management_enabled?
- else
- health_notifications_enabled
- end
+ (health_notifications_enabled.nil? && automatic_management_enabled?) || health_notifications_enabled?
end
def automatically_managed?
diff --git a/modules/storages/app/models/storages/storage_error.rb b/modules/storages/app/models/storages/storage_error.rb
index dd8cdefe63d..4ea1bf57c9e 100644
--- a/modules/storages/app/models/storages/storage_error.rb
+++ b/modules/storages/app/models/storages/storage_error.rb
@@ -40,9 +40,10 @@ module Storages
@data = data
end
- def to_active_model_errors
- errors = ActiveModel::Errors.new(self)
- errors.add(:storage_error, code, message: log_message)
+ def to_active_model_errors(klass = self)
+ errors = ActiveModel::Errors.new(klass)
+ attr = data.source.to_s.demodulize.underscore.to_sym
+ errors.add(attr, code)
errors
end
@@ -53,9 +54,9 @@ module Storages
output
end
- def storage_error = "storage error"
-
- def read_attribute_for_validation(attr) = send(attr)
+ def read_attribute_for_validation(attr)
+ attr.to_s
+ end
def self.human_attribute_name(attr, _options = {}) = attr
diff --git a/modules/storages/app/services/storages/nextcloud_group_folder_properties_sync_service.rb b/modules/storages/app/services/storages/nextcloud_group_folder_properties_sync_service.rb
index e99bbd56c8c..f8654d38c9b 100644
--- a/modules/storages/app/services/storages/nextcloud_group_folder_properties_sync_service.rb
+++ b/modules/storages/app/services/storages/nextcloud_group_folder_properties_sync_service.rb
@@ -32,45 +32,67 @@ module Storages
class NextcloudGroupFolderPropertiesSyncService
using Peripherals::ServiceResultRefinements
- PERMISSIONS_MAP = {
- read_files: 1,
- write_files: 2,
- create_files: 4,
- delete_files: 8,
- share_files: 16
- }.freeze
+ extend ActiveModel::Naming
+ extend ActiveModel::Translation
+
+ PERMISSIONS_MAP = { read_files: 1, write_files: 2, create_files: 4, delete_files: 8, share_files: 16 }.freeze
PERMISSIONS_KEYS = PERMISSIONS_MAP.keys.freeze
ALL_PERMISSIONS = PERMISSIONS_MAP.values.sum
NO_PERMISSIONS = 0
+ include Injector["nextcloud.commands.create_folder", "nextcloud.commands.rename_file", "nextcloud.commands.set_permissions",
+ "nextcloud.queries.group_users", "nextcloud.queries.file_ids", "nextcloud.authentication.userless",
+ "nextcloud.commands.add_user_to_group", "nextcloud.commands.remove_user_from_group"]
+
+ def self.i18n_scope = "services"
+
def self.call(storage)
new(storage).call
end
- def initialize(storage)
+ def read_attribute_for_validation(attr) = attr
+
+ def initialize(storage, **)
+ super(**)
@storage = storage
+ @result = ServiceResult.success(errors: ActiveModel::Errors.new(self))
end
def call
- prepare_remote_folders.on_failure { |service_result| return service_result }
- apply_permissions_to_folders
+ with_logging do
+ log_message "Starting AMPF Sync for Nextcloud Storage #{@storage.id}"
+ prepare_remote_folders.on_failure { return _1 }
+ apply_permissions_to_folders
+ end
end
private
- # rubocop:disable Metrics/AbcSize
+ # @param attribute [Symbol] attribute to which the error will be tied to
+ # @param storage_error [Storages::StorageError] an StorageError instance
+ # @param options [Hash<Symbol, Object>] optional extra parameters for the message generation
+ # @return [ServiceResult]
+ def add_error(attribute, storage_error, options: {})
+ if storage_error == :error
+ @result.errors.add(:base, storage_error, **options)
+ else
+ @result.errors.add(attribute, storage_error, **options)
+ end
+ @result
+ end
+
+ # @return [ServiceResult]
def prepare_remote_folders
remote_folders = remote_root_folder_properties.result_or do |error|
format_and_log_error(error, { folder: @storage.group_folder })
-
- return ServiceResult.failure(errors: error)
+ return add_error(:remote_folder_properties, error.code, options: { group: @storage.group }).fail!
end
- ensure_root_folder_permissions.on_failure do |service_result|
- format_and_log_error(service_result.errors, { folder: @storage.group_folder })
-
- return service_result
+ ensure_root_folder_permissions.result_or do |error|
+ format_and_log_error(error, { folder: @storage.group_folder })
+ return add_error(:ensure_root_folder_permissions, error.code,
+ options: { group: @storage.group, username: @storage.username }).fail!
end
ensure_folders_exist(remote_folders).on_success { hide_inactive_folders(remote_folders) }
@@ -95,31 +117,26 @@ module Storages
local_users = client_tokens_scope.order(:id).pluck(:origin_user_id)
- (remote_users - local_users - [@storage.username]).each do |user|
- remove_user_from_remote_group(user).error_and do |error|
+ remove_users_from_remote_group(remote_users - local_users - [@storage.username])
+ add_users_to_remote_group(local_users - remote_users - [@storage.username])
+ end
+
+ def add_users_to_remote_group(users_to_add)
+ users_to_add.each do |user|
+ add_user_to_group.call(storage: @storage, user:).error_and do |error|
format_and_log_error(error, group: @storage.group, user:)
end
end
+ end
- (local_users - remote_users - [@storage.username]).each do |user|
- add_user_to_remote_group(user).error_and do |error|
+ def remove_users_from_remote_group(users_to_remove)
+ users_to_remove.each do |user|
+ remove_user_from_group.call(storage: @storage, user:).error_and do |error|
format_and_log_error(error, group: @storage.group, user:)
end
end
end
- def add_user_to_remote_group(user)
- Peripherals::Registry
- .resolve("nextcloud.commands.add_user_to_group")
- .call(storage: @storage, user:)
- end
-
- def remove_user_from_remote_group(user)
- Peripherals::Registry
- .resolve("nextcloud.commands.remove_user_from_group")
- .call(storage: @storage, user:)
- end
-
def set_folders_permissions(remote_admins, project_storage)
admin_permissions = remote_admins.to_set.map do |username|
[username, ALL_PERMISSIONS]
@@ -139,10 +156,7 @@ module Storages
}
}
- Peripherals::Registry
- .resolve("nextcloud.commands.set_permissions")
- .call(storage: @storage, **command_params)
- .result_or do |error|
+ set_permissions.call(storage: @storage, **command_params).result_or do |error|
format_and_log_error(error, folder: project_storage.managed_project_folder_path)
end
end
@@ -158,10 +172,12 @@ module Storages
end
def hide_inactive_folders(remote_folders)
+ log_message "Hiding folders related to inactive projects"
project_folder_ids = active_project_storages_scope.pluck(:project_folder_id).compact
remote_folders.except("/#{@storage.group_folder}/").each do |(path, attrs)|
next if project_folder_ids.include?(attrs["fileid"])
+ log_message "Hiding project folder #{path}"
command_params = {
path:,
permissions: {
@@ -170,31 +186,33 @@ module Storages
}
}
- Peripherals::Registry
- .resolve("nextcloud.commands.set_permissions")
- .call(storage: @storage, **command_params)
- .on_failure do |service_result|
+ set_permissions.call(storage: @storage, **command_params).on_failure do |service_result|
format_and_log_error(service_result.errors, folder: path, context: "hide_folder")
+ add_error(:hide_inactive_folders, service_result.errors, options: { folder: path })
end
end
end
def ensure_folders_exist(remote_folders)
+ log_message "Ensuring project folders exist and are correctly named."
id_folder_map = remote_folders.to_h { |folder, properties| [properties["fileid"], folder] }
active_project_storages_scope.includes(:project).map do |project_storage|
- next create_folder(project_storage) unless id_folder_map.key?(project_storage.project_folder_id)
+ unless id_folder_map.key?(project_storage.project_folder_id)
+ log_message "#{project_storage.managed_project_folder_path} does not exist. Creating..."
+ next create_folder_stuff(project_storage)
+ end
current_path = id_folder_map[project_storage.project_folder_id]
if current_path != project_storage.managed_project_folder_path
+ log_message "#{current_path} is misnamed. Renaming to #{project_storage.managed_project_folder_path}"
target_folder_name = name_from_path(project_storage.managed_project_folder_path)
rename_folder(project_storage.project_folder_id, target_folder_name).on_failure do |service_result|
format_and_log_error(service_result.errors,
folder_id: project_storage.project_folder_id,
folder_name: target_folder_name)
- # we need to stop as this would mess with the other processes
- return service_result
+ return add_error(:rename_folder, service_result.errors).fail!
end
end
end
@@ -208,31 +226,29 @@ module Storages
end
def rename_folder(folder_id, folder_name)
- Peripherals::Registry
- .resolve("nextcloud.commands.rename_file")
- .call(storage: @storage, auth_strategy:, file_id: folder_id, name: folder_name)
+ rename_file.call(storage: @storage, auth_strategy:, file_id: folder_id, name: folder_name)
end
- def create_folder(project_storage)
+ def create_folder_stuff(project_storage)
folder_name = project_storage.managed_project_folder_path
parent_location = Peripherals::ParentFolder.new("/")
- created_folder = Peripherals::Registry
- .resolve("nextcloud.commands.create_folder")
- .call(storage: @storage, auth_strategy:, folder_name:, parent_location:)
- .result_or do |error|
- format_and_log_error(error, folder: folder_name)
+ created_folder = create_folder.call(storage: @storage, auth_strategy:, folder_name:, parent_location:)
+ .result_or do |error|
+ format_and_log_error(error, folder_name:)
- return ServiceResult.failure(errors: error)
+ return add_error(:create_folder, error, options: { folder_name:, parent_location: })
end
project_folder_id = created_folder.id
- last_project_folder = ::Storages::LastProjectFolder
- .find_by(
- project_storage_id: project_storage.id,
- mode: project_storage.project_folder_mode
- )
+ last_project_folder = LastProjectFolder
+ .find_by(project_storage_id: project_storage.id, mode: project_storage.project_folder_mode)
+ audit_last_project_folder(last_project_folder, project_folder_id)
+ project_storage.project_folder_id
+ end
+
+ def audit_last_project_folder(last_project_folder, project_folder_id)
ApplicationRecord.transaction do
last_project_folder.update!(origin_folder_id: project_folder_id)
project_storage.update!(project_folder_id:)
@@ -240,9 +256,8 @@ module Storages
end
end
- # rubocop:enable Metrics/AbcSize
-
def ensure_root_folder_permissions
+ log_message "Setting base permissions for user #{@storage.username} on the #{@storage.group_folder} folder"
command_params = {
path: @storage.group_folder,
permissions: {
@@ -251,24 +266,39 @@ module Storages
}
}
- Peripherals::Registry
- .resolve("nextcloud.commands.set_permissions")
- .call(storage: @storage, **command_params)
+ set_permissions.call(storage: @storage, **command_params)
end
### Base Queries/Commands
def remote_root_folder_properties
- Peripherals::Registry
- .resolve("nextcloud.queries.file_ids")
- .call(storage: @storage, path: @storage.group_folder)
+ log_message "Retrieving already existing folders under #{@storage.group_folder}"
+ file_ids.call(storage: @storage, path: @storage.group_folder)
end
def remote_group_users
- Peripherals::Registry
- .resolve("nextcloud.queries.group_users")
- .call(storage: @storage, group: @storage.group)
+ group_users.call(storage: @storage, group: @storage.group)
+ end
+
+ ### Model Scopes
+
+ def active_project_storages_scope
+ @storage.project_storages.active.automatic
+ end
+
+ def client_tokens_scope
+ OAuthClientToken.where(oauth_client: @storage.oauth_client)
+ end
+
+ def auth_strategy
+ @auth_strategy ||= userless.call
+ end
+
+ def admin_client_tokens_scope
+ OAuthClientToken.where(oauth_client: @storage.oauth_client, user: User.admin.active)
end
+ # Logging
+
def format_and_log_error(error, context = {})
payload = error.data.payload
data =
@@ -280,25 +310,19 @@ module Storages
end
error_message = context.merge({ command: error.data.source, message: error.log_message, data: })
- OpenProject.logger.warn error_message
+ logger.error error_message
end
- ### Model Scopes
-
- def active_project_storages_scope
- @storage.project_storages.active.automatic
+ def log_message(message)
+ logger.debug(message)
end
- def client_tokens_scope
- OAuthClientToken.where(oauth_client: @storage.oauth_client)
- end
-
- def auth_strategy
- Peripherals::Registry.resolve("nextcloud.authentication.userless").call
+ def with_logging(&)
+ logger.tagged(self.class, "storage-#{@storage.id}", &)
end
- def admin_client_tokens_scope
- OAuthClientToken.where(oauth_client: @storage.oauth_client, user: User.admin.active)
+ def logger
+ Rails.logger
end
end
end
diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.yml
index d8b69719a66..18500700dd8 100644
--- a/modules/storages/config/locales/en.yml
+++ b/modules/storages/config/locales/en.yml
@@ -1,5 +1,15 @@
---
en:
+ services:
+ errors:
+ models:
+ storages/nextcloud_group_folder_properties_sync_service:
+ unauthorized: "Please check if your AMPF password is correct"
+ error: "An unexpected error occurred. Please ensure that you Nextcloud instance is reachable and check OpenProject worker logs for more information"
+ attributes:
+ remote_folder_properties:
+ not_found: "The Group Folder %{group} wasn't found. Please check your Nextcloud setup."
+
activerecord:
attributes:
storages/file_link:
diff --git a/modules/storages/spec/services/storages/nextcloud_group_folder_properties_sync_service_spec.rb b/modules/storages/spec/services/storages/nextcloud_group_folder_properties_sync_service_spec.rb
index 7066d0f1249..efeb5a13824 100644
--- a/modules/storages/spec/services/storages/nextcloud_group_folder_properties_sync_service_spec.rb
+++ b/modules/storages/spec/services/storages/nextcloud_group_folder_properties_sync_service_spec.rb
@@ -632,6 +632,8 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
let(:oauth_client) { storage.oauth_client }
# rubocop:enable RSpec/IndexedLet
+ let(:prefix) { "services.errors.models.storages/nextcloud_group_folder_properties_sync_service" }
+
describe "#call" do
before do
create(:oauth_client_token, origin_user_id: "Obi-Wan", user: multiple_projects_user, oauth_client:)
@@ -684,11 +686,11 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
end
it "logs an error message" do
- allow(OpenProject.logger).to receive(:warn)
+ allow(Rails.logger).to receive(:error)
described_class.new(storage).call
- expect(OpenProject.logger)
- .to have_received(:warn)
+ expect(Rails.logger)
+ .to have_received(:error)
.with(folder: "OpenProject",
command: Storages::Peripherals::StorageInteraction::Nextcloud::Internal::PropfindQueryLegacy,
message: "Outbound request destination not found",
@@ -697,7 +699,10 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
it "returns a failure" do
result = described_class.new(storage).call
+
expect(result).to be_failure
+ expect(result.errors[:remote_folder_properties])
+ .to contain_exactly(I18n.t("#{prefix}.attributes.remote_folder_properties.not_found", group: storage.group))
end
end
@@ -746,16 +751,24 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
end
it "logs an error message" do
- allow(OpenProject.logger).to receive(:warn)
+ allow(Rails.logger).to receive(:error)
described_class.new(storage).call
- expect(OpenProject.logger)
- .to have_received(:warn)
+ expect(Rails.logger)
+ .to have_received(:error)
.with(folder: "OpenProject",
command: Storages::Peripherals::StorageInteraction::Nextcloud::SetPermissionsCommand,
message: "Outbound request not authorized",
data: { status: 401, body: "Heute nicht" })
end
+
+ it "returns a failure" do
+ result = described_class.new(storage).call
+
+ expect(result).to be_failure
+ expect(result.errors[:ensure_root_folder_permissions])
+ .to contain_exactly(I18n.t("#{prefix}.unauthorized"))
+ end
end
end
@@ -784,12 +797,12 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
end
it "logs the occurrence" do
- allow(OpenProject.logger).to receive(:warn)
+ allow(Rails.logger).to receive(:error)
described_class.new(storage).call
- expect(OpenProject.logger)
- .to have_received(:warn)
- .with(folder: "/OpenProject/[Sample] Project Name | Ehuu (#{project1.id})/",
+ expect(Rails.logger)
+ .to have_received(:error)
+ .with(folder_name: "/OpenProject/[Sample] Project Name | Ehuu (#{project1.id})/",
command: Storages::Peripherals::StorageInteraction::Nextcloud::CreateFolderCommand,
message: "Outbound request destination not found!",
data: "not found")
@@ -814,11 +827,11 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
end
it "logs the occurrence" do
- allow(OpenProject.logger).to receive(:warn)
+ allow(Rails.logger).to receive(:error)
described_class.new(storage).call
- expect(OpenProject.logger)
- .to have_received(:warn)
+ expect(Rails.logger)
+ .to have_received(:error)
.with(folder_id: project_storage2.project_folder_id,
folder_name: "Jedi Project Folder ||| (#{project2.id})",
command: Storages::Peripherals::StorageInteraction::Nextcloud::RenameFileCommand,
@@ -846,11 +859,11 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
end
it "logs the occurrence" do
- allow(OpenProject.logger).to receive(:warn)
+ allow(Rails.logger).to receive(:error)
described_class.new(storage).call
- expect(OpenProject.logger)
- .to have_received(:warn)
+ expect(Rails.logger)
+ .to have_received(:error)
.with(context: "hide_folder",
folder: "/OpenProject/Lost Jedi Project Folder #2/",
command: Storages::Peripherals::StorageInteraction::Nextcloud::SetPermissionsCommand,
@@ -878,11 +891,11 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
end
it "logs the occurrence" do
- allow(OpenProject.logger).to receive(:warn)
+ allow(Rails.logger).to receive(:error)
described_class.new(storage).call
- expect(OpenProject.logger)
- .to have_received(:warn)
+ expect(Rails.logger)
+ .to have_received(:error)
.with(folder: "/OpenProject/Jedi Project Folder ||| (#{project2.id})/",
command: Storages::Peripherals::StorageInteraction::Nextcloud::SetPermissionsCommand,
message: "Outbound request failed",
@@ -909,11 +922,11 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
end
it "logs the occurrence" do
- allow(OpenProject.logger).to receive(:warn)
+ allow(Rails.logger).to receive(:error)
described_class.new(storage).call
- expect(OpenProject.logger)
- .to have_received(:warn)
+ expect(Rails.logger)
+ .to have_received(:error)
.with(group: "OpenProject",
user: "Obi-Wan",
command: Storages::Peripherals::StorageInteraction::Nextcloud::AddUserToGroupCommand,
@@ -944,11 +957,11 @@ RSpec.describe Storages::NextcloudGroupFolderPropertiesSyncService, :webmock do
end
it "logs the occurrence and continues the flow" do
- allow(OpenProject.logger).to receive(:warn)
+ allow(Rails.logger).to receive(:error)
described_class.new(storage).call
- expect(OpenProject.logger)
- .to have_received(:warn)
+ expect(Rails.logger)
+ .to have_received(:error)
.with(group: "OpenProject",
user: "Darth Maul",
command: Storages::Peripherals::StorageInteraction::Nextcloud::RemoveUserFromGroupCommand,