Implements Spec 081 provider-connection cutover. Highlights: - Adds provider connection resolution + gating for operations/verification. - Adds provider credential observer wiring. - Updates Filament tenant verify flow to block with next-steps when provider connection isn’t ready. - Adds spec docs under specs/081-provider-connection-cutover/ and extensive Spec081 test coverage. Tests: - vendor/bin/sail artisan test --compact tests/Feature/Filament/TenantSetupTest.php - Focused suites for ProviderConnections/Verification ran during implementation (see local logs). Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box> Reviewed-on: #98
193 lines
7.8 KiB
PHP
193 lines
7.8 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(), '/');
|
|
$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 = $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(panel: 'admin') }}"
|
|
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>
|