diff --git a/Cmdlets/Public/Get-TeamViewerEffectivePermission.ps1 b/Cmdlets/Public/Get-TeamViewerEffectivePermission.ps1 new file mode 100644 index 0000000..9cb11cc --- /dev/null +++ b/Cmdlets/Public/Get-TeamViewerEffectivePermission.ps1 @@ -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 + } +} + diff --git a/Docs/Help/Get-TeamViewerEffectivePermission.md b/Docs/Help/Get-TeamViewerEffectivePermission.md new file mode 100644 index 0000000..275ab16 --- /dev/null +++ b/Docs/Help/Get-TeamViewerEffectivePermission.md @@ -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] [] +``` + +## 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 diff --git a/Docs/TeamViewerPS.md b/Docs/TeamViewerPS.md index d9e200a..e077a17 100644 --- a/Docs/TeamViewerPS.md +++ b/Docs/TeamViewerPS.md @@ -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 diff --git a/Tests/Public/Get-TeamViewerEffectivePermission.Tests.ps1 b/Tests/Public/Get-TeamViewerEffectivePermission.Tests.ps1 new file mode 100644 index 0000000..3c0bdb3 --- /dev/null +++ b/Tests/Public/Get-TeamViewerEffectivePermission.Tests.ps1 @@ -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' } + } + +}