Skip to content

Commit

Permalink
converted remaining TeamDrive functions to the new Drive namespace an…
Browse files Browse the repository at this point in the history
…d added Show/Hide-GSDrive functions for #197
  • Loading branch information
scrthq committed Jun 28, 2019
1 parent 469cbd9 commit 3b77528
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 89 deletions.
22 changes: 16 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* [PSGSuite - ChangeLog](#psgsuite---changelog)
* [PSGSuite - ChangeLog](#PSGSuite---ChangeLog)
* [2.29.0](#2290)
* [2.28.2](#2282)
* [2.28.1](#2281)
* [2.28.0](#2280)
Expand Down Expand Up @@ -80,16 +81,25 @@
* [2.0.2](#202)
* [2.0.1](#201)
* [2.0.0](#200)
* [New Functionality](#new-functionality)
* [Breaking Changes in 2.0.0](#breaking-changes-in-200)
* [Gmail Delegation Management Removed](#gmail-delegation-management-removed)
* [Functions Removed](#functions-removed)
* [Functions Aliased](#functions-aliased)
* [New Functionality](#New-Functionality)
* [Breaking Changes in 2.0.0](#Breaking-Changes-in-200)
* [Gmail Delegation Management Removed](#Gmail-Delegation-Management-Removed)
* [Functions Removed](#Functions-Removed)
* [Functions Aliased](#Functions-Aliased)

***

# PSGSuite - ChangeLog

## 2.29.0

* [Issue #201](https://github.com/scrthq/PSGSuite/issues/201)
* Fixed: Fields parameter on remaining `*-GSDriveFile` functions
* [Issue #197](https://github.com/scrthq/PSGSuite/issues/197)
* Updated: All remaining `*-TeamDrive` functions now use the new Drives namespace. All previous functions names have been converted to aliases to maintain backwards compatibility.
* Added: `Hide-GSDrive`
* Added: `Show-GSDrive`

## 2.28.2

* [Issue #194](https://github.com/scrthq/PSGSuite/issues/194)
Expand Down
4 changes: 4 additions & 0 deletions PSGSuite/Aliases/PSGSuite.Aliases.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Alias => => => => => => => => Function
@{
'Add-GSDriveFilePermissions' = 'Add-GSDrivePermission'
'Export-PSGSuiteConfiguration' = 'Set-PSGSuiteConfig'
Expand Down Expand Up @@ -33,10 +34,13 @@
'Import-PSGSuiteConfiguration' = 'Get-PSGSuiteConfig'
'Move-GSGmailMessageToTrash' = 'Remove-GSGmailMessage'
'New-GSCalendarResource' = 'New-GSResource'
'New-GSTeamDrive' = 'New-GSDrive'
'Remove-GSGmailMessageFromTrash' = 'Restore-GSGmailMessage'
'Remove-GSTeamDrive' = 'Remove-GSDrive'
'Set-PSGSuiteDefaultDomain' = 'Switch-PSGSuiteConfig'
'Switch-PSGSuiteDomain' = 'Switch-PSGSuiteConfig'
'Update-GSCalendarResource' = 'Update-GSResource'
'Update-GSGmailSendAsSettings' = 'Update-GSGmailSendAsAlias'
'Update-GSSheetValue' = 'Export-GSSheet'
'Update-GSTeamDrive' = 'Update-GSDrive'
}
64 changes: 64 additions & 0 deletions PSGSuite/Public/Drive/Hide-GSDrive.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
function Hide-GSDrive {
<#
.SYNOPSIS
Hides a Shared Drive from the default view
.DESCRIPTION
Hides a Shared Drive from the default view
.PARAMETER DriveId
The unique Id of the Shared Drive to hide
.PARAMETER User
The email or unique Id of the user who you'd like to hide the Shared Drive for.
Defaults to the AdminEmail user.
.EXAMPLE
Hide-GSDrive -DriveId $driveIds
Hides the specified DriveIds for the AdminEmail user
#>
[OutputType('Google.Apis.Drive.v3.Data.Drive')]
[cmdletbinding()]
Param
(
[parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true,ParameterSetName = "Get")]
[Alias('Id','TeamDriveId')]
[String[]]
$DriveId,
[parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)]
[Alias('Owner','PrimaryEmail','UserKey','Mail')]
[string]
$User = $Script:PSGSuite.AdminEmail
)
Process {
if ($User -ceq 'me') {
$User = $Script:PSGSuite.AdminEmail
}
elseif ($User -notlike "*@*.*") {
$User = "$($User)@$($Script:PSGSuite.Domain)"
}
$serviceParams = @{
Scope = 'https://www.googleapis.com/auth/drive'
ServiceType = 'Google.Apis.Drive.v3.DriveService'
User = $User
}
$service = New-GoogleService @serviceParams
foreach ($id in $DriveId) {
try {
$request = $service.Drives.Hide($id)
Write-Verbose "Hiding Shared Drive '$id' for user '$User'"
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
function New-GSTeamDrive {
function New-GSDrive {
<#
.SYNOPSIS
Creates a new Team Drive
Creates a new Shared Drive
.DESCRIPTION
Creates a new Team Drive
Creates a new Shared Drive
.PARAMETER Name
The name of the Team Drive
The name of the Shared Drive
.PARAMETER User
The user to create the Team Drive for (must have permissions to create Team Drives)
The user to create the Shared Drive for (must have permissions to create Shared Drives)
.PARAMETER RequestId
An ID, such as a random UUID, which uniquely identifies this user's request for idempotent creation of a Team Drive. A repeated request by the same user and with the same request ID will avoid creating duplicates by attempting to create the same Team Drive. If the Team Drive already exists a 409 error will be returned.
An ID, such as a random UUID, which uniquely identifies this user's request for idempotent creation of a Shared Drive. A repeated request by the same user and with the same request ID will avoid creating duplicates by attempting to create the same Shared Drive. If the Shared Drive already exists a 409 error will be returned.
.PARAMETER CanAddChildren
Whether the current user can add children to folders in this Team Drive
Whether the current user can add children to folders in this Shared Drive
.PARAMETER CanChangeTeamDriveBackground
Whether the current user can change the background of this Team Drive
.PARAMETER CanChangeDriveBackground
Whether the current user can change the background of this Shared Drive
.PARAMETER CanComment
Whether the current user can comment on files in this Team Drive
Whether the current user can comment on files in this Shared Drive
.PARAMETER CanCopy
Whether the current user can copy files in this Team Drive
Whether the current user can copy files in this Shared Drive
.PARAMETER CanDeleteTeamDrive
Whether the current user can delete this Team Drive. Attempting to delete the Team Drive may still fail if there are untrashed items inside the Team Drive
.PARAMETER CanDeleteDrive
Whether the current user can delete this Shared Drive. Attempting to delete the Shared Drive may still fail if there are untrashed items inside the Shared Drive
.PARAMETER CanDownload
Whether the current user can download files in this Team Drive
Whether the current user can download files in this Shared Drive
.PARAMETER CanEdit
Whether the current user can edit files in this Team Drive
Whether the current user can edit files in this Shared Drive
.PARAMETER CanListChildren
Whether the current user can list the children of folders in this Team Drive
Whether the current user can list the children of folders in this Shared Drive
.PARAMETER CanManageMembers
Whether the current user can add members to this Team Drive or remove them or change their role
Whether the current user can add members to this Shared Drive or remove them or change their role
.PARAMETER CanReadRevisions
Whether the current user can read the revisions resource of files in this Team Drive
Whether the current user can read the revisions resource of files in this Shared Drive
.PARAMETER CanRemoveChildren
Whether the current user can remove children from folders in this Team Drive
Whether the current user can remove children from folders in this Shared Drive
.PARAMETER CanRename
Whether the current user can rename files or folders in this Team Drive
Whether the current user can rename files or folders in this Shared Drive
.PARAMETER CanRenameTeamDrive
Whether the current user can rename this Team Drive
.PARAMETER CanRenameDrive
Whether the current user can rename this Shared Drive
.PARAMETER CanShare
Whether the current user can share files or folders in this Team Drive
Whether the current user can share files or folders in this Shared Drive
.EXAMPLE
New-GSTeamDrive -Name "Training Docs"
New-GSDrive -Name "Training Docs"
Creates a new Team Drive named "Training Docs"
Creates a new Shared Drive named "Training Docs"
#>
[OutputType('Google.Apis.Drive.v3.Data.TeamDrive')]
[OutputType('Google.Apis.Drive.v3.Data.Drive')]
[cmdletbinding()]
Param
(
Expand All @@ -81,17 +81,19 @@ function New-GSTeamDrive {
[Switch]
$CanAddChildren,
[parameter(Mandatory = $false)]
[Alias('CanChangeTeamDriveBackground')]
[Switch]
$CanChangeTeamDriveBackground,
$CanChangeDriveBackground,
[parameter(Mandatory = $false)]
[Switch]
$CanComment,
[parameter(Mandatory = $false)]
[Switch]
$CanCopy,
[parameter(Mandatory = $false)]
[Alias('CanDeleteTeamDrive')]
[Switch]
$CanDeleteTeamDrive,
$CanDeleteDrive,
[parameter(Mandatory = $false)]
[Switch]
$CanDownload,
Expand All @@ -114,8 +116,9 @@ function New-GSTeamDrive {
[Switch]
$CanRename,
[parameter(Mandatory = $false)]
[Alias('CanRenameTeamDrive')]
[Switch]
$CanRenameTeamDrive,
$CanRenameDrive,
[parameter(Mandatory = $false)]
[Switch]
$CanShare
Expand All @@ -134,8 +137,8 @@ function New-GSTeamDrive {
}
$service = New-GoogleService @serviceParams
try {
$body = New-Object 'Google.Apis.Drive.v3.Data.TeamDrive'
$capabilities = New-Object 'Google.Apis.Drive.v3.Data.TeamDrive+CapabilitiesData'
$body = New-Object 'Google.Apis.Drive.v3.Data.Drive'
$capabilities = New-Object 'Google.Apis.Drive.v3.Data.Drive+CapabilitiesData'
foreach ($key in $PSBoundParameters.Keys) {
switch ($key) {
Default {
Expand All @@ -149,8 +152,8 @@ function New-GSTeamDrive {
}
}
$body.Capabilities = $capabilities
$request = $service.Teamdrives.Create($body,$RequestId)
Write-Verbose "Creating Team Drive '$Name' for user '$User'"
$request = $service.Drives.Create($body,$RequestId)
Write-Verbose "Creating Shared Drive '$Name' for user '$User'"
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru | Add-Member -MemberType NoteProperty -Name 'RequestId' -Value $RequestId -PassThru
}
catch {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
function Remove-GSTeamDrive {
function Remove-GSDrive {
<#
.SYNOPSIS
Removes a Team Drive
Removes a Shared Drive
.DESCRIPTION
Removes a Team Drive
Removes a Shared Drive
.PARAMETER TeamDriveId
The Id of the Team Drive to remove
.PARAMETER DriveId
The Id of the Shared Drive to remove
.PARAMETER User
The email or unique Id of the user with permission to delete the Team Drive
The email or unique Id of the user with permission to delete the Shared Drive
Defaults to the AdminEmail user
.EXAMPLE
Remove-TeamDrive -TeamDriveId "0AJ8Xjq3FcdCKUk9PVA" -Confirm:$false
Remove-Drive -DriveId "0AJ8Xjq3FcdCKUk9PVA" -Confirm:$false
Removes the Team Drive '0AJ8Xjq3FcdCKUk9PVA', skipping confirmation
Removes the Shared Drive '0AJ8Xjq3FcdCKUk9PVA', skipping confirmation
#>
[cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
Param
(
[parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)]
[Alias('Id')]
[Alias('Id','TeamDriveId')]
[String[]]
$TeamDriveId,
$DriveId,
[parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)]
[Alias('Owner','PrimaryEmail','UserKey','Mail')]
[string]
Expand All @@ -45,12 +45,12 @@ function Remove-GSTeamDrive {
}
$service = New-GoogleService @serviceParams
try {
foreach ($id in $TeamDriveId) {
if ($PSCmdlet.ShouldProcess("Deleting Team Drive '$id' from user '$User'")) {
Write-Verbose "Deleting Team Drive '$id' from user '$User'"
$request = $service.Teamdrives.Delete($id)
foreach ($id in $DriveId) {
if ($PSCmdlet.ShouldProcess("Deleting Shared Drive '$id' from user '$User'")) {
Write-Verbose "Deleting Shared Drive '$id' from user '$User'"
$request = $service.Drives.Delete($id)
$request.Execute()
Write-Verbose "Team Drive '$id' successfully deleted from user '$User'"
Write-Verbose "Shared Drive '$id' successfully deleted from user '$User'"
}
}
}
Expand Down
64 changes: 64 additions & 0 deletions PSGSuite/Public/Drive/Show-GSDrive.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
function Show-GSDrive {
<#
.SYNOPSIS
Shows (unhides) a Shared Drive in the default view
.DESCRIPTION
Shows (unhides) a Shared Drive in the default view
.PARAMETER DriveId
The unique Id of the Shared Drive to unhide
.PARAMETER User
The email or unique Id of the user who you'd like to unhide the Shared Drive for.
Defaults to the AdminEmail user.
.EXAMPLE
Show-GSDrive -DriveId $driveIds
Unhides the specified DriveIds for the AdminEmail user
#>
[OutputType('Google.Apis.Drive.v3.Data.Drive')]
[cmdletbinding()]
Param
(
[parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true,ParameterSetName = "Get")]
[Alias('Id','TeamDriveId')]
[String[]]
$DriveId,
[parameter(Mandatory = $false,Position = 0,ValueFromPipelineByPropertyName = $true)]
[Alias('Owner','PrimaryEmail','UserKey','Mail')]
[string]
$User = $Script:PSGSuite.AdminEmail
)
Process {
if ($User -ceq 'me') {
$User = $Script:PSGSuite.AdminEmail
}
elseif ($User -notlike "*@*.*") {
$User = "$($User)@$($Script:PSGSuite.Domain)"
}
$serviceParams = @{
Scope = 'https://www.googleapis.com/auth/drive'
ServiceType = 'Google.Apis.Drive.v3.DriveService'
User = $User
}
$service = New-GoogleService @serviceParams
foreach ($id in $DriveId) {
try {
$request = $service.Drives.Unhide($id)
Write-Verbose "Unhiding Shared Drive '$id' for user '$User'"
$request.Execute() | Add-Member -MemberType NoteProperty -Name 'User' -Value $User -PassThru
}
catch {
if ($ErrorActionPreference -eq 'Stop') {
$PSCmdlet.ThrowTerminatingError($_)
}
else {
Write-Error $_
}
}
}
}
}
Loading

0 comments on commit 3b77528

Please sign in to comment.