Implements Spec 077 refinements: workspace Global Mode and navigation/context-bar redundancy cleanup.
Summary
- Global Mode: `/admin/workspaces` is workspace-optional (lists only member workspaces); explicit allowlist in `EnsureWorkspaceSelected`.
- Navigation cleanup: workspace switching is topbar-only; no sidebar “Switch workspace”; removes redundant “Manage workspaces” entry from context-bar.
- Context bar: when no workspace selected, tenant picker is disabled with guidance; on tenant-scoped routes `/admin/t/{tenant}/…` the tenant indicator is read-only (Filament tenant menu remains primary).
- Authorization: workspace creation is policy-driven (`WorkspacePolicy::create()`), enforced in `ChooseWorkspace` via Gate.
Safety / Compliance
- Livewire v4.0+ compliant (Filament v5).
- Panel provider registration remains in `bootstrap/providers.php` (no changes required).
- Global search: no new globally searchable resources added; no behavior changes introduced.
- Destructive actions: none added/changed.
- Assets: no new assets registered; deploy process unchanged (if assets are registered elsewhere, ensure `php artisan filament:assets` runs in deploy as usual).
Tests
- `vendor/bin/sail bin pint --dirty`
- `vendor/bin/sail artisan test --compact tests/Feature/Workspaces tests/Feature/Monitoring tests/Feature/OpsUx tests/Feature/Filament/WorkspaceContextTopbarAndTenantSelectionTest.php`
Spec artifacts
- `specs/077-workspace-nav-monitoring-hub/{spec,plan,tasks}.md`
- `specs/077-workspace-nav-monitoring-hub/contracts/routes.md`
Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box>
Reviewed-on: #94
175 lines
7.0 KiB
PHP
175 lines
7.0 KiB
PHP
@php
|
|
use App\Filament\Pages\ChooseWorkspace;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Models\WorkspaceMembership;
|
|
use App\Services\Auth\WorkspaceRoleCapabilityMap;
|
|
use App\Support\Auth\Capabilities;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Facades\Filament;
|
|
|
|
/** @var WorkspaceContext $workspaceContext */
|
|
$workspaceContext = app(WorkspaceContext::class);
|
|
|
|
$workspace = $workspaceContext->currentWorkspace(request());
|
|
|
|
$user = auth()->user();
|
|
|
|
$canSeeAllWorkspaceTenants = false;
|
|
if ($user instanceof User && $workspace) {
|
|
$roles = WorkspaceRoleCapabilityMap::rolesWithCapability(Capabilities::WORKSPACE_MEMBERSHIP_MANAGE);
|
|
|
|
$canSeeAllWorkspaceTenants = WorkspaceMembership::query()
|
|
->where('workspace_id', (int) $workspace->getKey())
|
|
->where('user_id', (int) $user->getKey())
|
|
->whereIn('role', $roles)
|
|
->exists();
|
|
}
|
|
|
|
$tenants = collect();
|
|
if ($user instanceof User && $workspace) {
|
|
if ($canSeeAllWorkspaceTenants) {
|
|
$tenants = Tenant::query()
|
|
->where('workspace_id', (int) $workspace->getKey())
|
|
->orderBy('name')
|
|
->get();
|
|
} else {
|
|
$tenants = collect($user->getTenants(Filament::getCurrentOrDefaultPanel()))
|
|
->filter(fn ($tenant): bool => $tenant instanceof Tenant && (int) $tenant->workspace_id === (int) $workspace->getKey())
|
|
->values();
|
|
}
|
|
}
|
|
|
|
$currentTenant = Filament::getTenant();
|
|
$currentTenantName = $currentTenant instanceof Tenant ? $currentTenant->getFilamentName() : null;
|
|
|
|
$path = '/'.ltrim(request()->path(), '/');
|
|
$isTenantScopedRoute = request()->route()?->hasParameter('tenant') || str_starts_with($path, '/admin/t/');
|
|
|
|
$lastTenantId = $workspaceContext->lastTenantId(request());
|
|
$canClearTenantContext = $currentTenantName !== null || $lastTenantId !== null;
|
|
@endphp
|
|
|
|
<div class="flex items-center gap-3">
|
|
<x-filament::dropdown placement="bottom-start" teleport>
|
|
<x-slot name="trigger">
|
|
<x-filament::button
|
|
color="gray"
|
|
outlined
|
|
size="sm"
|
|
icon="heroicon-o-squares-2x2"
|
|
>
|
|
{{ $workspace?->name ?? 'Select workspace' }}
|
|
</x-filament::button>
|
|
</x-slot>
|
|
|
|
<x-filament::dropdown.list>
|
|
<a
|
|
href="{{ ChooseWorkspace::getUrl() }}"
|
|
class="block px-3 py-2 text-sm hover:bg-gray-50 dark:hover:bg-gray-800"
|
|
>
|
|
Switch workspace
|
|
</a>
|
|
</x-filament::dropdown.list>
|
|
</x-filament::dropdown>
|
|
|
|
<div class="h-4 w-px bg-gray-200 dark:bg-gray-700"></div>
|
|
|
|
@if (! $workspace)
|
|
<div class="flex items-center gap-2">
|
|
<x-filament::button
|
|
color="gray"
|
|
outlined
|
|
size="sm"
|
|
icon="heroicon-o-building-office-2"
|
|
disabled
|
|
>
|
|
Select tenant
|
|
</x-filament::button>
|
|
|
|
<div class="text-xs text-gray-500 dark:text-gray-400">Choose a workspace first.</div>
|
|
</div>
|
|
@elseif ($isTenantScopedRoute)
|
|
<x-filament::button
|
|
color="gray"
|
|
outlined
|
|
size="sm"
|
|
icon="heroicon-o-building-office-2"
|
|
disabled
|
|
>
|
|
{{ $currentTenantName ?? 'Tenant' }}
|
|
</x-filament::button>
|
|
@else
|
|
<x-filament::dropdown placement="bottom-start" teleport>
|
|
<x-slot name="trigger">
|
|
<x-filament::button
|
|
color="gray"
|
|
outlined
|
|
size="sm"
|
|
icon="heroicon-o-building-office-2"
|
|
>
|
|
{{ $currentTenantName ?? 'Select tenant' }}
|
|
</x-filament::button>
|
|
</x-slot>
|
|
|
|
<x-filament::dropdown.list>
|
|
<div class="px-3 py-2 space-y-2" x-data="{ query: '' }">
|
|
<div class="text-xs font-medium text-gray-500 dark:text-gray-400">
|
|
Tenant context
|
|
@if ($canSeeAllWorkspaceTenants)
|
|
<span class="text-gray-400">· all workspace tenants</span>
|
|
@endif
|
|
</div>
|
|
|
|
@if ($tenants->isEmpty())
|
|
<div class="text-xs text-gray-500 dark:text-gray-400">
|
|
{{ $canSeeAllWorkspaceTenants ? 'No tenants exist in this workspace.' : 'No tenants you can access in this workspace.' }}
|
|
</div>
|
|
@else
|
|
<div class="space-y-2">
|
|
<input
|
|
type="text"
|
|
class="fi-input fi-text-input w-full"
|
|
placeholder="Search tenants…"
|
|
x-model="query"
|
|
/>
|
|
|
|
<div class="max-h-64 overflow-auto rounded-lg border border-gray-200 dark:border-gray-700">
|
|
@foreach ($tenants as $tenant)
|
|
<form method="POST" action="{{ route('admin.select-tenant') }}">
|
|
@csrf
|
|
<input type="hidden" name="tenant_id" value="{{ (int) $tenant->getKey() }}" />
|
|
|
|
<button
|
|
type="submit"
|
|
class="w-full px-3 py-2 text-left text-sm hover:bg-gray-50 dark:hover:bg-gray-800"
|
|
data-search="{{ (string) str($tenant->getFilamentName())->lower() }}"
|
|
x-show="query === '' || ($el.dataset.search ?? '').includes(query.toLowerCase())"
|
|
>
|
|
{{ $tenant->getFilamentName() }}
|
|
</button>
|
|
</form>
|
|
@endforeach
|
|
</div>
|
|
|
|
@if ($canClearTenantContext)
|
|
<form method="POST" action="{{ route('admin.clear-tenant-context') }}">
|
|
@csrf
|
|
|
|
<x-filament::button color="gray" size="sm" outlined>
|
|
Clear tenant context
|
|
</x-filament::button>
|
|
</form>
|
|
@endif
|
|
|
|
<div class="text-xs text-gray-500 dark:text-gray-400">
|
|
Switching tenants is explicit. Canonical monitoring URLs do not change tenant context.
|
|
</div>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
</x-filament::dropdown.list>
|
|
</x-filament::dropdown>
|
|
@endif
|
|
</div>
|