feat(core) : add CoreModule, user repository contract, notifier contract and enriched user contract
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Core;
|
||||||
|
|
||||||
|
use App\Shared\Domain\Module\ModuleInterface;
|
||||||
|
|
||||||
|
final class CoreModule implements ModuleInterface
|
||||||
|
{
|
||||||
|
public static function id(): string
|
||||||
|
{
|
||||||
|
return 'core';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function label(): string
|
||||||
|
{
|
||||||
|
return 'Core';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isRequired(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permissions posées pour le RBAC fin (1.2). Inertes tant que 1.2 n'est pas livré.
|
||||||
|
*
|
||||||
|
* @return list<array{code: string, label: string}>
|
||||||
|
*/
|
||||||
|
public static function permissions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['code' => 'core.user.read', 'label' => 'Consulter les utilisateurs'],
|
||||||
|
['code' => 'core.user.manage', 'label' => 'Gérer les utilisateurs'],
|
||||||
|
['code' => 'core.notification.read', 'label' => 'Consulter ses notifications'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Module\Core\Domain\Repository;
|
||||||
|
|
||||||
|
use App\Shared\Domain\Contract\UserInterface;
|
||||||
|
use DateTimeInterface;
|
||||||
|
|
||||||
|
interface UserRepositoryInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return list<UserInterface>
|
||||||
|
*/
|
||||||
|
public function findByRole(string $role): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<UserInterface>
|
||||||
|
*/
|
||||||
|
public function findActiveEmployees(DateTimeInterface $date): array;
|
||||||
|
|
||||||
|
public function findOneByUsername(string $username): ?UserInterface;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Shared\Domain\Contract;
|
||||||
|
|
||||||
|
interface NotifierInterface
|
||||||
|
{
|
||||||
|
public function notify(UserInterface $user, string $type, string $title, string $message): void;
|
||||||
|
}
|
||||||
@@ -4,7 +4,26 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Shared\Domain\Contract;
|
namespace App\Shared\Domain\Contract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrat de LECTURE de l'identité, consommé hors du module Core.
|
||||||
|
* Les écritures (setPassword, setters HR…) restent sur le concret Core\Domain\Entity\User.
|
||||||
|
*/
|
||||||
interface UserInterface
|
interface UserInterface
|
||||||
{
|
{
|
||||||
public function getId(): ?int;
|
public function getId(): ?int;
|
||||||
|
|
||||||
|
public function getUserIdentifier(): string;
|
||||||
|
|
||||||
|
public function getUsername(): ?string;
|
||||||
|
|
||||||
|
/** @return list<string> */
|
||||||
|
public function getRoles(): array;
|
||||||
|
|
||||||
|
public function getFirstName(): ?string;
|
||||||
|
|
||||||
|
public function getLastName(): ?string;
|
||||||
|
|
||||||
|
public function getAvatarUrl(): ?string;
|
||||||
|
|
||||||
|
public function getIsEmployee(): bool;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Unit\Module\Core;
|
||||||
|
|
||||||
|
use App\Module\Core\CoreModule;
|
||||||
|
use App\Shared\Domain\Module\ModuleInterface;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class CoreModuleTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testItIsAModule(): void
|
||||||
|
{
|
||||||
|
self::assertInstanceOf(ModuleInterface::class, new CoreModule());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIdentity(): void
|
||||||
|
{
|
||||||
|
self::assertSame('core', CoreModule::id());
|
||||||
|
self::assertTrue(CoreModule::isRequired());
|
||||||
|
self::assertNotSame('', CoreModule::label());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPermissionsAreWellFormed(): void
|
||||||
|
{
|
||||||
|
foreach (CoreModule::permissions() as $permission) {
|
||||||
|
self::assertArrayHasKey('code', $permission);
|
||||||
|
self::assertArrayHasKey('label', $permission);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -79,6 +79,42 @@ final class TimestampableBlamableSubscriberTest extends TestCase
|
|||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUserIdentifier(): string
|
||||||
|
{
|
||||||
|
return 'user-'.$this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUsername(): ?string
|
||||||
|
{
|
||||||
|
return 'user-'.$this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<string> */
|
||||||
|
public function getRoles(): array
|
||||||
|
{
|
||||||
|
return ['ROLE_USER'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFirstName(): ?string
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLastName(): ?string
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAvatarUrl(): ?string
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIsEmployee(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user