aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/User/PartiallyDeletedUsersBackend.php
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-09-11 19:33:53 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2024-09-26 20:48:45 +0200
commitd57a2dd465abe2db11575bc592c89b910694a063 (patch)
tree369f991505e25c5042034dd81c5ad4a3760b27bc /lib/private/User/PartiallyDeletedUsersBackend.php
parent16833aff863290e4b298a2e69015d97cd230be47 (diff)
downloadnextcloud-server-d57a2dd465abe2db11575bc592c89b910694a063.tar.gz
nextcloud-server-d57a2dd465abe2db11575bc592c89b910694a063.zip
fix: Skip users that still exist in backendfix/resiliant-user-removal
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'lib/private/User/PartiallyDeletedUsersBackend.php')
-rw-r--r--lib/private/User/PartiallyDeletedUsersBackend.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/private/User/PartiallyDeletedUsersBackend.php b/lib/private/User/PartiallyDeletedUsersBackend.php
new file mode 100644
index 00000000000..298ddaff6c6
--- /dev/null
+++ b/lib/private/User/PartiallyDeletedUsersBackend.php
@@ -0,0 +1,56 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OC\User;
+
+use OCP\IConfig;
+use OCP\IUserBackend;
+use OCP\User\Backend\IGetHomeBackend;
+
+/**
+ * This is a "fake" backend for users that were deleted,
+ * but not properly removed from Nextcloud (e.g. an exception occurred).
+ * This backend is only needed because some APIs in user-deleted-events require a "real" user with backend.
+ */
+class PartiallyDeletedUsersBackend extends Backend implements IGetHomeBackend, IUserBackend {
+
+ public function __construct(
+ private IConfig $config,
+ ) {
+ }
+
+ public function deleteUser($uid): bool {
+ // fake true, deleting failed users is automatically handled by User::delete()
+ return true;
+ }
+
+ public function getBackendName(): string {
+ return 'deleted users';
+ }
+
+ public function userExists($uid) {
+ return $this->config->getUserValue($uid, 'core', 'deleted') === 'true';
+ }
+
+ public function getHome(string $uid): string|false {
+ return $this->config->getUserValue($uid, 'core', 'deleted.home-path') ?: false;
+ }
+
+ public function getUsers($search = '', $limit = null, $offset = null) {
+ return $this->config->getUsersForUserValue('core', 'deleted', 'true');
+ }
+
+ /**
+ * Unmark a user as deleted.
+ * This typically the case if the user deletion failed in the backend but before the backend deleted the user,
+ * meaning the user still exists so we unmark them as it still can be accessed (and deleted) normally.
+ */
+ public function unmarkUser(string $userId): void {
+ $this->config->deleteUserValue($userId, 'core', 'deleted');
+ $this->config->deleteUserValue($userId, 'core', 'deleted.home-path');
+ }
+
+}