Skip to content

Commit 80af0d8

Browse files
Merge pull request KelvinTegelaar#1731 from Zacgoose/copilot/update-user-defaults-logic
Return AllTenants user templates along with specific tenant user templates
2 parents 2ce4011 + 4345257 commit 80af0d8

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListNewUserDefaults.ps1

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ function Invoke-ListNewUserDefaults {
1313
# Get the TenantFilter from query parameters
1414
$TenantFilter = $Request.Query.TenantFilter
1515
Write-Host "TenantFilter from request: $TenantFilter"
16+
17+
# Get the includeAllTenants flag from query or body parameters (defaults to true)
18+
$IncludeAllTenants = if ($Request.Query.includeAllTenants -eq 'false' -or $Request.Body.includeAllTenants -eq 'false') {
19+
$false
20+
} else {
21+
$true
22+
}
23+
Write-Host "IncludeAllTenants: $IncludeAllTenants"
1624

1725
# Get the templates table
1826
$Table = Get-CippTable -tablename 'templates'
@@ -36,7 +44,19 @@ function Invoke-ListNewUserDefaults {
3644

3745
# Filter by tenant if TenantFilter is provided
3846
if ($TenantFilter) {
39-
$Templates = $Templates | Where-Object -Property tenantFilter -EQ $TenantFilter
47+
if ($TenantFilter -eq 'AllTenants') {
48+
# When requesting AllTenants, return only templates stored under AllTenants
49+
$Templates = $Templates | Where-Object -Property tenantFilter -eq 'AllTenants'
50+
} else {
51+
# When requesting a specific tenant
52+
if ($IncludeAllTenants) {
53+
# Include both tenant-specific and AllTenants templates
54+
$Templates = $Templates | Where-Object { $_.tenantFilter -eq $TenantFilter -or $_.tenantFilter -eq 'AllTenants' }
55+
} else {
56+
# Return only tenant-specific templates (exclude AllTenants)
57+
$Templates = $Templates | Where-Object -Property tenantFilter -eq $TenantFilter
58+
}
59+
}
4060
Write-Host "Templates after filtering: $($Templates.Count)"
4161
}
4262

@@ -45,7 +65,7 @@ function Invoke-ListNewUserDefaults {
4565

4666
# If a specific ID is requested, filter to that template
4767
if ($Request.query.ID) {
48-
$Templates = $Templates | Where-Object -Property GUID -EQ $Request.query.ID
68+
$Templates = $Templates | Where-Object -Property GUID -eq $Request.query.ID
4969
}
5070

5171
$Templates = ConvertTo-Json -InputObject @($Templates) -Depth 100

0 commit comments

Comments
 (0)