feat(modules): harden module platform with event constants, validation checks, and CLI improvements
- Add ModuleEvents constants class with all 8 event strings; update dispatch call sites - ValidateCommand: check AuthorizationPolicy container registration (check 20) - ValidateCommand: warn on unknown event_listeners keys (check 21) - make:module --simple flag for minimal manifests - module:deactivate reverse-dependency warning - 12 new PHPUnit tests covering all improvements Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace MintyPHP\Service\User;
|
||||
|
||||
use MintyPHP\App\Module\ModuleEventDispatcher;
|
||||
use MintyPHP\App\Module\ModuleEvents;
|
||||
use MintyPHP\I18n;
|
||||
use MintyPHP\Repository\Support\DatabaseSessionRepository;
|
||||
use MintyPHP\Repository\User\UserListQueryRepositoryInterface;
|
||||
@@ -118,7 +119,7 @@ class UserAccountService
|
||||
'target_uuid' => (string) ($user['uuid'] ?? ''),
|
||||
]);
|
||||
|
||||
$this->eventDispatcher?->dispatch('user.deleted', [
|
||||
$this->eventDispatcher?->dispatch(ModuleEvents::USER_DELETED, [
|
||||
'user_id' => $userId,
|
||||
'uuid' => (string) ($user['uuid'] ?? ''),
|
||||
'actor_user_id' => $currentUserId,
|
||||
@@ -191,7 +192,7 @@ class UserAccountService
|
||||
]);
|
||||
|
||||
foreach ($deletedUsers as $deletedUser) {
|
||||
$this->eventDispatcher?->dispatch('user.deleted', [
|
||||
$this->eventDispatcher?->dispatch(ModuleEvents::USER_DELETED, [
|
||||
'user_id' => (int) $deletedUser['id'],
|
||||
'uuid' => (string) $deletedUser['uuid'],
|
||||
'actor_user_id' => $currentUserId,
|
||||
@@ -336,7 +337,7 @@ class UserAccountService
|
||||
],
|
||||
]);
|
||||
|
||||
$this->eventDispatcher?->dispatch('user.created', [
|
||||
$this->eventDispatcher?->dispatch(ModuleEvents::USER_CREATED, [
|
||||
'user_id' => $userId,
|
||||
'uuid' => is_string($uuid) ? $uuid : '',
|
||||
'actor_user_id' => $currentUserId,
|
||||
@@ -467,7 +468,7 @@ class UserAccountService
|
||||
$tenantIds = $this->extractTenantIdsFromAssignments(
|
||||
$this->safeAssignmentsForUser($userId)
|
||||
);
|
||||
$eventType = ((int) $form['active'] === 1) ? 'user.activated' : 'user.deactivated';
|
||||
$eventType = ((int) $form['active'] === 1) ? ModuleEvents::USER_ACTIVATED : ModuleEvents::USER_DEACTIVATED;
|
||||
$this->eventDispatcher?->dispatch($eventType, [
|
||||
'user_id' => $userId,
|
||||
'uuid' => (string) ($existing['uuid'] ?? ''),
|
||||
@@ -521,7 +522,7 @@ class UserAccountService
|
||||
$tenantIds = $this->extractTenantIdsFromAssignments(
|
||||
$this->safeAssignmentsForUser($userId)
|
||||
);
|
||||
$this->eventDispatcher?->dispatch($active ? 'user.activated' : 'user.deactivated', [
|
||||
$this->eventDispatcher?->dispatch($active ? ModuleEvents::USER_ACTIVATED : ModuleEvents::USER_DEACTIVATED, [
|
||||
'user_id' => $userId,
|
||||
'uuid' => (string) ($user['uuid'] ?? ''),
|
||||
'display_name' => trim((string) ($user['display_name'] ?? '')),
|
||||
@@ -587,7 +588,7 @@ class UserAccountService
|
||||
$tenantIds = $this->extractTenantIdsFromAssignments(
|
||||
$this->safeAssignmentsForUser($targetUserId)
|
||||
);
|
||||
$this->eventDispatcher?->dispatch($active ? 'user.activated' : 'user.deactivated', [
|
||||
$this->eventDispatcher?->dispatch($active ? ModuleEvents::USER_ACTIVATED : ModuleEvents::USER_DEACTIVATED, [
|
||||
'user_id' => $targetUserId,
|
||||
'uuid' => (string) ($user['uuid'] ?? ''),
|
||||
'display_name' => trim((string) ($user['display_name'] ?? '')),
|
||||
@@ -801,7 +802,7 @@ class UserAccountService
|
||||
return;
|
||||
}
|
||||
|
||||
$this->eventDispatcher?->dispatch('user.assignment_changed', [
|
||||
$this->eventDispatcher?->dispatch(ModuleEvents::USER_ASSIGNMENT_CHANGED, [
|
||||
'user_id' => $userId,
|
||||
'uuid' => (string) ($user['uuid'] ?? ''),
|
||||
'display_name' => trim((string) ($user['display_name'] ?? '')),
|
||||
|
||||
Reference in New Issue
Block a user