Skip to content

Commit b7b5ac2

Browse files
committed
add graph preset validation
1 parent fc499e3 commit b7b5ac2

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Tools/Invoke-ExecGraphExplorerPreset.ps1

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

3-
Function Invoke-ExecGraphExplorerPreset {
3+
function Invoke-ExecGraphExplorerPreset {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -22,7 +22,7 @@ Function Invoke-ExecGraphExplorerPreset {
2222

2323
switch ($Action) {
2424
'Copy' {
25-
$Id = $Request.Body.preset.id ? $Request.Body.preset.id: (New-Guid).Guid
25+
$Id = $Request.Body.preset.id ? $Request.Body.preset.id : (New-Guid).Guid
2626
}
2727
'Save' {
2828
$Id = $Request.Body.preset.id
@@ -42,6 +42,32 @@ Function Invoke-ExecGraphExplorerPreset {
4242
$params.'$select' = ($params.'$select').value -join ','
4343
}
4444

45+
if (!$Request.Body.preset.name) {
46+
$Message = 'Error: Preset name is required'
47+
$StatusCode = [HttpStatusCode]::BadRequest
48+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
49+
StatusCode = $StatusCode
50+
Body = @{
51+
Results = $Message
52+
Success = $false
53+
}
54+
})
55+
return
56+
}
57+
58+
if (!$Request.Body.preset.endpoint) {
59+
$Message = 'Error: Preset endpoint is required'
60+
$StatusCode = [HttpStatusCode]::BadRequest
61+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
62+
StatusCode = $StatusCode
63+
Body = @{
64+
Results = $Message
65+
Success = $false
66+
}
67+
})
68+
return
69+
}
70+
4571
$Preset = [PSCustomObject]@{
4672
PartitionKey = 'Preset'
4773
RowKey = [string]$Id

Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1

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

3-
Function Invoke-ListGraphExplorerPresets {
3+
function Invoke-ListGraphExplorerPresets {
44
<#
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
@@ -19,14 +19,14 @@ Function Invoke-ListGraphExplorerPresets {
1919

2020
try {
2121
$Table = Get-CIPPTable -TableName 'GraphPresets'
22-
$Presets = Get-CIPPAzDataTableEntity @Table -Filter "Owner eq '$Username' or IsShared eq true" | Sort-Object -Property name
22+
$Presets = Get-CIPPAzDataTableEntity @Table | Where-Object { $Username -eq $_.Owner -or $_.IsShared -eq $true } | Sort-Object -Property name
2323
$Results = foreach ($Preset in $Presets) {
2424
[PSCustomObject]@{
2525
id = $Preset.Id
2626
name = $Preset.name
2727
IsShared = $Preset.IsShared
2828
IsMyPreset = $Preset.Owner -eq $Username
29-
params = ConvertFrom-Json -InputObject $Preset.Params
29+
params = (ConvertFrom-Json -InputObject $Preset.Params)
3030
}
3131
}
3232

@@ -35,6 +35,8 @@ Function Invoke-ListGraphExplorerPresets {
3535
$Results = $Results | Where-Object { ($_.params.endpoint -replace '^/', '') -eq $Endpoint }
3636
}
3737
} catch {
38+
Write-Warning "Could not list presets. $($_.Exception.Message)"
39+
Write-Information $_.InvocationInfo.PositionMessage
3840
$Results = @()
3941
}
4042
# Associate values to output bindings by calling 'Push-OutputBinding'.

0 commit comments

Comments
 (0)