Skip to content

Commit 634e27d

Browse files
committed
catch invalid json parsing and provide initial values
1 parent 25419ba commit 634e27d

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,31 @@ function Invoke-ListUserSettings {
1717

1818
try {
1919
$Table = Get-CippTable -tablename 'UserSettings'
20-
$UserSettings = Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq 'allUsers'"
21-
if (!$UserSettings) { $UserSettings = Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$Username'" }
22-
$UserSettings = $UserSettings.JSON | ConvertFrom-Json -Depth 10 -ErrorAction SilentlyContinue
20+
$UserSettings = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'UserSettings' and RowKey eq 'allUsers'"
21+
if (!$UserSettings) { $UserSettings = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'UserSettings' and RowKey eq '$Username'" }
22+
23+
try {
24+
$UserSettings = $UserSettings.JSON | ConvertFrom-Json -Depth 10 -ErrorAction SilentlyContinue
25+
} catch {
26+
Write-Warning "Failed to convert UserSettings JSON: $($_.Exception.Message)"
27+
$UserSettings = [pscustomobject]@{
28+
direction = 'ltr'
29+
paletteMode = 'light'
30+
currentTheme = @{ value = 'light'; label = 'light' }
31+
pinNav = $true
32+
showDevtools = $false
33+
customBranding = @{
34+
colour = '#F77F00'
35+
logo = $null
36+
}
37+
}
38+
}
2339
#Get branding settings
2440
if ($UserSettings) {
2541
$brandingTable = Get-CippTable -tablename 'Config'
26-
$BrandingSettings = Get-CIPPAzDataTableEntity @brandingTable -Filter "RowKey eq 'BrandingSettings'"
42+
$BrandingSettings = Get-CIPPAzDataTableEntity @brandingTable -Filter "PartitionKey eq 'BrandingSettings' and RowKey eq 'BrandingSettings'"
2743
if ($BrandingSettings) {
28-
$UserSettings | Add-Member -MemberType NoteProperty -Name 'BrandingSettings' -Value $BrandingSettings -Force | Out-Null
44+
$UserSettings | Add-Member -MemberType NoteProperty -Name 'customBranding' -Value $BrandingSettings -Force | Out-Null
2945
}
3046
}
3147
$StatusCode = [HttpStatusCode]::OK

0 commit comments

Comments
 (0)