Skip to content

Commit f45dba0

Browse files
authored
Merge pull request #1589 from KelvinTegelaar/dev
Dev to hotfix
2 parents f8a29d4 + e9fd45d commit f45dba0

File tree

53 files changed

+634
-516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+634
-516
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
2+
# More GitHub Actions for Azure: https://github.com/Azure/actions
3+
4+
name: Build and deploy Powershell project to Azure Function App - clouduptest
5+
6+
on:
7+
push:
8+
branches:
9+
- dev
10+
workflow_dispatch:
11+
12+
env:
13+
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
14+
15+
jobs:
16+
deploy:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: 'Checkout GitHub Action'
21+
uses: actions/checkout@v4
22+
23+
- name: 'Run Azure Functions Action'
24+
uses: Azure/functions-action@v1
25+
id: fa
26+
with:
27+
app-name: 'clouduptest'
28+
slot-name: 'Production'
29+
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
30+
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_9B9E8B9A9BBE446188BCA9F126A1B646 }}
31+
sku: 'flexconsumption'
32+

Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ function Add-CIPPScheduledTask {
1919
[Parameter(Mandatory = $true, ParameterSetName = 'RunNow')]
2020
[string]$RowKey,
2121

22+
[Parameter(Mandatory = $false, ParameterSetName = 'Default')]
23+
[string]$DesiredStartTime = $null,
24+
2225
[Parameter(Mandatory = $false, ParameterSetName = 'Default')]
2326
[Parameter(Mandatory = $false, ParameterSetName = 'RunNow')]
2427
$Headers
@@ -119,8 +122,24 @@ function Add-CIPPScheduledTask {
119122
$task.Recurrence.value
120123
}
121124

122-
if ([int64]$task.ScheduledTime -eq 0 -or [string]::IsNullOrEmpty($task.ScheduledTime)) {
123-
$task.ScheduledTime = [int64](([datetime]::UtcNow) - (Get-Date '1/1/1970')).TotalSeconds
125+
if ($DesiredStartTime) {
126+
try {
127+
# Parse the epoch time
128+
$epochSeconds = [int64]$DesiredStartTime
129+
# Set ScheduledTime to the desired time
130+
$task.ScheduledTime = $epochSeconds
131+
} catch {
132+
Write-Warning "Failed to parse DesiredStartTime: $DesiredStartTime. Using provided ScheduledTime."
133+
# Fall back to default
134+
if ([int64]$task.ScheduledTime -eq 0 -or [string]::IsNullOrEmpty($task.ScheduledTime)) {
135+
$task.ScheduledTime = [int64](([datetime]::UtcNow) - (Get-Date '1/1/1970')).TotalSeconds
136+
}
137+
}
138+
} else {
139+
# No DesiredStartTime - use current behavior (immediate execution)
140+
if ([int64]$task.ScheduledTime -eq 0 -or [string]::IsNullOrEmpty($task.ScheduledTime)) {
141+
$task.ScheduledTime = [int64](([datetime]::UtcNow) - (Get-Date '1/1/1970')).TotalSeconds
142+
}
124143
}
125144
$excludedTenants = if ($task.excludedTenants.value) {
126145
$task.excludedTenants.value -join ','
@@ -166,6 +185,10 @@ function Add-CIPPScheduledTask {
166185
Hidden = [bool]$Hidden
167186
Results = 'Planned'
168187
}
188+
# Always store DesiredStartTime if provided
189+
if ($DesiredStartTime) {
190+
$entity['DesiredStartTime'] = [string]$DesiredStartTime
191+
}
169192

170193
# Store the original tenant filter for group expansion during execution
171194
if ($originalTenantFilter -is [PSCustomObject] -and $originalTenantFilter.type -eq 'Group') {
@@ -190,6 +213,7 @@ function Add-CIPPScheduledTask {
190213
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
191214
return "Could not add task: $ErrorMessage"
192215
}
216+
Write-LogMessage -headers $Headers -API 'ScheduledTask' -message "Added task $($entity.Name) with ID $($entity.RowKey)" -Sev 'Info' -Tenant $tenantFilter
193217
return "Successfully added task: $($entity.Name)"
194218
}
195219
} catch {

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertDepTokenExpiry.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function Get-CIPPAlertDepTokenExpiry {
44
Entrypoint
55
#>
66
[CmdletBinding()]
7-
Param (
7+
param (
88
[Parameter(Mandatory = $false)]
99
[Alias('input')]
1010
$InputValue,
@@ -13,7 +13,7 @@ function Get-CIPPAlertDepTokenExpiry {
1313

1414
try {
1515
try {
16-
$DepTokens = (New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/depOnboardingSettings' -tenantid $TenantFilter).value
16+
$DepTokens = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/deviceManagement/depOnboardingSettings' -tenantid $TenantFilter
1717
$AlertData = foreach ($Dep in $DepTokens) {
1818
if ($Dep.tokenExpirationDateTime -lt (Get-Date).AddDays(30) -and $Dep.tokenExpirationDateTime -gt (Get-Date).AddDays(-7)) {
1919
$Message = 'Apple Device Enrollment Program token expiring on {0}' -f $Dep.tokenExpirationDateTime

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertNoCAConfig.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ function Get-CIPPAlertNoCAConfig {
1212
)
1313

1414
try {
15-
$CAAvailable = (New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/subscribedSkus' -tenantid $TenantFilter -ErrorAction Stop).serviceplans
16-
if ('AAD_PREMIUM' -in $CAAvailable.servicePlanName) {
15+
# Only consider CA available when a SKU that grants it has enabled seats (> 0)
16+
$SubscribedSkus = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/subscribedSkus?`$select=prepaidUnits,servicePlans" -tenantid $TenantFilter -ErrorAction Stop
17+
$CAAvailable = foreach ($sku in $SubscribedSkus) {
18+
if ([int]$sku.prepaidUnits.enabled -gt 0) { $sku.servicePlans }
19+
}
20+
21+
if (('AAD_PREMIUM' -in $CAAvailable.servicePlanName) -or ('AAD_PREMIUM_P2' -in $CAAvailable.servicePlanName)) {
1722
$CAPolicies = (New-GraphGetRequest -uri 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies' -tenantid $TenantFilter)
1823
if (!$CAPolicies.id) {
1924
$AlertData = 'Conditional Access is available, but no policies could be found.'

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertVppTokenExpiry.ps1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ function Get-CIPPAlertVppTokenExpiry {
44
Entrypoint
55
#>
66
[CmdletBinding()]
7-
Param (
7+
param (
88
[Parameter(Mandatory = $false)]
99
[Alias('input')]
1010
$InputValue,
1111
$TenantFilter
1212
)
1313
try {
1414
try {
15-
$VppTokens = (New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/deviceAppManagement/vppTokens' -tenantid $TenantFilter).value
15+
$VppTokens = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/deviceAppManagement/vppTokens' -tenantid $TenantFilter
1616
$AlertData = foreach ($Vpp in $VppTokens) {
1717
if ($Vpp.state -ne 'valid') {
1818
$Message = 'Apple Volume Purchase Program Token is not valid, new token required'
1919
$Vpp | Select-Object -Property organizationName, appleId, vppTokenAccountType, @{Name = 'Message'; Expression = { $Message } }
20-
}
21-
if ($Vpp.expirationDateTime -lt (Get-Date).AddDays(30) -and $Vpp.expirationDateTime -gt (Get-Date).AddDays(-7)) {
20+
} elseif ($Vpp.expirationDateTime -lt (Get-Date).AddDays(30).ToUniversalTime() -and $Vpp.expirationDateTime -gt (Get-Date).AddDays(-7).ToUniversalTime()) {
2221
$Message = 'Apple Volume Purchase Program token expiring on {0}' -f $Vpp.expirationDateTime
2322
$Vpp | Select-Object -Property organizationName, appleId, vppTokenAccountType, @{Name = 'Message'; Expression = { $Message } }
2423
}

Modules/CIPPCore/Public/Authentication/Get-CippAllowedPermissions.ps1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ function Get-CippAllowedPermissions {
7070

7171
# For admin and superadmin: Compute permissions from base role include/exclude rules
7272
if ($PrimaryRole -in @('admin', 'superadmin')) {
73-
Write-Information "Computing permissions for $PrimaryRole using base role rules"
7473

7574
if ($BaseRole) {
7675
# Start with all permissions and apply include/exclude rules
@@ -143,7 +142,19 @@ function Get-CippAllowedPermissions {
143142
}
144143

145144
# Restrict base permissions to only those allowed by custom roles
146-
$RestrictedPermissions = $BasePermissions | Where-Object { $CustomRolePermissions -contains $_ }
145+
# Include Read permissions when ReadWrite permissions are present
146+
$RestrictedPermissions = $BasePermissions | Where-Object {
147+
$Permission = $_
148+
if ($CustomRolePermissions -contains $Permission) {
149+
$true
150+
} elseif ($Permission -match 'Read$') {
151+
# Check if there's a corresponding ReadWrite permission
152+
$ReadWritePermission = $Permission -replace 'Read', 'ReadWrite'
153+
$CustomRolePermissions -contains $ReadWritePermission
154+
} else {
155+
$false
156+
}
157+
}
147158
foreach ($Permission in $RestrictedPermissions) {
148159
if ($null -ne $Permission -and $Permission -is [string]) {
149160
$AllowedPermissions.Add($Permission)
@@ -161,8 +172,6 @@ function Get-CippAllowedPermissions {
161172
}
162173
# Handle users with only custom roles (no base role)
163174
elseif ($CustomRoles.Count -gt 0) {
164-
Write-Information 'Computing permissions for custom roles only'
165-
166175
foreach ($CustomRole in $CustomRoles) {
167176
try {
168177
$RolePermissions = Get-CIPPRolePermissions -RoleName $CustomRole

Modules/CIPPCore/Public/CippQueue/Invoke-ListCippQueue.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ function Invoke-ListCippQueue {
1515
$CippQueue = Get-CippTable -TableName 'CippQueue'
1616
$CippQueueTasks = Get-CippTable -TableName 'CippQueueTasks'
1717
$3HoursAgo = (Get-Date).ToUniversalTime().AddHours(-3).ToString('yyyy-MM-ddTHH:mm:ssZ')
18-
$CippQueueData = Get-CIPPAzDataTableEntity @CippQueue -Filter "Timestamp ge datetime'$3HoursAgo'" | Sort-Object -Property Timestamp -Descending
18+
$CippQueueData = Get-CIPPAzDataTableEntity @CippQueue -Filter "PartitionKey eq 'CippQueue' and Timestamp ge datetime'$3HoursAgo'" | Sort-Object -Property Timestamp -Descending
1919

2020
$QueueData = foreach ($Queue in $CippQueueData) {
21-
$Tasks = Get-CIPPAzDataTableEntity @CippQueueTasks -Filter "QueueId eq '$($Queue.RowKey)'" | Where-Object { $_.Name } | Select-Object @{n = 'Timestamp'; exp = { $_.Timestamp.DateTime.ToUniversalTime() } }, Name, Status
21+
$Tasks = Get-CIPPAzDataTableEntity @CippQueueTasks -Filter "PartitionKey eq 'Task' and QueueId eq '$($Queue.RowKey)'" | Where-Object { $_.Name } | Select-Object @{n = 'Timestamp'; exp = { $_.Timestamp.DateTime.ToUniversalTime() } }, Name, Status
2222
$TaskStatus = @{}
2323
$Tasks | Group-Object -Property Status | ForEach-Object {
2424
$TaskStatus.$($_.Name) = $_.Count

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ListGraphRequest.ps1

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ function Invoke-ListGraphRequest {
3333
$Parameters.'$expand' = $Request.Query.'$expand'
3434
}
3535

36+
if ($Request.Query.expand) {
37+
$Parameters.'expand' = $Request.Query.expand
38+
}
39+
3640
if ($Request.Query.'$top') {
3741
$Parameters.'$top' = $Request.Query.'$top'
3842
}
@@ -120,13 +124,13 @@ function Invoke-ListGraphRequest {
120124

121125
try {
122126
$Results = Get-GraphRequestList @GraphRequestParams
123-
if ($Results.nextLink) {
124-
Write-Host "NextLink: $($Results.nextLink | Select-Object -Last 1)"
125-
if ($Request.Query.TenantFilter -ne 'AllTenants') {
126-
$Metadata['nextLink'] = $Results.nextLink | Select-Object -Last 1
127+
if ($Results | Where-Object { $_.PSObject.Properties.Name -contains 'nextLink' }) {
128+
if (![string]::IsNullOrEmpty($Results.nextLink) -and $Request.Query.TenantFilter -ne 'AllTenants') {
129+
Write-Host "NextLink: $($Results.nextLink | Where-Object { $_ } | Select-Object -Last 1)"
130+
$Metadata['nextLink'] = $Results.nextLink | Where-Object { $_ } | Select-Object -Last 1
127131
}
128-
#Results is an array of objects, so we need to remove the last object before returning
129-
$Results = $Results | Select-Object -First ($Results.Count - 1)
132+
# Remove nextLink trailing object only if it’s the last item
133+
$Results = $Results | Where-Object { $_.PSObject.Properties.Name -notcontains 'nextLink' }
130134
}
131135
if ($Request.Query.ListProperties) {
132136
$Columns = ($Results | Select-Object -First 1).PSObject.Properties.Name

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Scheduler/Invoke-AddScheduledItem.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function Invoke-AddScheduledItem {
3131
$Result = "Error scheduling task: $($_.Exception.Message)"
3232
}
3333
} else {
34-
$Result = Add-CIPPScheduledTask -Task $Request.Body -Headers $Request.Headers -hidden $hidden -DisallowDuplicateName $Request.Query.DisallowDuplicateName
34+
$Result = Add-CIPPScheduledTask -Task $Request.Body -Headers $Request.Headers -hidden $hidden -DisallowDuplicateName $Request.Query.DisallowDuplicateName -DesiredStartTime $Request.Body.DesiredStartTime
3535
Write-LogMessage -headers $Request.Headers -API $APINAME -message $Result -Sev 'Info'
3636
}
3737
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecRestoreBackup.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Invoke-ExecRestoreBackup {
1717

1818
if ($Request.Body.BackupName -like 'CippBackup_*') {
1919
$Table = Get-CippTable -tablename 'CIPPBackup'
20-
$Backup = Get-CippAzDataTableEntity @Table -Filter "RowKey eq '$($Request.Body.BackupName)'"
20+
$Backup = Get-CippAzDataTableEntity @Table -Filter "RowKey eq '$($Request.Body.BackupName)' or OriginalEntityId eq '$($Request.Body.BackupName)'"
2121
if ($Backup) {
2222
$BackupData = $Backup.Backup | ConvertFrom-Json -ErrorAction SilentlyContinue | Select-Object * -ExcludeProperty ETag, Timestamp
2323
$BackupData | ForEach-Object {

0 commit comments

Comments
 (0)