From 02f5877f46c2a2709d8d77fe4fd77a0dfc0f469c Mon Sep 17 00:00:00 2001 From: bidi Date: Tue, 10 Dec 2024 16:03:10 +0200 Subject: [PATCH 1/6] updated user deleted status Signed-off-by: bidi --- .../migrations/Version20241120160406.php | 2 +- .../src/Middleware/RememberMeMiddleware.php | 2 +- src/User/src/Controller/AccountController.php | 13 ++++--- src/User/src/Entity/User.php | 21 +--------- src/User/src/Entity/UserInterface.php | 2 - src/User/src/Enum/UserStatusEnum.php | 1 + src/User/src/Form/ProfileDeleteForm.php | 2 +- src/User/src/Repository/UserRepository.php | 17 +++++++-- src/User/src/Service/UserService.php | 38 +++++++++++-------- src/User/src/Service/UserServiceInterface.php | 2 + .../Middleware/RememberMeMiddlewareTest.php | 2 - 11 files changed, 52 insertions(+), 50 deletions(-) diff --git a/data/doctrine/migrations/Version20241120160406.php b/data/doctrine/migrations/Version20241120160406.php index 89697f69..9ed9fbb7 100644 --- a/data/doctrine/migrations/Version20241120160406.php +++ b/data/doctrine/migrations/Version20241120160406.php @@ -21,7 +21,7 @@ public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs $this->addSql('CREATE TABLE contact_message (uuid BINARY(16) NOT NULL, email VARCHAR(150) NOT NULL, name VARCHAR(150) NOT NULL, subject LONGTEXT NOT NULL, message LONGTEXT NOT NULL, platform LONGTEXT NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); - $this->addSql('CREATE TABLE user (uuid BINARY(16) NOT NULL, identity VARCHAR(191) NOT NULL, password VARCHAR(191) NOT NULL, status ENUM(\'active\', \'pending\') DEFAULT \'pending\' NOT NULL, isDeleted TINYINT(1) NOT NULL, hash VARCHAR(64) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_8D93D6496A95E9C4 (identity), UNIQUE INDEX UNIQ_8D93D649D1B862B8 (hash), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); + $this->addSql('CREATE TABLE user (uuid BINARY(16) NOT NULL, identity VARCHAR(191) NOT NULL, password VARCHAR(191) NOT NULL, status ENUM(\'active\', \'pending\', \'deleted\') DEFAULT \'pending\' NOT NULL, hash VARCHAR(64) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_8D93D6496A95E9C4 (identity), UNIQUE INDEX UNIQ_8D93D649D1B862B8 (hash), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE user_roles (userUuid BINARY(16) NOT NULL, roleUuid BINARY(16) NOT NULL, INDEX IDX_54FCD59FD73087E9 (userUuid), INDEX IDX_54FCD59F88446210 (roleUuid), PRIMARY KEY(userUuid, roleUuid)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE user_avatar (uuid BINARY(16) NOT NULL, name VARCHAR(191) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, userUuid BINARY(16) NOT NULL, UNIQUE INDEX UNIQ_73256912D73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); $this->addSql('CREATE TABLE user_detail (uuid BINARY(16) NOT NULL, firstName VARCHAR(191) DEFAULT NULL, lastName VARCHAR(191) DEFAULT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, userUuid BINARY(16) NOT NULL, UNIQUE INDEX UNIQ_4B5464AED73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4'); diff --git a/src/App/src/Middleware/RememberMeMiddleware.php b/src/App/src/Middleware/RememberMeMiddleware.php index e8148e03..80699b3e 100644 --- a/src/App/src/Middleware/RememberMeMiddleware.php +++ b/src/App/src/Middleware/RememberMeMiddleware.php @@ -46,7 +46,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $hash === $rememberUser->getRememberMeToken() && $rememberUser->getUserAgent() === $deviceType && $rememberUser->getExpireDate() > new DateTimeImmutable('now') && - $user->getIsDeleted() === false + $user->isDeleted() === false ) { $userIdentity = UserIdentity::fromEntity($user); $this->authenticationService->getStorage()->write($userIdentity); diff --git a/src/User/src/Controller/AccountController.php b/src/User/src/Controller/AccountController.php index 3bf88ee4..d8d4896f 100644 --- a/src/User/src/Controller/AccountController.php +++ b/src/User/src/Controller/AccountController.php @@ -66,6 +66,11 @@ public function activateAction(): ResponseInterface return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); } + if ($user->isDeleted()) { + $this->messenger->addError(Message::ACCOUNT_NOT_FOUND, 'user-login'); + return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); + } + if ($user->isActive()) { $this->messenger->addError(Message::USER_ALREADY_ACTIVATED, 'user-login'); return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); @@ -96,7 +101,7 @@ public function unregisterAction(): ResponseInterface return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); } - if ($user->getIsDeleted() === User::IS_DELETED_YES) { + if ($user->isDeleted()) { $this->messenger->addError(Message::USER_ALREADY_DEACTIVATED, 'user-login'); return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); } @@ -107,7 +112,7 @@ public function unregisterAction(): ResponseInterface } try { - $this->userService->updateUser($user, ['isDeleted' => User::IS_DELETED_YES]); + $this->userService->deleteUser($user); } catch (Exception $exception) { $this->messenger->addError($exception->getMessage(), 'user-login'); return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); @@ -423,10 +428,8 @@ public function deleteAccountAction(): ResponseInterface if (RequestMethodInterface::METHOD_POST === $this->request->getMethod()) { $form->setData($this->request->getParsedBody()); if ($form->isValid()) { - /** @var array $userData */ - $userData = $form->getData(); try { - $this->userService->updateUser($user, $userData); + $this->userService->deleteUser($user); $this->userService->deleteAvatar($user); } catch (Exception $e) { $this->messenger->addData('shouldRebind', true); diff --git a/src/User/src/Entity/User.php b/src/User/src/Entity/User.php index 4457895e..cd04414f 100644 --- a/src/User/src/Entity/User.php +++ b/src/User/src/Entity/User.php @@ -45,9 +45,6 @@ class User extends AbstractEntity implements UserInterface #[ORM\Column(type: 'user_status_enum', options: ['default' => UserStatusEnum::Pending])] protected UserStatusEnum $status = UserStatusEnum::Pending; - #[ORM\Column(name: 'isDeleted', type: 'boolean')] - protected bool $isDeleted = self::IS_DELETED_NO; - #[ORM\Column(name: 'hash', type: 'string', length: 64, unique: true, nullable: false)] protected string $hash; @@ -138,18 +135,6 @@ public function setStatus(UserStatusEnum $status): self return $this; } - public function getIsDeleted(): bool - { - return $this->isDeleted; - } - - public function setIsDeleted(bool $isDeleted): self - { - $this->isDeleted = $isDeleted; - - return $this; - } - public function getHash(): string { return $this->hash; @@ -213,11 +198,9 @@ public function isPending(): bool return $this->status === UserStatusEnum::Pending; } - public function markAsDeleted(): self + public function isDeleted(): bool { - $this->isDeleted = self::IS_DELETED_YES; - - return $this; + return $this->status === UserStatusEnum::Deleted; } public function getName(): string diff --git a/src/User/src/Entity/UserInterface.php b/src/User/src/Entity/UserInterface.php index 892a2914..3e93b875 100644 --- a/src/User/src/Entity/UserInterface.php +++ b/src/User/src/Entity/UserInterface.php @@ -38,8 +38,6 @@ public function addRole(UserRole $role): UserInterface; public function removeRole(UserRole $role): UserInterface; - public function getIsDeleted(): bool; - public function getArrayCopy(): array; public function activate(): UserInterface; diff --git a/src/User/src/Enum/UserStatusEnum.php b/src/User/src/Enum/UserStatusEnum.php index 9953d498..c9ccb486 100644 --- a/src/User/src/Enum/UserStatusEnum.php +++ b/src/User/src/Enum/UserStatusEnum.php @@ -8,4 +8,5 @@ enum UserStatusEnum: string { case Active = 'active'; case Pending = 'pending'; + case Deleted = 'deleted'; } diff --git a/src/User/src/Form/ProfileDeleteForm.php b/src/User/src/Form/ProfileDeleteForm.php index a6dbb0f3..0f3f150e 100644 --- a/src/User/src/Form/ProfileDeleteForm.php +++ b/src/User/src/Form/ProfileDeleteForm.php @@ -44,7 +44,7 @@ public function init(): void 'title' => 'Delete account', ], 'options' => [ - 'label' => 'I want to delete account', + 'label' => 'I want to delete my account', 'use_hidden_element' => false, 'checked_value' => (string) User::IS_DELETED_YES, 'unchecked_value' => (string) User::IS_DELETED_NO, diff --git a/src/User/src/Repository/UserRepository.php b/src/User/src/Repository/UserRepository.php index 697e3b43..0c06d75c 100644 --- a/src/User/src/Repository/UserRepository.php +++ b/src/User/src/Repository/UserRepository.php @@ -11,6 +11,7 @@ use Exception; use Frontend\User\Entity\User; use Frontend\User\Entity\UserRememberMe; +use Frontend\User\Enum\UserStatusEnum; use Ramsey\Uuid\Uuid; use function is_string; @@ -36,6 +37,9 @@ public function findByUuid(string $uuid): ?User ->where("user.uuid = :uuid") ->setParameter('uuid', $uuid) ->setMaxResults(1); + + //ignore deleted users + $qb->andWhere('user.status != :status')->setParameter('status', UserStatusEnum::Deleted); return $qb->getQuery()->useQueryCache(true)->getOneOrNullResult(); } @@ -72,7 +76,10 @@ public function findByResetPasswordHash(string $hash): ?User $qb = $this->getEntityManager()->createQueryBuilder(); $qb->select(['user', 'resetPasswords'])->from(User::class, 'user') ->leftJoin('user.resetPasswords', 'resetPasswords') - ->andWhere('resetPasswords.hash = :hash')->setParameter('hash', $hash); + ->andWhere('resetPasswords.hash = :hash') + ->setParameter('hash', $hash) + ->andWhere('user.status != :deleted') + ->setParameter('deleted', UserStatusEnum::Deleted); return $qb->getQuery()->useQueryCache(true)->getSingleResult(); } catch (Exception) { @@ -95,7 +102,9 @@ public function getRememberUser(string $token): ?UserRememberMe $qb->select('user_remember_me') ->from(UserRememberMe::class, 'user_remember_me') ->where('user_remember_me.rememberMeToken = :token') - ->setParameter('token', $token); + ->setParameter('token', $token) + ->andWhere('user.status != :deleted') + ->setParameter('deleted', UserStatusEnum::Deleted); return $qb->getQuery()->useQueryCache(true)->getOneOrNullResult(); } @@ -111,7 +120,9 @@ public function findRememberMeUser(User $user, string $userAgent): ?UserRemember ->where('user_remember_me.user = :uuid') ->setParameter('uuid', $user->getUuid()->getBytes()) ->andWhere('user_remember_me.userAgent = :userAgent') - ->setParameter('userAgent', $userAgent); + ->setParameter('userAgent', $userAgent) + ->andWhere('user.status != :deleted') + ->setParameter('deleted', UserStatusEnum::Deleted); return $qb->getQuery()->useQueryCache(true)->getOneOrNullResult(); } diff --git a/src/User/src/Service/UserService.php b/src/User/src/Service/UserService.php index 43ef421e..ec9c0c3e 100644 --- a/src/User/src/Service/UserService.php +++ b/src/User/src/Service/UserService.php @@ -138,22 +138,6 @@ public function updateUser(User $user, array $data = []): User $user->setStatus($data['status']); } - if (isset($data['isDeleted'])) { - $user->setIsDeleted((bool) $data['isDeleted']); - - if ((bool) $data['isDeleted'] === true) { - // make user anonymous - $user->setIdentity( - sprintf('anonymous%s@%s', date('dmYHis'), $this->config['userAnonymizeAppend']) - ); - $userDetails = $user->getDetail(); - $userDetails->setFirstName('anonymous' . date('dmYHis')); - $userDetails->setLastName('anonymous' . date('dmYHis')); - - $user->setDetail($userDetails); - } - } - if (isset($data['hash'])) { $user->setHash($data['hash']); } @@ -189,6 +173,28 @@ public function updateUser(User $user, array $data = []): User return $this->userRepository->saveUser($user); } + public function deleteUser(User $user): User + { + $user->setStatus(UserStatusEnum::Deleted); + + if ($user->isDeleted()) { + $placeholder = $this->getAnonymousPlaceholder(); + + // make user anonymous + $user + ->setIdentity($placeholder . $this->config['userAnonymizeAppend']) + ->getDetail() + ->setFirstName($placeholder) + ->setLastName($placeholder); + } + return $this->userRepository->saveUser($user); + } + + private function getAnonymousPlaceholder(): string + { + return 'anonymous' . date('dmYHis'); + } + protected function createAvatar(User $user, UploadedFile $uploadedFile): UserAvatar { $path = sprintf('%s/%s/', $this->config['uploads']['user']['path'], $user->getUuid()->toString()); diff --git a/src/User/src/Service/UserServiceInterface.php b/src/User/src/Service/UserServiceInterface.php index 4eaf646d..324ff8c3 100644 --- a/src/User/src/Service/UserServiceInterface.php +++ b/src/User/src/Service/UserServiceInterface.php @@ -34,6 +34,8 @@ public function deleteExpiredRememberMeTokens(): void; public function updateUser(User $user, array $data = []): UserInterface; + public function deleteUser(User $user): UserInterface; + public function deleteAvatar(User $user): void; public function deleteAvatarFile(string $path): bool; diff --git a/test/Unit/App/Middleware/RememberMeMiddlewareTest.php b/test/Unit/App/Middleware/RememberMeMiddlewareTest.php index 97c0975c..f0ccac7f 100644 --- a/test/Unit/App/Middleware/RememberMeMiddlewareTest.php +++ b/test/Unit/App/Middleware/RememberMeMiddlewareTest.php @@ -68,7 +68,6 @@ public function testAutologin(): void $user = (new User()) ->setIdentity('test@dotkernel.com') - ->setIsDeleted(false) ->activate(); $detail = (new UserDetail()) @@ -126,7 +125,6 @@ public function testAutologinExpired(): void $user = (new User()) ->setIdentity('test@dotkernel.com') - ->setIsDeleted(false) ->activate(); $detail = (new UserDetail()) From 2856b8721911425768eeb403c4b3988bcda41043 Mon Sep 17 00:00:00 2001 From: bidi Date: Tue, 10 Dec 2024 17:10:32 +0200 Subject: [PATCH 2/6] updated config Signed-off-by: bidi --- config/autoload/authentication.global.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/autoload/authentication.global.php b/config/autoload/authentication.global.php index e637f772..e89305ec 100644 --- a/config/autoload/authentication.global.php +++ b/config/autoload/authentication.global.php @@ -24,10 +24,6 @@ 'value' => UserStatusEnum::Active, 'message' => Message::USER_NOT_ACTIVATED, ], - 'isDeleted' => [ - 'value' => false, - 'message' => Message::ACCOUNT_NOT_FOUND, - ], ], ], ], From a987e0329ea21cfa666fcfac1531ce31ede9494d Mon Sep 17 00:00:00 2001 From: bidi Date: Tue, 10 Dec 2024 17:13:37 +0200 Subject: [PATCH 3/6] phpcs fix Signed-off-by: bidi --- config/autoload/authentication.global.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/autoload/authentication.global.php b/config/autoload/authentication.global.php index e89305ec..494ee9d9 100644 --- a/config/autoload/authentication.global.php +++ b/config/autoload/authentication.global.php @@ -20,7 +20,7 @@ 'invalid_credential' => Message::INVALID_CREDENTIALS, ], 'options' => [ - 'status' => [ + 'status' => [ 'value' => UserStatusEnum::Active, 'message' => Message::USER_NOT_ACTIVATED, ], From d332f7109557a9af032c74c3cce48a991b121dc1 Mon Sep 17 00:00:00 2001 From: bidi Date: Wed, 11 Dec 2024 15:32:18 +0200 Subject: [PATCH 4/6] updated user filters for status deleted Signed-off-by: bidi --- src/User/src/Controller/AccountController.php | 10 ------- src/User/src/Service/UserService.php | 26 ++++++++++--------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/User/src/Controller/AccountController.php b/src/User/src/Controller/AccountController.php index d8d4896f..8c68e8ea 100644 --- a/src/User/src/Controller/AccountController.php +++ b/src/User/src/Controller/AccountController.php @@ -66,11 +66,6 @@ public function activateAction(): ResponseInterface return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); } - if ($user->isDeleted()) { - $this->messenger->addError(Message::ACCOUNT_NOT_FOUND, 'user-login'); - return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); - } - if ($user->isActive()) { $this->messenger->addError(Message::USER_ALREADY_ACTIVATED, 'user-login'); return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); @@ -101,11 +96,6 @@ public function unregisterAction(): ResponseInterface return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); } - if ($user->isDeleted()) { - $this->messenger->addError(Message::USER_ALREADY_DEACTIVATED, 'user-login'); - return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); - } - if (! $user->isPending()) { $this->messenger->addError(Message::USER_UNREGISTER_STATUS, 'user-login'); return new RedirectResponse($this->router->generateUri('user', ['action' => 'login'])); diff --git a/src/User/src/Service/UserService.php b/src/User/src/Service/UserService.php index ec9c0c3e..e7b64442 100644 --- a/src/User/src/Service/UserService.php +++ b/src/User/src/Service/UserService.php @@ -176,17 +176,14 @@ public function updateUser(User $user, array $data = []): User public function deleteUser(User $user): User { $user->setStatus(UserStatusEnum::Deleted); - - if ($user->isDeleted()) { - $placeholder = $this->getAnonymousPlaceholder(); - - // make user anonymous - $user - ->setIdentity($placeholder . $this->config['userAnonymizeAppend']) - ->getDetail() - ->setFirstName($placeholder) - ->setLastName($placeholder); - } + $placeholder = $this->getAnonymousPlaceholder(); + + // make user anonymous + $user + ->setIdentity($placeholder . $this->config['userAnonymizeAppend']) + ->getDetail() + ->setFirstName($placeholder) + ->setLastName($placeholder); return $this->userRepository->saveUser($user); } @@ -288,7 +285,12 @@ public function findOneBy(array $params = []): ?User return null; } - return $this->userRepository->findOneBy($params); + $user = $this->userRepository->findOneBy($params); + if ($user->isDeleted()) { + return null; + } + + return $user; } public function activateUser(User $user): User From 1b9d2a4926915731c041d7e46a0d9857412ad6f4 Mon Sep 17 00:00:00 2001 From: bidi Date: Wed, 11 Dec 2024 18:01:55 +0200 Subject: [PATCH 5/6] updated find user, authentication Signed-off-by: bidi --- .../src/Adapter/AuthenticationAdapter.php | 11 ++++++++++ src/User/src/Service/UserService.php | 21 ++++++++++++++++--- .../Adapter/AuthenticationAdapterTest.php | 3 +++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/User/src/Adapter/AuthenticationAdapter.php b/src/User/src/Adapter/AuthenticationAdapter.php index 26de6d52..9b2c6808 100644 --- a/src/User/src/Adapter/AuthenticationAdapter.php +++ b/src/User/src/Adapter/AuthenticationAdapter.php @@ -5,6 +5,7 @@ namespace Frontend\User\Adapter; use Doctrine\ORM\EntityRepository; +use Frontend\App\Common\Message; use Frontend\User\Entity\UserIdentity; use Frontend\User\Exception\AuthenticationAdapterException; use Laminas\Authentication\Adapter\AbstractAdapter; @@ -39,6 +40,16 @@ public function authenticate(): Result ); } + $methodName = 'isDeleted'; + $this->checkMethod($identityClass, $methodName); + if ($identityClass->$methodName()) { + return new Result( + Result::FAILURE_IDENTITY_NOT_FOUND, + null, + [Message::ACCOUNT_NOT_FOUND] + ); + } + $getCredential = 'get' . ucfirst($this->config['credential_property']); $this->checkMethod($identityClass, $getCredential); diff --git a/src/User/src/Service/UserService.php b/src/User/src/Service/UserService.php index e7b64442..8fdf2c99 100644 --- a/src/User/src/Service/UserService.php +++ b/src/User/src/Service/UserService.php @@ -26,6 +26,7 @@ use Laminas\Diactoros\UploadedFile; use Mezzio\Template\TemplateRendererInterface; use Ramsey\Uuid\Uuid; +use Symfony\Component\Mailer\Exception\TransportExceptionInterface; use function date; use function file_exists; @@ -74,7 +75,13 @@ public function __construct( */ public function findByUuid(string $uuid): ?User { - return $this->userRepository->findByUuid($uuid); + $user = $this->userRepository->findByUuid($uuid); + + if (! $user instanceof User || $user->isDeleted()) { + return null; + } + + return $user; } /** @@ -286,7 +293,8 @@ public function findOneBy(array $params = []): ?User } $user = $this->userRepository->findOneBy($params); - if ($user->isDeleted()) { + + if (! $user instanceof User || $user->isDeleted()) { return null; } @@ -323,11 +331,18 @@ public function findByResetPasswordHash(?string $hash): ?User return null; } - return $this->userRepository->findByResetPasswordHash($hash); + $user = $this->userRepository->findByResetPasswordHash($hash); + + if (! $user instanceof User || $user->isDeleted()) { + return null; + } + + return $user; } /** * @throws MailException + * @throws TransportExceptionInterface */ public function sendResetPasswordCompletedMail(User $user): bool { diff --git a/test/Unit/User/Adapter/AuthenticationAdapterTest.php b/test/Unit/User/Adapter/AuthenticationAdapterTest.php index 7411ddd3..c1436103 100644 --- a/test/Unit/User/Adapter/AuthenticationAdapterTest.php +++ b/test/Unit/User/Adapter/AuthenticationAdapterTest.php @@ -182,6 +182,9 @@ public function testCheckMethodThrowsException(): void $this->expectExceptionMessage( (AuthenticationAdapterException::methodNotExists('getPassword', $class::class))->getMessage() ); + $this->expectExceptionMessage( + (AuthenticationAdapterException::methodNotExists('isDeleted', $class::class))->getMessage() + ); $adapter = new AuthenticationAdapter($repository, $this->getConfig($class)); From ec0ad08ec38f7739d22c2525b01bbaade58b4996 Mon Sep 17 00:00:00 2001 From: bidi Date: Mon, 16 Dec 2024 12:11:28 +0200 Subject: [PATCH 6/6] refactoring Signed-off-by: bidi --- src/User/src/Service/UserService.php | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/User/src/Service/UserService.php b/src/User/src/Service/UserService.php index 8fdf2c99..2ecb41f2 100644 --- a/src/User/src/Service/UserService.php +++ b/src/User/src/Service/UserService.php @@ -75,13 +75,7 @@ public function __construct( */ public function findByUuid(string $uuid): ?User { - $user = $this->userRepository->findByUuid($uuid); - - if (! $user instanceof User || $user->isDeleted()) { - return null; - } - - return $user; + return $this->userRepository->findByUuid($uuid); } /** @@ -182,11 +176,11 @@ public function updateUser(User $user, array $data = []): User public function deleteUser(User $user): User { - $user->setStatus(UserStatusEnum::Deleted); $placeholder = $this->getAnonymousPlaceholder(); // make user anonymous $user + ->setStatus(UserStatusEnum::Deleted) ->setIdentity($placeholder . $this->config['userAnonymizeAppend']) ->getDetail() ->setFirstName($placeholder) @@ -331,13 +325,7 @@ public function findByResetPasswordHash(?string $hash): ?User return null; } - $user = $this->userRepository->findByResetPasswordHash($hash); - - if (! $user instanceof User || $user->isDeleted()) { - return null; - } - - return $user; + return $this->userRepository->findByResetPasswordHash($hash); } /**