Skip to content

Commit

Permalink
Merge pull request #60 from teamviewer/Predefined_Roles
Browse files Browse the repository at this point in the history
Predefined roles
  • Loading branch information
ChristianJ-TV authored Oct 20, 2023
2 parents a973477 + d10439c commit d89601f
Show file tree
Hide file tree
Showing 13 changed files with 432 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Build/New-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Write-Verbose 'Creating build output directories...'
New-Item -Type Directory $Build_OutputPath | Out-Null

# Compile all functions into a single psm file
$Build_ModulePath = (Join-Path -Path $Repo_CmdletPath -ChildPath 'TeamViewerPS.psm1')
$Build_ModulePath = (Join-Path -Path $Build_OutputPath -ChildPath 'TeamViewerPS.psm1')

Write-Verbose 'Compiling single-file TeamViewer module...'
$ModuleTypes = @(Get-ChildItem -Path (Join-Path -Path $Repo_CmdletPath -ChildPath 'TeamViewerPS.Types.ps1'))
Expand Down
21 changes: 21 additions & 0 deletions Cmdlets/Private/ConvertTo-TeamViewerPredefinedRole.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function ConvertTo-TeamViewerPredefinedRole {
param(
[Parameter(ValueFromPipeline = $true)]
[PSObject]
$InputObject
)
process {
if($InputObject){
$properties = @{
PredefinedRoleId = $InputObject.PredefineduserRoleId
}
}

$result = New-Object -TypeName PSObject -Property $properties
$result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.PredefinedRole')
$result | Add-Member -MemberType ScriptMethod -Name 'ToString' -Force -Value {
Write-Output "[$($this.PredefinedRoleID)]"
}
Write-Output $result
}
}
2 changes: 1 addition & 1 deletion Cmdlets/Private/Resolve-TeamViewerUserRoleId.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
function Resolve-TeamViewerUserRoleId {
param(
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
[object]
[Object]
$UserRole
)
Process {
Expand Down
25 changes: 25 additions & 0 deletions Cmdlets/Public/Get-TeamViewerPredefinedRole.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function Get-TeamViewerPredefinedRole {
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken
)


Begin {
$parameters = @{}
$resourceUri = "$(Get-TeamViewerApiUri)/userroles/predefined"
}

Process {
$response = Invoke-TeamViewerRestMethod `
-ApiToken $ApiToken `
-Uri $resourceUri `
-Method Get `
-Body $parameters `
-WriteErrorTo $PSCmdlet `
-ErrorAction Stop
Write-Output ($response | ConvertTo-TeamViewerPredefinedRole)

}
}
27 changes: 27 additions & 0 deletions Cmdlets/Public/Remove-TeamViewerPredefinedRole.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function Remove-TeamViewerPredefinedRole {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken
)


Begin {
$parameters = @{}
$resourceUri = "$(Get-TeamViewerApiUri)/userroles/predefined"
}

Process {
if ($PSCmdlet.ShouldProcess('PredefinedRole', 'Remove Predefined role')) {
Invoke-TeamViewerRestMethod `
-ApiToken $ApiToken `
-Uri $resourceUri `
-Method DELETE `
-Body $parameters `
-WriteErrorTo $PSCmdlet `
-ErrorAction Stop | `
Out-Null
}
}
}
29 changes: 29 additions & 0 deletions Cmdlets/Public/Set-TeamViewerPredefinedRole.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function Set-TeamViewerPredefinedRole {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken,

[Parameter(Mandatory = $true, ValueFromPipeline = $true )]
[ValidateScript({ $_ | Resolve-TeamViewerUserRoleId })]
[object]
$RoleId
)

Process {
$Role = $RoleId | Resolve-TeamViewerUserRoleId
$resourceUri = "$(Get-TeamViewerApiUri)/userroles/$Role/predefined"
if ($PSCmdlet.ShouldProcess($Role, 'Set Predefined Role')) {
Invoke-TeamViewerRestMethod `
-ApiToken $ApiToken `
-Uri $resourceUri `
-Method Put `
-ContentType 'application/json; charset=utf-8' `
-WriteErrorTo $PSCmdlet `
-ErrorAction Stop | `
Out-Null
}
}

}
2 changes: 1 addition & 1 deletion Cmdlets/TeamViewerPS.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# NestedModules = @()

