-
Notifications
You must be signed in to change notification settings - Fork 502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix BadRequest error when trying to remove AADUser group memberships #5418
base: Dev
Are you sure you want to change the base?
Conversation
…g to remove user group membership
…en trying to remove AADUser group membership
…en trying to remove AADUser group membership
There is an issue in the code with $user.id on the function Set-TargetResource, $user is created in line 425 as a result of calling Get-TargetResource without Id Depending on the if in line 505, $user gets updated on line 561. In this case, if updated it will have the Id property When changing group membership, the operation will fail if the Id property is not updated. |
Hi @snunezMSFT, thanks for submitting this PR. Could you please also add an entry to the changelog, so we can keep track of all changes in a version? |
Thanks Yorik, I have updated the changelog adding one line describing the issue fixed. |
The problem here is the missing ' in the filter when calling Get-MgGroup, why are you making additional requests to Graph to call Get-MgUser? New-MgUser is supposed to return the Id of the just created object, if that's not the case and the reason behind why you call Get-MgUser then that it's an additional issue to the one that you originally reported and should be addressed separately or at least documented. |
I see, that works when it's a new user it works but not for other cases. It's better if you instead return the Id of the user in Get-TargetResource and add it as parameter, that way you don't have to make additional requests to Graph to find out the Id. |
Thanks @ricmestre, yes, as you stated the issue is that the code works when there is a new user, but not for existing users. I have added the Get-MgUser as I see it later in the code for managing RoleMemberships around line 679. Calling Get-MgUser everytime is less efficient, but it has less impact in the existing behavior. One improvement is to call it earlier in the code and save the value in $userId. So if it is a new user, the $userId will be $user.Id, when it is an existing user, then $userId is the result for calling one time Get-MgUser |
…Set-TargetResource function
To avoid multiple calls to Get-MgUser as @ricmestre has suggested, I have changed the code for using $userId for User Id when changing role and group membership in Set-TargetResource function. Role changes already had the call for Get-MgUser (now redundant). Group changes were missing the Id if the user is not new |
Pull Request (PR) description
This Pull Request (PR) fixes the following issues