Implements Spec 076 enterprise remediation UX for tenant required permissions. Highlights - Above-the-fold overview (impact + counts) with missing-first experience - Feature-based grouping, filters/search, copy-to-clipboard for missing app/delegated permissions - Tenant-scoped deny-as-not-found semantics; DB-only viewing - Centralized badge semantics (no ad-hoc status mapping) Testing - Feature tests for default filters, grouping, copy output, and non-member 404 behavior. Integration - Adds deep links from verification checks to the Required permissions page. Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box> Reviewed-on: #92
185 lines
4.8 KiB
PHP
185 lines
4.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Filament\Resources\ProviderConnectionResource;
|
|
use App\Models\ProviderConnection;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Services\Auth\CapabilityResolver;
|
|
use App\Services\Intune\TenantRequiredPermissionsViewModelBuilder;
|
|
use App\Support\Auth\Capabilities;
|
|
use Filament\Pages\Page;
|
|
|
|
class TenantRequiredPermissions extends Page
|
|
{
|
|
protected static bool $shouldRegisterNavigation = false;
|
|
|
|
protected static ?string $slug = 'required-permissions';
|
|
|
|
protected static ?string $title = 'Required permissions';
|
|
|
|
protected string $view = 'filament.pages.tenant-required-permissions';
|
|
|
|
public string $status = 'missing';
|
|
|
|
public string $type = 'all';
|
|
|
|
/**
|
|
* @var array<int, string>
|
|
*/
|
|
public array $features = [];
|
|
|
|
public string $search = '';
|
|
|
|
/**
|
|
* @var array<string, mixed>
|
|
*/
|
|
public array $viewModel = [];
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
$tenant = Tenant::current();
|
|
$user = auth()->user();
|
|
|
|
if (! $tenant instanceof Tenant || ! $user instanceof User) {
|
|
return false;
|
|
}
|
|
|
|
/** @var CapabilityResolver $resolver */
|
|
$resolver = app(CapabilityResolver::class);
|
|
|
|
return $resolver->can($user, $tenant, Capabilities::TENANT_VIEW);
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$queryFeatures = request()->query('features', $this->features);
|
|
|
|
$state = TenantRequiredPermissionsViewModelBuilder::normalizeFilterState([
|
|
'status' => request()->query('status', $this->status),
|
|
'type' => request()->query('type', $this->type),
|
|
'features' => is_array($queryFeatures) ? $queryFeatures : [],
|
|
'search' => request()->query('search', $this->search),
|
|
]);
|
|
|
|
$this->status = $state['status'];
|
|
$this->type = $state['type'];
|
|
$this->features = $state['features'];
|
|
$this->search = $state['search'];
|
|
|
|
$this->refreshViewModel();
|
|
}
|
|
|
|
public function updatedStatus(): void
|
|
{
|
|
$this->refreshViewModel();
|
|
}
|
|
|
|
public function updatedType(): void
|
|
{
|
|
$this->refreshViewModel();
|
|
}
|
|
|
|
public function updatedFeatures(): void
|
|
{
|
|
$this->refreshViewModel();
|
|
}
|
|
|
|
public function updatedSearch(): void
|
|
{
|
|
$this->refreshViewModel();
|
|
}
|
|
|
|
public function applyFeatureFilter(string $feature): void
|
|
{
|
|
$feature = trim($feature);
|
|
|
|
if ($feature === '') {
|
|
return;
|
|
}
|
|
|
|
if (in_array($feature, $this->features, true)) {
|
|
$this->features = array_values(array_filter(
|
|
$this->features,
|
|
static fn (string $value): bool => $value !== $feature,
|
|
));
|
|
} else {
|
|
$this->features[] = $feature;
|
|
}
|
|
|
|
$this->features = array_values(array_unique($this->features));
|
|
|
|
$this->refreshViewModel();
|
|
}
|
|
|
|
public function clearFeatureFilter(): void
|
|
{
|
|
$this->features = [];
|
|
|
|
$this->refreshViewModel();
|
|
}
|
|
|
|
public function resetFilters(): void
|
|
{
|
|
$this->status = 'missing';
|
|
$this->type = 'all';
|
|
$this->features = [];
|
|
$this->search = '';
|
|
|
|
$this->refreshViewModel();
|
|
}
|
|
|
|
private function refreshViewModel(): void
|
|
{
|
|
$tenant = Tenant::current();
|
|
|
|
if (! $tenant instanceof Tenant) {
|
|
$this->viewModel = [];
|
|
|
|
return;
|
|
}
|
|
|
|
$builder = app(TenantRequiredPermissionsViewModelBuilder::class);
|
|
|
|
$this->viewModel = $builder->build($tenant, [
|
|
'status' => $this->status,
|
|
'type' => $this->type,
|
|
'features' => $this->features,
|
|
'search' => $this->search,
|
|
]);
|
|
|
|
$filters = $this->viewModel['filters'] ?? null;
|
|
|
|
if (is_array($filters)) {
|
|
$this->status = (string) ($filters['status'] ?? $this->status);
|
|
$this->type = (string) ($filters['type'] ?? $this->type);
|
|
$this->features = is_array($filters['features'] ?? null) ? $filters['features'] : $this->features;
|
|
$this->search = (string) ($filters['search'] ?? $this->search);
|
|
}
|
|
}
|
|
|
|
public function reRunVerificationUrl(): ?string
|
|
{
|
|
$tenant = Tenant::current();
|
|
|
|
if (! $tenant instanceof Tenant) {
|
|
return null;
|
|
}
|
|
|
|
$connectionId = ProviderConnection::query()
|
|
->where('tenant_id', (int) $tenant->getKey())
|
|
->orderByDesc('is_default')
|
|
->orderByDesc('id')
|
|
->value('id');
|
|
|
|
if (! is_int($connectionId)) {
|
|
return ProviderConnectionResource::getUrl('index', tenant: $tenant);
|
|
}
|
|
|
|
return ProviderConnectionResource::getUrl('edit', ['record' => $connectionId], tenant: $tenant);
|
|
}
|
|
}
|