From 854ce80df7627dc7643ed58408c52fe62914a7a6 Mon Sep 17 00:00:00 2001 From: Ahmed Darrazi Date: Thu, 1 Jan 2026 12:59:23 +0100 Subject: [PATCH] fix: normalize scripts settings blocks --- .../Intune/ScriptsPolicyNormalizer.php | 26 ++++++++++++------- .../policy-settings-standard.blade.php | 8 ++++-- tests/Unit/ScriptsPolicyNormalizerTest.php | 5 +++- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/app/Services/Intune/ScriptsPolicyNormalizer.php b/app/Services/Intune/ScriptsPolicyNormalizer.php index 1593604..945e520 100644 --- a/app/Services/Intune/ScriptsPolicyNormalizer.php +++ b/app/Services/Intune/ScriptsPolicyNormalizer.php @@ -27,16 +27,16 @@ public function normalize(?array $snapshot, string $policyType, ?string $platfor $displayName = Arr::get($snapshot, 'displayName') ?? Arr::get($snapshot, 'name'); $description = Arr::get($snapshot, 'description'); - $settings = []; + $entries = []; - $settings[] = ['key' => 'Type', 'value' => $policyType]; + $entries[] = ['key' => 'Type', 'value' => $policyType]; if (is_string($displayName) && $displayName !== '') { - $settings[] = ['key' => 'Display name', 'value' => $displayName]; + $entries[] = ['key' => 'Display name', 'value' => $displayName]; } if (is_string($description) && $description !== '') { - $settings[] = ['key' => 'Description', 'value' => $description]; + $entries[] = ['key' => 'Description', 'value' => $description]; } // Script content and large blobs should not dominate normalized output. @@ -52,28 +52,34 @@ public function normalize(?array $snapshot, string $policyType, ?string $platfor $value = Arr::get($snapshot, $key); if (is_string($value) && $value !== '') { - $settings[] = ['key' => $key, 'value' => sprintf('[content: %d chars]', strlen($value))]; + $entries[] = ['key' => $key, 'value' => sprintf('[content: %d chars]', strlen($value))]; } } $schedule = Arr::get($snapshot, 'runSchedule'); if (is_array($schedule) && $schedule !== []) { - $settings[] = ['key' => 'Run schedule', 'value' => Arr::except($schedule, ['@odata.type'])]; + $entries[] = ['key' => 'Run schedule', 'value' => Arr::except($schedule, ['@odata.type'])]; } $frequency = Arr::get($snapshot, 'runFrequency'); if (is_string($frequency) && $frequency !== '') { - $settings[] = ['key' => 'Run frequency', 'value' => $frequency]; + $entries[] = ['key' => 'Run frequency', 'value' => $frequency]; } $roleScopeTagIds = Arr::get($snapshot, 'roleScopeTagIds'); if (is_array($roleScopeTagIds) && $roleScopeTagIds !== []) { - $settings[] = ['key' => 'Scope tag IDs', 'value' => array_values($roleScopeTagIds)]; + $entries[] = ['key' => 'Scope tag IDs', 'value' => array_values($roleScopeTagIds)]; } return [ 'status' => 'ok', - 'settings' => $settings, + 'settings' => [ + [ + 'type' => 'keyValue', + 'title' => 'Script settings', + 'entries' => $entries, + ], + ], 'warnings' => [], ]; } @@ -85,6 +91,6 @@ public function flattenForDiff(?array $snapshot, string $policyType, ?string $pl { $normalized = $this->normalize($snapshot, $policyType, $platform); - return $this->defaultNormalizer->flattenForDiff($normalized['settings'] ?? []); + return $this->defaultNormalizer->flattenNormalizedForDiff($normalized); } } diff --git a/resources/views/filament/infolists/entries/policy-settings-standard.blade.php b/resources/views/filament/infolists/entries/policy-settings-standard.blade.php index 9fb9398..9788fc4 100644 --- a/resources/views/filament/infolists/entries/policy-settings-standard.blade.php +++ b/resources/views/filament/infolists/entries/policy-settings-standard.blade.php @@ -65,7 +65,11 @@ {{-- Settings Blocks (for OMA Settings, Key/Value pairs, etc.) --}} @foreach($settings as $block) - @if($block['type'] === 'table') + @php + $blockType = is_array($block) ? ($block['type'] ?? null) : null; + @endphp + + @if($blockType === 'table') - @elseif($block['type'] === 'keyValue') + @elseif($blockType === 'keyValue') toBe('ok'); expect($result['settings'])->toBeArray()->not->toBeEmpty(); - expect(collect($result['settings'])->pluck('key')->all())->toContain('Display name'); + expect($result['settings'][0]['type'])->toBe('keyValue'); + expect(collect($result['settings'][0]['entries'])->pluck('key')->all())->toContain('Display name'); }); it('normalizes deviceShellScript into readable settings', function () { @@ -36,6 +37,7 @@ expect($result['status'])->toBe('ok'); expect($result['settings'])->toBeArray()->not->toBeEmpty(); + expect($result['settings'][0]['type'])->toBe('keyValue'); }); it('normalizes deviceHealthScript into readable settings', function () { @@ -52,4 +54,5 @@ expect($result['status'])->toBe('ok'); expect($result['settings'])->toBeArray()->not->toBeEmpty(); + expect($result['settings'][0]['type'])->toBe('keyValue'); });