Skip to content

Commit 16a4aca

Browse files
fixes #4849
1 parent 0b55586 commit 16a4aca

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/GDAP/Invoke-ExecGDAPRoleTemplate.ps1

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,33 @@ Function Invoke-ExecGDAPRoleTemplate {
4444
}
4545
}
4646
'Edit' {
47-
$RowKey = $Request.Body.TemplateId
48-
$Template = $Templates | Where-Object -Property RowKey -EQ $RowKey
47+
# Use OriginalTemplateId if provided (for rename), otherwise use TemplateId
48+
$OriginalRowKey = $Request.Body.OriginalTemplateId ?? $Request.Body.TemplateId
49+
$NewRowKey = $Request.Body.TemplateId
50+
$Template = $Templates | Where-Object -Property RowKey -EQ $OriginalRowKey
4951
if ($Template) {
5052
$RoleMappings = $Request.Body.RoleMappings
51-
Add-CIPPGDAPRoleTemplate -TemplateId $RowKey -RoleMappings $RoleMappings -Overwrite
52-
Write-LogMessage -headers $Headers -API $APIName -message "Updated role mappings for GDAP template '$RowKey'" -Sev 'Info'
53-
$Body = @{
54-
Results = "Updated role mappings for template $RowKey"
53+
54+
# If the template ID is being changed, delete the old one and create a new one
55+
if ($OriginalRowKey -ne $NewRowKey) {
56+
Remove-AzDataTableEntity -Force @Table -Entity $Template
57+
Add-CIPPGDAPRoleTemplate -TemplateId $NewRowKey -RoleMappings $RoleMappings -Overwrite
58+
Write-LogMessage -headers $Headers -API $APIName -message "Renamed GDAP template from '$OriginalRowKey' to '$NewRowKey' and updated role mappings" -Sev 'Info'
59+
$Body = @{
60+
Results = "Renamed template from $OriginalRowKey to $NewRowKey and updated role mappings"
61+
}
62+
} else {
63+
# Just update the existing template
64+
Add-CIPPGDAPRoleTemplate -TemplateId $NewRowKey -RoleMappings $RoleMappings -Overwrite
65+
Write-LogMessage -headers $Headers -API $APIName -message "Updated role mappings for GDAP template '$NewRowKey'" -Sev 'Info'
66+
$Body = @{
67+
Results = "Updated role mappings for template $NewRowKey"
68+
}
5569
}
5670
} else {
57-
Write-LogMessage -headers $Headers -API $APIName -message "GDAP role template '$RowKey' not found for editing" -Sev 'Warning'
71+
Write-LogMessage -headers $Headers -API $APIName -message "GDAP role template '$OriginalRowKey' not found for editing" -Sev 'Warning'
5872
$Body = @{
59-
Results = "Template $RowKey not found"
73+
Results = "Template $OriginalRowKey not found"
6074
}
6175
}
6276
}

0 commit comments

Comments
 (0)