MANGO-2945 Add a script that finds EMS dangling references - #33
Open
MertCingoz wants to merge 1 commit into
Open
MANGO-2945 Add a script that finds EMS dangling references#33MertCingoz wants to merge 1 commit into
MertCingoz wants to merge 1 commit into
Conversation
Deleting a role does not remove its xid from the Platform Manager (EMS) JSON stores, and the editors cannot remove an xid that no longer resolves to a role, so the ghost xid stays visible in the Site, Device, Device Type and General Overview cards forever. The script reports these and, with dryRun turned off, removes them. It also reports every other kind of dangling reference in those stores - sites, device types, devices, watch lists and custom pages - without changing them, since the right repair there is a judgement call per entity.
jazdw
approved these changes
Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ems-dangling-references.js, a script that reports references to things that no longerexist in the Platform Manager (EMS) JSON stores, and removes the dangling role xids.
still appear.
Current behavior
Deleting a role does not remove its xid from the EMS stores, and the editors cannot remove an xid
that no longer resolves to a role, so it stays visible in the Site, Device, Device Type and
General Overview cards forever. Other broken pointers in those stores (a device pointing at a
deleted site, a tab naming a deleted watch list) are just as invisible.
Expected behavior
One run reports every dangling reference, each addressed by store xid plus a JSON pointer. With
dryRun = falsethe dangling role xids are removed; that grants and revokes nothing, since a rolexid that does not resolve is already dropped when the permission is evaluated
(
EmsService#hasPermission). Everything else is reported only — the right repair there is ajudgement call per entity.
Changes
New file
ems-dangling-references.js, withdryRun(defaulttrue) andauditOtherReferences(default
true) at the top.readPermissions/<name>ReadPermissionsarray as rolexids, so card locations added later are covered. Writes are one re-read-then-write per array, so
a concurrent Platform Manager edit is skipped rather than clobbered, and each is audited. Arrays
pruned to nothing are flagged — they become superadmin-only, which they already were in practice.
xid,Device.siteXid,Device.deviceTypeXid,DeviceType.sites[], site columns whosedeviceIDmatches no device, andWATCHLIST/DASHBOARDtabs naming a missing watch list or page."missing" is not a fact there and wants its own report.
Resources
Report shape (dry run):
Tests
Run against Mango 5.7.5 with roles deleted out from under the EMS stores: the dry run matches the
xids the cards show as unremovable,
dryRun = falseclears them, and a re-run finds nothing left.Take a configuration export with "JSON Data" selected before turning
dryRunoff.Checklist