-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
!deploy v2.24.0 - add Revoke-GSStudentGuardianInvitation
## 2.24.0 * [Issue #159](#159) - [@Foggy2](https://github.com/Foggy2) * Added: `Revoke-GSStudentGuardianInvitation` to revoke student guardian invitations (Classroom API)
- Loading branch information
Showing
4 changed files
with
112 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
102 changes: 102 additions & 0 deletions
102
PSGSuite/Public/Classroom/Revoke-GSStudentGuardianInvitation.ps1
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
function Revoke-GSStudentGuardianInvitation { | ||
<# | ||
.SYNOPSIS | ||
Revokes a student guardian invitation. | ||
.DESCRIPTION | ||
Revokes a student guardian invitation. | ||
This method returns the following error codes: | ||
* PERMISSION_DENIED if the current user does not have permission to manage guardians, if guardians are not enabled for the domain in question or for other access errors. | ||
* FAILED_PRECONDITION if the guardian link is not in the PENDING state. | ||
* INVALID_ARGUMENT if the format of the student ID provided cannot be recognized (it is not an email address, nor a user_id from this API), or if the passed GuardianInvitation has a state other than COMPLETE, or if it modifies fields other than state. | ||
* NOT_FOUND if the student ID provided is a valid student ID, but Classroom has no record of that student, or if the id field does not refer to a guardian invitation known to Classroom. | ||
.PARAMETER StudentId | ||
The ID of the student whose guardian invitation is to be revoked. The identifier can be one of the following: | ||
* the numeric identifier for the user | ||
* the email address of the user | ||
.PARAMETER InvitationId | ||
The id field of the GuardianInvitation to be revoked. | ||
.PARAMETER User | ||
The user to authenticate the request as | ||
.EXAMPLE | ||
Revoke-GSStudentGuardianInvitation -StudentId [email protected] -InvitationId $invitationId | ||
.EXAMPLE | ||
Import-Csv .\Student_Guardian_List_To_Revoke.csv | Revoke-GSStudentGuardianInvitation | ||
Process a CSV with two columns containing headers "Student" and "Guardian" and revokes the invites accordingly, i.e. | ||
| StudentId | InvitationId | | ||
|:--------------------:|:------------------:| | ||
| [email protected] | 198okj4k9827872177 | | ||
| [email protected] | 09120uuip21ru0ff0u | | ||
#> | ||
[OutputType('Google.Apis.Classroom.v1.Data.GuardianInvitation')] | ||
[cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact = "High")] | ||
Param | ||
( | ||
[parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] | ||
[Alias('Student')] | ||
[String] | ||
$StudentId, | ||
[parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)] | ||
[Alias('Invitation','InviteId','Invite')] | ||
[String[]] | ||
$InvitationId, | ||
[parameter(Mandatory = $false)] | ||
[String] | ||
$User = $Script:PSGSuite.AdminEmail | ||
) | ||
Begin { | ||
if ($User -ceq 'me') { | ||
$User = $Script:PSGSuite.AdminEmail | ||
} | ||
elseif ($User -notlike "*@*.*") { | ||
$User = "$($User)@$($Script:PSGSuite.Domain)" | ||
} | ||
$serviceParams = @{ | ||
Scope = 'https://www.googleapis.com/auth/classroom.guardianlinks.students' | ||
ServiceType = 'Google.Apis.Classroom.v1.ClassroomService' | ||
User = $User | ||
} | ||
$service = New-GoogleService @serviceParams | ||
} | ||
Process { | ||
if ( -not ($StudentId -as [decimal])) { | ||
if ($StudentId -ceq 'me') { | ||
$StudentId = $Script:PSGSuite.AdminEmail | ||
} | ||
elseif ($StudentId -notlike "*@*.*") { | ||
$StudentId = "$($StudentId)@$($Script:PSGSuite.Domain)" | ||
} | ||
} | ||
foreach ($invId in $InvitationId) { | ||
try { | ||
if ($PSCmdlet.ShouldProcess("Revoking Guardian Invitation '$invId' for Student '$StudentId'")) { | ||
Write-Verbose "Revoking Guardian Invitation '$invId' for Student '$StudentId'" | ||
$body = New-Object 'Google.Apis.Classroom.v1.Data.GuardianInvitation' -Property @{ | ||
State = "COMPLETE" | ||
} | ||
$request = $service.UserProfiles.GuardianInvitations.Patch($body,$StudentId,$invId) | ||
$request.UpdateMask = "state" | ||
$request.Execute() | ||
} | ||
} | ||
catch { | ||
if ($ErrorActionPreference -eq 'Stop') { | ||
$PSCmdlet.ThrowTerminatingError($_) | ||
} | ||
else { | ||
Write-Error $_ | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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