Skip to content

Commit 5832e5d

Browse files
authored
Merge pull request #505 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents a0e7e67 + c67b785 commit 5832e5d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroupTemplate.ps1

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,42 @@ function Invoke-AddGroupTemplate {
1414
throw 'You must enter a displayname'
1515
}
1616

17-
# Normalize group type to match New-CIPPGroup expectations (handle both camelCase and lowercase)
17+
# Normalize group type to match New-CIPPGroup expectations
18+
# Handle values from ListGroups calculatedGroupType and frontend form values
1819
$groupType = switch -wildcard ($Request.Body.groupType.ToLower()) {
19-
'*dynamicdistribution*' { 'dynamicDistribution'; break } # Check this first before *dynamic* and *distribution*
20+
# Values from ListGroups calculatedGroupType
21+
'*mail-enabled security*' { 'security'; break }
22+
'*microsoft 365*' { 'm365'; break }
23+
'*distribution list*' { 'distribution'; break }
24+
# Dynamic groups don't have a specific calculatedGroupType - they're detected by membershipRule
25+
# Frontend form values (camelCase and lowercase)
26+
'*dynamicdistribution*' { 'dynamicDistribution'; break }
2027
'*dynamic*' { 'dynamic'; break }
2128
'*azurerole*' { 'azureRole'; break }
2229
'*unified*' { 'm365'; break }
23-
'*microsoft*' { 'm365'; break }
2430
'*m365*' { 'm365'; break }
2531
'*generic*' { 'generic'; break }
26-
'*security*' { 'security'; break }
32+
'*security*' { 'generic'; break }
2733
'*distribution*' { 'distribution'; break }
2834
'*mail*' { 'distribution'; break }
2935
default { $Request.Body.groupType }
3036
}
3137

3238
# Override to dynamic if membership rules are provided (for backward compatibility)
3339
# but only if it's not already a dynamicDistribution group
34-
if ($Request.body.membershipRules -and $groupType -notin @('dynamicDistribution')) {
40+
if ($Request.body.membershipRules -and ![string]::IsNullOrEmpty($Request.Body.membershipRules) -and $Request.Body.membershipRules -ne 'membershipRule' -and $groupType -notin @('dynamicDistribution')) {
3541
$groupType = 'dynamic'
3642
}
3743
# Normalize field names to handle different casing from various forms
3844
$displayName = $Request.Body.displayName ?? $Request.Body.Displayname ?? $Request.Body.displayname
3945
$description = $Request.Body.description ?? $Request.Body.Description
46+
$MembershipRules = ([string]::IsNullOrEmpty($Request.Body.membershipRules) -or $Request.Body.membershipRules -eq 'membershipRule') ? $null : $Request.Body.membershipRules
4047

4148
$object = [PSCustomObject]@{
4249
displayName = $displayName
4350
description = $description
4451
groupType = $groupType
45-
membershipRules = $Request.Body.membershipRules
52+
membershipRules = $MembershipRules
4653
allowExternal = $Request.Body.allowExternal
4754
username = $Request.Body.username # Can contain variables like @%tenantfilter%
4855
GUID = $GUID

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-ListGroupTemplates.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ function Invoke-ListGroupTemplates {
1616
$data = $_.JSON | ConvertFrom-Json
1717

1818
# Normalize groupType to camelCase for consistent frontend handling
19+
# Handle both stored normalized values and legacy values
1920
$normalizedGroupType = switch -Wildcard ($data.groupType.ToLower()) {
21+
# Already normalized values (most common)
22+
'dynamicdistribution' { 'dynamicDistribution'; break }
23+
'azurerole' { 'azureRole'; break }
24+
# Legacy values that might exist in stored templates
2025
'*dynamicdistribution*' { 'dynamicDistribution'; break }
2126
'*dynamic*' { 'dynamic'; break }
2227
'*azurerole*' { 'azureRole'; break }

0 commit comments

Comments
 (0)