# Functions to export from this module.
FunctionsToExport = @('Add-TeamViewerAssignment', 'Add-TeamViewerCustomization', 'Add-TeamViewerManagedDevice', 'Add-TeamViewerManager', 'Add-TeamViewerAccountToUserRole', 'Add-TeamViewerUserGroupToUserRole', 'Add-TeamViewerSsoExclusion', 'Add-TeamViewerUserGroupMember', 'Connect-TeamViewerApi', 'Disconnect-TeamViewerApi', 'Export-TeamViewerSystemInformation', 'Get-TeamViewerAccount', 'Get-TeamViewerConnectionReport', 'Get-TeamViewerContact', 'Get-TeamViewerCustomModuleId', 'Get-TeamViewerDevice', 'Get-TeamViewerEventLog', 'Get-TeamViewerGroup', 'Get-TeamViewerId', 'Get-TeamViewerInstallationDirectory', 'Get-TeamViewerLogFilePath', 'Get-TeamViewerManagedDevice', 'Get-TeamViewerManagedGroup', 'Get-TeamViewerManagementId', 'Get-TeamViewerManager', 'Get-TeamViewerPolicy', 'Get-TeamViewerRoleAssignmentToAccount', 'Get-TeamViewerRoleAssignmentToUserGroup', 'Get-TeamViewerService', 'Get-TeamViewerSsoDomain', 'Get-TeamViewerSsoExclusion', 'Get-TeamViewerUser', 'Get-TeamViewerUserGroup', 'Get-TeamViewerUserGroupMember', 'Get-TeamViewerUserRole', 'Get-TeamViewerVersion', 'Invoke-TeamViewerPackageDownload', 'Invoke-TeamViewerPing', 'New-TeamViewerContact', 'New-TeamViewerDevice', 'New-TeamViewerGroup', 'New-TeamViewerManagedGroup', 'New-TeamViewerPolicy', 'New-TeamViewerUser', 'New-TeamViewerUserGroup', 'New-TeamViewerUserRole', 'Publish-TeamViewerGroup', 'Remove-TeamViewerAssignment', 'Remove-TeamViewerContact', 'Remove-TeamViewerCustomization', 'Remove-TeamViewerDevice', 'Remove-TeamViewerGroup', 'Remove-TeamViewerManagedDevice', 'Remove-TeamViewerManagedDeviceManagement', 'Remove-TeamViewerManagedGroup', 'Remove-TeamViewerManager', 'Remove-TeamViewerPolicy', 'Remove-TeamViewerPolicyFromManagedDevice', 'Remove-TeamViewerPSProxy', 'Remove-TeamViewerAccountFromUserRole', 'Remove-TeamViewerUserGroupFromUserRole', 'Remove-TeamViewerSsoExclusion', 'Remove-TeamViewerUser', 'Remove-TeamViewerUserGroup', 'Remove-TeamViewerUserGroupMember', 'Remove-TeamViewerUserRole', 'Restart-TeamViewerService', 'Set-TeamViewerAccount', 'Set-TeamViewerAPIUri', 'Set-TeamViewerDevice', 'Set-TeamViewerGroup', 'Set-TeamViewerManagedDevice', 'Set-TeamViewerManagedGroup', 'Set-TeamViewerManager', 'Set-TeamViewerPolicy', 'Set-TeamViewerPSProxy', 'Set-TeamViewerUser', 'Set-TeamViewerUserGroup', 'Set-TeamViewerUserRole', 'Start-TeamViewerService', 'Stop-TeamViewerService', 'Test-TeamViewerConnectivity', 'Test-TeamViewerInstallation', 'Unpublish-TeamViewerGroup')
FunctionsToExport = @('Add-TeamViewerAssignment','Add-TeamViewerCustomization','Add-TeamViewerManagedDevice','Add-TeamViewerManager','Add-TeamViewerAccountToUserRole','Add-TeamViewerUserGroupToUserRole','Add-TeamViewerSsoExclusion','Add-TeamViewerUserGroupMember','Connect-TeamViewerApi','Disconnect-TeamViewerApi','Export-TeamViewerSystemInformation','Get-TeamViewerAccount','Get-TeamViewerConnectionReport','Get-TeamViewerContact','Get-TeamViewerCustomModuleId','Get-TeamViewerDevice','Get-TeamViewerEventLog','Get-TeamViewerGroup','Get-TeamViewerId','Get-TeamViewerInstallationDirectory','Get-TeamViewerLogFilePath','Get-TeamViewerManagedDevice','Get-TeamViewerManagedGroup','Get-TeamViewerManagementId','Get-TeamViewerManager','Get-TeamViewerPolicy','Get-TeamViewerPredefinedRole','Get-TeamViewerRoleAssignmentToAccount','Get-TeamViewerRoleAssignmentToUserGroup','Get-TeamViewerService','Get-TeamViewerSsoDomain','Get-TeamViewerSsoExclusion','Get-TeamViewerUser','Get-TeamViewerUserGroup','Get-TeamViewerUserGroupMember','Get-TeamViewerUserRole','Get-TeamViewerVersion','Invoke-TeamViewerPackageDownload','Invoke-TeamViewerPing','New-TeamViewerContact','New-TeamViewerDevice','New-TeamViewerGroup','New-TeamViewerManagedGroup','New-TeamViewerPolicy','New-TeamViewerUser','New-TeamViewerUserGroup','New-TeamViewerUserRole','Publish-TeamViewerGroup','Remove-TeamViewerAssignment','Remove-TeamViewerContact','Remove-TeamViewerCustomization','Remove-TeamViewerDevice','Remove-TeamViewerGroup','Remove-TeamViewerManagedDevice','Remove-TeamViewerManagedDeviceManagement','Remove-TeamViewerManagedGroup','Remove-TeamViewerManager','Remove-TeamViewerPolicy','Remove-TeamViewerPolicyFromManagedDevice','Remove-TeamViewerPredefinedRole','Remove-TeamViewerPSProxy','Remove-TeamViewerAccountFromUserRole','Remove-TeamViewerUserGroupFromUserRole','Remove-TeamViewerSsoExclusion','Remove-TeamViewerUser','Remove-TeamViewerUserGroup','Remove-TeamViewerUserGroupMember','Remove-TeamViewerUserRole','Restart-TeamViewerService','Set-TeamViewerAccount','Set-TeamViewerAPIUri','Set-TeamViewerDevice','Set-TeamViewerGroup','Set-TeamViewerManagedDevice','Set-TeamViewerManagedGroup','Set-TeamViewerManager','Set-TeamViewerPolicy','Set-TeamViewerPredefinedRole','Set-TeamViewerPSProxy','Set-TeamViewerUser','Set-TeamViewerUserGroup','Set-TeamViewerUserRole','Start-TeamViewerService','Stop-TeamViewerService','Test-TeamViewerConnectivity','Test-TeamViewerInstallation','Unpublish-TeamViewerGroup')

