Summary Consolidates the “Tenant Operate Hub” work (Spec 085) and the follow-up adjustments from the 086 session merge into a single branch ready to merge into dev. Primary focus: stabilize Ops/Operate Hub UX flows, tighten/align authorization semantics, and make the full Sail test suite green. Key Changes Ops UX / Verification Readonly members can view verification operation runs (reports) while starting verification remains restricted. Normalized failure reason-code handling and aligned UX expectations with the provider reason-code taxonomy. Onboarding wizard UX “Start verification” CTA is hidden while a verification run is active; “Refresh” is shown during in-progress runs. Treats provider_permission_denied as a blocking reason (while keeping legacy compatibility). Test + fixture hardening Standardized use of default provider connection fixtures in tests where sync/restore flows require it. Fixed multiple Filament URL/tenant-context test cases to avoid 404s and reduce tenancy routing brittleness. Policy sync / restore safety Enrollment configuration type collision classification tests now exercise the real sync path (with required provider connection present). Restore edge-case safety tests updated to reflect current provider-connection requirements. Testing vendor/bin/sail artisan test --compact (green) vendor/bin/sail bin pint --dirty (green) Notes Includes merged 086 session work already (no separate PR needed). Co-authored-by: Ahmed Darrazi <ahmeddarrazi@ebc83aaa-d947-4a08-b88e-bd72ac9645f7.fritz.box> Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box> Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.fritz.box> Reviewed-on: #103
197 lines
8.0 KiB
PHP
197 lines
8.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\OperateHub\OperateHubShell;
|
|
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();
|
|
}
|
|
}
|
|
|
|
$operateHubShell = app(OperateHubShell::class);
|
|
$currentTenant = $operateHubShell->activeEntitledTenant(request());
|
|
$currentTenantName = $currentTenant instanceof Tenant ? $currentTenant->getFilamentName() : null;
|
|
|
|
$hasAnyFilamentTenantContext = Filament::getTenant() instanceof Tenant;
|
|
|
|
$path = '/'.ltrim(request()->path(), '/');
|
|
$route = request()->route();
|
|
$routeName = (string) ($route?->getName() ?? '');
|
|
$tenantQuery = request()->query('tenant');
|
|
$hasTenantQuery = is_string($tenantQuery) && trim($tenantQuery) !== '';
|
|
|
|
if ($currentTenantName === null && $hasTenantQuery) {
|
|
$queriedTenant = $tenants->first(function ($tenant) use ($tenantQuery): bool {
|
|
return $tenant instanceof Tenant
|
|
&& ((string) $tenant->external_id === (string) $tenantQuery || (string) $tenant->getKey() === (string) $tenantQuery);
|
|
});
|
|
|
|
if ($queriedTenant instanceof Tenant) {
|
|
$currentTenantName = $queriedTenant->getFilamentName();
|
|
}
|
|
}
|
|
|
|
$isTenantScopedRoute = $route?->hasParameter('tenant')
|
|
|| str_starts_with($path, '/admin/t/')
|
|
|| ($hasTenantQuery && str_starts_with($routeName, 'filament.admin.'));
|
|
|
|
$lastTenantId = $workspaceContext->lastTenantId(request());
|
|
$canClearTenantContext = $hasAnyFilamentTenantContext || $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="{{ route('filament.admin.resources.workspaces.index') }}"
|
|
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 type="submit" 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>
|