PartiallyDeletedUsersBackend.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\User;
  7. use OCP\IConfig;
  8. use OCP\IUserBackend;
  9. use OCP\User\Backend\IGetHomeBackend;
  10. /**
  11. * This is a "fake" backend for users that were deleted,
  12. * but not properly removed from Nextcloud (e.g. an exception occurred).
  13. * This backend is only needed because some APIs in user-deleted-events require a "real" user with backend.
  14. */
  15. class PartiallyDeletedUsersBackend extends Backend implements IGetHomeBackend, IUserBackend {
  16. public function __construct(
  17. private IConfig $config,
  18. ) {
  19. }
  20. public function deleteUser($uid): bool {
  21. // fake true, deleting failed users is automatically handled by User::delete()
  22. return true;
  23. }
  24. public function getBackendName(): string {
  25. return 'deleted users';
  26. }
  27. public function userExists($uid) {
  28. return $this->config->getUserValue($uid, 'core', 'deleted') === 'true';
  29. }
  30. public function getHome(string $uid): string|false {
  31. return $this->config->getUserValue($uid, 'core', 'deleted.home-path') ?: false;
  32. }
  33. public function getUsers($search = '', $limit = null, $offset = null) {
  34. return $this->config->getUsersForUserValue('core', 'deleted', 'true');
  35. }
  36. /**
  37. * Unmark a user as deleted.
  38. * This typically the case if the user deletion failed in the backend but before the backend deleted the user,
  39. * meaning the user still exists so we unmark them as it still can be accessed (and deleted) normally.
  40. */
  41. public function unmarkUser(string $userId): void {
  42. $this->config->deleteUserValue($userId, 'core', 'deleted');
  43. $this->config->deleteUserValue($userId, 'core', 'deleted.home-path');
  44. }
  45. }