Skip to content

Commit 5f833f3

Browse files
authored
Merge pull request #1716 from KelvinTegelaar/dev
Dev to hotfix
2 parents 9cd0600 + 56231d6 commit 5f833f3

File tree

19 files changed

+432
-125
lines changed

19 files changed

+432
-125
lines changed

Modules/CIPPCore/Public/Authentication/Test-CIPPAccessUserRole.ps1

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ function Test-CIPPAccessUserRole {
2020
$User
2121
)
2222
$Roles = @()
23-
$Table = Get-CippTable -TableName cacheAccessUserRoles
24-
$Filter = "PartitionKey eq 'AccessUser' and RowKey eq '$($User.userDetails)' and Timestamp ge datetime'$((Get-Date).AddMinutes(-15).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffZ'))'"
25-
$UserRole = Get-CIPPAzDataTableEntity @Table -Filter $Filter
23+
24+
try {
25+
$Table = Get-CippTable -TableName cacheAccessUserRoles
26+
$Filter = "PartitionKey eq 'AccessUser' and RowKey eq '$($User.userDetails)' and Timestamp ge datetime'$((Get-Date).AddMinutes(-15).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffZ'))'"
27+
$UserRole = Get-CIPPAzDataTableEntity @Table -Filter $Filter
28+
} catch {
29+
Write-Information "Could not access cached user roles table. $($_.Exception.Message)"
30+
$UserRole = $null
31+
}
2632
if ($UserRole) {
2733
Write-Information "Found cached user role for $($User.userDetails)"
2834
$Roles = $UserRole.Role | ConvertFrom-Json
@@ -59,12 +65,16 @@ function Test-CIPPAccessUserRole {
5965
}
6066

6167
if (($Roles | Measure-Object).Count -gt 2) {
62-
$UserRole = [PSCustomObject]@{
63-
PartitionKey = 'AccessUser'
64-
RowKey = [string]$User.userDetails
65-
Role = [string](ConvertTo-Json -Compress -InputObject $Roles)
68+
try {
69+
$UserRole = [PSCustomObject]@{
70+
PartitionKey = 'AccessUser'
71+
RowKey = [string]$User.userDetails
72+
Role = [string](ConvertTo-Json -Compress -InputObject $Roles)
73+
}
74+
Add-CIPPAzDataTableEntity @Table -Entity $UserRole -Force
75+
} catch {
76+
Write-Information "Could not cache user roles for $($User.userDetails). $($_.Exception.Message)"
6677
}
67-
Add-CIPPAzDataTableEntity @Table -Entity $UserRole -Force
6878
}
6979
}
7080
$User.userRoles = $Roles

Modules/CIPPCore/Public/Clear-CippDurables.ps1

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
function Clear-CippDurables {
22
[CmdletBinding(SupportsShouldProcess = $true)]
3-
Param()
3+
param()
44
# Collect info
55
$StorageContext = New-AzStorageContext -ConnectionString $env:AzureWebJobsStorage
66
$FunctionName = $env:WEBSITE_SITE_NAME -replace '-', ''
77

88
# Get orchestrators
99
$InstancesTable = Get-CippTable -TableName ('{0}Instances' -f $FunctionName)
1010
$HistoryTable = Get-CippTable -TableName ('{0}History' -f $FunctionName)
11+
$QueueTable = Get-CippTable -TableName 'CippQueue'
12+
$CippQueueTasks = Get-CippTable -TableName 'CippQueueTasks'
13+
14+
Remove-AzDataTable @InstancesTable
15+
Remove-AzDataTable @HistoryTable
16+
Remove-AzDataTable @QueueTable
17+
Remove-AzDataTable @CippQueueTasks
1118

1219
$Queues = Get-AzStorageQueue -Context $StorageContext -Name ('{0}*' -f $FunctionName) | Select-Object -Property Name, ApproximateMessageCount, QueueClient
1320

@@ -19,8 +26,6 @@ function Clear-CippDurables {
1926
}
2027
}
2128

22-
Remove-AzDataTable @InstancesTable
23-
Remove-AzDataTable @HistoryTable
2429
$BlobContainer = '{0}-largemessages' -f $FunctionName
2530
if (Get-AzStorageContainer -Name $BlobContainer -Context $StorageContext -ErrorAction SilentlyContinue) {
2631
Write-Information "- Removing blob container: $BlobContainer"
@@ -29,32 +34,6 @@ function Clear-CippDurables {
2934
}
3035
}
3136

32-
$QueueTable = Get-CippTable -TableName 'CippQueue'
33-
$CippQueue = Invoke-ListCippQueue
34-
$QueueEntities = foreach ($Queue in $CippQueue) {
35-
if ($Queue.Status -eq 'Running') {
36-
$Queue.TotalTasks = $Queue.CompletedTasks
37-
$Queue | Select-Object -Property PartitionKey, RowKey, TotalTasks
38-
}
39-
}
40-
if (($QueueEntities | Measure-Object).Count -gt 0) {
41-
if ($PSCmdlet.ShouldProcess('Queues', 'Mark Failed')) {
42-
Update-AzDataTableEntity -Force @QueueTable -Entity $QueueEntities
43-
}
44-
}
45-
46-
$CippQueueTasks = Get-CippTable -TableName 'CippQueueTasks'
47-
$RunningTasks = Get-CIPPAzDataTableEntity @CippQueueTasks -Filter "PartitionKey eq 'Task' and Status eq 'Running'" -Property RowKey, PartitionKey, Status
48-
if (($RunningTasks | Measure-Object).Count -gt 0) {
49-
if ($PSCmdlet.ShouldProcess('Tasks', 'Mark Failed')) {
50-
$UpdatedTasks = foreach ($Task in $RunningTasks) {
51-
$Task.Status = 'Failed'
52-
$Task
53-
}
54-
Update-AzDataTableEntity -Force @CippQueueTasks -Entity $UpdatedTasks
55-
}
56-
}
57-
5837
$null = Get-CippTable -TableName ('{0}History' -f $FunctionName)
5938
Write-Information 'Durable Orchestrators and Queues have been cleared'
6039
return $true

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ function Push-ExecScheduledCommand {
77
$item = $Item | ConvertTo-Json -Depth 100 | ConvertFrom-Json
88
Write-Information "We are going to be running a scheduled task: $($Item.TaskInfo | ConvertTo-Json -Depth 10)"
99

10+
$script:ScheduledTaskId = $Item.TaskInfo.RowKey
11+
1012
$Table = Get-CippTable -tablename 'ScheduledTasks'
1113
$task = $Item.TaskInfo
1214
$commandParameters = $Item.Parameters | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashtable
@@ -21,10 +23,12 @@ function Push-ExecScheduledCommand {
2123
$CurrentTask = Get-AzDataTableEntity @Table -Filter "PartitionKey eq '$($task.PartitionKey)' and RowKey eq '$($task.RowKey)'"
2224
if (!$CurrentTask) {
2325
Write-Information "The task $($task.Name) for tenant $($task.Tenant) does not exist in the ScheduledTasks table. Exiting."
26+
Remove-Variable -Name ScheduledTaskId -Scope Script -ErrorAction SilentlyContinue
2427
return
2528
}
2629
if ($CurrentTask.TaskState -eq 'Completed') {
2730
Write-Information "The task $($task.Name) for tenant $($task.Tenant) is already completed. Skipping execution."
31+
Remove-Variable -Name ScheduledTaskId -Scope Script -ErrorAction SilentlyContinue
2832
return
2933
}
3034

@@ -69,6 +73,7 @@ function Push-ExecScheduledCommand {
6973
TaskState = 'Planned'
7074
ScheduledTime = [string]$nextRunUnixTime
7175
}
76+
Remove-Variable -Name ScheduledTaskId -Scope Script -ErrorAction SilentlyContinue
7277
return
7378
}
7479
}
@@ -94,6 +99,7 @@ function Push-ExecScheduledCommand {
9499
}
95100

96101
Write-LogMessage -API 'Scheduler_UserTasks' -tenant $Tenant -tenantid $TenantInfo.customerId -message "Failed to execute task $($task.Name): The command $($Item.Command) does not exist." -sev Error
102+
Remove-Variable -Name ScheduledTaskId -Scope Script -ErrorAction SilentlyContinue
97103
return
98104
}
99105

