## Summary - add explicit workspace closure and tenant removal lifecycle truth with a bounded `WorkspaceLifecycleService` - surface closure and removal posture across admin/system pages, chooser recovery, and canonical historical viewers - block new review-pack and operation starts for closed workspaces or removed tenants while preserving memberships, audit, and history - add focused Pest coverage plus the Spec 292 artifacts for the implemented slice ## Testing - `export PATH="/bin:/usr/bin:/usr/local/bin:$PATH" && cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/System/Directory/ViewWorkspaceClosureTest.php tests/Feature/System/Ops/ClosedWorkspaceHistoricalAccessTest.php tests/Feature/Filament/Resources/Workspaces/WorkspaceClosureStatusTest.php tests/Feature/Filament/Resources/TenantResource/TenantWorkspaceRemovalTest.php tests/Feature/Filament/Pages/WorkspaceContextClosureRecoveryTest.php` - `export PATH="/bin:/usr/bin:/usr/local/bin:$PATH" && cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` - manual integrated-browser smoke for admin tenant remove/restore plus chooser recovery and system workspace close/reopen Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #337
88 lines
3.3 KiB
PHP
88 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\Tenants;
|
|
|
|
use App\Models\ManagedEnvironment;
|
|
|
|
final readonly class ReferencedTenantLifecyclePresentation
|
|
{
|
|
public function __construct(
|
|
public string $viewerContext,
|
|
public ?int $tenantId,
|
|
public ?string $tenantName,
|
|
public TenantLifecyclePresentation $presentation,
|
|
public bool $removedFromWorkspace,
|
|
public bool $workspaceClosed,
|
|
public ?string $contextNote,
|
|
) {}
|
|
|
|
public static function forOperationRun(ManagedEnvironment $tenant): self
|
|
{
|
|
return self::fromTenant($tenant, 'operation_run');
|
|
}
|
|
|
|
public static function fromTenant(ManagedEnvironment $tenant, string $viewerContext): self
|
|
{
|
|
$presentation = TenantLifecyclePresentation::fromTenant($tenant);
|
|
|
|
return new self(
|
|
viewerContext: $viewerContext,
|
|
tenantId: (int) $tenant->getKey(),
|
|
tenantName: $tenant->name,
|
|
presentation: $presentation,
|
|
removedFromWorkspace: $tenant->isRemovedFromWorkspace(),
|
|
workspaceClosed: (bool) $tenant->workspace?->isClosed(),
|
|
contextNote: self::contextNoteFor($presentation, $tenant->isRemovedFromWorkspace(), (bool) $tenant->workspace?->isClosed()),
|
|
);
|
|
}
|
|
|
|
public static function forInvalid(string $viewerContext, ?ManagedEnvironment $tenant = null, ?string $normalizedValue = null): self
|
|
{
|
|
return new self(
|
|
viewerContext: $viewerContext,
|
|
tenantId: $tenant instanceof ManagedEnvironment ? (int) $tenant->getKey() : null,
|
|
tenantName: $tenant?->name,
|
|
presentation: TenantLifecyclePresentation::invalid($normalizedValue),
|
|
removedFromWorkspace: $tenant?->isRemovedFromWorkspace() ?? false,
|
|
workspaceClosed: (bool) $tenant?->workspace?->isClosed(),
|
|
contextNote: 'Some tenant follow-up actions may be unavailable from this canonical workspace view.',
|
|
);
|
|
}
|
|
|
|
public function selectorAvailabilityMessage(): ?string
|
|
{
|
|
if ($this->removedFromWorkspace) {
|
|
return 'This tenant was removed from its workspace and may not appear in the tenant selector.';
|
|
}
|
|
|
|
if ($this->workspaceClosed) {
|
|
return 'This tenant belongs to a closed workspace and may not appear in active tenant context.';
|
|
}
|
|
|
|
if ($this->presentation->isInvalidFallback) {
|
|
return 'This tenant has an invalid lifecycle value and may not appear in the tenant selector.';
|
|
}
|
|
|
|
if (! $this->presentation->isSelectableAsContext()) {
|
|
return 'This tenant is currently '.$this->presentation->lowercaseLabel().' and may not appear in the tenant selector.';
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private static function contextNoteFor(TenantLifecyclePresentation $presentation, bool $removedFromWorkspace, bool $workspaceClosed): ?string
|
|
{
|
|
if ($removedFromWorkspace || $workspaceClosed) {
|
|
return 'Historical operation context remains available, but active tenant follow-up actions are unavailable from this canonical workspace view.';
|
|
}
|
|
|
|
if ($presentation->isInvalidFallback || ! $presentation->isSelectableAsContext()) {
|
|
return 'Some tenant follow-up actions may be unavailable from this canonical workspace view.';
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|