Skip to content

Commit 5d4ed1d

Browse files
authored
Merge pull request #431 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 6d3b6c2 + 72aba48 commit 5d4ed1d

File tree

16 files changed

+226
-37
lines changed

16 files changed

+226
-37
lines changed

Modules/CIPPCore/Public/CippQueue/Invoke-ListCippQueue.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@ function Invoke-ListCippQueue {
55
.ROLE
66
CIPP.Core.Read
77
#>
8-
param($Request = $null, $TriggerMetadata = $null)
8+
param($Request = $null, $TriggerMetadata = $null, $Reference = $null, $QueueId = $null)
99

1010
if ($Request) {
1111
$APIName = $Request.Params.CIPPEndpoint
1212
Write-LogMessage -headers $Request.Headers -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1313
}
1414

15-
$QueueId = $Request.Query.QueueId
15+
$QueueId = $Request.Query.QueueId ?? $QueueId
16+
$Reference = $Request.Query.Reference ?? $Reference
1617

1718
$CippQueue = Get-CippTable -TableName 'CippQueue'
1819
$CippQueueTasks = Get-CippTable -TableName 'CippQueueTasks'
1920
$3HoursAgo = (Get-Date).ToUniversalTime().AddHours(-3).ToString('yyyy-MM-ddTHH:mm:ssZ')
2021

2122
if ($QueueId) {
2223
$Filter = "PartitionKey eq 'CippQueue' and RowKey eq '$QueueId'"
24+
} elseif ($Reference) {
25+
$Filter = "PartitionKey eq 'CippQueue' and Reference eq '$Reference' and Timestamp ge datetime'$3HoursAgo'"
2326
} else {
2427
$Filter = "PartitionKey eq 'CippQueue' and Timestamp ge datetime'$3HoursAgo'"
2528
}

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ListMailboxRulesQueue.ps1

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ function Push-ListMailboxRulesQueue {
1212

1313
$Table = Get-CIPPTable -TableName cachembxrules
1414
try {
15-
$Rules = New-ExoRequest -tenantid $domainName -cmdlet 'Get-Mailbox' -Select 'userPrincipalName,GUID' | ForEach-Object -Parallel {
16-
Import-Module CIPPCore
17-
$MbxRules = New-ExoRequest -Anchor $_.UserPrincipalName -tenantid $using:domainName -cmdlet 'Get-InboxRule' -cmdParams @{Mailbox = $_.GUID; IncludeHidden = $true } | Where-Object { $_.Name -ne 'Junk E-Mail Rule' -and $_.Name -notlike 'Microsoft.Exchange.OOF.*' }
18-
foreach ($Rule in $MbxRules) {
19-
$Rule | Add-Member -NotePropertyName 'UserPrincipalName' -NotePropertyValue $_.userPrincipalName
20-
$Rule
15+
$Mailboxes = New-ExoRequest -tenantid $domainName -cmdlet 'Get-Mailbox' -Select 'userPrincipalName,GUID'
16+
$Request = $Mailboxes | ForEach-Object {
17+
@{
18+
OperationGuid = $_.UserPrincipalName
19+
CmdletInput = @{
20+
CmdletName = 'Get-InboxRule'
21+
Parameters = @{
22+
Mailbox = $_.UserPrincipalName
23+
}
24+
}
2125
}
2226
}
27+
28+
$Rules = New-ExoBulkRequest -tenantid $domainName -cmdletArray @($Request) | Where-Object { $_.Identity }
2329
if (($Rules | Measure-Object).Count -gt 0) {
2430
$GraphRequest = foreach ($Rule in $Rules) {
2531
[PSCustomObject]@{

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-UpdateTenants.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function Push-UpdateTenants {
55
#>
66
Param($Item)
77
$QueueReference = 'UpdateTenants'
8-
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -ne 'Completed' -and $_.Status -ne 'Failed' }
8+
$RunningQueue = Invoke-ListCippQueue -Reference $QueueReference | Where-Object { $_.Status -ne 'Completed' -and $_.Status -ne 'Failed' }
99

1010
$Queue = New-CippQueueEntry -Name 'Update Tenants' -Reference $QueueReference -TotalTasks 1
1111
try {

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-ListMailboxRules.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,21 @@ function Invoke-ListMailboxRules {
1919

2020
$Table = Get-CIPPTable -TableName cachembxrules
2121
if ($TenantFilter -ne 'AllTenants') {
22-
$Table.Filter = "Tenant eq '$TenantFilter'"
22+
$Table.Filter = "PartitionKey eq 'MailboxRules' and Tenant eq '$TenantFilter'"
23+
} else {
24+
$Table.Filter = "PartitionKey eq 'MailboxRules'"
2325
}
26+
27+
Write-Information 'Getting cached mailbox rules'
2428
$Rows = Get-CIPPAzDataTableEntity @Table | Where-Object -Property Timestamp -GT (Get-Date).AddHours(-1)
2529
$PartitionKey = 'MailboxRules'
2630
$QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey
27-
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
31+
$RunningQueue = Invoke-ListCippQueue -Reference $QueueReference | Where-Object { $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
2832

2933
$Metadata = @{}
3034
# If a queue is running, we will not start a new one
3135
if ($RunningQueue -and !$Rows) {
36+
Write-Information "Queue is already running for $TenantFilter"
3237
$Metadata = [PSCustomObject]@{
3338
QueueMessage = "Still loading data for $TenantFilter. Please check back in a few more minutes"
3439
QueueId = $RunningQueue.RowKey
@@ -37,7 +42,7 @@ function Invoke-ListMailboxRules {
3742
Waiting = $true
3843
}
3944
} elseif ((!$Rows -and !$RunningQueue) -or ($TenantFilter -eq 'AllTenants' -and ($Rows | Measure-Object).Count -eq 1)) {
40-
45+
Write-Information "No cached mailbox rules found for $TenantFilter, starting new orchestration"
4146
if ($TenantFilter -eq 'AllTenants') {
4247
$Tenants = Get-Tenants -IncludeErrors | Select-Object defaultDomainName
4348
$Type = 'All Tenants'
@@ -65,10 +70,6 @@ function Invoke-ListMailboxRules {
6570
}
6671

6772
} else {
68-
if ($TenantFilter -ne 'AllTenants') {
69-
$Rows = $Rows | Where-Object -Property Tenant -EQ $TenantFilter
70-
$Rows = $Rows
71-
}
7273
$Metadata = [PSCustomObject]@{
7374
QueueId = $RunningQueue.RowKey ?? $null
7475
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Transport/Invoke-ListTransportRules.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ListTransportRules {
3+
function Invoke-ListTransportRules {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -28,19 +28,21 @@ Function Invoke-ListTransportRules {
2828
$Filter = "PartitionKey eq '$PartitionKey'"
2929
$Rows = Get-CIPPAzDataTableEntity @Table -filter $Filter | Where-Object -Property Timestamp -GT (Get-Date).AddMinutes(-60)
3030
$QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey
31-
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
31+
$RunningQueue = Invoke-ListCippQueue -Reference $QueueReference | Where-Object { $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
3232

3333
# If a queue is running, we will not start a new one
3434
if ($RunningQueue) {
3535
$Metadata = [PSCustomObject]@{
3636
QueueMessage = 'Still loading transport rules for all tenants. Please check back in a few more minutes'
37+
QueueId = $RunningQueue.RowKey
3738
}
3839
} elseif (!$Rows -and !$RunningQueue) {
3940
# If no rows are found and no queue is running, we will start a new one
4041
$TenantList = Get-Tenants -IncludeErrors
4142
$Queue = New-CippQueueEntry -Name 'Transport Rules - All Tenants' -Link '/email/transport/list-rules?tenantFilter=AllTenants' -Reference $QueueReference -TotalTasks ($TenantList | Measure-Object).Count
4243
$Metadata = [PSCustomObject]@{
4344
QueueMessage = 'Loading transport rules for all tenants. Please check back in a few minutes'
45+
QueueId = $Queue.RowKey
4446
}
4547
$InputObject = [PSCustomObject]@{
4648
OrchestratorName = 'TransportRuleOrchestrator'
@@ -57,6 +59,9 @@ Function Invoke-ListTransportRules {
5759
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress) | Out-Null
5860
} else {
5961
# Return cached data
62+
$Metadata = [PSCustomObject]@{
63+
QueueId = $RunningQueue.RowKey ?? $null
64+
}
6065
$Rules = $Rows
6166
foreach ($rule in $Rules) {
6267
$RuleObj = $rule.TransportRule | ConvertFrom-Json

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function Invoke-ExecJITAdmin {
7070

7171
$QueueReference = '{0}-{1}' -f $Request.Query.TenantFilter, $PartitionKey # $TenantFilter is 'AllTenants'
7272
Write-Information "QueueReference: $QueueReference"
73-
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
73+
$RunningQueue = Invoke-ListCippQueue -Reference $QueueReference | Where-Object { $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
7474

7575
if ($RunningQueue) {
7676
$Metadata = [PSCustomObject]@{

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ function Invoke-ListUserSettings {
3636
}
3737
}
3838
}
39+
40+
try {
41+
$UserSpecificSettings = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'UserSettings' and RowKey eq '$Username'"
42+
$UserSpecificSettings = $UserSpecificSettings.JSON | ConvertFrom-Json -Depth 10 -ErrorAction SilentlyContinue
43+
}
44+
catch {
45+
Write-Warning "Failed to convert UserSpecificSettings JSON: $($_.Exception.Message)"
46+
}
47+
3948
#Get branding settings
4049
if ($UserSettings) {
4150
$brandingTable = Get-CippTable -tablename 'Config'
@@ -44,6 +53,11 @@ function Invoke-ListUserSettings {
4453
$UserSettings | Add-Member -MemberType NoteProperty -Name 'customBranding' -Value $BrandingSettings -Force | Out-Null
4554
}
4655
}
56+
57+
if ($UserSpecificSettings) {
58+
$UserSettings | Add-Member -MemberType NoteProperty -Name 'UserSpecificSettings' -Value $UserSpecificSettings -Force | Out-Null
59+
}
60+
4761
$StatusCode = [HttpStatusCode]::OK
4862
$Results = $UserSettings
4963
} catch {

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Security/Invoke-ExecAlertsList.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function Invoke-ExecAlertsList {
6363
$Filter = "PartitionKey eq '$PartitionKey'"
6464
$Rows = Get-CIPPAzDataTableEntity @Table -filter $Filter | Where-Object -Property Timestamp -GT (Get-Date).AddMinutes(-30)
6565
$QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey
66-
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
66+
$RunningQueue = Invoke-ListCippQueue -Reference $QueueReference | Where-Object { $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
6767
# If a queue is running, we will not start a new one
6868
if ($RunningQueue) {
6969
$Metadata = [PSCustomObject]@{

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Security/Invoke-ExecIncidentsList.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function Invoke-ExecIncidentsList {
4747
$Filter = "PartitionKey eq '$PartitionKey'"
4848
$Rows = Get-CIPPAzDataTableEntity @Table -filter $Filter | Where-Object -Property Timestamp -GT (Get-Date).AddMinutes(-30)
4949
$QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey
50-
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
50+
$RunningQueue = Invoke-ListCippQueue -Reference $QueueReference | Where-Object { $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
5151
# If a queue is running, we will not start a new one
5252
if ($RunningQueue) {
5353
$Metadata = [PSCustomObject]@{
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using namespace System.Net
2+
3+
function Invoke-EditTenantOffboardingDefaults {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint,AnyTenant
7+
.ROLE
8+
Tenant.Config.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $Request.Params.CIPPEndpoint
14+
$Headers = $Request.Headers
15+
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
16+
17+
# Interact with query parameters or the body of the request.
18+
$customerId = $Request.Body.customerId
19+
$offboardingDefaults = $Request.Body.offboardingDefaults
20+
21+
if (!$customerId) {
22+
$response = @{
23+
state = 'error'
24+
resultText = 'Customer ID is required'
25+
}
26+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
27+
StatusCode = [HttpStatusCode]::BadRequest
28+
Body = $response
29+
})
30+
return
31+
}
32+
33+
$PropertiesTable = Get-CippTable -TableName 'TenantProperties'
34+
35+
try {
36+
# Convert the offboarding defaults to JSON string and ensure it's treated as a string
37+
$jsonValue = [string]($offboardingDefaults | ConvertTo-Json -Compress)
38+
39+
if ($jsonValue -and $jsonValue -ne '{}' -and $jsonValue -ne 'null' -and $jsonValue -ne '') {
40+
# Save offboarding defaults
41+
$offboardingEntity = @{
42+
PartitionKey = [string]$customerId
43+
RowKey = [string]'OffboardingDefaults'
44+
Value = [string]$jsonValue
45+
}
46+
$null = Add-CIPPAzDataTableEntity @PropertiesTable -Entity $offboardingEntity -Force
47+
Write-LogMessage -headers $Headers -tenant $customerId -API $APIName -message "Updated tenant offboarding defaults" -Sev 'Info'
48+
49+
$resultText = 'Tenant offboarding defaults updated successfully'
50+
} else {
51+
# Remove offboarding defaults if empty or null
52+
$Existing = Get-CIPPAzDataTableEntity @PropertiesTable -Filter "PartitionKey eq '$customerId' and RowKey eq 'OffboardingDefaults'"
53+
if ($Existing) {
54+
Remove-AzDataTableEntity @PropertiesTable -Entity $Existing
55+
Write-LogMessage -headers $Headers -tenant $customerId -API $APIName -message "Removed tenant offboarding defaults" -Sev 'Info'
56+
}
57+
58+
$resultText = 'Tenant offboarding defaults cleared successfully'
59+
}
60+
61+
$response = @{
62+
state = 'success'
63+
resultText = $resultText
64+
}
65+
66+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
67+
StatusCode = [HttpStatusCode]::OK
68+
Body = $response
69+
})
70+
} catch {
71+
Write-LogMessage -headers $Headers -tenant $customerId -API $APINAME -message "Edit Tenant Offboarding Defaults failed. The error is: $($_.Exception.Message)" -Sev 'Error'
72+
$response = @{
73+
state = 'error'
74+
resultText = $_.Exception.Message
75+
}
76+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
77+
StatusCode = [HttpStatusCode]::InternalServerError
78+
Body = $response
79+
})
80+
}
81+
}

0 commit comments

Comments
 (0)