Implements Spec 114 System Console Control Tower pages, widgets, triage actions, directory views, and enterprise polish (badges, repair workspace owners table, health indicator).
96 lines
2.7 KiB
PHP
96 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\System\Pages\Directory;
|
|
|
|
use App\Models\OperationRun;
|
|
use App\Models\PlatformUser;
|
|
use App\Models\ProviderConnection;
|
|
use App\Models\Tenant;
|
|
use App\Models\TenantPermission;
|
|
use App\Support\Auth\PlatformCapabilities;
|
|
use App\Support\OperationCatalog;
|
|
use App\Support\System\SystemDirectoryLinks;
|
|
use App\Support\System\SystemOperationRunLinks;
|
|
use Filament\Pages\Page;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class ViewTenant extends Page
|
|
{
|
|
protected static bool $shouldRegisterNavigation = false;
|
|
|
|
protected static ?string $slug = 'directory/tenants/{tenant}';
|
|
|
|
protected string $view = 'filament.system.pages.directory.view-tenant';
|
|
|
|
public Tenant $tenant;
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
$user = auth('platform')->user();
|
|
|
|
return $user instanceof PlatformUser
|
|
&& $user->hasCapability(PlatformCapabilities::DIRECTORY_VIEW);
|
|
}
|
|
|
|
public function mount(Tenant $tenant): void
|
|
{
|
|
$tenant->load('workspace');
|
|
|
|
$this->tenant = $tenant;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, ProviderConnection>
|
|
*/
|
|
public function providerConnections(): Collection
|
|
{
|
|
return ProviderConnection::query()
|
|
->where('tenant_id', (int) $this->tenant->getKey())
|
|
->orderByDesc('is_default')
|
|
->orderBy('provider')
|
|
->get(['id', 'provider', 'status', 'health_status', 'is_default', 'last_health_check_at']);
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, TenantPermission>
|
|
*/
|
|
public function tenantPermissions(): Collection
|
|
{
|
|
return TenantPermission::query()
|
|
->where('tenant_id', (int) $this->tenant->getKey())
|
|
->orderBy('permission_key')
|
|
->limit(20)
|
|
->get(['id', 'permission_key', 'status', 'last_checked_at']);
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, array{id: int, label: string, started: string, url: string}>
|
|
*/
|
|
public function recentRuns(): Collection
|
|
{
|
|
return OperationRun::query()
|
|
->where('tenant_id', (int) $this->tenant->getKey())
|
|
->latest('id')
|
|
->limit(8)
|
|
->get(['id', 'type', 'created_at'])
|
|
->map(fn (OperationRun $run): array => [
|
|
'id' => (int) $run->getKey(),
|
|
'label' => OperationCatalog::label((string) $run->type),
|
|
'started' => $run->created_at?->diffForHumans() ?? '—',
|
|
'url' => SystemOperationRunLinks::view($run),
|
|
]);
|
|
}
|
|
|
|
public function adminTenantUrl(): string
|
|
{
|
|
return SystemDirectoryLinks::adminTenant($this->tenant);
|
|
}
|
|
|
|
public function runsUrl(): string
|
|
{
|
|
return SystemOperationRunLinks::index();
|
|
}
|
|
}
|