Skip to content

Commit

Permalink
Merge pull request #61 from teamviewer/RenameUserRoleToRole
Browse files Browse the repository at this point in the history
Harmonize cmdlet names
  • Loading branch information
ChristianJ-TV authored Oct 22, 2023
2 parents d89601f + dcf5853 commit fe07112
Show file tree
Hide file tree
Showing 44 changed files with 309 additions and 310 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Added

- Adds commands to manage the user roles of a TeamViewer company.
- Adds commands to manage the roles of a TeamViewer company.
- Adds `Set-TeamViewerApiURi` to use TeamViewer test API.
- Adds `Add-TeamViewerAssignment` and `Remove-TeamViewerAssignment` commands to assign and unassign a device from a TeamViewer company.
- Adds `Add-TeamViewerCustomization` and `Remove-TeamViewerCustomization` commands to apply and remove customization.
Expand Down
8 changes: 4 additions & 4 deletions Cmdlets/Private/ConvertTo-TeamViewerPredefinedRole.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ function ConvertTo-TeamViewerPredefinedRole {
$InputObject
)
process {
if($InputObject){
$properties = @{
PredefinedRoleId = $InputObject.PredefineduserRoleId
if ($InputObject) {
$properties = @{
PredefinedRoleId = $InputObject.PredefinedUserRoleId
}
}
}

$result = New-Object -TypeName PSObject -Property $properties
$result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.PredefinedRole')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function ConvertTo-TeamViewerUserRole {
function ConvertTo-TeamViewerRole {
param(
[Parameter(ValueFromPipeline)]
[PSObject]
Expand All @@ -15,7 +15,7 @@ function ConvertTo-TeamViewerUserRole {
}
}
$result = New-Object -TypeName PSObject -Property $properties
$result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.UserRole')
$result.PSObject.TypeNames.Insert(0, 'TeamViewerPS.Role')
$result | Add-Member -MemberType ScriptMethod -Name 'ToString' -Force -Value {
Write-Output "[$($this.RoleName)] [$($this.RoleID)] $($this.Permissions))"
}
Expand Down
19 changes: 19 additions & 0 deletions Cmdlets/Private/Resolve-TeamViewerRoleId.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

function Resolve-TeamViewerRoleId {
param(
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
[Object]
$Role
)
Process {
if ($Role.PSObject.TypeNames -contains 'TeamViewerPS.Role') {
return [string]$Role.RoleID
}
elseif ($Role -match '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$') {
return [string]$Role
}
else {
throw "Invalid role identifier '$Role'. Must be either a [TeamViewerPS.Role] or [UUID] "
}
}
}
19 changes: 0 additions & 19 deletions Cmdlets/Private/Resolve-TeamViewerUserRoleId.ps1

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
function Add-TeamViewerUserGroupToUserRole {
function Add-TeamViewerUserGroupToRole {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken,

[Parameter(Mandatory = $true)]
[ValidateScript( { $_ | Resolve-TeamViewerUserRoleId } )]
[Alias('UserRoleId')]
[ValidateScript( { $_ | Resolve-TeamViewerRoleId } )]
[Alias('RoleId')]
[object]
$UserRole,
$Role,

[Parameter(Mandatory = $true)]
[ValidateScript( { $_ | Resolve-TeamViewerUserGroupId } )]
Expand All @@ -20,7 +20,7 @@ function Add-TeamViewerUserGroupToUserRole {
)

Begin {
$RoleId = $UserRole | Resolve-TeamViewerUserRoleId
$RoleId = $Role | Resolve-TeamViewerRoleId
$null = $ApiToken
$resourceUri = "$(Get-TeamViewerApiUri)/userroles/assign/usergroup"
$body = @{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
function Add-TeamViewerAccountToUserRole {
function Add-TeamViewerUserToRole {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken,

[Parameter(Mandatory = $true)]
[ValidateScript( { $_ | Resolve-TeamViewerUserRoleId } )]
[Alias('UserRole')]
[ValidateScript( { $_ | Resolve-TeamViewerRoleId } )]
[Alias('Role')]
[object]
$UserRoleId,
$RoleId,

[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Alias('Id', 'UserIds')]
Expand All @@ -18,7 +18,7 @@ function Add-TeamViewerAccountToUserRole {
)

Begin {
$id = $UserRoleId | Resolve-TeamViewerUserRoleId
$id = $RoleId | Resolve-TeamViewerRoleId
$null = $ApiToken
$resourceUri = "$(Get-TeamViewerApiUri)/userroles/assign/account"
$AccountsToAdd = @()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-TeamViewerUserRole {
function Get-TeamViewerRole {
[CmdletBinding(DefaultParameterSetName = '')]
param(
[Parameter(Mandatory = $true)]
Expand All @@ -19,6 +19,6 @@ Process{
-Body $parameters `
-WriteErrorTo $PSCmdlet `
-ErrorAction Stop
Write-Output ($response.Roles | ConvertTo-TeamViewerUserRole )
Write-Output ($response.Roles | ConvertTo-TeamViewerRole )
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function Get-TeamViewerRoleAssignmentToAccount {
function Get-TeamViewerUserByRole {
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken,

[Parameter(Mandatory = $true)]
[ValidateScript( { $_ | Resolve-TeamViewerUserRoleId } )]
[Alias('UserRole')]
[ValidateScript( { $_ | Resolve-TeamViewerRoleId } )]
[Alias('Role')]
[string]
$UserRoleId
$RoleId
)


$resourceUri = "$(Get-TeamViewerApiUri)/userroles/assignments/account?userRoleId=$UserRoleId"
$resourceUri = "$(Get-TeamViewerApiUri)/userroles/assignments/account?userRoleId=$RoleId"
$parameters = $null
do {
$response = Invoke-TeamViewerRestMethod `
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function Get-TeamViewerRoleAssignmentToUserGroup {
function Get-TeamViewerUserGroupByRole {
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken,

[Parameter(Mandatory = $true)]
[ValidateScript({ $_ | Resolve-TeamviewerUserRoleId })]
[Alias('UserRole')]
[ValidateScript({ $_ | Resolve-TeamViewerRoleId })]
[Alias('Role')]
[string]
$UserRoleId
$RoleId
)

Begin {
$resourceUri = "$(Get-TeamViewerApiUri)/userroles/assignments/usergroups?userRoleId=$UserRoleId"
$resourceUri = "$(Get-TeamViewerApiUri)/userroles/assignments/usergroups?userRoleId=$RoleId"
$parameters = $null
}
Process {
Expand All @@ -25,7 +25,7 @@ function Get-TeamViewerRoleAssignmentToUserGroup {
-WriteErrorTo $PSCmdlet `
-ErrorAction Stop
if ($response.ContinuationToken) {
$resourceUri += "&continuationToken=" + $response.ContinuationToken
$resourceUri += '&continuationToken=' + $response.ContinuationToken
}
Write-Output ($response.AssignedToGroups | ConvertTo-TeamViewerRoleAssignedUserGroup )
}while ($response.ContinuationToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

function New-TeamViewerUserRole {
function New-TeamViewerRole {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true )]
[securestring]
$ApiToken,

[Parameter(Mandatory = $true)]
[Alias('UserRoleName')]
[Alias('RoleName')]
[string]
$Name,

Expand All @@ -29,7 +29,7 @@ function New-TeamViewerUserRole {
}

Process {
if ($PSCmdlet.ShouldProcess($Name, 'Create User Role')) {
if ($PSCmdlet.ShouldProcess($Name, 'Create Role')) {
$response = Invoke-TeamViewerRestMethod `
-ApiToken $ApiToken `
-Uri $resourceUri `
Expand All @@ -39,7 +39,7 @@ function New-TeamViewerUserRole {
-WriteErrorTo $PSCmdlet `
-ErrorAction Stop

$result = ($response.Role | ConvertTo-TeamViewerUserRole)
$result = ($response.Role | ConvertTo-TeamViewerRole)
Write-Output $result
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
function Remove-TeamViewerUserRole {
function Remove-TeamViewerRole {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken,

[Parameter(Mandatory = $true)]
[ValidateScript( { $_ | Resolve-TeamViewerUserRoleId } )]
[Alias('UserRole')]
[ValidateScript( { $_ | Resolve-TeamViewerRoleId } )]
[Alias('Role')]
[Alias('Id')]
[object]
$UserRoleId
$RoleId
)

Begin {
$resourceUri = "$(Get-TeamViewerApiUri)/userroles?userRoleId=$UserRoleId"
$resourceUri = "$(Get-TeamViewerApiUri)/userroles?userRoleId=$RoleId"
}

Process {
if ($PSCmdlet.ShouldProcess($UserRoleId.ToString(), 'Remove User Role')) {
if ($PSCmdlet.ShouldProcess($RoleId.ToString(), 'Remove Role')) {
Invoke-TeamViewerRestMethod `
-ApiToken $ApiToken `
-Uri $resourceUri `
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
function Remove-TeamViewerAccountFromUserRole {
function Remove-TeamViewerUserFromRole {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
[securestring]
$ApiToken,

[Parameter(Mandatory = $true)]
[ValidateScript( { $_ | Resolve-TeamViewerUserRoleId } )]
[Alias('UserRole')]
[ValidateScript( { $_ | Resolve-TeamViewerRoleId } )]
[Alias('Role')]
[object]
$UserRoleId,
$RoleId,

[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Alias('Id', 'UserIds')]
Expand All @@ -18,7 +18,7 @@ function Remove-TeamViewerAccountFromUserRole {
)

Begin {
$id = $UserRoleId | Resolve-TeamViewerUserRoleId
$id = $RoleId | Resolve-TeamViewerRoleId
$null = $ApiToken
$resourceUri = "$(Get-TeamViewerApiUri)/userroles/unassign/account"
$AccountsToRemove = @()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Remove-TeamViewerUserGroupFromUserRole {
function Remove-TeamViewerUserGroupFromRole {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true)]
Expand Down
4 changes: 2 additions & 2 deletions Cmdlets/Public/Set-TeamViewerPredefinedRole.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ function Set-TeamViewerPredefinedRole {
$ApiToken,

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

Process {
$Role = $RoleId | Resolve-TeamViewerUserRoleId
$Role = $RoleId | Resolve-TeamViewerRoleId
$resourceUri = "$(Get-TeamViewerApiUri)/userroles/$Role/predefined"
if ($PSCmdlet.ShouldProcess($Role, 'Set Predefined Role')) {
Invoke-TeamViewerRestMethod `
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

function Set-TeamViewerUserRole {
function Set-TeamViewerRole {
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[Parameter(Mandatory = $true )]
[securestring]
$ApiToken,

[Parameter(Mandatory = $true)]
[Alias('UserRoleName')]
[Alias('RoleName')]
[string]
$Name,

Expand All @@ -17,25 +17,25 @@ function Set-TeamViewerUserRole {
$Permissions,

[Parameter(Mandatory = $true)]
[ValidateScript( { $_ | Resolve-TeamViewerUserRoleId } )]
[Alias('UserRole')]
[ValidateScript( { $_ | Resolve-TeamViewerRoleId } )]
[Alias('Role')]
[object]
$UserRoleId
$RoleId
)
Begin {
$resourceUri = "$(Get-TeamViewerApiUri)/userroles"
$body = @{
Name = $Name
Permissions = @()
UserRoleId = $UserRoleId
UserRoleId = $RoleId

}
if ($Permissions) {
$body.Permissions = @($Permissions)
}
}
Process {
if ($PSCmdlet.ShouldProcess($Name, 'Update User Role')) {
if ($PSCmdlet.ShouldProcess($Name, 'Update Role')) {
$response = Invoke-TeamViewerRestMethod `
-ApiToken $ApiToken `
-Uri $resourceUri `
Expand Down
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-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')
FunctionsToExport = @('Add-TeamViewerAssignment', 'Add-TeamViewerCustomization', 'Add-TeamViewerManagedDevice', 'Add-TeamViewerManager', 'Add-TeamViewerUserToRole', 'Add-TeamViewerUserGroupToRole', '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-TeamViewerUserByRole', 'Get-TeamViewerUserGroupByRole', 'Get-TeamViewerService', 'Get-TeamViewerSsoDomain', 'Get-TeamViewerSsoExclusion', 'Get-TeamViewerUser', 'Get-TeamViewerUserGroup', 'Get-TeamViewerUserGroupMember', 'Get-TeamViewerRole', 'Get-TeamViewerVersion', 'Invoke-TeamViewerPackageDownload', 'Invoke-TeamViewerPing', 'New-TeamViewerContact', 'New-TeamViewerDevice', 'New-TeamViewerGroup', 'New-TeamViewerManagedGroup', 'New-TeamViewerPolicy', 'New-TeamViewerUser', 'New-TeamViewerUserGroup', 'New-TeamViewerRole', '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-TeamViewerUserFromRole', 'Remove-TeamViewerUserGroupFromRole', 'Remove-TeamViewerSsoExclusion', 'Remove-TeamViewerUser', 'Remove-TeamViewerUserGroup', 'Remove-TeamViewerUserGroupMember', 'Remove-TeamViewerRole', '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-TeamViewerRole', 'Start-TeamViewerService', 'Stop-TeamViewerService', 'Test-TeamViewerConnectivity', 'Test-TeamViewerInstallation', 'Unpublish-TeamViewerGroup')

# Cmdlets to export from this module.
CmdletsToExport = @()
Expand Down
Loading

0 comments on commit fe07112

Please sign in to comment.