Edit an existing assignment instead of delete-then-re-add (Fixes #57) - #74
Open
juandresrodca wants to merge 1 commit into
Open
Edit an existing assignment instead of delete-then-re-add (Fixes #57)#74juandresrodca wants to merge 1 commit into
juandresrodca wants to merge 1 commit into
Conversation
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
marked this pull request as ready for review
July 31, 2026 22:09
Contributor
Author
|
Let me know if is require some change on the code. |
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.
Edit an existing assignment instead of delete-then-re-add (Fixes #57)
Problem (root cause)
AddAssignmentButton.ps1fetches 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 appalready 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-SameAssignmentTargetmatches:All Users/All Devices: virtual targets with nogroupId, matched on@odata.typealone.@odata.typeandgroupId.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
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).
[All Devices no-filter] + [Group g1], addingAll Devices + filtergives[Group g1] + [All Devices WITH filter](the filterless one isreplaced).
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).