## Summary - normalize provider-neutral target-scope and identity contracts across provider connection resolution, operation-start gating, verification reporting, and boundary configuration - align provider connection resource, onboarding, tenant summaries, and operation follow-up on the same shared scope contract while keeping Microsoft-specific profile details in provider-owned metadata - add Spec 281 artifacts and focused feature/browser coverage for the new provider-scope contract - move the tenant dashboard context-chip rail into Filament header widgets so the metadata row renders directly under the page subtitle ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Providers/ProviderConnectionTargetScopeNeutralityTest.php tests/Feature/Providers/ProviderIdentityResolutionNeutralityTest.php tests/Feature/Providers/ProviderOperationStartGateTargetScopeContextTest.php tests/Feature/Filament/ProviderConnectionResourceScopeSummaryTest.php tests/Feature/Onboarding/ManagedTenantOnboardingProviderConnectionScopeTest.php tests/Feature/Guards/ProviderConnectionMicrosoftScopeLeakGuardTest.php` - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Browser/Spec281ProviderConnectionScopeSmokeTest.php` - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Dashboard/TenantDashboardProductizationSummaryTest.php` - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Browser/Dashboard/TenantDashboardProductizationSmokeTest.php` - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` ## Notes - Filament remains on v5 with Livewire v4-compatible surfaces only. - Provider registration location is unchanged; Laravel 11+ providers stay in `apps/platform/bootstrap/providers.php`. - `ProviderConnectionResource` remains non-globally-searchable and still exposes View/Edit pages. - No new asset registration was added; deploy-time `filament:assets` expectations are unchanged. - No new destructive action path was introduced; existing server authorization and confirmation handling remain in place where applicable. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #339
139 lines
5.0 KiB
PHP
139 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Support\Providers\TargetScope;
|
|
|
|
use App\Models\ProviderConnection;
|
|
use App\Support\Badges\BadgeDomain;
|
|
use App\Support\Badges\BadgeRenderer;
|
|
use App\Support\Providers\ProviderConsentStatus;
|
|
use App\Support\Providers\ProviderVerificationStatus;
|
|
|
|
final class ProviderConnectionSurfaceSummary
|
|
{
|
|
/**
|
|
* @param list<ProviderIdentityContextMetadata> $contextualIdentityDetails
|
|
*/
|
|
public function __construct(
|
|
public readonly string $provider,
|
|
public readonly ProviderConnectionTargetScopeDescriptor $targetScope,
|
|
public readonly string $consentState,
|
|
public readonly string $verificationState,
|
|
public readonly string $readinessSummary,
|
|
public readonly array $contextualIdentityDetails = [],
|
|
public readonly bool $isEnabled = true,
|
|
) {}
|
|
|
|
public static function forConnection(ProviderConnection $connection): self
|
|
{
|
|
/** @var ProviderConnectionTargetScopeNormalizer $normalizer */
|
|
$normalizer = app(ProviderConnectionTargetScopeNormalizer::class);
|
|
$targetScope = $normalizer->descriptorForConnection($connection);
|
|
$consentState = self::stateValue($connection->consent_status);
|
|
$verificationState = self::stateValue($connection->verification_status);
|
|
|
|
return new self(
|
|
provider: trim((string) $connection->provider),
|
|
targetScope: $targetScope,
|
|
consentState: $consentState,
|
|
verificationState: $verificationState,
|
|
readinessSummary: self::readinessSummary(
|
|
isEnabled: (bool) $connection->is_enabled,
|
|
consentState: $consentState,
|
|
verificationState: $verificationState,
|
|
),
|
|
contextualIdentityDetails: $normalizer->contextualIdentityDetailsForConnection($connection),
|
|
isEnabled: (bool) $connection->is_enabled,
|
|
);
|
|
}
|
|
|
|
public function targetScopeSummary(): string
|
|
{
|
|
return $this->targetScope->summary();
|
|
}
|
|
|
|
public function contextualIdentityLine(): ?string
|
|
{
|
|
if ($this->contextualIdentityDetails === []) {
|
|
return null;
|
|
}
|
|
|
|
return collect($this->contextualIdentityDetails)
|
|
->map(fn (ProviderIdentityContextMetadata $detail): string => sprintf('%s: %s', $detail->detailLabel, $detail->detailValue))
|
|
->implode("\n");
|
|
}
|
|
|
|
/**
|
|
* @return array{
|
|
* provider: string,
|
|
* target_scope: array<string, string>,
|
|
* consent_state: string,
|
|
* verification_state: string,
|
|
* readiness_summary: string,
|
|
* target_scope_summary: string,
|
|
* provider_context: array{provider: string, details: list<array<string, string>>},
|
|
* contextual_identity_line: ?string,
|
|
* is_enabled: bool
|
|
* }
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'provider' => $this->provider,
|
|
'target_scope' => $this->targetScope->toArray(),
|
|
'consent_state' => $this->consentState,
|
|
'verification_state' => $this->verificationState,
|
|
'readiness_summary' => $this->readinessSummary,
|
|
'target_scope_summary' => $this->targetScopeSummary(),
|
|
'provider_context' => $this->providerContext(),
|
|
'contextual_identity_line' => $this->contextualIdentityLine(),
|
|
'is_enabled' => $this->isEnabled,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{provider: string, details: list<array<string, string>>}
|
|
*/
|
|
public function providerContext(): array
|
|
{
|
|
return [
|
|
'provider' => $this->provider,
|
|
'details' => array_map(
|
|
static fn (ProviderIdentityContextMetadata $detail): array => $detail->toArray(),
|
|
$this->contextualIdentityDetails,
|
|
),
|
|
];
|
|
}
|
|
|
|
private static function stateValue(mixed $state): string
|
|
{
|
|
if ($state instanceof ProviderConsentStatus || $state instanceof ProviderVerificationStatus) {
|
|
return $state->value;
|
|
}
|
|
|
|
return trim((string) $state);
|
|
}
|
|
|
|
private static function readinessSummary(bool $isEnabled, string $consentState, string $verificationState): string
|
|
{
|
|
if (! $isEnabled) {
|
|
return 'Disabled';
|
|
}
|
|
|
|
if ($consentState !== ProviderConsentStatus::Granted->value) {
|
|
return sprintf(
|
|
'Consent %s',
|
|
strtolower(BadgeRenderer::spec(BadgeDomain::ProviderConsentStatus, $consentState)->label),
|
|
);
|
|
}
|
|
|
|
return match ($verificationState) {
|
|
ProviderVerificationStatus::Healthy->value => 'Ready',
|
|
ProviderVerificationStatus::Degraded->value => 'Ready with warnings',
|
|
ProviderVerificationStatus::Blocked->value => 'Verification blocked',
|
|
ProviderVerificationStatus::Error->value => 'Verification failed',
|
|
ProviderVerificationStatus::Pending->value => 'Verification pending',
|
|
default => 'Verification not run',
|
|
};
|
|
}
|
|
}
|