Skip to content

Edit an existing assignment instead of delete-then-re-add (Fixes #57) - #74

Open
juandresrodca wants to merge 1 commit into
MG-Cloudflow:mainfrom
juandresrodca:feature/57-edit-existing-assignment
Open

Edit an existing assignment instead of delete-then-re-add (Fixes #57)#74
juandresrodca wants to merge 1 commit into
MG-Cloudflow:mainfrom
juandresrodca:feature/57-edit-existing-assignment

Conversation

@juandresrodca

@juandresrodca juandresrodca commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Edit an existing assignment instead of delete-then-re-add (Fixes #57)

⚠️ Needs dev-tenant validation before submitting. This changes a Graph mutating path
(/assign). The target-matching logic is unit-tested, but the end-to-end Graph result should be
confirmed in a test tenant first (see Testing).

Problem (root cause)

AddAssignmentButton.ps1 fetches the policy's current assignments, appends the new assignment,
and re-POSTs the whole set to /assign. When the selected target is already assigned (e.g. an app
already assigned to All Devices), the set then contains two assignments for the same target.
Graph ignores the duplicate, so a newly added include filter never takes effect, and the user has to
delete the assignment and re-create it (issue #57).

Fix

Before appending the new assignment, drop any existing assignment that targets the same audience,
so the new selection replaces it. A small helper Test-SameAssignmentTarget matches:

  • All Users / All Devices: virtual targets with no groupId, matched on @odata.type alone.
  • group include / exclude: matched on @odata.type and groupId.

Net effect: re-adding an already-assigned target now updates it (adds/changes the filter, intent,
or settings) instead of being ignored, which is the "edit assignment" behaviour requested.

Autopilot profiles are unaffected (they POST individual assignments and don't go through this set).

Testing

  • Unit-tested Test-SameAssignmentTarget (function extracted via AST): All Devices vs All Devices
    (match), All Devices vs All Users (no match), group g1 vs g1 (match), g1 vs g2 (no match), include g1
    vs exclude g1 (no match).
  • End-to-end (simulated): existing [All Devices no-filter] + [Group g1], adding
    All Devices + filter gives [Group g1] + [All Devices WITH filter] (the filterless one is
    replaced).
  • Parses with no new errors; no BOM/encoding changes.
  • Not yet validated against a live tenant. Recommended before merge: pick an app already assigned
    to All Devices, use Add Assignment on All Devices with an include filter, save, and confirm the
    filter now shows (and no duplicate/again-ignored behaviour).

Add Assignment always appended the new assignment and re-posted the full set to
/assign. When the chosen target was already assigned (e.g. All Devices), Graph
received two assignments for the same target and ignored the new one, so changes
such as adding an include filter never took effect - the user had to delete the
assignment and re-create it (issue MG-Cloudflow#57).

Before appending, drop any existing assignment that targets the same audience
(matched on @odata.type, plus groupId for group targets) so the new selection
replaces it. This lets an existing assignment be edited - for example adding a
filter to an All Devices assignment - without delete-then-re-add.

Fixes MG-Cloudflow#57
@juandresrodca
juandresrodca marked this pull request as ready for review July 31, 2026 22:09
@juandresrodca

Copy link
Copy Markdown
Contributor Author

Let me know if is require some change on the code.
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement request] Edit / update assignment

1 participant