Skip to content

Commit b995698

Browse files
committed
Fix CA template list and table side filter when ID/GUID provided
1 parent 1b8c0c1 commit b995698

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/Tenant/Conditional/Invoke-ListCAtemplates.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function Invoke-ListCAtemplates {
99
#>
1010
[CmdletBinding()]
1111
param($Request, $TriggerMetadata)
12-
Write-Host $Request.query.id
12+
$GUID = $Request.query.id ?? $Request.query.ID ?? $Request.query.guid ?? $Request.query.GUID
1313
#Migrating old policies whenever you do a list
1414
$Table = Get-CippTable -tablename 'templates'
1515
$Imported = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'settings'"
@@ -31,10 +31,10 @@ function Invoke-ListCAtemplates {
3131
}
3232
#List new policies
3333
$Table = Get-CippTable -tablename 'templates'
34-
$Filter = "PartitionKey eq 'CATemplate'"
35-
$RawTemplates = (Get-CIPPAzDataTableEntity @Table -Filter $Filter)
3634

3735
if ($Request.query.mode -eq 'Tag') {
36+
$Filter = "PartitionKey eq 'CATemplate'"
37+
$RawTemplates = (Get-CIPPAzDataTableEntity @Table -Filter $Filter)
3838
#when the mode is tag, show all the potential tags, return the object with: label: tag, value: tag, count: number of templates with that tag, unique only
3939
$Templates = @($RawTemplates | Where-Object { $_.Package } | Group-Object -Property Package | ForEach-Object {
4040
$package = $_.Name
@@ -59,6 +59,14 @@ function Invoke-ListCAtemplates {
5959
}
6060
} | Sort-Object -Property label)
6161
} else {
62+
if ($GUID) {
63+
$SafeGUID = ConvertTo-CIPPODataFilterValue -Value $GUID -Type Guid
64+
$Filter = "PartitionKey eq 'CATemplate' and GUID eq '$SafeGUID'"
65+
$RawTemplates = (Get-CIPPAzDataTableEntity @Table -Filter $Filter)
66+
}
67+
else {
68+
$RawTemplates = (Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'CATemplate'")
69+
}
6270
$Templates = $RawTemplates | ForEach-Object {
6371
try {
6472
$row = $_
@@ -74,8 +82,6 @@ function Invoke-ListCAtemplates {
7482
} | Sort-Object -Property displayName
7583
}
7684

77-
if ($Request.query.ID) { $Templates = $Templates | Where-Object -Property GUID -EQ $Request.query.id }
78-
7985
$Templates = ConvertTo-Json -InputObject @($Templates) -Depth 100
8086
return ([HttpResponseContext]@{
8187
StatusCode = [HttpStatusCode]::OK

0 commit comments

Comments
 (0)