Skip to content

Commit 20b490f

Browse files
authored
Merge pull request #229 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 2b5f89b + cd42c9d commit 20b490f

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

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

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,46 @@ Function Invoke-EditUser {
8888
try {
8989

9090
if ($licenses -or $UserObj.removeLicenses) {
91-
$CurrentLicenses = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($UserObj.id)" -tenantid $UserObj.tenantFilter
92-
#if the list of skuIds in $CurrentLicenses.assignedLicenses is EXACTLY the same as $licenses, we don't need to do anything, but the order in both can be different.
93-
if (($CurrentLicenses.assignedLicenses.skuId -join ',') -eq ($licenses -join ',') -and $UserObj.removeLicenses -eq $false) {
94-
Write-Host "$($CurrentLicenses.assignedLicenses.skuId -join ',') $(($licenses -join ','))"
95-
$null = $results.Add( 'Success. User license is already correct.' )
91+
if ($UserObj.sherwebLicense) {
92+
$License = Set-SherwebSubscription -TenantFilter $UserObj.tenantFilter -SKU $UserObj.sherwebLicense -Add 1
93+
$null = $results.Add('Added Sherweb License, scheduling assignment')
94+
$taskObject = [PSCustomObject]@{
95+
TenantFilter = $UserObj.tenantFilter
96+
Name = "Assign License: $Username"
97+
Command = @{
98+
value = 'Set-CIPPUserLicense'
99+
}
100+
Parameters = [pscustomobject]@{
101+
userId = $UserObj.id
102+
APIName = 'Sherweb License Assignment'
103+
AddLicenses = $licenses
104+
}
105+
ScheduledTime = 0 #right now, which is in the next 15 minutes and should cover most cases.
106+
PostExecution = @{
107+
Webhook = [bool]$Request.Body.PostExecution.webhook
108+
Email = [bool]$Request.Body.PostExecution.email
109+
PSA = [bool]$Request.Body.PostExecution.psa
110+
}
111+
}
112+
Add-CIPPScheduledTask -Task $taskObject -hidden $false -Headers $Headers
96113
} else {
97-
if ($UserObj.removeLicenses) {
98-
$licResults = Set-CIPPUserLicense -UserId $UserObj.id -TenantFilter $UserObj.tenantFilter -RemoveLicenses $CurrentLicenses.assignedLicenses.skuId -Headers $Request.Headers
99-
$null = $results.Add($licResults)
114+
$CurrentLicenses = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($UserObj.id)" -tenantid $UserObj.tenantFilter
115+
#if the list of skuIds in $CurrentLicenses.assignedLicenses is EXACTLY the same as $licenses, we don't need to do anything, but the order in both can be different.
116+
if (($CurrentLicenses.assignedLicenses.skuId -join ',') -eq ($licenses -join ',') -and $UserObj.removeLicenses -eq $false) {
117+
Write-Host "$($CurrentLicenses.assignedLicenses.skuId -join ',') $(($licenses -join ','))"
118+
$null = $results.Add( 'Success. User license is already correct.' )
100119
} else {
101-
#Remove all objects from $CurrentLicenses.assignedLicenses.skuId that are in $licenses
102-
$RemoveLicenses = $CurrentLicenses.assignedLicenses.skuId | Where-Object { $_ -notin $licenses }
103-
$licResults = Set-CIPPUserLicense -UserId $UserObj.id -TenantFilter $UserObj.tenantFilter -RemoveLicenses $RemoveLicenses -AddLicenses $licenses -Headers $Request.headers
104-
$null = $results.Add($licResults)
105-
}
120+
if ($UserObj.removeLicenses) {
121+
$licResults = Set-CIPPUserLicense -UserId $UserObj.id -TenantFilter $UserObj.tenantFilter -RemoveLicenses $CurrentLicenses.assignedLicenses.skuId -Headers $Request.Headers
122+
$null = $results.Add($licResults)
123+
} else {
124+
#Remove all objects from $CurrentLicenses.assignedLicenses.skuId that are in $licenses
125+
$RemoveLicenses = $CurrentLicenses.assignedLicenses.skuId | Where-Object { $_ -notin $licenses }
126+
$licResults = Set-CIPPUserLicense -UserId $UserObj.id -TenantFilter $UserObj.tenantFilter -RemoveLicenses $RemoveLicenses -AddLicenses $licenses -Headers $Request.headers
127+
$null = $results.Add($licResults)
128+
}
106129

130+
}
107131
}
108132
}
109133

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ExecBPA.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function Invoke-ExecBPA {
1111
$ConfigTable = Get-CIPPTable -tablename Config
1212
$Config = Get-CIPPAzDataTableEntity @ConfigTable -Filter "PartitionKey eq 'OffloadFunctions' and RowKey eq 'OffloadFunctions'"
1313

14-
$TenantFilter = $Request.Query.tenantFilter ? $Request.Query.tenantFilter.value : $Request.Body.tenantfilter
14+
$TenantFilter = $Request.Query.tenantFilter ? $Request.Query.tenantFilter.value : $Request.Body.tenantfilter.value
1515

1616
if ($Config -and $Config.state -eq $true) {
1717
if ($env:CIPP_PROCESSOR -ne 'true') {

0 commit comments

Comments
 (0)