Skip to content

Commit cb18d7a

Browse files
committed
Add includeAllTenants flag to user defaults listing
Introduces an includeAllTenants flag to control whether tenant-specific or all-tenant templates are included when listing new user defaults. Improves filtering logic to support more flexible template retrieval based on tenant context.
1 parent 2ce4011 commit cb18d7a

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ function Invoke-ListNewUserDefaults {
1212

1313
# Get the TenantFilter from query parameters
1414
$TenantFilter = $Request.Query.TenantFilter
15-
Write-Host "TenantFilter from request: $TenantFilter"
15+
16+
# Get the includeAllTenants flag from query or body parameters (defaults to true)
17+
$IncludeAllTenants = if ($Request.Query.includeAllTenants -eq 'false' -or $Request.Body.includeAllTenants -eq 'false') {
18+
$false
19+
} else {
20+
$true
21+
}
1622

1723
# Get the templates table
1824
$Table = Get-CippTable -tablename 'templates'
@@ -25,27 +31,35 @@ function Invoke-ListNewUserDefaults {
2531
$data = $row.JSON | ConvertFrom-Json -Depth 100 -ErrorAction Stop
2632
$data | Add-Member -NotePropertyName 'GUID' -NotePropertyValue $row.GUID -Force
2733
$data | Add-Member -NotePropertyName 'RowKey' -NotePropertyValue $row.RowKey -Force
28-
Write-Host "Template found: $($data.templateName), tenantFilter: $($data.tenantFilter)"
2934
$data
3035
} catch {
3136
Write-Warning "Failed to process User Default template: $($row.RowKey) - $($_.Exception.Message)"
3237
}
3338
}
3439

35-
Write-Host "Total templates before filtering: $($Templates.Count)"
36-
3740
# Filter by tenant if TenantFilter is provided
3841
if ($TenantFilter) {
39-
$Templates = $Templates | Where-Object -Property tenantFilter -EQ $TenantFilter
40-
Write-Host "Templates after filtering: $($Templates.Count)"
42+
if ($TenantFilter -eq 'AllTenants') {
43+
# When requesting AllTenants, return only templates stored under AllTenants
44+
$Templates = $Templates | Where-Object -Property tenantFilter -eq 'AllTenants'
45+
} else {
46+
# When requesting a specific tenant
47+
if ($IncludeAllTenants) {
48+
# Include both tenant-specific and AllTenants templates
49+
$Templates = $Templates | Where-Object { $_.tenantFilter -eq $TenantFilter -or $_.tenantFilter -eq 'AllTenants' }
50+
} else {
51+
# Return only tenant-specific templates (exclude AllTenants)
52+
$Templates = $Templates | Where-Object -Property tenantFilter -eq $TenantFilter
53+
}
54+
}
4155
}
4256

4357
# Sort by template name
4458
$Templates = $Templates | Sort-Object -Property templateName
4559

4660
# If a specific ID is requested, filter to that template
4761
if ($Request.query.ID) {
48-
$Templates = $Templates | Where-Object -Property GUID -EQ $Request.query.ID
62+
$Templates = $Templates | Where-Object -Property GUID -eq $Request.query.ID
4963
}
5064

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

0 commit comments

Comments
 (0)