Skip to content

Commit 298cd8f

Browse files
committed
updated user status, removed isDeleted
Signed-off-by: bidi <bidi@apidemia.com>
1 parent 6f5dae0 commit 298cd8f

File tree

12 files changed

+12
-52
lines changed

12 files changed

+12
-52
lines changed

data/doctrine/fixtures/UserLoader.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function load(ObjectManager $manager): void
3434
->setIdentity('test@dotkernel.com')
3535
->usePassword('dotkernel')
3636
->setStatus(UserStatusEnum::Active)
37-
->setIsDeleted(false)
3837
->setHash(User::generateHash())
3938
->addRole($guestRole)
4039
->addRole($userRole);

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, 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');
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');
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Api\App\Message;
1212
use Api\App\UserIdentity;
1313
use Api\User\Entity\User;
14+
use Api\User\Enum\UserStatusEnum;
1415
use Api\User\Repository\UserRepository;
1516
use Dot\DependencyInjection\Attribute\Inject;
1617
use Fig\Http\Message\StatusCodeInterface;
@@ -60,7 +61,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6061
break;
6162
case 'frontend':
6263
$user = $this->userRepository->findOneBy(['identity' => $defaultUser->getIdentity()]);
63-
if (! $user instanceof User || $user->isDeleted()) {
64+
if (! $user instanceof User || $user->getStatus() === UserStatusEnum::Deleted) {
6465
return $this->unauthorizedResponse(sprintf(
6566
Message::USER_NOT_FOUND_BY_IDENTITY,
6667
$defaultUser->getIdentity()

src/User/src/Entity/User.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ class User extends AbstractEntity implements UserEntityInterface
5151
#[ORM\Column(type: 'user_status_enum', options: ['default' => UserStatusEnum::Pending])]
5252
protected UserStatusEnum $status = UserStatusEnum::Pending;
5353

54-
#[ORM\Column(name: "isDeleted", type: "boolean")]
55-
protected bool $isDeleted = false;
56-
5754
#[ORM\Column(name: "hash", type: "string", length: 64, unique: true)]
5855
protected string $hash;
5956

@@ -103,18 +100,6 @@ public function setStatus(UserStatusEnum $status): self
103100
return $this;
104101
}
105102

106-
public function isDeleted(): bool
107-
{
108-
return $this->isDeleted;
109-
}
110-
111-
public function setIsDeleted(bool $isDeleted): self
112-
{
113-
$this->isDeleted = $isDeleted;
114-
115-
return $this;
116-
}
117-
118103
public function getHash(): string
119104
{
120105
return $this->hash;
@@ -273,13 +258,6 @@ public function isPending(): bool
273258
return $this->status === UserStatusEnum::Pending;
274259
}
275260

276-
public function markAsDeleted(): self
277-
{
278-
$this->isDeleted = true;
279-
280-
return $this;
281-
}
282-
283261
public function renewHash(): self
284262
{
285263
$this->hash = self::generateHash();
@@ -311,7 +289,6 @@ public function getArrayCopy(): array
311289
'hash' => $this->getHash(),
312290
'identity' => $this->getIdentity(),
313291
'status' => $this->getStatus(),
314-
'isDeleted' => $this->isDeleted(),
315292
'avatar' => $this->getAvatar()?->getArrayCopy(),
316293
'detail' => $this->getDetail()->getArrayCopy(),
317294
'roles' => $this->getRoles()->map(function (UserRole $userRole) {

src/User/src/Enum/UserStatusEnum.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ enum UserStatusEnum: string
88
{
99
case Active = 'active';
1010
case Pending = 'pending';
11+
case Deleted = 'deleted';
1112
}

src/User/src/OpenAPI.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,6 @@
10671067
new OA\Property(property: 'hash', type: 'string'),
10681068
new OA\Property(property: 'identity', type: 'string'),
10691069
new OA\Property(property: 'status', type: 'string', example: UserStatusEnum::Active),
1070-
new OA\Property(property: 'isDeleted', type: 'boolean', example: false),
10711070
new OA\Property(property: 'avatar', ref: '#/components/schemas/UserAvatar', nullable: true),
10721071
new OA\Property(property: 'detail', ref: '#/components/schemas/UserDetail'),
10731072
new OA\Property(

src/User/src/Repository/UserRepository.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,6 @@ public function getUsers(array $filters = []): UserCollection
5252
$qb->andWhere('user.status = :status')->setParameter('status', $filters['status']);
5353
}
5454

55-
if (isset($filters['deleted'])) {
56-
switch ($filters['deleted']) {
57-
case 'true':
58-
$qb->andWhere('user.isDeleted = :isDeleted')->setParameter('isDeleted', true);
59-
break;
60-
case 'false':
61-
$qb->andWhere('user.isDeleted = :isDeleted')->setParameter('isDeleted', false);
62-
break;
63-
}
64-
}
65-
6655
if (! empty($filters['search'])) {
6756
$qb->andWhere(
6857
$qb->expr()->orX(
@@ -115,8 +104,9 @@ public function getUserEntityByUserCredentials(
115104
$qb->select(['u.password', 'u.status'])
116105
->from(User::class, 'u')
117106
->andWhere('u.identity = :identity')
118-
->andWhere('u.isDeleted = 0')
119-
->setParameter('identity', $username);
107+
->andWhere('u.status != :status')
108+
->setParameter('identity', $username)
109+
->setParameter('status', UserStatusEnum::Deleted);
120110
break;
121111
default:
122112
throw new OAuthServerException(Message::INVALID_CLIENT_ID, 6, 'invalid_client', 401);

src/User/src/Service/UserService.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function deleteUser(User $user): User
115115
{
116116
$this->revokeTokens($user);
117117

118-
return $this->anonymizeUser($user->markAsDeleted());
118+
return $this->anonymizeUser($user->setStatus(UserStatusEnum::Deleted));
119119
}
120120

121121
/**
@@ -370,10 +370,6 @@ public function updateUser(User $user, array $data = []): User
370370
$user->setStatus($data['status']);
371371
}
372372

373-
if (isset($data['isDeleted'])) {
374-
$user->setIsDeleted($data['isDeleted']);
375-
}
376-
377373
if (isset($data['hash'])) {
378374
$user->setHash($data['hash']);
379375
}

test/Functional/AdminTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,13 @@ public function testAdminCanCreateUserAccount(): void
401401
$this->assertArrayHasKey('hash', $data);
402402
$this->assertArrayHasKey('identity', $data);
403403
$this->assertArrayHasKey('status', $data);
404-
$this->assertArrayHasKey('isDeleted', $data);
405404
$this->assertArrayHasKey('avatar', $data);
406405
$this->assertArrayHasKey('detail', $data);
407406
$this->assertArrayHasKey('roles', $data);
408407
$this->assertNotEmpty($data['uuid']);
409408
$this->assertNotEmpty($data['hash']);
410409
$this->assertSame($userData['identity'], $data['identity']);
411410
$this->assertSame(UserStatusEnum::Pending->value, $data['status']);
412-
$this->assertFalse($data['isDeleted']);
413411
$this->assertEmpty($data['avatar']);
414412
$this->assertEmpty($data['resetPasswords']);
415413
$this->assertArrayHasKey('firstName', $data['detail']);
@@ -463,7 +461,7 @@ public function testAdminCanDeleteUserAccount(): void
463461
$userRepository = $this->getEntityManager()->getRepository(User::class);
464462
$user = $userRepository->find($user->getUuid()->toString());
465463

466-
$this->assertTrue($user?->isDeleted());
464+
$this->assertTrue($user?->getStatus() === UserStatusEnum::Deleted);
467465
}
468466

469467
/**

test/Functional/UserTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public function testRegisterAccount(): void
108108

109109
$this->assertSame($user['identity'], $data['identity']);
110110
$this->assertSame(UserStatusEnum::Pending->value, $data['status']);
111-
$this->assertFalse($data['isDeleted']);
112111
$this->assertArrayHasKey('detail', $data);
113112
$this->assertArrayHasKey('email', $data['detail']);
114113
$this->assertArrayHasKey('firstName', $data['detail']);
@@ -297,7 +296,7 @@ public function testDeleteMyAccount(): void
297296

298297
$userRepository = $this->getEntityManager()->getRepository(User::class);
299298
$deletedUser = $userRepository->find($user->getUuid()->toString());
300-
$this->assertTrue($deletedUser?->isDeleted());
299+
$this->assertTrue($deletedUser?->getStatus() === UserStatusEnum::Deleted);
301300
}
302301

303302
public function testRequestResetPasswordInvalidHash(): void

0 commit comments

Comments
 (0)