Skip to content

Commit

Permalink
invisible paging.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Sep 5, 2024
1 parent 7be9a29 commit 01685e0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function Invoke-ListGraphRequest {
$Parameters.'$count' = ([string]([System.Boolean]$Request.Query.'$count')).ToLower()
}


if ($Request.Query.'$orderby') {
$Parameters.'$orderby' = $Request.Query.'$orderby'
}
Expand Down Expand Up @@ -75,6 +76,14 @@ function Invoke-ListGraphRequest {
$GraphRequestParams.NoPagination = [System.Boolean]$Request.Query.NoPagination
}

if ($Request.Query.manualPagination) {
$GraphRequestParams.NoPagination = [System.Boolean]$Request.Query.manualPagination
}

if ($Request.Query.nextLink) {
$GraphRequestParams.nextLink = $Request.Query.nextLink
}

if ($Request.Query.CountOnly) {
$GraphRequestParams.CountOnly = [System.Boolean]$Request.Query.CountOnly
}
Expand Down
6 changes: 5 additions & 1 deletion Modules/CIPPCore/Public/GraphHelper/New-GraphGetRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function New-GraphGetRequest {
$noPagination,
$NoAuthCheck,
$skipTokenCache,
$Caller,
[switch]$ComplexFilter,
[switch]$CountOnly,
[switch]$IncludeResponseHeaders
Expand Down Expand Up @@ -58,8 +59,11 @@ function New-GraphGetRequest {
$Data.'@odata.count'
$NextURL = $null
} else {
if ($Data.PSObject.Properties.Name -contains 'value') { $data.value } else { ($Data) }
if ($Data.PSObject.Properties.Name -contains 'value') { $data.value } else { $Data }
if ($noPagination) {
if ($Caller -eq 'Get-GraphRequestList') {
@{ 'nextLink' = $data.'@odata.nextLink' }
}
$nextURL = $null
} else {
$NextPageUriFound = $false
Expand Down
13 changes: 12 additions & 1 deletion Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function Get-GraphRequestList {
[string]$TenantFilter = $env:TenantID,
[Parameter(Mandatory = $true)]
[string]$Endpoint,
[string]$nextLink,
[hashtable]$Parameters = @{},
[string]$QueueId,
[string]$CippLink,
Expand Down Expand Up @@ -285,7 +286,17 @@ function Get-GraphRequestList {
}

if (!$QueueThresholdExceeded) {
$GraphRequestResults = New-GraphGetRequest @GraphRequest -ErrorAction Stop | Select-Object *, @{l = 'Tenant'; e = { $TenantFilter } }, @{l = 'CippStatus'; e = { 'Good' } }
#nextLink should ONLY be used in direct calls with manual pagination. It should not be used in queueing
if ($nextLink) { $GraphRequest.uri = $nextLink }

$GraphRequestResults = New-GraphGetRequest @GraphRequest -Caller 'Get-GraphRequestList' -ErrorAction Stop
if ($GraphRequestResults.nextLink) {
$Metadata['nextLink'] = $GraphRequestResults.nextLink | Select-Object -Last 1
#GraphRequestResults is an array of objects, so we need to remove the last object before returning
$GraphRequestResults = $GraphRequestResults | Select-Object -First ($GraphRequestResults.Count - 1)
}
$GraphRequestResults = $GraphRequestResults | Select-Object *, @{n = 'Tenant'; e = { $TenantFilter } }, @{n = 'CippStatus'; e = { 'Good' } }

if ($ReverseTenantLookup -and $GraphRequestResults) {
$ReverseLookupRequests = $GraphRequestResults.$ReverseTenantLookupProperty | Sort-Object -Unique | ForEach-Object {
@{
Expand Down

0 comments on commit 01685e0

Please sign in to comment.