Skip to content

Commit 662c6ff

Browse files
authored
Merge pull request #270 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 0e7a48d + 02a318b commit 662c6ff

29 files changed

+249
-199
lines changed

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-UpdatePermissionsQueue.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ function Push-UpdatePermissionsQueue {
1616
$Table = Get-CIPPTable -TableName cpvtenants
1717
$CPVRows = Get-CIPPAzDataTableEntity @Table | Where-Object -Property Tenant -EQ $Item.customerId
1818

19-
if (!$CPVRows -or $env:ApplicationID -notin $CPVRows.applicationId) {
19+
$Tenant = Get-Tenants -TenantFilter $Item.customerId -IncludeErrors
20+
21+
if ((!$CPVRows -or $env:ApplicationID -notin $CPVRows.applicationId) -and $Tenant.delegatedPrivilegeStatus -ne 'directTenant') {
2022
Write-LogMessage -tenant $Item.defaultDomainName -tenantId $Item.customerId -message 'A New tenant has been added, or a new CIPP-SAM Application is in use' -Sev 'Warn' -API 'NewTenant'
2123
Write-Information 'Adding CPV permissions'
2224
Set-CIPPCPVConsent -Tenantfilter $Item.customerId

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ExecCPVPermissions {
3+
function Invoke-ExecCPVPermissions {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -15,7 +15,7 @@ Function Invoke-ExecCPVPermissions {
1515
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616
$TenantFilter = $Request.Body.tenantFilter
1717

18-
$Tenant = Get-Tenants -IncludeAll | Where-Object -Property customerId -EQ $TenantFilter | Select-Object -First 1
18+
$Tenant = Get-Tenants -TenantFilter $TenantFilter -IncludeErrors
1919

2020
if ($Tenant) {
2121
Write-Host "Our tenant is $($Tenant.displayName) - $($Tenant.defaultDomainName)"

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Setup/Invoke-ExecAddTenant.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ExecAddTenant {
3+
function Invoke-ExecAddTenant {
44
<#
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
@@ -63,7 +63,8 @@ Function Invoke-ExecAddTenant {
6363

6464
# Add tenant to table
6565
Add-CIPPAzDataTableEntity @TenantsTable -Entity $NewTenant -Force | Out-Null
66-
$Results = @{'message' = "Successfully added tenant $tenantId to the tenant list with directTenant status."; 'severity' = 'success' }
66+
$Results = @{'message' = "Successfully added tenant $displayName ($defaultDomainName) to the tenant list with Direct Tenant status."; 'severity' = 'success' }
67+
Write-LogMessage -tenant $defaultDomainName -tenantid $tenantId -API 'Add-Tenant' -message "Added tenant $displayName ($defaultDomainName) with Direct Tenant status." -Sev 'Info'
6768
}
6869
} catch {
6970
$Results = @{'message' = "Failed to add tenant: $($_.Exception.Message)"; 'state' = 'error'; 'severity' = 'error' }

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-AddGroup.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-AddGroup {
3+
function Invoke-AddGroup {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -38,11 +38,11 @@ Function Invoke-AddGroup {
3838
if ($GroupObject.groupType -eq 'm365') {
3939
$BodyParams | Add-Member -NotePropertyName 'groupTypes' -NotePropertyValue @('Unified')
4040
}
41-
if ($GroupObject.owners -AND $GroupObject.groupType -in 'generic', 'azurerole', 'security') {
41+
if ($GroupObject.owners) {
4242
$BodyParams | Add-Member -NotePropertyName '[email protected]' -NotePropertyValue (($GroupObject.owners) | ForEach-Object { "https://graph.microsoft.com/v1.0/users/$($_.value)" })
4343
$BodyParams.'[email protected]' = @($BodyParams.'[email protected]')
4444
}
45-
if ($GroupObject.members -AND $GroupObject.groupType -in 'generic', 'azurerole', 'security') {
45+
if ($GroupObject.members) {
4646
$BodyParams | Add-Member -NotePropertyName '[email protected]' -NotePropertyValue (($GroupObject.members) | ForEach-Object { "https://graph.microsoft.com/v1.0/users/$($_.value)" })
4747
$BodyParams.'[email protected]' = @($BodyParams.'[email protected]')
4848
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-ListGroups.ps1

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ListGroups {
3+
function Invoke-ListGroups {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -95,18 +95,16 @@ Function Invoke-ListGroups {
9595
} else {
9696
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/groups/$($GroupID)/$($members)?`$top=999&select=$selectstring" -tenantid $TenantFilter | Select-Object *, @{ Name = 'primDomain'; Expression = { $_.mail -split '@' | Select-Object -Last 1 } },
9797
@{Name = 'membersCsv'; Expression = { $_.members.userPrincipalName -join ',' } },
98-
@{Name = 'teamsEnabled'; Expression = { if ($_.resourceProvisioningOptions -Like '*Team*') { $true }else { $false } } },
98+
@{Name = 'teamsEnabled'; Expression = { if ($_.resourceProvisioningOptions -like '*Team*') { $true }else { $false } } },
9999
@{Name = 'calculatedGroupType'; Expression = {
100-
101-
if ($_.mailEnabled -and $_.securityEnabled) {
100+
if ($_.groupTypes -contains 'Unified') {
101+
'Microsoft 365'
102+
} elseif ($_.mailEnabled -and $_.securityEnabled) {
102103
'Mail-Enabled Security'
103104
}
104105
if (!$_.mailEnabled -and $_.securityEnabled) {
105106
'Security'
106107
}
107-
if ($_.groupTypes -contains 'Unified') {
108-
'Microsoft 365'
109-
}
110108
if (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (!$_.securityEnabled)) {
111109
'Distribution List'
112110
}

Modules/CIPPCore/Public/Entrypoints/Orchestrator Functions/Start-UpdatePermissionsOrchestrator.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Start-UpdatePermissionsOrchestrator {
1515
'displayName' = '*Partner Tenant'
1616
}
1717

18-
$TenantList = Get-Tenants -IncludeAll | Where-Object { $_.Excluded -eq $false -and $_.delegatedPrivilegeStatus -eq 'directTenant' }
18+
$TenantList = Get-Tenants -IncludeAll | Where-Object { $_.Excluded -eq $false }
1919

2020
$Tenants = [System.Collections.Generic.List[object]]::new()
2121
foreach ($Tenant in $TenantList) {

Modules/CIPPCore/Public/GraphHelper/New-GraphGetRequest.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ function New-GraphGetRequest {
2626

2727
if ($NoAuthCheck -eq $true -or $IsAuthorised) {
2828
if ($scope -eq 'ExchangeOnline') {
29-
$AccessToken = Get-ClassicAPIToken -resource 'https://outlook.office365.com' -Tenantid $tenantid
30-
$headers = @{ Authorization = "Bearer $($AccessToken.access_token)" }
29+
$headers = Get-GraphToken -tenantid $tenantid -scope 'https://outlook.office365.com/.default' -AsApp $asapp -SkipCache $skipTokenCache
3130
} else {
3231
$headers = Get-GraphToken -tenantid $tenantid -scope $scope -AsApp $asapp -SkipCache $skipTokenCache
3332
}

Modules/CIPPCore/Public/GraphHelper/New-TeamsAPIGetRequest.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ function New-TeamsAPIGetRequest($Uri, $tenantID, $Method = 'GET', $Resource = '4
55
#>
66

77
if ((Get-AuthorisedRequest -Uri $uri -TenantID $tenantid)) {
8-
$token = Get-ClassicAPIToken -Tenant $tenantid -Resource $Resource
8+
$token = Get-GraphToken -TenantID $tenantID -Scope "$Resource/.default"
99

1010
$NextURL = $Uri
1111
$ReturnedData = do {
1212
try {
1313
$Data = Invoke-RestMethod -ContentType "$ContentType;charset=UTF-8" -Uri $NextURL -Method $Method -Headers @{
14-
Authorization = "Bearer $($token.access_token)"
14+
Authorization = $token.Authorization
1515
'x-ms-client-request-id' = [guid]::NewGuid().ToString()
1616
'x-ms-client-session-id' = [guid]::NewGuid().ToString()
1717
'x-ms-correlation-id' = [guid]::NewGuid()
@@ -29,4 +29,4 @@ function New-TeamsAPIGetRequest($Uri, $tenantID, $Method = 'GET', $Resource = '4
2929
} else {
3030
Write-Error 'Not allowed. You cannot manage your own tenant or tenants not under your scope'
3131
}
32-
}
32+
}

Modules/CIPPCore/Public/New-CIPPUserTask.ps1

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,32 @@ function New-CIPPUserTask {
2020

2121
try {
2222
if ($UserObj.licenses.value) {
23-
$LicenseResults = Set-CIPPUserLicense -UserId $CreationResults.Username -TenantFilter $UserObj.tenantFilter -AddLicenses $UserObj.licenses.value -Headers $Headers
24-
$Results.Add($LicenseResults)
23+
if ($UserObj.sherwebLicense.value) {
24+
$License = Set-SherwebSubscription -TenantFilter $UserObj.tenantFilter -SKU $UserObj.sherwebLicense.value -Add 1
25+
$null = $results.Add('Added Sherweb License, scheduling assignment')
26+
$taskObject = [PSCustomObject]@{
27+
TenantFilter = $UserObj.tenantFilter
28+
Name = "Assign License: $UserPrincipalName"
29+
Command = @{
30+
value = 'Set-CIPPUserLicense'
31+
}
32+
Parameters = [pscustomobject]@{
33+
userId = $UserObj.id
34+
APIName = 'Sherweb License Assignment'
35+
AddLicenses = $licenses
36+
}
37+
ScheduledTime = 0 #right now, which is in the next 15 minutes and should cover most cases.
38+
PostExecution = @{
39+
Webhook = [bool]$Request.Body.PostExecution.webhook
40+
Email = [bool]$Request.Body.PostExecution.email
41+
PSA = [bool]$Request.Body.PostExecution.psa
42+
}
43+
}
44+
Add-CIPPScheduledTask -Task $taskObject -hidden $false -Headers $Headers
45+
} else {
46+
$LicenseResults = Set-CIPPUserLicense -UserId $CreationResults.Username -TenantFilter $UserObj.tenantFilter -AddLicenses $UserObj.licenses.value -Headers $Headers
47+
$Results.Add($LicenseResults)
48+
}
2549
}
2650
} catch {
2751
Write-LogMessage -headers $Headers -API $APIName -tenant $($UserObj.tenantFilter) -message "Failed to assign the license. Error:$($_.Exception.Message)" -Sev 'Error'

Modules/CIPPCore/Public/Set-CIPPCPVConsent.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ function Set-CIPPCPVConsent {
1717
if ($Tenant.customerId -ne $TenantFilter) {
1818
return @('Not a valid tenant')
1919
}
20+
if ($Tenant.delegatedPrivilegeStatus -eq 'directTenant') {
21+
return @('Application is already consented to this tenant')
22+
}
2023

2124
if ($ResetSP) {
2225
try {
@@ -40,7 +43,7 @@ function Set-CIPPCPVConsent {
4043
'DelegatedPermissionGrant.ReadWrite.All',
4144
'Directory.ReadWrite.All',
4245
'AppRoleAssignment.ReadWrite.All'
43-
) -Join ','
46+
) -join ','
4447
}
4548
)
4649
} | ConvertTo-Json

0 commit comments

Comments
 (0)