Skip to content

Commit

Permalink
Merge pull request KelvinTegelaar#495 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
hotfix for two small bugs that annoy me
  • Loading branch information
KelvinTegelaar authored Nov 28, 2023
2 parents 2e825b4 + 51bff62 commit 3d158c2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 62 deletions.
3 changes: 3 additions & 0 deletions BestPracticeAnalyser_All/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ $AddRow = foreach ($Template in $templates) {
'string' {
$Result.Add($field.Name, [string]$FieldInfo)
}
'percentage' {

}
}
} catch {
Write-LogMessage -API 'BPA' -tenant $tenant -message "Error storing $($field.Name) for $($TenantName.displayName) with GUID $($TenantName.customerId). Error: $($_.Exception.Message)" -sev Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Function Invoke-ExecSAMSetup {
[CmdletBinding()]
param($Request, $TriggerMetadata)

$UserCreds = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($request.headers.'x-ms-client-principal')) | ConvertFrom-Json)
if ($Request.query.error) {
Add-Type -AssemblyName System.Web
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
Expand Down
118 changes: 58 additions & 60 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-ListBPA.ps1
Original file line number Diff line number Diff line change
@@ -1,85 +1,83 @@
using namespace System.Net
using namespace System.Net

Function Invoke-ListBPA {
Function Invoke-ListBPA {
<#
.FUNCTIONALITY
Entrypoint
#>
[CmdletBinding()]
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
# Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"
$APIName = $TriggerMetadata.FunctionName
# Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"

$Table = get-cipptable 'cachebpav2'
$name = $Request.query.Report
if ($name -eq $null) { $name = 'CIPP Best Practices v1.0 - Table view' }
$Table = get-cipptable 'cachebpav2'
$name = $Request.query.Report
if ($name -eq $null) { $name = 'CIPP Best Practices v1.0 - Table view' }

# Get all possible JSON files for reports, find the correct one, select the Columns
$JSONFields = @()
$Columns = $null
$CippRoot = (Get-Item $PSScriptRoot).Parent.FullName
(Get-ChildItem -Path "$CippRoot\Config\*.BPATemplate.json" -Recurse | Select-Object -ExpandProperty FullName | ForEach-Object {
$Template = $(Get-Content $_) | ConvertFrom-Json
if ($Template.Name -eq $NAME) {
$JSONFields = $Template.Fields | Where-Object { $_.StoreAs -eq 'JSON' } | ForEach-Object { $_.name }
$Columns = $Template.fields.FrontendFields | Where-Object -Property name -NE $null
$Style = $Template.Style
}
})
# Get all possible JSON files for reports, find the correct one, select the Columns
$JSONFields = @()
$Columns = $null
(Get-ChildItem -Path 'Config\*.BPATemplate.json' -Recurse | Select-Object -ExpandProperty FullName | ForEach-Object {
$Template = $(Get-Content $_) | ConvertFrom-Json
if ($Template.Name -eq $NAME) {
$JSONFields = $Template.Fields | Where-Object { $_.StoreAs -eq 'JSON' } | ForEach-Object { $_.name }
$Columns = $Template.fields.FrontendFields | Where-Object -Property name -NE $null
$Style = $Template.Style
}
})


if ($Request.query.tenantFilter -ne 'AllTenants' -and $Style -eq 'Tenant') {
$mergedObject = New-Object pscustomobject
if ($Request.query.tenantFilter -ne 'AllTenants' -and $Style -eq 'Tenant') {
$mergedObject = New-Object pscustomobject

$Data = (Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq '$($Request.query.tenantFilter)'") | ForEach-Object {
$row = $_
$JSONFields | ForEach-Object {
$jsonContent = $row.$_
if ($jsonContent -ne $null -and $jsonContent -ne 'FAILED') {
$row.$_ = $jsonContent | ConvertFrom-Json -Depth 15
$Data = (Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq '$($Request.query.tenantFilter)'") | ForEach-Object {
$row = $_
$JSONFields | ForEach-Object {
$jsonContent = $row.$_
if ($jsonContent -ne $null -and $jsonContent -ne 'FAILED') {
$row.$_ = $jsonContent | ConvertFrom-Json -Depth 15
}
}
$row.PSObject.Properties | ForEach-Object {
$mergedObject | Add-Member -NotePropertyName $_.Name -NotePropertyValue $_.Value -Force
}
}
$row.PSObject.Properties | ForEach-Object {
$mergedObject | Add-Member -NotePropertyName $_.Name -NotePropertyValue $_.Value -Force
}
}

$Data = $mergedObject
}
else {
$Tenants = Get-Tenants -IncludeErrors
$Data = (Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$NAME'") | ForEach-Object {
$row = $_
$JSONFields | ForEach-Object {
$jsonContent = $row.$_
if ($jsonContent -ne $null -and $jsonContent -ne 'FAILED') {
$row.$_ = $jsonContent | ConvertFrom-Json -Depth 15
$Data = $mergedObject
} else {
$Tenants = Get-Tenants -IncludeErrors
$Data = (Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$NAME'") | ForEach-Object {
$row = $_
$JSONFields | ForEach-Object {
$jsonContent = $row.$_
if ($jsonContent -ne $null -and $jsonContent -ne 'FAILED') {
$row.$_ = $jsonContent | ConvertFrom-Json -Depth 15
}
}
$row | Where-Object -Property PartitionKey -In $Tenants.customerId
}
$row | Where-Object -Property PartitionKey -In $Tenants.customerId
}


}
}

$Results = [PSCustomObject]@{
Data = $Data
Columns = $Columns
Style = $Style
}
$Results = [PSCustomObject]@{
Data = $Data
Columns = $Columns
Style = $Style
}

if (!$Results) {
$Results = @{
Columns = @( value = 'Results'; name = 'Results')
Data = @(@{ Results = 'The BPA has not yet run.' })
if (!$Results) {
$Results = @{
Columns = @( value = 'Results'; name = 'Results')
Data = @(@{ Results = 'The BPA has not yet run.' })
}
}
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = ($Results | ConvertTo-Json -Depth 15)
})
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = ($Results | ConvertTo-Json -Depth 15)
})

}
}
2 changes: 1 addition & 1 deletion version_latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.7.0
4.7.1

0 comments on commit 3d158c2

Please sign in to comment.