Implements Spec 084 (verification-surfaces-unification). Highlights - Unifies tenant + onboarding verification start on `provider.connection.check` (OperationRun-based, enqueue-only). - Ensures completed blocked runs persist a schema-valid `context.verification_report` stub (DB-only viewers never show “unavailable”). - Adds tenant embedded verification report widget with DB-only rendering + canonical tenantless “View run” links. - Enforces 404/403 semantics for tenantless run viewing (workspace membership + tenant entitlement required; otherwise 404). - Fixes admin panel widgets to resolve tenant from record context so Owners can start verification and recent operations renders correctly. Tests - Ran: `vendor/bin/sail artisan test --compact tests/Feature/Verification/ tests/Feature/ProviderConnections/ProviderOperationBlockedGuidanceSpec081Test.php tests/Feature/Onboarding/OnboardingVerificationTest.php tests/Feature/RunAuthorizationTenantIsolationTest.php tests/Feature/Filament/TenantVerificationReportWidgetTest.php tests/Feature/Filament/RecentOperationsSummaryWidgetTest.php` Notes - Filament v5 / Livewire v4 compatible. - No new assets; no changes to provider registration. Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box> Reviewed-on: #102
114 lines
3.7 KiB
PHP
114 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Verification;
|
|
|
|
use App\Jobs\ProviderConnectionHealthCheckJob;
|
|
use App\Models\OperationRun;
|
|
use App\Models\ProviderConnection;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Services\Providers\ProviderOperationStartGate;
|
|
use App\Services\Providers\ProviderOperationStartResult;
|
|
use App\Support\Auth\Capabilities;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use InvalidArgumentException;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
final class StartVerification
|
|
{
|
|
public function __construct(
|
|
private readonly ProviderOperationStartGate $providers,
|
|
) {}
|
|
|
|
/**
|
|
* Start (or dedupe) a provider-connection verification run.
|
|
*
|
|
* @param array<string, mixed> $extraContext
|
|
*/
|
|
public function providerConnectionCheck(
|
|
Tenant $tenant,
|
|
ProviderConnection $connection,
|
|
User $initiator,
|
|
array $extraContext = [],
|
|
): ProviderOperationStartResult {
|
|
return $this->providerConnectionCheckUsingConnection(
|
|
tenant: $tenant,
|
|
connection: $connection,
|
|
initiator: $initiator,
|
|
extraContext: $extraContext,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Start (or dedupe) a provider-connection verification run for the tenant default connection.
|
|
*
|
|
* @param array<string, mixed> $extraContext
|
|
*/
|
|
public function providerConnectionCheckForTenant(
|
|
Tenant $tenant,
|
|
User $initiator,
|
|
array $extraContext = [],
|
|
): ProviderOperationStartResult {
|
|
if (! $initiator->canAccessTenant($tenant)) {
|
|
throw new NotFoundHttpException;
|
|
}
|
|
|
|
Gate::forUser($initiator)->authorize(Capabilities::PROVIDER_RUN, $tenant);
|
|
|
|
return $this->providers->start(
|
|
tenant: $tenant,
|
|
connection: null,
|
|
operationType: 'provider.connection.check',
|
|
dispatcher: fn (OperationRun $run): mixed => $this->dispatchConnectionHealthCheck($run, $tenant, $initiator),
|
|
initiator: $initiator,
|
|
extraContext: $extraContext,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Start (or dedupe) a provider-connection verification run for an explicit connection.
|
|
*
|
|
* @param array<string, mixed> $extraContext
|
|
*/
|
|
public function providerConnectionCheckUsingConnection(
|
|
Tenant $tenant,
|
|
ProviderConnection $connection,
|
|
User $initiator,
|
|
array $extraContext = [],
|
|
): ProviderOperationStartResult {
|
|
if (! $initiator->canAccessTenant($tenant)) {
|
|
throw new NotFoundHttpException;
|
|
}
|
|
|
|
Gate::forUser($initiator)->authorize(Capabilities::PROVIDER_RUN, $tenant);
|
|
|
|
return $this->providers->start(
|
|
tenant: $tenant,
|
|
connection: $connection,
|
|
operationType: 'provider.connection.check',
|
|
dispatcher: fn (OperationRun $run): mixed => $this->dispatchConnectionHealthCheck($run, $tenant, $initiator),
|
|
initiator: $initiator,
|
|
extraContext: $extraContext,
|
|
);
|
|
}
|
|
|
|
private function dispatchConnectionHealthCheck(OperationRun $run, Tenant $tenant, User $initiator): mixed
|
|
{
|
|
$context = is_array($run->context ?? null) ? $run->context : [];
|
|
$providerConnectionId = $context['provider_connection_id'] ?? null;
|
|
|
|
if (! is_numeric($providerConnectionId)) {
|
|
throw new InvalidArgumentException('Provider connection id is missing from run context.');
|
|
}
|
|
|
|
return ProviderConnectionHealthCheckJob::dispatch(
|
|
tenantId: (int) $tenant->getKey(),
|
|
userId: (int) $initiator->getKey(),
|
|
providerConnectionId: (int) $providerConnectionId,
|
|
operationRun: $run,
|
|
);
|
|
}
|
|
}
|