Skip to content

Commit 5e31162

Browse files
committed
clone role functionality
1 parent 7a751e0 commit 5e31162

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecCustomRole.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,32 @@ function Invoke-ExecCustomRole {
6161
$Body = @{Results = "Failed to save custom role $($Request.Body.RoleName)" }
6262
}
6363
}
64+
'Clone' {
65+
try {
66+
if ($Request.Body.NewRoleName -in $DefaultRoles) {
67+
throw "Role name $($Request.Body.NewRoleName) cannot be used"
68+
}
69+
$ExistingRole = Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$($Request.Body.RoleName.ToLower())'"
70+
if (!$ExistingRole) {
71+
throw "Role $($Request.Body.RoleName) not found"
72+
}
73+
$NewRole = @{
74+
'PartitionKey' = 'CustomRoles'
75+
'RowKey' = "$($Request.Body.NewRoleName.ToLower())"
76+
'Permissions' = $ExistingRole.Permissions
77+
'AllowedTenants' = $ExistingRole.AllowedTenants
78+
'BlockedTenants' = $ExistingRole.BlockedTenants
79+
'BlockedEndpoints' = $ExistingRole.BlockedEndpoints
80+
}
81+
Add-CIPPAzDataTableEntity @Table -Entity $NewRole -Force | Out-Null
82+
$Body = @{Results = "Custom role '$($Request.Body.NewRoleName)' cloned from '$($Request.Body.RoleName)'" }
83+
Write-LogMessage -headers $Request.Headers -API 'ExecCustomRole' -message "Cloned custom role $($Request.Body.RoleName) to $($Request.Body.NewRoleName)" -Sev 'Info'
84+
} catch {
85+
Write-Warning "Failed to clone custom role $($Request.Body.RoleName): $($_.Exception.Message)"
86+
Write-Warning $_.InvocationInfo.PositionMessage
87+
$Body = @{Results = "Failed to clone custom role $($Request.Body.RoleName)" }
88+
}
89+
}
6490
'Delete' {
6591
Write-Information "Deleting custom role $($Request.Body.RoleName)"
6692
$Role = Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$($Request.Body.RoleName)'" -Property RowKey, PartitionKey

0 commit comments

Comments
 (0)