@@ -330,4 +336,5 @@ function Push-ExecScheduledCommand {
330336
if ($TaskType -ne 'Alert') {
331337
Write-LogMessage -API 'Scheduler_UserTasks' -tenant $Tenant -tenantid $TenantInfo.customerId -message "Successfully executed task: $($task.Name)" -sev Info
332338
}
339+
Remove-Variable -Name ScheduledTaskId -Scope Script -ErrorAction SilentlyContinue
333340
}

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Standards/Push-CIPPStandard.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,7 @@ function Push-CIPPStandard {
5656
Write-Warning "Error running standard $($Standard) for tenant $($Tenant) - $($_.Exception.Message)"
5757
Write-Information $_.InvocationInfo.PositionMessage
5858
throw $_.Exception.Message
59+
} finally {
60+
Remove-Variable -Name StandardInfo -Scope Script -ErrorAction SilentlyContinue
5961
}
6062
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecEditTemplate.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ function Invoke-ExecEditTemplate {
2020
$Template = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'IntuneTemplate' and RowKey eq '$GUID'"
2121
$OriginalJSON = $Template.JSON
2222

23+
$TemplateData = $Template.JSON | ConvertFrom-Json
24+
$TemplateType = $TemplateData.Type
25+
2326
if ($Template.SHA) {
2427
$NewGuid = [guid]::NewGuid().ToString()
2528
} else {
@@ -36,7 +39,7 @@ function Invoke-ExecEditTemplate {
3639
RawJson = $RawJSON
3740
DisplayName = $Request.Body.displayName
3841
Description = $Request.Body.description
39-
templateType = $Template.Type
42+
templateType = $TemplateType
4043
Package = $Template.Package
4144
Headers = $Request.Headers
4245
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecApiClient.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function Invoke-ExecApiClient {
148148
if (!$Client) {
149149
$Results = @{
150150
resultText = 'API client not found'
151-
severity = 'error'
151+
state = 'error'
152152
}
153153
} else {
154154
$ApiConfig = New-CIPPAPIConfig -ResetSecret -AppId $Request.Body.ClientId -Headers $Request.Headers

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Setup/Invoke-ExecUpdateRefreshToken.ps1

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function Invoke-ExecUpdateRefreshToken {
1+
function Invoke-ExecUpdateRefreshToken {
22
<#
33
.FUNCTIONALITY
44
Entrypoint,AnyTenant
@@ -49,16 +49,21 @@ Function Invoke-ExecUpdateRefreshToken {
4949
$TenantName = $request.body.tenantId
5050
}
5151
$Results = @{
52-
'message' = "Successfully updated the credentials for $($TenantName). You may continue to the next step, or add additional tenants if required."
53-
'severity' = 'success'
52+
'resultText' = "Successfully updated the credentials for $($TenantName). You may continue to the next step, or add additional tenants if required."
53+
'state' = 'success'
5454
}
5555
} catch {
56-
$Results = [pscustomobject]@{'Results' = "Failed. $($_.InvocationInfo.ScriptLineNumber): $($_.Exception.message)"; severity = 'failed' }
57-
}
56+
$Results = [pscustomobject]@{
57+
'Results' = @{
58+
resultText = "Failed. $($_.InvocationInfo.ScriptLineNumber): $($_.Exception.message)"
59+
state = 'failed'
60+
}
61+
}
5862

59-
return ([HttpResponseContext]@{
60-
StatusCode = [HttpStatusCode]::OK
61-
Body = $Results
62-
})
63+
return ([HttpResponseContext]@{
64+
StatusCode = [HttpStatusCode]::OK
65+
Body = $Results
66+
})
6367

68+
}
6469
}

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function Invoke-ExecCopyForSent {
1+
function Invoke-ExecCopyForSent {
22
<#
33
.FUNCTIONALITY
44
Entrypoint
@@ -13,13 +13,21 @@ Function Invoke-ExecCopyForSent {
1313

1414

1515
# Interact with query parameters or the body of the request.
16-
$TenantFilter = $Request.Query.TenantFilter ?? $Request.Body.TenantFilter
16+
$TenantFilter = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter
1717
$UserID = $Request.Query.ID ?? $Request.Body.ID
18-
$MessageCopyForSentAsEnabled = $Request.Query.MessageCopyForSentAsEnabled ?? $Request.Body.MessageCopyForSentAsEnabled
19-
$MessageCopyForSentAsEnabled = [System.Convert]::ToBoolean($MessageCopyForSentAsEnabled)
18+
$MessageCopyState = $Request.Query.messageCopyState ?? $Request.Body.messageCopyState
19+
$MessageCopyState = [System.Convert]::ToBoolean($MessageCopyState)
2020

21-
Try {
22-
$Result = Set-CIPPMessageCopy -userid $UserID -tenantFilter $TenantFilter -APIName $APIName -Headers $Headers -MessageCopyForSentAsEnabled $MessageCopyForSentAsEnabled
21+
try {
22+
$params = @{
23+
UserId = $UserID
24+
TenantFilter = $TenantFilter
25+
APIName = $APIName
26+
Headers = $Headers
27+
MessageCopyForSentAsEnabled = $MessageCopyState
28+
MessageCopyForSendOnBehalfEnabled = $MessageCopyState
29+
}
30+
$Result = Set-CIPPMessageCopy @params
2331
$StatusCode = [HttpStatusCode]::OK
2432
} catch {
2533
$Result = "$($_.Exception.Message)"

0 commit comments

Comments
 (0)