Policies: Vergleich als zweispaltige Gegenüberstellung (A | B)

Statt gestapelter JSON-Blöcke jetzt eine Tabelle: pro settingDefinitionId eine
Zeile mit Wert A neben Wert B. Kompakter, lesbarer Kurzwert (Get-SettingDisplayValue:
Choice/Simple/Collections) im Vordergrund, volles kanonisches JSON als Tooltip.
Status-Einfärbung (unterschiedlich/nur A/nur B/gleich) + Filter "nur Unterschiede".
Endpoint liefert dafür vereinheitlichte rows (Union der Keys) mit short/full je Seite.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
marcoandClaude Opus 4.8 committed 2026-10-19 13:31:25 +02:00
1 parent e35005e489
commit 19e479a08d
3 files changed
+113 -61

No files matched your search

+61 -20
View File
@@ -1121,9 +1121,42 @@ function Invoke-PolicyConsolidateEndpoint {
# ============================================================
# Zwei Settings-Catalog-Policies vergleichen (Diff nach settingDefinitionId)
# ============================================================
# Body: { ids:[idA, idB] }. Liefert: nur in A / nur in B / gleich / unterschiedlich.
# Nutzt dieselbe Extraktion wie die Konsolidierung (Get-SettingDefinitionId +
# Get-SettingCanonicalJson -> kanonischer Wert-Vergleich).
# Kompakter, lesbarer Wert einer settingInstance (fuer die Gegenueberstellung).
# Best-effort: Choice -> letzte Wert-Komponente, Simple -> Wert, Collections -> Liste/Anzahl.
# Das volle (kanonische) JSON bleibt separat erhalten.
function Get-SettingDisplayValue {
param($SettingElement)
$si = Get-PolicyProp $SettingElement 'settingInstance'
if (-not $si) { $si = $SettingElement }
$cv = Get-PolicyProp $si 'choiceSettingValue'
if ($cv) {
$v = [string](Get-PolicyProp $cv 'value')
$tail = ($v -split '_')[-1]
$kids = @(Get-PolicyProp $cv 'children') | Where-Object { $_ }
if (@($kids).Count -gt 0) { return "$tail (+$(@($kids).Count) Unter)" }
return $tail
}
$sv = Get-PolicyProp $si 'simpleSettingValue'
if ($sv) { return [string](Get-PolicyProp $sv 'value') }
$scv = @(Get-PolicyProp $si 'simpleSettingCollectionValue') | Where-Object { $_ }
if (@($scv).Count -gt 0) {
$joined = (@($scv | ForEach-Object { [string](Get-PolicyProp $_ 'value') }) -join ', ')
if ($joined.Length -gt 140) { $joined = $joined.Substring(0, 137) + '...' }
return $joined
}
$ccv = @(Get-PolicyProp $si 'choiceSettingCollectionValue') | Where-Object { $_ }
if (@($ccv).Count -gt 0) {
return (@($ccv | ForEach-Object { ([string](Get-PolicyProp $_ 'value') -split '_')[-1] }) -join ', ')
}
$gcv = @(Get-PolicyProp $si 'groupSettingCollectionValue') | Where-Object { $_ }
if (@($gcv).Count -gt 0) { return "$(@($gcv).Count) Gruppe(n)" }
return ''
}
# Body: { ids:[idA, idB] }. Liefert A/B-Metadaten + vereinheitlichte Zeilen (Union
# der settingDefinitionId), jede mit Status (same|different|onlyA|onlyB) sowie
# Kurzwert und vollem (kanonischem) Wert je Seite - fuer die Gegenueberstellung.
function Invoke-PolicyCompareEndpoint {
param($Body)
try { Assert-GraphConnected } catch { return @{ __status = 401; error = 'Nicht mit Microsoft Graph verbunden' } }
@@ -1141,7 +1174,7 @@ function Invoke-PolicyCompareEndpoint {
if (-not $el) { continue }
$defId = Get-SettingDefinitionId $el
if (-not $defId) { continue }
$map[$defId] = Get-SettingCanonicalJson $el
$map[$defId] = @{ canon = Get-SettingCanonicalJson $el; short = Get-SettingDisplayValue $el }
}
$pols += @{
id = [string]$id
@@ -1153,28 +1186,36 @@ function Invoke-PolicyCompareEndpoint {
}
$a = $pols[0]; $b = $pols[1]
$onlyA = @(); $onlyB = @(); $same = @(); $different = @()
foreach ($k in @($a.map.Keys)) {
if ($b.map.Contains($k)) {
if ($a.map[$k] -eq $b.map[$k]) { $same += @{ settingDefinitionId = $k; value = $a.map[$k] } }
else { $different += @{ settingDefinitionId = $k; valueA = $a.map[$k]; valueB = $b.map[$k] } }
} else {
$onlyA += @{ settingDefinitionId = $k; value = $a.map[$k] }
}
}
foreach ($k in @($b.map.Keys)) {
if (-not $a.map.Contains($k)) { $onlyB += @{ settingDefinitionId = $k; value = $b.map[$k] } }
# Union der Keys: A-Reihenfolge, dann die nur in B vorhandenen anhaengen.
$keys = [System.Collections.Generic.List[string]]::new()
foreach ($k in @($a.map.Keys)) { [void]$keys.Add([string]$k) }
foreach ($k in @($b.map.Keys)) { if (-not $a.map.Contains($k)) { [void]$keys.Add([string]$k) } }
$rows = @()
$cDiff = 0; $cOnlyA = 0; $cOnlyB = 0; $cSame = 0
foreach ($k in $keys) {
$inA = $a.map.Contains($k); $inB = $b.map.Contains($k)
$ea = $null; $eb = $null
if ($inA) { $ea = $a.map[$k] }
if ($inB) { $eb = $b.map[$k] }
$status = ''
if ($inA -and $inB) {
if ($ea.canon -eq $eb.canon) { $status = 'same'; $cSame++ } else { $status = 'different'; $cDiff++ }
} elseif ($inA) { $status = 'onlyA'; $cOnlyA++ } else { $status = 'onlyB'; $cOnlyB++ }
$row = [ordered]@{ id = $k; status = $status }
if ($inA) { $row['shortA'] = $ea.short; $row['fullA'] = $ea.canon }
if ($inB) { $row['shortB'] = $eb.short; $row['fullB'] = $eb.canon }
$rows += $row
}
return @{
ok = $true
a = @{ id = $a.id; name = $a.name; platform = $a.platform; count = $a.count }
b = @{ id = $b.id; name = $b.name; platform = $b.platform; count = $b.count }
onlyA = @($onlyA)
onlyB = @($onlyB)
same = @($same)
different = @($different)
counts = @{ onlyA = @($onlyA).Count; onlyB = @($onlyB).Count; same = @($same).Count; different = @($different).Count }
rows = @($rows)
counts = @{ different = $cDiff; onlyA = $cOnlyA; onlyB = $cOnlyB; same = $cSame }
}
}
+34 -28
View File
@@ -6619,6 +6619,7 @@ document.getElementById('polConsConfirm')?.addEventListener('click', polDoConsol
// Policies vergleichen (zwei Settings-Catalog-Policies -> Diff)
// =============================================================
let _polCmpResult = null;
let _polCmpOnlyDiff = false;
async function openPolCompare() {
const keys = [...PolState.selected].filter(k => k.startsWith('settingscatalog::'));
@@ -6645,48 +6646,53 @@ function polCmpShortId(id) {
return `<span class="pol-cmp-id" title="${escapeHtml(s)}"><b>${escapeHtml(tail)}</b> <span class="muted">${escapeHtml(s)}</span></span>`;
}
function polCmpVal(v) {
return `<code class="pol-cmp-val">${escapeHtml(String(v ?? ''))}</code>`;
// Eine Wert-Zelle (Kurzwert sichtbar, volles JSON als Tooltip). Leer = „—".
function polCmpCell(short, full, extraCls) {
if (short == null && full == null) return '<div class="pol-cmp-c empty">—</div>';
const s = (short === '' || short == null) ? '∅' : short;
return `<div class="pol-cmp-c ${extraCls || ''}" title="${escapeHtml(full || '')}">${escapeHtml(s)}</div>`;
}
function renderPolCompare(res) {
_polCmpResult = res;
const c = res.counts || {};
const aName = res.a?.name || 'A', bName = res.b?.name || 'B';
document.getElementById('polCmpSummary').innerHTML =
`<div class="pol-cmp-head">`
+ `<div><b>A:</b> ${escapeHtml(res.a?.name || '—')} <span class="muted">(${res.a?.count ?? 0} Settings · ${escapeHtml(res.a?.platform || '')})</span></div>`
+ `<div><b>B:</b> ${escapeHtml(res.b?.name || '—')} <span class="muted">(${res.b?.count ?? 0} Settings · ${escapeHtml(res.b?.platform || '')})</span></div>`
+ `</div>`
+ `<div class="pol-cmp-counts">`
`<div class="pol-cmp-counts">`
+ `<span class="pol-cmp-badge diff">${c.different || 0} unterschiedlich</span>`
+ `<span class="pol-cmp-badge a">${c.onlyA || 0} nur in A</span>`
+ `<span class="pol-cmp-badge b">${c.onlyB || 0} nur in B</span>`
+ `<span class="pol-cmp-badge same">${c.same || 0} gleich</span>`
+ `<label class="pol-cmp-filter"><input type="checkbox" id="polCmpOnlyDiff" ${_polCmpOnlyDiff ? 'checked' : ''}> Nur Unterschiede</label>`
+ `</div>`;
const cb = document.getElementById('polCmpOnlyDiff');
if (cb) cb.onchange = () => { _polCmpOnlyDiff = cb.checked; renderPolCompare(_polCmpResult); };
const rows = (res.rows || []).filter(r => _polCmpOnlyDiff ? r.status !== 'same' : true);
const header =
`<div class="pol-cmp-trow head">`
+ `<div class="pol-cmp-setting">Einstellung (${(res.rows || []).length})</div>`
+ `<div class="pol-cmp-c col-a" title="${escapeHtml(aName)}">A · ${escapeHtml(aName)}</div>`
+ `<div class="pol-cmp-c col-b" title="${escapeHtml(bName)}">B · ${escapeHtml(bName)}</div>`
+ `</div>`;
const sect = (title, cls, rows) => rows.length
? `<div class="pol-cmp-sect"><div class="pol-cmp-sect-h ${cls}">${title} (${rows.length})</div>${rows.join('')}</div>`
: '';
const bodyRows = rows.map(r => {
const diffCls = r.status === 'different' ? 'diff' : '';
return `<div class="pol-cmp-trow ${r.status}">`
+ `<div class="pol-cmp-setting">${polCmpShortId(r.id)}</div>`
+ polCmpCell(r.shortA, r.fullA, diffCls)
+ polCmpCell(r.shortB, r.fullB, diffCls)
+ `</div>`;
}).join('');
const diffRows = (res.different || []).map(r =>
`<div class="pol-cmp-row diff">${polCmpShortId(r.settingDefinitionId)}`
+ `<div class="pol-cmp-ab"><span class="pol-cmp-side"><b>A</b> ${polCmpVal(r.valueA)}</span>`
+ `<span class="pol-cmp-side"><b>B</b> ${polCmpVal(r.valueB)}</span></div></div>`);
const onlyARows = (res.onlyA || []).map(r =>
`<div class="pol-cmp-row">${polCmpShortId(r.settingDefinitionId)} ${polCmpVal(r.value)}</div>`);
const onlyBRows = (res.onlyB || []).map(r =>
`<div class="pol-cmp-row">${polCmpShortId(r.settingDefinitionId)} ${polCmpVal(r.value)}</div>`);
const sameRows = (res.same || []).map(r =>
`<div class="pol-cmp-row">${polCmpShortId(r.settingDefinitionId)} ${polCmpVal(r.value)}</div>`);
document.getElementById('polCmpBody').innerHTML =
sect('Unterschiedlich', 'diff', diffRows)
+ sect('Nur in A', 'a', onlyARows)
+ sect('Nur in B', 'b', onlyBRows)
+ sect('Gleich', 'same', sameRows)
|| '<div class="muted">Keine Einstellungen zum Vergleichen.</div>';
document.getElementById('polCmpBody').innerHTML = rows.length
? `<div class="pol-cmp-table">${header}${bodyRows}</div>`
: '<div class="muted" style="padding:8px;">Keine Einstellungen (mit aktivem Filter).</div>';
document.getElementById('polCmpInfo').textContent =
`${(res.a?.count ?? 0)} ↔ ${(res.b?.count ?? 0)} Settings`;
`A: ${res.a?.count ?? 0} · B: ${res.b?.count ?? 0} Settings`;
}
document.getElementById('btnPolCompare')?.addEventListener('click', openPolCompare);
+18 -13
View File
@@ -5499,20 +5499,25 @@ body.read-only .app-row {
.pol-cmp-badge.a { background: rgba(96,165,250,.15); color: #60a5fa; }
.pol-cmp-badge.b { background: rgba(167,139,250,.15); color: #a78bfa; }
.pol-cmp-badge.same { background: rgba(74,222,128,.15); color: #4ade80; }
.pol-cmp-sect { margin-top: 12px; }
.pol-cmp-sect-h { font-weight: 600; font-size: 12.5px; padding: 4px 8px; border-radius: 6px; margin-bottom: 4px; background: var(--hairline-soft); }
.pol-cmp-sect-h.diff { background: rgba(251,191,36,.12); color: #fbbf24; }
.pol-cmp-sect-h.a { background: rgba(96,165,250,.12); color: #60a5fa; }
.pol-cmp-sect-h.b { background: rgba(167,139,250,.12); color: #a78bfa; }
.pol-cmp-sect-h.same { background: rgba(74,222,128,.12); color: #4ade80; }
.pol-cmp-row { padding: 5px 8px; border-bottom: 1px solid var(--hairline-soft, rgba(255,255,255,.06)); font-size: 12.5px; }
.pol-cmp-row:last-child { border-bottom: 0; }
.pol-cmp-filter { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; }
.pol-cmp-id { display: inline-block; }
.pol-cmp-id .muted { font-size: 11px; word-break: break-all; }
.pol-cmp-val { display: inline-block; font-size: 11.5px; background: var(--bg3, var(--hover)); padding: 1px 6px; border-radius: 4px; word-break: break-all; }
.pol-cmp-ab { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 3px; }
.pol-cmp-side { flex: 1 1 240px; }
.pol-cmp-side b { color: var(--text-dim, #888); margin-right: 4px; }
.pol-cmp-id .muted { font-size: 10.5px; word-break: break-all; }
/* Zweispaltige Gegenueberstellung A | B */
.pol-cmp-table { display: grid; grid-template-columns: minmax(200px, 1.5fr) 1fr 1fr; border: 1px solid var(--hairline, #333); border-radius: 8px; overflow: hidden; font-size: 12px; }
.pol-cmp-trow { display: contents; }
.pol-cmp-trow > div { padding: 6px 8px; border-bottom: 1px solid var(--hairline-soft, rgba(255,255,255,.06)); min-width: 0; }
.pol-cmp-trow.head > div { position: sticky; top: 0; background: var(--bg3, var(--hover)); font-weight: 600; z-index: 1; }
.pol-cmp-trow.head .col-a { color: #60a5fa; }
.pol-cmp-trow.head .col-b { color: #a78bfa; }
.pol-cmp-setting { background: var(--canvas); }
.pol-cmp-c { word-break: break-all; }
.pol-cmp-c.empty { color: var(--muted, #777); text-align: center; }
.pol-cmp-c.diff { background: rgba(251,191,36,.12); color: #fbbf24; font-weight: 600; }
/* Zeilen-Einfaerbung nach Status (dezent) */
.pol-cmp-trow.onlyA .pol-cmp-setting { box-shadow: inset 3px 0 0 #60a5fa; }
.pol-cmp-trow.onlyB .pol-cmp-setting { box-shadow: inset 3px 0 0 #a78bfa; }
.pol-cmp-trow.different .pol-cmp-setting { box-shadow: inset 3px 0 0 #fbbf24; }
.pol-cmp-trow.same .pol-cmp-c { color: var(--text-dim, #999); }
.pol-cons-src { margin: 6px 0 0; padding-left: 18px; font-size: 12px; }
.pol-cons-src li { margin: 1px 0; }
.pol-cons-conf-head { margin: 14px 0 6px; font-weight: 600; font-size: 13px; }