# Cmdlets to export from this module.
CmdletsToExport = @()
Expand Down
76 changes: 76 additions & 0 deletions Docs/Help/Get-TeamViewerPredefinedRole.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
external help file: TeamViewerPS-help.xml
Module Name: TeamViewerPS
online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Get-TeamViewerPredefinedRole.md
schema: 2.0.0
---

# Get-TeamViewerPredefinedRole

## SYNOPSIS

Retrieve the Predefine Role in a TeamViewer company.

## SYNTAX

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

## DESCRIPTION

Retrieves the Predefined role among the existing roles in the TeamViewer company associated with the API access token.

## EXAMPLES

### Example 1

```powershell
PS /> Get-TeamViewerPredefinedRole
```

Retrieves the Predefined Role ID.

### Example 2

```powershell
PS /> forEach-Object { Get-TeamViewerUserRole | Where-Object { $_.RoleID -eq (Get-TeamViewerPredefinedRole).PredefinedRoleID } }
```

Retrieves the complete information about the predefined role.

## 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
An array of `TeamViewerPS.PredefinedRole` objects.

## NOTES

## RELATED LINKS
66 changes: 66 additions & 0 deletions Docs/Help/Remove-TeamViewerPredefinedRole.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/Remove-TeamViewerPredefinedRole.md
schema: 2.0.0
---

# Remove-TeamViewerPredefinedRole

## SYNOPSIS

Remove existing Predefined Role.

## SYNTAX

```powershell
Remove-TeamViewerPredefinedRole [-ApiToken] <SecureString> [-UserRoleId] <Object> [-WhatIf] [-Confirm]
[<CommonParameters>]
```

## DESCRIPTION

Sets the existing Predefined Role not as Predefined. The role is still available under User Roles.
Existing User assignments to this role are unaffected.

## EXAMPLES

### Example 1

```powershell
PS /> Remove-TeamViewerPredefinedRole
```

Removes the Predefined Role tag from the Existing Predefined Role.

## 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
## NOTES
## RELATED LINKS
88 changes: 88 additions & 0 deletions Docs/Help/Set-TeamViewerPredefinedRole.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
external help file: TeamViewerPS-help.xml
Module Name: TeamViewerPS
online version: https://github.com/teamviewer/TeamViewerPS/blob/main/Docs/Help/Set-TeamViewerPredefinedRole.md
schema: 2.0.0
---

# Set-TeamViewerPredefinedRole

## SYNOPSIS

Add Predefined User Role.

## SYNTAX

```powershell
Set-TeamViewerPredefinedRole [-ApiToken] <SecureString> [-RoleId] <Object> [<CommonParameters>]
```

## DESCRIPTION

Set an existing role as Predefined Role. It allows user creation with Predefined role assigned to the new user.

## EXAMPLES

### Example 1

```powershell
PS /> Set-TeamViewerPredefinedRole -RoleId '9b465ea2-2f75-4101-a057-58a81ed0e57b'
```

Sets user role with id `9b465ea2-2f75-4101-a057-58a81ed0e57b` as Predefined Role.

### Example 1

```powershell
PS /> Get-TeamViewerUserRole | where-Object { ($_.RoleName -eq 'Test Role') } | Set-TeamViewerPredefinedRole
```

Sets user role with name `Test Role` as Predefined Role.

## 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
```
### -RoleId
The user role to be set as Predefined Role.
```yaml
Type: Object
Parameter Sets: (All)
Aliases: UserRole

Required: True
Position: 1
Default value: None
Accept pipeline input: True
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
## NOTES
## RELATED LINKS
Loading

0 comments on commit d89601f

Please sign in to comment.