Skip to content

Commit deccc55

Browse files
authored
Merge pull request #478 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 2099f34 + 1d1882a commit deccc55

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/New-CippCoreRequest.ps1

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,17 @@ function New-CippCoreRequest {
3838
Write-LogMessage -headers $Headers -API $Request.Params.CIPPEndpoint -message 'Accessed this API' -Sev 'Debug'
3939
if ($Access) {
4040
$Response = & $FunctionName @HttpTrigger
41-
if ($Response.StatusCode) {
42-
return ([HttpResponseContext]$Response)
41+
# Filter to only return HttpResponseContext objects
42+
$HttpResponse = $Response | Where-Object { $_.PSObject.TypeNames -contains 'HttpResponseContext' -or ($_.StatusCode -and $_.Body) }
43+
if ($HttpResponse) {
44+
# Return the first valid HttpResponseContext found
45+
return ([HttpResponseContext]($HttpResponse | Select-Object -First 1))
46+
} else {
47+
# If no valid response context found, create a default success response
48+
return ([HttpResponseContext]@{
49+
StatusCode = [HttpStatusCode]::OK
50+
Body = $Response
51+
})
4352
}
4453
}
4554
} catch {
@@ -61,4 +70,4 @@ function New-CippCoreRequest {
6170
Body = 'Request not processed'
6271
})
6372
}
64-
}
73+
}

Modules/CIPPCore/Public/Set-CIPPCAExclusion.ps1

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Set-CIPPCAExclusion {
1919
$ExcludeUsers.Add($User)
2020
}
2121
foreach ($User in $Users.value) {
22-
if ($ExcludeUsers -notcontains $User) {
22+
if ($User -and $User -ne '' -and $ExcludeUsers -notcontains $User) {
2323
$ExcludeUsers.Add($User)
2424
}
2525
}
@@ -42,14 +42,20 @@ function Set-CIPPCAExclusion {
4242
}
4343

4444
$RawJson = ConvertTo-Json -Depth 10 -InputObject $NewExclusions
45-
if ($PSCmdlet.ShouldProcess($PolicyId, "Add exclusion for $UserID")) {
45+
46+
if ($Users) {
47+
$UserIdentifier = ($Username -join ', ')
48+
} else {
49+
$UserIdentifier = $UserID
50+
}
51+
if ($PSCmdlet.ShouldProcess($PolicyId, "Add exclusion for $UserIdentifier")) {
4652
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/identity/conditionalAccess/policies/$($CheckExisting.id)" -tenantid $tenantfilter -type PATCH -body $RawJSON -AsApp $true
4753
}
4854
}
4955

5056
if ($ExclusionType -eq 'remove') {
5157
if ($Users) {
52-
$UserID = $Users.value
58+
$UserID = $Users.value | Where-Object { $_ -and $_ -ne '' }
5359
$Username = $Users.addedFields.userPrincipalName
5460
} else {
5561
if ($UserID -match '^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$') {
@@ -64,7 +70,13 @@ function Set-CIPPCAExclusion {
6470
}
6571
}
6672
$RawJson = ConvertTo-Json -Depth 10 -InputObject $NewExclusions
67-
if ($PSCmdlet.ShouldProcess($PolicyId, "Remove exclusion for $UserID")) {
73+
74+
if ($Users) {
75+
$UserIdentifier = ($Username -join ', ')
76+
} else {
77+
$UserIdentifier = $UserID
78+
}
79+
if ($PSCmdlet.ShouldProcess($PolicyId, "Remove exclusion for $UserIdentifier")) {
6880
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/identity/conditionalAccess/policies/$($CheckExisting.id)" -tenantid $tenantfilter -type PATCH -body $RawJSON -AsApp $true
6981
}
7082
}

0 commit comments

Comments
 (0)