TenantAtlas/resources/views/filament/partials/workspace-switcher.blade.php
ahmido 38d9826f5e feat: workspace context enforcement + ownership safeguards (#86)
Implements workspace-first enforcement and UX:
- Workspace selected before tenant flows; /admin routes into choose-workspace/choose-tenant
- Tenant lists and default tenant selection are scoped to current workspace
- Workspaces UI is tenantless at /admin/workspaces

Security hardening:
- Workspaces can never have 0 owners (blocks last-owner removal/demotion)
- Blocked attempts are audited with action_id=workspace_membership.last_owner_blocked + required metadata
- Optional break-glass recovery page to re-assign workspace owner (audited)

Tests:
- Added/updated Pest feature tests covering redirects, scoping, tenantless workspaces, last-owner guards, and break-glass recovery.

Notes:
- Filament v5 strict Page property signatures respected in RepairWorkspaceOwners.

Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box>
Reviewed-on: #86
2026-02-02 23:00:56 +00:00

48 lines
1.7 KiB
PHP

@php
/** @var \App\Support\Workspaces\WorkspaceContext $workspaceContext */
$workspaceContext = app(\App\Support\Workspaces\WorkspaceContext::class);
$user = auth()->user();
$currentWorkspaceId = $workspaceContext->currentWorkspaceId(request());
$workspaces = collect();
if ($user instanceof \App\Models\User) {
$workspaces = \App\Models\Workspace::query()
->whereIn('id', function ($query) use ($user): void {
$query->from('workspace_memberships')
->select('workspace_id')
->where('user_id', $user->getKey());
})
->whereNull('archived_at')
->orderBy('name')
->get();
}
@endphp
@if ($workspaces->isNotEmpty())
<x-filament::dropdown.list>
<div class="px-3 py-2">
<form method="POST" action="{{ route('admin.switch-workspace') }}" class="space-y-2">
@csrf
<div class="text-xs font-medium text-gray-500 dark:text-gray-400">Workspace</div>
<select
name="workspace_id"
class="fi-input fi-select w-full"
x-data
x-on:change="$el.form.submit()"
>
@foreach ($workspaces as $workspace)
<option value="{{ $workspace->getKey() }}" {{ (int) $workspace->getKey() === (int) $currentWorkspaceId ? 'selected' : '' }}>
{{ $workspace->name }}
</option>
@endforeach
</select>
<div class="text-xs text-gray-500 dark:text-gray-400">Switch workspace</div>
</form>
</div>
</x-filament::dropdown.list>
@endif