Skip to content

Commit 4e1ff1f

Browse files
committed
resolved comments
Signed-off-by: bidi <[email protected]>
1 parent 0852816 commit 4e1ff1f

File tree

6 files changed

+11
-4
lines changed

6 files changed

+11
-4
lines changed

data/doctrine/migrations/Version20241030082958.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function up(Schema $schema): void
3030
$this->addSql('CREATE TABLE oauth_clients (id INT UNSIGNED AUTO_INCREMENT NOT NULL, name VARCHAR(40) NOT NULL, secret VARCHAR(100) DEFAULT NULL, redirect VARCHAR(191) NOT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, isConfidential TINYINT(1) DEFAULT 0 NOT NULL, user_id BINARY(16) DEFAULT NULL, INDEX IDX_13CE8101A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4');
3131
$this->addSql('CREATE TABLE oauth_refresh_tokens (id INT UNSIGNED AUTO_INCREMENT NOT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, expires_at DATETIME NOT NULL, access_token_id INT UNSIGNED DEFAULT NULL, INDEX IDX_5AB6872CCB2688 (access_token_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4');
3232
$this->addSql('CREATE TABLE oauth_scopes (id INT UNSIGNED AUTO_INCREMENT NOT NULL, scope VARCHAR(191) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4');
33-
$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, 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');
33+
$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');
3434
$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');
3535
$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) DEFAULT NULL, UNIQUE INDEX UNIQ_73256912D73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4');
3636
$this->addSql('CREATE TABLE user_detail (uuid BINARY(16) NOT NULL, firstName VARCHAR(191) DEFAULT NULL, lastName VARCHAR(191) DEFAULT NULL, email VARCHAR(191) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, userUuid BINARY(16) DEFAULT NULL, UNIQUE INDEX UNIQ_4B5464AED73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4');

src/App/src/Middleware/AuthorizationMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6161
break;
6262
case 'frontend':
6363
$user = $this->userRepository->findOneBy(['identity' => $defaultUser->getIdentity()]);
64-
if (! $user instanceof User || $user->getStatus() === UserStatusEnum::Deleted) {
64+
if (! $user instanceof User || $user->isDeleted()) {
6565
return $this->unauthorizedResponse(sprintf(
6666
Message::USER_NOT_FOUND_BY_IDENTITY,
6767
$defaultUser->getIdentity()

src/User/src/Entity/User.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ public function isPending(): bool
258258
return $this->status === UserStatusEnum::Pending;
259259
}
260260

261+
public function isDeleted(): bool
262+
{
263+
return $this->status === UserStatusEnum::Deleted;
264+
}
265+
261266
public function renewHash(): self
262267
{
263268
$this->hash = self::generateHash();

src/User/src/Repository/UserRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public function getUsers(array $filters = []): UserCollection
5050

5151
if (! empty($filters['status'])) {
5252
$qb->andWhere('user.status = :status')->setParameter('status', $filters['status']);
53+
} else {
54+
$qb->andWhere('user.status != :status')->setParameter('status', UserStatusEnum::Deleted);
5355
}
5456

5557
if (! empty($filters['search'])) {

test/Functional/AdminTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public function testAdminCanDeleteUserAccount(): void
461461
$userRepository = $this->getEntityManager()->getRepository(User::class);
462462
$user = $userRepository->find($user->getUuid()->toString());
463463

464-
$this->assertTrue($user?->getStatus() === UserStatusEnum::Deleted);
464+
$this->assertTrue($user?->isDeleted());
465465
}
466466

467467
/**

test/Functional/UserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public function testDeleteMyAccount(): void
296296

297297
$userRepository = $this->getEntityManager()->getRepository(User::class);
298298
$deletedUser = $userRepository->find($user->getUuid()->toString());
299-
$this->assertTrue($deletedUser?->getStatus() === UserStatusEnum::Deleted);
299+
$this->assertTrue($deletedUser?->isDeleted());
300300
}
301301

302302
public function testRequestResetPasswordInvalidHash(): void

0 commit comments

Comments
 (0)