TenantAtlas/apps/platform/app/Support/OperationalControls/OperationalControlEvaluator.php
ahmido d96abc65fb
Some checks failed
Main Confidence / confidence (push) Failing after 1m23s
Remove Findings lifecycle backfill operational surface (controls slice) (#280)
Removes the Findings lifecycle backfill from the Operational Controls UI and OperationalControlCatalog.

This patch is a safe, controls-only change; runbooks, jobs and other runtime artifacts are NOT removed yet. Follow-up work will delete the runbook service/scope, jobs, commands, and update tests.

Files changed:
- apps/platform/app/Filament/System/Pages/Ops/Controls.php
- apps/platform/app/Support/OperationalControls/OperationalControlCatalog.php
- apps/platform/tests/Feature/System/OpsControls/OperationalControlManagementTest.php
- apps/platform/tests/Unit/Support/OperationalControls/OperationalControlCatalogTest.php
- apps/platform/tests/Unit/Support/OperationalControls/OperationalControlScopeResolutionTest.php

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #280
2026-04-26 15:43:47 +00:00

63 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Support\OperationalControls;
use App\Models\OperationalControlActivation;
use App\Models\Workspace;
final class OperationalControlEvaluator
{
public function __construct(
private readonly OperationalControlCatalog $catalog,
) {}
public function evaluate(string $controlKey, Workspace|int|null $workspace = null): OperationalControlDecision
{
$definition = $this->catalog->definition($controlKey);
$workspaceId = $workspace instanceof Workspace
? (int) $workspace->getKey()
: (is_int($workspace) ? $workspace : null);
$globalActivation = OperationalControlActivation::query()
->forControl($definition['key'])
->forGlobalScope()
->notExpired()
->latest('id')
->first();
if ($globalActivation instanceof OperationalControlActivation) {
return OperationalControlDecision::paused(
controlKey: $definition['key'],
matchedScopeType: 'global',
workspaceId: null,
reasonText: $globalActivation->reason_text,
expiresAt: $globalActivation->expires_at,
sourceActivationId: (int) $globalActivation->getKey(),
);
}
if ($workspaceId !== null) {
$workspaceActivation = OperationalControlActivation::query()
->forControl($definition['key'])
->forWorkspaceScope($workspaceId)
->notExpired()
->latest('id')
->first();
if ($workspaceActivation instanceof OperationalControlActivation) {
return OperationalControlDecision::paused(
controlKey: $definition['key'],
matchedScopeType: 'workspace',
workspaceId: $workspaceId,
reasonText: $workspaceActivation->reason_text,
expiresAt: $workspaceActivation->expires_at,
sourceActivationId: (int) $workspaceActivation->getKey(),
);
}
}
return OperationalControlDecision::enabled($definition['key']);
}
}