@@ -11,21 +11,74 @@ function Invoke-ListTenantAllowBlockList {
1111 $TenantFilter = $Request.Query.tenantFilter
1212 $ListTypes = ' Sender' , ' Url' , ' FileHash' , ' IP'
1313 try {
14- $Results = $ListTypes | ForEach-Object - Parallel {
15- Import-Module CIPPCore
16- $TempResults = New-ExoRequest - tenantid $using :TenantFilter - cmdlet ' Get-TenantAllowBlockListItems' - cmdParams @ {ListType = $_ }
17- $TempResults | Add-Member - MemberType NoteProperty - Name ListType - Value $_
18- $TempResults | Select-Object - ExcludeProperty * ' @data.type' * , * ' (DateTime])' *
19- } - ThrottleLimit 5
20-
14+ if ($TenantFilter -ne ' AllTenants' ) {
15+ $Results = $ListTypes | ForEach-Object - Parallel {
16+ Import-Module CIPPCore
17+ $TempResults = New-ExoRequest - tenantid $using :TenantFilter - cmdlet ' Get-TenantAllowBlockListItems' - cmdParams @ { ListType = $_ }
18+ $TempResults | Add-Member - MemberType NoteProperty - Name ListType - Value $_ - Force
19+ $TempResults | Add-Member - MemberType NoteProperty - Name Tenant - Value $using :TenantFilter - Force
20+ $TempResults | Select-Object - ExcludeProperty * ' @data.type' * , * ' (DateTime])' *
21+ } - ThrottleLimit 5
22+ $Metadata = [PSCustomObject ]@ {}
23+ } else {
24+ $Table = Get-CIPPTable - TableName ' cacheTenantAllowBlockList'
25+ $PartitionKey = ' TenantAllowBlockList'
26+ $Filter = " PartitionKey eq '$PartitionKey '"
27+ $Rows = Get-CIPPAzDataTableEntity @Table - filter $Filter | Where-Object - Property Timestamp -GT (Get-Date ).AddMinutes(-60 )
28+ $QueueReference = ' {0}-{1}' -f $TenantFilter , $PartitionKey
29+ $RunningQueue = Invoke-ListCippQueue - Reference $QueueReference | Where-Object { $_.Status -notmatch ' Completed' -and $_.Status -notmatch ' Failed' }
30+ if ($RunningQueue ) {
31+ $Metadata = [PSCustomObject ]@ {
32+ QueueMessage = ' Still loading data for all tenants. Please check back in a few more minutes'
33+ QueueId = $RunningQueue.RowKey
34+ }
35+ $Results = @ ()
36+ } elseif (! $Rows -and ! $RunningQueue ) {
37+ $TenantList = Get-Tenants - IncludeErrors
38+ $Queue = New-CippQueueEntry - Name ' Tenant Allow/Block List - All Tenants' - Link ' /tenant/administration/allow-block-list?customerId=AllTenants' - Reference $QueueReference - TotalTasks ($TenantList | Measure-Object ).Count
39+ $Metadata = [PSCustomObject ]@ {
40+ QueueMessage = ' Loading data for all tenants. Please check back in a few minutes'
41+ QueueId = $Queue.RowKey
42+ }
43+ $InputObject = [PSCustomObject ]@ {
44+ OrchestratorName = ' TenantAllowBlockListOrchestrator'
45+ QueueFunction = @ {
46+ FunctionName = ' GetTenants'
47+ QueueId = $Queue.RowKey
48+ TenantParams = @ {
49+ IncludeErrors = $true
50+ }
51+ DurableName = ' ListTenantAllowBlockListAllTenants'
52+ }
53+ SkipLog = $true
54+ }
55+ Start-NewOrchestration - FunctionName ' CIPPOrchestrator' - InputObject ($InputObject | ConvertTo-Json - Depth 5 - Compress) | Out-Null
56+ $Results = @ ()
57+ } else {
58+ $Metadata = [PSCustomObject ]@ {
59+ QueueId = $RunningQueue.RowKey ?? $null
60+ }
61+ $Results = foreach ($Row in $Rows ) {
62+ $Row.Entry | ConvertFrom-Json
63+ }
64+ }
65+ }
2166 $StatusCode = [HttpStatusCode ]::OK
2267 } catch {
2368 $ErrorMessage = Get-NormalizedError - Message $_.Exception.Message
2469 $StatusCode = [HttpStatusCode ]::Forbidden
2570 $Results = $ErrorMessage
2671 }
72+
73+ if (! $Body ) {
74+ $Body = [PSCustomObject ]@ {
75+ Results = @ ($Results )
76+ Metadata = $Metadata
77+ }
78+ }
79+
2780 return [HttpResponseContext ]@ {
2881 StatusCode = $StatusCode
29- Body = @ ( $Results )
82+ Body = $Body
3083 }
3184}
0 commit comments