feat: introduce user management events

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-07 22:32:45 -04:00
parent 985e4a6450
commit f147ffc5c7
11 changed files with 457 additions and 19 deletions
+7 -5
View File
@@ -4,7 +4,8 @@ declare(strict_types=1);
namespace KTXC\Console\User;
use KTXC\Service\TenantService;
use KTXC\Context\TenantContext;
use KTXC\Service\UserAccountsService;
use KTXC\Stores\UserAccountsStore;
use KTXC\Stores\UserRolesStore;
use Psr\Log\LoggerInterface;
@@ -28,8 +29,9 @@ use Symfony\Component\Console\Style\SymfonyStyle;
class UserCreateCommand extends Command
{
public function __construct(
private readonly TenantService $tenantService,
private readonly TenantContext $tenantContext,
private readonly UserAccountsStore $userStore,
private readonly UserAccountsService $userService,
private readonly UserRolesStore $rolesStore,
private readonly LoggerInterface $logger
) {
@@ -59,11 +61,11 @@ class UserCreateCommand extends Command
$io->title('Create User');
try {
// Ensure the tenant exists
if (!$this->tenantService->fetchById($tenant)) {
if (!$this->tenantContext->resolveIdentifier($tenant)) {
$io->error("Tenant '{$tenant}' not found.");
return Command::FAILURE;
}
$tenant = $this->tenantContext->requireIdentifier();
// Ensure identity is unique within the tenant
if ($this->userStore->fetchByIdentity($tenant, $identity)) {
@@ -95,7 +97,7 @@ class UserCreateCommand extends Command
$userData['uid'] = $input->getOption('uid');
}
$user = $this->userStore->createUser($tenant, $userData);
$user = $this->userService->createUser($userData);
$this->logger->info('User created via console', [
'tenant' => $tenant,
+11 -1
View File
@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace KTXC\Console\User;
use KTXC\Context\TenantContext;
use KTXC\Service\UserAccountsService;
use KTXC\Stores\UserAccountsStore;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
@@ -26,7 +28,9 @@ use Symfony\Component\Console\Style\SymfonyStyle;
class UserDeleteCommand extends Command
{
public function __construct(
private readonly TenantContext $tenantContext,
private readonly UserAccountsStore $userStore,
private readonly UserAccountsService $userService,
private readonly LoggerInterface $logger
) {
parent::__construct();
@@ -52,6 +56,12 @@ class UserDeleteCommand extends Command
$io->title('Delete User');
try {
if (!$this->tenantContext->resolveIdentifier($tenant)) {
$io->error("Tenant '{$tenant}' not found.");
return Command::FAILURE;
}
$tenant = $this->tenantContext->requireIdentifier();
$user = $this->userStore->fetchByIdentity($tenant, $identity);
if (!$user) {
@@ -64,7 +74,7 @@ class UserDeleteCommand extends Command
return Command::SUCCESS;
}
if (!$this->userStore->deleteUser($tenant, $user['uid'])) {
if (!$this->userService->deleteUser($user['uid'])) {
$io->error("Failed to delete user '{$identity}'.");
return Command::FAILURE;
}