013-scripts-management #19
@ -27,16 +27,16 @@ public function normalize(?array $snapshot, string $policyType, ?string $platfor
|
|||||||
$displayName = Arr::get($snapshot, 'displayName') ?? Arr::get($snapshot, 'name');
|
$displayName = Arr::get($snapshot, 'displayName') ?? Arr::get($snapshot, 'name');
|
||||||
$description = Arr::get($snapshot, 'description');
|
$description = Arr::get($snapshot, 'description');
|
||||||
|
|
||||||
$settings = [];
|
$entries = [];
|
||||||
|
|
||||||
$settings[] = ['key' => 'Type', 'value' => $policyType];
|
$entries[] = ['key' => 'Type', 'value' => $policyType];
|
||||||
|
|
||||||
if (is_string($displayName) && $displayName !== '') {
|
if (is_string($displayName) && $displayName !== '') {
|
||||||
$settings[] = ['key' => 'Display name', 'value' => $displayName];
|
$entries[] = ['key' => 'Display name', 'value' => $displayName];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_string($description) && $description !== '') {
|
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.
|
// 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);
|
$value = Arr::get($snapshot, $key);
|
||||||
|
|
||||||
if (is_string($value) && $value !== '') {
|
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');
|
$schedule = Arr::get($snapshot, 'runSchedule');
|
||||||
if (is_array($schedule) && $schedule !== []) {
|
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');
|
$frequency = Arr::get($snapshot, 'runFrequency');
|
||||||
if (is_string($frequency) && $frequency !== '') {
|
if (is_string($frequency) && $frequency !== '') {
|
||||||
$settings[] = ['key' => 'Run frequency', 'value' => $frequency];
|
$entries[] = ['key' => 'Run frequency', 'value' => $frequency];
|
||||||
}
|
}
|
||||||
|
|
||||||
$roleScopeTagIds = Arr::get($snapshot, 'roleScopeTagIds');
|
$roleScopeTagIds = Arr::get($snapshot, 'roleScopeTagIds');
|
||||||
if (is_array($roleScopeTagIds) && $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 [
|
return [
|
||||||
'status' => 'ok',
|
'status' => 'ok',
|
||||||
'settings' => $settings,
|
'settings' => [
|
||||||
|
[
|
||||||
|
'type' => 'keyValue',
|
||||||
|
'title' => 'Script settings',
|
||||||
|
'entries' => $entries,
|
||||||
|
],
|
||||||
|
],
|
||||||
'warnings' => [],
|
'warnings' => [],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -85,6 +91,6 @@ public function flattenForDiff(?array $snapshot, string $policyType, ?string $pl
|
|||||||
{
|
{
|
||||||
$normalized = $this->normalize($snapshot, $policyType, $platform);
|
$normalized = $this->normalize($snapshot, $policyType, $platform);
|
||||||
|
|
||||||
return $this->defaultNormalizer->flattenForDiff($normalized['settings'] ?? []);
|
return $this->defaultNormalizer->flattenNormalizedForDiff($normalized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,7 +65,11 @@
|
|||||||
|
|
||||||
{{-- Settings Blocks (for OMA Settings, Key/Value pairs, etc.) --}}
|
{{-- Settings Blocks (for OMA Settings, Key/Value pairs, etc.) --}}
|
||||||
@foreach($settings as $block)
|
@foreach($settings as $block)
|
||||||
@if($block['type'] === 'table')
|
@php
|
||||||
|
$blockType = is_array($block) ? ($block['type'] ?? null) : null;
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
@if($blockType === 'table')
|
||||||
<x-filament::section
|
<x-filament::section
|
||||||
:heading="$block['title'] ?? 'Settings'"
|
:heading="$block['title'] ?? 'Settings'"
|
||||||
collapsible
|
collapsible
|
||||||
@ -105,7 +109,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</x-filament::section>
|
</x-filament::section>
|
||||||
|
|
||||||
@elseif($block['type'] === 'keyValue')
|
@elseif($blockType === 'keyValue')
|
||||||
<x-filament::section
|
<x-filament::section
|
||||||
:heading="$block['title'] ?? 'Settings'"
|
:heading="$block['title'] ?? 'Settings'"
|
||||||
collapsible
|
collapsible
|
||||||
|
|||||||
@ -20,7 +20,8 @@
|
|||||||
|
|
||||||
expect($result['status'])->toBe('ok');
|
expect($result['status'])->toBe('ok');
|
||||||
expect($result['settings'])->toBeArray()->not->toBeEmpty();
|
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 () {
|
it('normalizes deviceShellScript into readable settings', function () {
|
||||||
@ -36,6 +37,7 @@
|
|||||||
|
|
||||||
expect($result['status'])->toBe('ok');
|
expect($result['status'])->toBe('ok');
|
||||||
expect($result['settings'])->toBeArray()->not->toBeEmpty();
|
expect($result['settings'])->toBeArray()->not->toBeEmpty();
|
||||||
|
expect($result['settings'][0]['type'])->toBe('keyValue');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('normalizes deviceHealthScript into readable settings', function () {
|
it('normalizes deviceHealthScript into readable settings', function () {
|
||||||
@ -52,4 +54,5 @@
|
|||||||
|
|
||||||
expect($result['status'])->toBe('ok');
|
expect($result['status'])->toBe('ok');
|
||||||
expect($result['settings'])->toBeArray()->not->toBeEmpty();
|
expect($result['settings'])->toBeArray()->not->toBeEmpty();
|
||||||
|
expect($result['settings'][0]['type'])->toBe('keyValue');
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user