Skip to content

Commit 9969b9f

Browse files
committed
feat(named-locations): support removing multiple IPs and locations
- Updated Set-CIPPNamedLocation to handle multiple IPs and locations for removal. - Enhanced Invoke-ExecNamedLocation to correctly process input values.
1 parent d2d5469 commit 9969b9f

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Conditional/Invoke-ExecNamedLocation.ps1

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,25 @@ function Invoke-ExecNamedLocation {
1111
$APIName = $Request.Params.CIPPEndpoint
1212
$Headers = $Request.Headers
1313

14-
15-
1614
# Interact with query parameters or the body of the request.
1715
$TenantFilter = $Request.Body.tenantFilter ?? $Request.Query.tenantFilter
1816
$NamedLocationId = $Request.Body.namedLocationId ?? $Request.Query.namedLocationId
1917
$Change = $Request.Body.change ?? $Request.Query.change
20-
$Content = $Request.Body.input ?? $Request.Query.input
21-
if ($content.value) { $content = $content.value }
18+
$Content = $Request.Body.input.value ?? $Request.Query.input.value
2219

2320
try {
24-
$results = Set-CIPPNamedLocation -NamedLocationId $NamedLocationId -TenantFilter $TenantFilter -Change $Change -Content $Content -Headers $Headers
21+
$Results = Set-CIPPNamedLocation -NamedLocationId $NamedLocationId -TenantFilter $TenantFilter -Change $Change -Content $Content -Headers $Headers
2522
$StatusCode = [HttpStatusCode]::OK
2623
} catch {
2724
$ErrorMessage = Get-CippException -Exception $_
2825
Write-LogMessage -headers $Headers -API $APIName -message "Failed to edit named location: $($ErrorMessage.NormalizedError)" -Sev 'Error' -tenant $TenantFilter -LogData $ErrorMessage
29-
$results = "Failed to edit named location. Error: $($ErrorMessage.NormalizedError)"
26+
$Results = "Failed to edit named location. Error: $($ErrorMessage.NormalizedError)"
3027
$StatusCode = [HttpStatusCode]::InternalServerError
3128
}
3229

3330
return ([HttpResponseContext]@{
3431
StatusCode = $StatusCode
35-
Body = @{'Results' = @($results) }
32+
Body = @{'Results' = @($Results) }
3633
})
3734

3835
}

Modules/CIPPCore/Public/Set-CIPPNamedLocation.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ function Set-CIPPNamedLocation {
2424
$ActionDescription = "Adding location $Content to named location"
2525
}
2626
'removeIp' {
27-
$NamedLocations.ipRanges = @($NamedLocations.ipRanges | Where-Object -Property cidrAddress -NE $Content)
28-
$ActionDescription = "Removing IP $Content from named location"
27+
$IpsToRemove = @($Content)
28+
$NamedLocations.ipRanges = @($NamedLocations.ipRanges | Where-Object { $_.cidrAddress -notin $IpsToRemove })
29+
$ActionDescription = "Removing IP(s) $($IpsToRemove -join ', ') from named location"
2930
}
3031
'removeLocation' {
31-
$NamedLocations.countriesAndRegions = @($NamedLocations.countriesAndRegions | Where-Object { $_ -NE $Content })
32-
$ActionDescription = "Removing location $Content from named location"
32+
$LocationsToRemove = @($Content)
33+
$NamedLocations.countriesAndRegions = @($NamedLocations.countriesAndRegions | Where-Object { $_ -notin $LocationsToRemove })
34+
$ActionDescription = "Removing location(s) $($LocationsToRemove -join ', ') from named location"
3335
}
3436
'rename' {
3537
$NamedLocations.displayName = $Content

0 commit comments

Comments
 (0)