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
127 lines
3.9 KiB
PHP
127 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\OperationRunService;
|
|
use App\Models\Tenant;
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Console\Command;
|
|
|
|
class TenantpilotDispatchDirectoryGroupsSync extends Command
|
|
{
|
|
protected $signature = 'tenantpilot:directory-groups:dispatch {--tenant=* : Limit to tenant_id/external_id}';
|
|
|
|
protected $description = 'Dispatch scheduled directory group sync runs (idempotent per tenant minute-slot).';
|
|
|
|
public function handle(): int
|
|
{
|
|
if (! (bool) config('directory_groups.schedule.enabled', false)) {
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$now = CarbonImmutable::now('UTC');
|
|
$timeUtc = (string) config('directory_groups.schedule.time_utc', '02:00');
|
|
|
|
if (! $this->isDueAt($now, $timeUtc)) {
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
if (! class_exists(\App\Jobs\EntraGroupSyncJob::class)) {
|
|
$this->warn('EntraGroupSyncJob is not available; skipping scheduled directory group sync dispatch.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$tenantIdentifiers = array_values(array_filter(array_map('strval', array_merge(
|
|
(array) $this->option('tenant'),
|
|
(array) config('directory_groups.schedule.tenants', []),
|
|
))));
|
|
|
|
$tenants = $this->resolveTenants($tenantIdentifiers);
|
|
|
|
$selectionKey = 'groups-v1:all';
|
|
$slotKey = $now->format('YmdHi').'Z';
|
|
|
|
$created = 0;
|
|
$skipped = 0;
|
|
|
|
foreach ($tenants as $tenant) {
|
|
/** @var OperationRunService $opService */
|
|
$opService = app(OperationRunService::class);
|
|
$opRun = $opService->ensureRunWithIdentityStrict(
|
|
tenant: $tenant,
|
|
type: 'directory_groups.sync',
|
|
identityInputs: [
|
|
'selection_key' => $selectionKey,
|
|
'slot_key' => $slotKey,
|
|
],
|
|
context: [
|
|
'selection_key' => $selectionKey,
|
|
'slot_key' => $slotKey,
|
|
'trigger' => 'scheduled',
|
|
],
|
|
initiator: null,
|
|
);
|
|
|
|
if (! $opRun->wasRecentlyCreated) {
|
|
$skipped++;
|
|
continue;
|
|
}
|
|
|
|
$created++;
|
|
|
|
dispatch(new \App\Jobs\EntraGroupSyncJob(
|
|
tenantId: $tenant->getKey(),
|
|
selectionKey: $selectionKey,
|
|
slotKey: $slotKey,
|
|
runId: null,
|
|
operationRun: $opRun,
|
|
));
|
|
}
|
|
|
|
$this->info(sprintf(
|
|
'Scanned %d tenant(s), created %d run(s), skipped %d duplicate run(s).',
|
|
$tenants->count(),
|
|
$created,
|
|
$skipped,
|
|
));
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* @param array<int, string> $tenantIdentifiers
|
|
*/
|
|
private function resolveTenants(array $tenantIdentifiers): \Illuminate\Support\Collection
|
|
{
|
|
$query = Tenant::activeQuery();
|
|
|
|
if ($tenantIdentifiers !== []) {
|
|
$query->where(function ($subQuery) use ($tenantIdentifiers) {
|
|
foreach ($tenantIdentifiers as $identifier) {
|
|
if (ctype_digit($identifier)) {
|
|
$subQuery->orWhereKey((int) $identifier);
|
|
|
|
continue;
|
|
}
|
|
|
|
$subQuery->orWhere('tenant_id', $identifier)
|
|
->orWhere('external_id', $identifier);
|
|
}
|
|
});
|
|
}
|
|
|
|
return $query->get();
|
|
}
|
|
|
|
private function isDueAt(CarbonImmutable $now, string $timeUtc): bool
|
|
{
|
|
if (! preg_match('/^(?<hour>[01]\\d|2[0-3]):(?<minute>[0-5]\\d)$/', $timeUtc, $matches)) {
|
|
return false;
|
|
}
|
|
|
|
return (int) $matches['hour'] === (int) $now->format('H')
|
|
&& (int) $matches['minute'] === (int) $now->format('i');
|
|
}
|
|
}
|