## Summary - retire the tenant panel runtime and converge operator routing on the workspace-first admin shell - update tenant, operations, and required-permissions navigation helpers to use canonical workspace-scoped URLs - repair the focused feature coverage, add the Spec 280 browser smoke, and record the implementation close-out in the requirements checklist ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/WorkspaceFoundation tests/Feature/Workspaces tests/Feature/ManagedEnvironment tests/Feature/RequiredPermissions tests/Feature/Operations tests/Feature/MonitoringOperationsTest.php` - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Browser/Spec280WorkspaceTenancyEnvironmentRoutingSmokeTest.php` - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` ## Note - `origin/platform` is not present on the remote; `platform-dev` is the clean base branch that limits this PR to the Spec 280 prep commit plus the implementation commit. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #340
114 lines
3.3 KiB
PHP
114 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Pages\Workspaces;
|
|
|
|
use App\Filament\Pages\ChooseTenant;
|
|
use App\Filament\Resources\TenantResource;
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Services\Tenants\TenantOperabilityService;
|
|
use App\Support\Tenants\TenantInteractionLane;
|
|
use App\Support\Tenants\TenantOperabilityQuestion;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Pages\Page;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
class ManagedTenantsLanding extends Page
|
|
{
|
|
protected static bool $shouldRegisterNavigation = false;
|
|
|
|
protected static bool $isDiscovered = false;
|
|
|
|
protected static string $layout = 'filament-panels::components.layout.simple';
|
|
|
|
protected static ?string $title = 'Managed tenants';
|
|
|
|
protected string $view = 'filament.pages.workspaces.managed-tenants-landing';
|
|
|
|
public Workspace $workspace;
|
|
|
|
/**
|
|
* The Filament simple layout renders the topbar by default, which includes
|
|
* lazy-loaded database notifications. On this workspace-scoped landing page,
|
|
* those background Livewire requests currently 404.
|
|
*/
|
|
protected function getLayoutData(): array
|
|
{
|
|
return [
|
|
'hasTopbar' => false,
|
|
];
|
|
}
|
|
|
|
public function mount(Workspace $workspace): void
|
|
{
|
|
$this->workspace = $workspace;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, ManagedEnvironment>
|
|
*/
|
|
public function getTenants(): Collection
|
|
{
|
|
$user = auth()->user();
|
|
|
|
if (! $user instanceof User) {
|
|
return ManagedEnvironment::query()->whereRaw('1 = 0')->get();
|
|
}
|
|
|
|
$tenantIds = $user->tenantMemberships()
|
|
->pluck('managed_environment_id');
|
|
|
|
return ManagedEnvironment::query()
|
|
->withTrashed()
|
|
->whereIn('id', $tenantIds)
|
|
->where('workspace_id', $this->workspace->getKey())
|
|
->orderBy('name')
|
|
->get()
|
|
->filter(function (ManagedEnvironment $tenant) use ($user): bool {
|
|
return app(TenantOperabilityService::class)->outcomeFor(
|
|
tenant: $tenant,
|
|
question: TenantOperabilityQuestion::AdministrativeDiscoverability,
|
|
actor: $user,
|
|
workspaceId: app(WorkspaceContext::class)->currentWorkspaceId(request()),
|
|
lane: TenantInteractionLane::AdministrativeManagement,
|
|
)->allowed;
|
|
})
|
|
->values();
|
|
}
|
|
|
|
public function goToChooseTenant(): void
|
|
{
|
|
$this->redirect(route('admin.workspace.managed-tenants.index', ['workspace' => $this->workspace]));
|
|
}
|
|
|
|
public function openTenant(int $tenantId): void
|
|
{
|
|
$user = auth()->user();
|
|
|
|
if (! $user instanceof User) {
|
|
abort(403);
|
|
}
|
|
|
|
$tenant = ManagedEnvironment::query()
|
|
->withTrashed()
|
|
->where('workspace_id', $this->workspace->getKey())
|
|
->whereKey($tenantId)
|
|
->first();
|
|
|
|
if (! $tenant instanceof ManagedEnvironment) {
|
|
abort(404);
|
|
}
|
|
|
|
if (! $user->canAccessTenant($tenant)) {
|
|
abort(404);
|
|
}
|
|
|
|
$this->redirect(
|
|
\App\Filament\Pages\TenantDashboard::getUrl(tenant: $tenant)
|
|
);
|
|
}
|
|
}
|