Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions Cmdlets/Public/Get-TeamViewerRole.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,35 @@ function Get-TeamViewerRole {
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken
$ApiToken,

[switch]
[Alias('ListPermissions')]
$Permissions
)

Begin{
$parameters = @{ }
$resourceUri = "$(Get-TeamViewerApiUri)/userroles"
Begin {
$parameters = @{ }
$resourceUri = "$(Get-TeamViewerApiUri)/userroles"
if ($Permissions) {
$resourceUri += '/permissions'
}
}

Process{
$response = Invoke-TeamViewerRestMethod `
-ApiToken $ApiToken `
-Uri $resourceUri `
-Method Get `
-Body $parameters `
-WriteErrorTo $PSCmdlet `
-ErrorAction Stop
Write-Output ($response.Roles | ConvertTo-TeamViewerRole )
}
Process {
$response = Invoke-TeamViewerRestMethod `
-ApiToken $ApiToken `
-Uri $resourceUri `
-Method Get `
-Body $parameters `
-WriteErrorTo $PSCmdlet `
-ErrorAction Stop
if ($Permissions) {
return [PSCustomObject] $response
}
else {
Write-Output ($response.Roles | ConvertTo-TeamViewerRole )
}
}
}

27 changes: 26 additions & 1 deletion Docs/Help/Get-TeamViewerRole.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Lists all roles and their permissions in a TeamViewer company.
## SYNTAX

```powershell
Get-TeamViewerRole [-ApiToken] <SecureString> [<CommonParameters>]
Get-TeamViewerRole [-ApiToken] <SecureString> [-Permissions] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -31,6 +31,15 @@ PS /> Get-TeamViewerRole

Lists all roles and their permissions.

### Example 2

```powershell
PS /> Get-TeamViewerRole -ApiToken $token -Permissions
```

Lists all the possible permissions.


## PARAMETERS

### -ApiToken
Expand All @@ -48,6 +57,21 @@ Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Permissions

Return the list of currently supported permissions.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: ListPermissions

Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters

Expand All @@ -66,3 +90,4 @@ An array of `TeamViewerPS.Role` objects.
## NOTES

## RELATED LINKS

8 changes: 8 additions & 0 deletions Tests/Public/Get-TeamViewerRole.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ Describe 'Get-TeamViewerRole' {
$Uri -eq '//unit.test/userroles' -And `
$Method -eq 'Get' }
}
It 'Should call the correct API endpoint to list permissions' {
Get-TeamViewerRole -ApiToken $testApiToken -Permissions

Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter {
$ApiToken -eq $testApiToken -And `
$Uri -eq '//unit.test/userroles/permissions' -And `
$Method -eq 'Get' }
}

It 'Should return Role objects' {
$result = Get-TeamViewerRole -ApiToken $testApiToken
Expand Down