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
26 changes: 26 additions & 0 deletions Cmdlets/Public/Get-TeamViewerEffectivePermission.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function Get-TeamViewerEffectivePermission {
[CmdletBinding(DefaultParameterSetName = '')]
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken
)

begin {
$resourceUri = "$(Get-TeamViewerApiUri)/users/effectivepermissions"
}

process {
$response = Invoke-TeamViewerRestMethod `
-ApiToken $ApiToken `
-Uri $resourceUri `
-Method Get `
-WriteErrorTo $PSCmdlet `
-ErrorAction Stop
if ($null -eq $response -or $response.Count -eq 0) {
$response = @{}
}
return [PSCustomObject] $response
}
}

66 changes: 66 additions & 0 deletions Docs/Help/Get-TeamViewerEffectivePermission.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
external help file: TeamViewerPS-help.xml
Module Name: TeamViewerPS
online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerEffectivePermission.md
schema: 2.0.0
---

# Get-TeamViewerEffectivePermission

## SYNOPSIS

Lists all effective permissions in a TeamViewer company.

## SYNTAX

```powershell
Get-TeamViewerEffectivePermission [-ApiToken] <SecureString> [<CommonParameters>]
```

## DESCRIPTION

Lists all effective permissions in the TeamViewer company associated with the API access token.

## EXAMPLES

### Example 1

```powershell
PS /> Get-TeamViewerEffectivePermission
```

Lists all effective permissions.

## PARAMETERS

### -ApiToken

The TeamViewer API access token.

```yaml
Type: SecureString
Parameter Sets: (All)
Aliases:

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

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### None

## OUTPUTS

### System.Object

## NOTES

## RELATED LINKS
1 change: 1 addition & 0 deletions Docs/TeamViewerPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ The following functions are available in this category:

[`Remove-TeamViewerUserTFA`](Help/Remove-TeamViewerUserTFA.md)

['Get-TeamViewerEffectivePermission'](Help/Get-TeamViewerEffectivePermission.md)

## User Groups

Expand Down
59 changes: 59 additions & 0 deletions Tests/Public/Get-TeamViewerEffectivePermission.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
BeforeAll {
. "$PSScriptRoot\..\..\Cmdlets\Public\Get-TeamViewerEffectivePermission.ps1"

@(Get-ChildItem -Path "$PSScriptRoot\..\..\Cmdlets\Private\*.ps1") | `
ForEach-Object { . $_.FullName }

$testApiToken = [securestring]@{}
$null = $testApiToken

Mock Get-TeamViewerApiUri { '//unit.test' }
Mock Invoke-TeamViewerRestMethod {
@{
AllowGroupSharing = $true
ManageAdmins = $false
ManageUsers = $true
ModifyConnections = $true
DeleteConnections = $true
}
}
}

Describe 'Get-TeamViewerEffectivePermission' {

It 'Should call the correct API endpoint to list permission' {
Get-TeamViewerEffectivePermission -ApiToken $testApiToken

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

It 'Should convert input object to TeamViewerPS.EffectivePermission' {

$result = Get-TeamViewerEffectivePermission -ApiToken $testApiToken

$result | Should -BeOfType [PSCustomObject]
$result.AllowGroupSharing | Should -Be $true
$result.ManageAdmins | Should -Be $false
$result.ManageUsers | Should -Be $true
$result.ModifyConnections | Should -Be $true
}

It 'Should return an empty object if no permissions are assigned' {
Mock Invoke-TeamViewerRestMethod {
@{
}
}

$result = Get-TeamViewerEffectivePermission -ApiToken $testApiToken
$result | Should -BeOfType [PSCustomObject]
$result.PSObject.Properties | Should -Be $null
Assert-MockCalled Invoke-TeamViewerRestMethod -Times 1 -Scope It -ParameterFilter {
$ApiToken -eq $testApiToken -and `
$Uri -eq '//unit.test/users/effectivepermissions' -and `
$Method -eq 'Get' }
}

}