Skip to content
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

Add Support for UserRelations #129

Closed
mattwoolnough opened this issue Dec 11, 2018 · 9 comments
Closed

Add Support for UserRelations #129

mattwoolnough opened this issue Dec 11, 2018 · 9 comments
Assignees

Comments

@mattwoolnough
Copy link
Contributor

Add Support for UserRelation

https://developers.google.com/resources/api-libraries/documentation/admin/directory_v1/java/latest/com/google/api/services/admin/directory/model/class-use/UserRelation.html

@mattwoolnough
Copy link
Contributor Author

mattwoolnough commented Dec 12, 2018

Looking for some ideas on how to implement the deletion of relations.

To remove a relation via the HTTP API, a PUT of an empty JSON array is required:

{
 "relations": []  
}

@scrthq
Copy link
Member

scrthq commented Dec 14, 2018

@mattwoolnough - I believe I implemented something on another function for a similar purpose, let me try and dig it out. IIRC, you need to set the value as an empty generic list if the parameter is used in $PSBoundParameters but is $null. Give me a bit =]

@mattwoolnough
Copy link
Contributor Author

Sorry, to delete the JSON below is required. Did you happen to find the code you were thinking of?

{
 "relations": null  
}

@scrthq
Copy link
Member

scrthq commented Dec 19, 2018

@mattwoolnough - still hunting for it, but I know that the .NET SDK regards sending $null as not being sent at all, not a deliberate $null. I see your PR as well. I've been pretty slammed with normal work + family + holidays, so my sincere apologies for not being as quick on the response and deploying your PR's as well! Working on pulling in a few additional things into the next release as well if possible, so it's been a battle.

@scrthq
Copy link
Member

scrthq commented Dec 19, 2018

have you tried just sending $null as the value for that property with a call to Update-GSUser? The section in the switch statement should still create a blank list and submit that, if I remember correctly.

@scrthq
Copy link
Member

scrthq commented Dec 19, 2018

disregard, just tested and that didn't do anything (at least for Relations anyway)

@scrthq
Copy link
Member

scrthq commented Dec 19, 2018

Alright, found the bit of code that I was thinking of similar to removing values:

#16 (comment)

Did some testing based on this and the following works (although is does leave a null reference for the Relation value when pulling the user information via API):


Before (view from Admin console and view from $user.Relations):

image

image


After:

Update-GSUser -User $user.PrimaryEmail -Relations (Add-GSUserRelation -Type manager -Value $null)

image

image

@scrthq
Copy link
Member

scrthq commented Dec 19, 2018

alright, that's going to be the only applicable approach for clearing the value of a single relation/phone/etc. I've looked at your code in your PR for Remove-GSUserPhone and have applied something more widespread directly on Update-GSUser to allow passing $null as the value to clear out all entries for that property type.

Example in use:

Update-GSUser -User $user.PrimaryEmail -Relations $null

image

scrthq added a commit that referenced this issue Dec 19, 2018
## 2.21.0

* [PR #130](#130) / [Issue #129](#129)
  * Added: Support for UserRelations management in `New-GSUser -Relations $relations` and `Update-GSUser -Relations $relations` via `Add-GSUserRelation` helper function. - _Thanks, [@mattwoolnough](https://github.com/mattwoolnough)!_
  * Added: Logic to `Update-GSUser` to enable clearing of all values for user properties `Phones`, `ExternalIds`, `Organizations`, and `Relations` by REST API call via passing `$null` as the value when calling `Update-GSUser`. - _Thanks, [@mattwoolnough](https://github.com/mattwoolnough)!_
* [Issue #129](#129)
  * Fixed: Documentation for `Get-GSSheetInfo` around the `Fields` parameter.
  * Added: Additional correction of casing for `Fields` values in `Get-GSSheetInfo` so that it will always submit the values using the correct case, even if providing the incorrect case as the value to the parameter.
@scrthq
Copy link
Member

scrthq commented Dec 19, 2018

@mattwoolnough - Thanks for the contributions around this! UserRelation support is out now in v2.21.0. I've also included the updated logic for clearing out ExternalIds, Phones, Relations, and Organizations into Update-GSUser via passing $null as the value for those parameters. As noted, if you need to clear out a specific item, just pass $null for the value of the item on the appropriate helper function.

Let me know if you have any questions regarding this!

@scrthq scrthq closed this as completed Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants