diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-26 03:08:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-26 03:08:57 +0300 |
commit | b8fcf7c3d6c3b48e59e6aae5b1a6b536bba8ac40 (patch) | |
tree | 947b357adb3c1b51f2fb7ec761a7d9a35c260e28 /app/services | |
parent | 5edc7a04de12237658e7149385661aede45d681c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/groups/transfer_service.rb | 32 | ||||
-rw-r--r-- | app/services/projects/transfer_service.rb | 34 |
2 files changed, 66 insertions, 0 deletions
diff --git a/app/services/groups/transfer_service.rb b/app/services/groups/transfer_service.rb index 81d4dfddaab..64256e43ce3 100644 --- a/app/services/groups/transfer_service.rb +++ b/app/services/groups/transfer_service.rb @@ -11,19 +11,51 @@ module Groups @error = nil end + def log_group_transfer_success(group, new_parent_group) + log_transfer(group, new_parent_group, nil) + end + + def log_group_transfer_error(group, new_parent_group, error_message) + log_transfer(group, new_parent_group, error_message) + end + def execute(new_parent_group) @new_parent_group = new_parent_group ensure_allowed_transfer proceed_to_transfer + log_group_transfer_success(@group, @new_parent_group) + rescue TransferError, ActiveRecord::RecordInvalid, Gitlab::UpdatePathError => e @group.errors.clear @error = s_("TransferGroup|Transfer failed: %{error_message}") % { error_message: e.message } + + log_group_transfer_error(@group, @new_parent_group, e.message) + false end private + def log_transfer(group, new_namespace, error_message = nil) + action = error_message.nil? ? "was" : "was not" + + log_payload = { + message: "Group #{action} transferred to a new namespace", + group_path: group.full_path, + group_id: group.id, + new_parent_group_path: new_parent_group&.full_path, + new_parent_group_id: new_parent_group&.id, + error_message: error_message + } + + if error_message.nil? + ::Gitlab::AppLogger.info(log_payload) + else + ::Gitlab::AppLogger.error(log_payload) + end + end + def proceed_to_transfer old_root_ancestor_id = @group.root_ancestor.id was_root_group = @group.root? diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 1bae7bde168..642ec37619f 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -13,6 +13,14 @@ module Projects include Gitlab::ShellAdapter TransferError = Class.new(StandardError) + def log_project_transfer_success(project, new_namespace) + log_transfer(project, new_namespace, nil) + end + + def log_project_transfer_error(project, new_namespace, error_message) + log_transfer(project, new_namespace, error_message) + end + def execute(new_namespace) @new_namespace = new_namespace @@ -36,10 +44,15 @@ module Projects transfer(project) + log_project_transfer_success(project, @new_namespace) + true rescue Projects::TransferService::TransferError => ex project.reset project.errors.add(:new_namespace, ex.message) + + log_project_transfer_error(project, @new_namespace, ex.message) + false end @@ -47,6 +60,27 @@ module Projects attr_reader :old_path, :new_path, :new_namespace, :old_namespace + def log_transfer(project, new_namespace, error_message = nil) + action = error_message.nil? ? "was" : "was not" + + log_payload = { + message: "Project #{action} transferred to a new namespace", + project_id: project.id, + project_path: project.full_path, + project_namespace: project.namespace.full_path, + namespace_id: project.namespace_id, + new_namespace_id: new_namespace&.id, + new_project_namespace: new_namespace&.full_path, + error_message: error_message + } + + if error_message.nil? + ::Gitlab::AppLogger.info(log_payload) + else + ::Gitlab::AppLogger.error(log_payload) + end + end + # rubocop: disable CodeReuse/ActiveRecord def transfer(project) @old_path = project.full_path |