## Summary
Implements Spec 145 for tenant action taxonomy and lifecycle-safe visibility.
This PR:
- adds a central tenant action policy surface and supporting value objects
- aligns tenant list, detail, edit, onboarding, and widget surfaces around lifecycle-safe actions
- standardizes operator-facing lifecycle wording around View, Resume onboarding, Archive, Restore, and Complete onboarding
- tightens onboarding and tenant lifecycle authorization semantics, including honest 404 vs 403 behavior
- updates related regression coverage and spec artifacts for Spec 145
- fixes follow-on full-suite regressions uncovered during validation, including onboarding browser flows, provider consent fixtures, workspace redirect DI expectations, and critical table/action/UI expectation drift
## Validation
Executed and passed:
- vendor/bin/sail bin pint --dirty --format agent
- vendor/bin/sail artisan test --compact
Result:
- 2581 passed
- 8 skipped
- 13534 assertions
## Notes
- Base branch: dev
- Feature branch commit: a33a41b
- Filament v5 / Livewire v4 compliance preserved
- No panel provider registration changes; Laravel 12 provider registration remains in bootstrap/providers.php
- No new globally searchable resource behavior added in this slice
- Destructive lifecycle actions remain confirmation-gated and authorization-protected
Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #174
132 lines
2.9 KiB
PHP
132 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\Tenants;
|
|
|
|
use App\Models\Tenant;
|
|
use BackedEnum;
|
|
use Stringable;
|
|
|
|
enum TenantLifecycle: string
|
|
{
|
|
case Draft = 'draft';
|
|
case Onboarding = 'onboarding';
|
|
case Active = 'active';
|
|
case Archived = 'archived';
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
public static function values(): array
|
|
{
|
|
return array_map(
|
|
static fn (self $lifecycle): string => $lifecycle->value,
|
|
self::cases(),
|
|
);
|
|
}
|
|
|
|
public static function fromTenant(Tenant $tenant): self
|
|
{
|
|
if ($tenant->trashed()) {
|
|
return self::Archived;
|
|
}
|
|
|
|
return self::fromValue($tenant->status);
|
|
}
|
|
|
|
public static function fromValue(mixed $value, self $default = self::Active): self
|
|
{
|
|
return self::tryFromValue($value) ?? $default;
|
|
}
|
|
|
|
public static function tryFromValue(mixed $value): ?self
|
|
{
|
|
$normalized = self::normalize($value);
|
|
|
|
return $normalized === null ? null : self::tryFrom($normalized);
|
|
}
|
|
|
|
public static function normalize(mixed $value): ?string
|
|
{
|
|
if ($value === null) {
|
|
return null;
|
|
}
|
|
|
|
if ($value instanceof BackedEnum) {
|
|
$value = $value->value;
|
|
}
|
|
|
|
if ($value instanceof Stringable) {
|
|
$value = (string) $value;
|
|
}
|
|
|
|
if (! is_string($value)) {
|
|
return null;
|
|
}
|
|
|
|
$normalized = strtolower(trim($value));
|
|
$normalized = str_replace([' ', '-'], '_', $normalized);
|
|
|
|
return match ($normalized) {
|
|
'pending' => self::Onboarding->value,
|
|
default => $normalized !== '' ? $normalized : null,
|
|
};
|
|
}
|
|
|
|
public function label(): string
|
|
{
|
|
return match ($this) {
|
|
self::Draft => 'Draft',
|
|
self::Onboarding => 'Onboarding',
|
|
self::Active => 'Active',
|
|
self::Archived => 'Archived',
|
|
};
|
|
}
|
|
|
|
public function canSelectAsContext(): bool
|
|
{
|
|
return $this === self::Active;
|
|
}
|
|
|
|
public function canViewTenantSurface(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function canOperate(): bool
|
|
{
|
|
return $this === self::Active;
|
|
}
|
|
|
|
public function canArchive(): bool
|
|
{
|
|
return $this === self::Active;
|
|
}
|
|
|
|
public function canRestore(): bool
|
|
{
|
|
return $this === self::Archived;
|
|
}
|
|
|
|
public function canResumeOnboarding(): bool
|
|
{
|
|
return in_array($this, [self::Draft, self::Onboarding], true);
|
|
}
|
|
|
|
public function canReferenceInWorkspaceMonitoring(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function allowsManagementAction(string $actionKey): bool
|
|
{
|
|
return match ($actionKey) {
|
|
'resume_onboarding' => $this->canResumeOnboarding(),
|
|
'archive' => $this->canArchive(),
|
|
'restore' => $this->canRestore(),
|
|
default => false,
|
|
};
|
|
}
|
|
}
|