Skip to content

Commit 41ffea7

Browse files
authored
Merge pull request #145 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 1e2beb4 + 3ad424d commit 41ffea7

28 files changed

+631
-228
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-AddContact.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Function Invoke-AddContact {
3232
$null = New-ExoRequest -tenantid $TenantId -cmdlet 'Set-MailContact' -cmdParams @{Identity = $NewContact.id; HiddenFromAddressListsEnabled = [boolean]$ContactObject.hidefromGAL } -UseSystemMailbox $true
3333

3434
# Log the result
35-
$Result = "Created contact $($ContactObject.displayName) with id $($NewContact.id)"
35+
$Result = "Created contact $($ContactObject.displayName) with email address $($ContactObject.email)"
3636
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantId -message $Result -Sev 'Info'
3737
$StatusCode = [HttpStatusCode]::OK
3838

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-ExecGroupsDeliveryManagement.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Function Invoke-ExecGroupsDeliveryManagement {
2121
$ID = $Request.Query.ID ?? $Request.Body.ID
2222

2323
Try {
24-
$Result = Set-CIPPGroupAuthentication -ID $ID -GroupType $GroupType -OnlyAllowInternalString $OnlyAllowInternal -tenantFilter $TenantFilter -APIName $APIName -Headers $Headers
24+
$Result = Set-CIPPGroupAuthentication -ID $ID -GroupType $GroupType -OnlyAllowInternal $OnlyAllowInternal -tenantFilter $TenantFilter -APIName $APIName -Headers $Headers
2525
$StatusCode = [HttpStatusCode]::OK
2626
} catch {
2727
$Result = "$($_.Exception.Message)"

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-RemoveContact.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ Function Invoke-RemoveContact {
1111
param($Request, $TriggerMetadata)
1212

1313
$APIName = $Request.Params.CIPPEndpoint
14-
$TenantFilter = $Request.Query.tenantFilter
14+
$TenantFilter = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter
1515
Write-LogMessage -Headers $Request.Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616

1717
# Interact with query parameters or the body of the request.
1818
$GUID = $Request.query.GUID ?? $Request.body.GUID
19+
$Mail = $Request.query.Mail ?? $Request.body.Mail
1920

2021
try {
2122
$Params = @{
2223
Identity = $GUID
2324
}
2425
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Remove-MailContact' -cmdParams $Params -UseSystemMailbox $true
2526
Write-LogMessage -Headers $Request.Headers -API $APIName -tenant $TenantFilter -message "Deleted contact $GUID" -sev Debug
26-
$Result = "Deleted $GUID"
27+
$Result = "Deleted $Mail"
2728
$StatusCode = [HttpStatusCode]::OK
2829
} catch {
2930
$ErrorMessage = Get-CippException -Exception $_

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,16 @@ Function Invoke-AddGroup {
6464
Type = $GroupObject.groupType
6565
RequireSenderAuthenticationEnabled = [bool]!$GroupObject.allowExternal
6666
}
67+
if ($GroupObject.owners) {
68+
$ExoParams.ManagedBy = @($GroupObject.owners.value)
69+
}
70+
if ($GroupObject.members) {
71+
$ExoParams.Members = @($GroupObject.members.value)
72+
}
6773
$GraphRequest = New-ExoRequest -tenantid $tenant -cmdlet 'New-DistributionGroup' -cmdParams $ExoParams
6874
}
6975
}
76+
7077
"Successfully created group $($GroupObject.displayName) for $($tenant)"
7178
Write-LogMessage -headers $Request.Headers -API $APIName -tenant $tenant -message "Created group $($GroupObject.displayName) with id $($GraphRequest.id)" -Sev Info
7279

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

Lines changed: 232 additions & 80 deletions
Large diffs are not rendered by default.

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

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Function Invoke-ListGroups {
1616
$TenantFilter = $Request.Query.TenantFilter
1717
$selectstring = "id,createdDateTime,displayName,description,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule,grouptypes,onPremisesSyncEnabled,resourceProvisioningOptions,userPrincipalName&`$expand=members(`$select=userPrincipalName)"
1818

19-
$BulkRequestArrayList = [System.Collections.ArrayList]@()
19+
$BulkRequestArrayList = [System.Collections.Generic.List[object]]::new()
2020

2121
if ($Request.Query.GroupID) {
2222
$selectstring = 'id,createdDateTime,displayName,description,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule,groupTypes,userPrincipalName'
@@ -36,21 +36,60 @@ Function Invoke-ListGroups {
3636
}
3737

3838
if ($Request.Query.owners) {
39-
$selectstring = 'id,userPrincipalName,displayName,hideFromOutlookClients,hideFromAddressLists,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule'
40-
$BulkRequestArrayList.add(@{
41-
id = 3
42-
method = 'GET'
43-
url = "groups/$($Request.Query.GroupID)/owners?`$top=999&select=$selectstring"
44-
})
39+
if ($Request.Query.groupType -ne 'Distribution List' -or $Request.Query.groupType -ne 'Mail-Enabled Security') {
40+
$selectstring = 'id,userPrincipalName,displayName,hideFromOutlookClients,hideFromAddressLists,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule'
41+
$BulkRequestArrayList.add(@{
42+
id = 3
43+
method = 'GET'
44+
url = "groups/$($Request.Query.GroupID)/owners?`$top=999&select=$selectstring"
45+
})
46+
} else {
47+
$OwnerIds = New-ExoRequest -cmdlet 'Get-DistributionGroup' -tenantid $TenantFilter -cmdParams @{Identity = $Request.Query.GroupID } -useSystemMailbox $true | Select-Object -ExpandProperty ManagedBy
48+
49+
$BulkRequestArrayList.add(@{
50+
id = 3
51+
method = 'POST'
52+
url = 'directoryObjects/getByIds'
53+
body = @{
54+
ids = @($OwnerIds)
55+
}
56+
headers = @{
57+
'Content-Type' = 'application/json'
58+
}
59+
})
60+
}
61+
}
62+
63+
if ($Request.Query.groupType -eq 'Distribution List' -or $Request.Query.groupType -eq 'Mail-Enabled Security') {
64+
# get the outside the organization RequireSenderAuthenticationEnabled setting
65+
$OnlyAllowInternal = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-DistributionGroup' -cmdParams @{Identity = $Request.Query.GroupID } -useSystemMailbox $true | Select-Object -ExpandProperty RequireSenderAuthenticationEnabled
66+
} elseif ($GroupType -eq 'Microsoft 365') {
67+
$OnlyAllowInternal = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-UnifiedGroup' -cmdParams @{Identity = $Request.Query.GroupID } -useSystemMailbox $true | Select-Object -ExpandProperty RequireSenderAuthenticationEnabled
68+
} else {
69+
$OnlyAllowInternal = $null
70+
}
71+
72+
if ($Request.Query.groupType -eq 'Microsoft 365') {
73+
$UnifiedGroup = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-UnifiedGroup' -cmdParams @{Identity = $Request.Query.GroupID } -useSystemMailbox $true | Select-Object -Property subscriptionEnabled, AutoSubscribeNewMembers
74+
75+
if ($UnifiedGroup.subscriptionEnabled -eq $true -and $UnifiedGroup.AutoSubscribeNewMembers -eq $true) {
76+
$SendCopies = $true
77+
} else {
78+
$SendCopies = $false
79+
}
80+
} else {
81+
$SendCopies = $null
4582
}
4683

4784
try {
4885
if ($BulkRequestArrayList.Count -gt 0) {
4986
$RawGraphRequest = New-GraphBulkRequest -tenantid $TenantFilter -scope 'https://graph.microsoft.com/.default' -Requests @($BulkRequestArrayList) -asapp $true
5087
$GraphRequest = [PSCustomObject]@{
51-
groupInfo = ($RawGraphRequest | Where-Object { $_.id -eq 1 }).body
52-
members = ($RawGraphRequest | Where-Object { $_.id -eq 2 }).body.value
53-
owners = ($RawGraphRequest | Where-Object { $_.id -eq 3 }).body.value
88+
groupInfo = ($RawGraphRequest | Where-Object { $_.id -eq 1 }).body
89+
members = ($RawGraphRequest | Where-Object { $_.id -eq 2 }).body.value
90+
owners = ($RawGraphRequest | Where-Object { $_.id -eq 3 }).body.value
91+
allowExternal = (!$OnlyAllowInternal)
92+
sendCopies = $SendCopies
5493
}
5594
} else {
5695
$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 } },
@@ -85,6 +124,7 @@ Function Invoke-ListGroups {
85124

86125
$StatusCode = [HttpStatusCode]::OK
87126
} catch {
127+
Write-Warning $_.InvocationInfo.PositionMessage
88128
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
89129
$StatusCode = [HttpStatusCode]::Forbidden
90130
$GraphRequest = $ErrorMessage
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using namespace System.Net
2+
3+
Function Invoke-ListStandardsCompare {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Tenant.BestPracticeAnalyser.Read
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
# Create mock data for testing with the correct API structure
14+
# Only tenant data with values, no compliance information or standard values
15+
$Results = @(
16+
@{
17+
tenantFilter = 'TenantOne'
18+
standardsResults = @(
19+
@{
20+
standardId = 'standards.MailContacts'
21+
standardName = 'Mail Contacts'
22+
value = @{
23+
GeneralContact = '[email protected]'
24+
SecurityContact = '[email protected]'
25+
MarketingContact = '[email protected]'
26+
TechContact = '[email protected]'
27+
}
28+
},
29+
@{
30+
standardId = 'standards.AuditLog'
31+
standardName = 'Audit Log'
32+
value = $true
33+
},
34+
@{
35+
standardId = 'standards.ProfilePhotos'
36+
standardName = 'Profile Photos'
37+
value = @{
38+
state = @{
39+
label = 'Enabled'
40+
value = 'enabled'
41+
}
42+
}
43+
}
44+
)
45+
},
46+
@{
47+
tenantFilter = 'dev.johnwduprey.com'
48+
standardsResults = @(
49+
@{
50+
standardId = 'standards.MailContacts'
51+
standardName = 'Mail Contacts'
52+
value = @{
53+
GeneralContact = '[email protected]'
54+
SecurityContact = '[email protected]'
55+
}
56+
},
57+
@{
58+
standardId = 'standards.AuditLog'
59+
standardName = 'Audit Log'
60+
value = $false
61+
}
62+
)
63+
}
64+
)
65+
66+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
67+
StatusCode = [HttpStatusCode]::OK
68+
Body = (ConvertTo-Json -Depth 15 -InputObject $Results)
69+
})
70+
71+
}

Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-DurableCleanup.ps1

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@ function Start-DurableCleanup {
2626

2727
$CleanupCount = 0
2828
$QueueCount = 0
29+
$ClearQueues = $false
30+
31+
$FunctionsWithLongRunningOrchestrators = [System.Collections.Generic.List[object]]::new()
2932
foreach ($Table in $InstancesTables) {
33+
$RunningOrchestratorCount = 0
3034
$Table = Get-CippTable -TableName $Table
31-
$ClearQueues = $false
3235
$FunctionName = $Table.TableName -replace 'Instances', ''
3336
$Orchestrators = Get-CIPPAzDataTableEntity @Table -Filter "RuntimeStatus eq 'Running'" | Select-Object * -ExcludeProperty Input
37+
$Queues = Get-AzStorageQueue -Context $StorageContext -Name ('{0}*' -f $FunctionName) | Select-Object -Property Name, ApproximateMessageCount, QueueClient
38+
$RunningOrchestratorCount = $Orchestrators.Count
3439
$LongRunningOrchestrators = $Orchestrators | Where-Object { $_.CreatedTime.DateTime -lt $TargetTime }
40+
if ($LongRunningOrchestrators.Count -gt 0) {
41+
$FunctionsWithLongRunningOrchestrators.Add(@{'FunctionName' = $FunctionName })
42+
}
3543
foreach ($Orchestrator in $LongRunningOrchestrators) {
3644
$CreatedTime = [DateTime]::SpecifyKind($Orchestrator.CreatedTime.DateTime, [DateTimeKind]::Utc)
3745
$TimeSpan = New-TimeSpan -Start $CreatedTime -End (Get-Date).ToUniversalTime()
@@ -45,9 +53,7 @@ function Start-DurableCleanup {
4553
$CleanupCount++
4654
}
4755
}
48-
49-
if ($ClearQueues) {
50-
$Queues = Get-AzStorageQueue -Context $StorageContext -Name ('{0}*' -f $FunctionName) | Select-Object -Property Name, ApproximateMessageCount, QueueClient
56+
if ($ClearQueues -or ($RunningOrchestratorCount -eq 0 -and $Queues.ApproximateMessageCount -gt 0)) {
5157
$RunningQueues = $Queues | Where-Object { $_.ApproximateMessageCount -gt 0 }
5258
foreach ($Queue in $RunningQueues) {
5359
Write-Information "- Removing queue: $($Queue.Name), message count: $($Queue.ApproximateMessageCount)"
@@ -58,5 +64,10 @@ function Start-DurableCleanup {
5864
}
5965
}
6066
}
61-
Write-Information "Cleanup complete. $CleanupCount orchestrators were terminated. $QueueCount queues were cleared."
67+
68+
if ($CleanupCount -gt 0 -or $QueueCount -gt 0) {
69+
Write-LogMessage -api 'Durable Cleanup' -message "$CleanupCount orchestrators were terminated. $QueueCount queues were cleared." -sev 'Info' -LogData $FunctionsWithLongRunningOrchestrators
70+
}
71+
72+
Write-Information "Durable cleanup complete. $CleanupCount orchestrators were terminated. $QueueCount queues were cleared."
6273
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ function New-ExoBulkRequest {
4545
$IdToCmdletName = @{}
4646

4747
# Split the cmdletArray into batches of 10
48-
$batches = [System.Collections.ArrayList]@()
48+
$batches = [System.Collections.Generic.List[object]]::new()
4949
for ($i = 0; $i -lt $cmdletArray.Length; $i += 10) {
50-
$null = $batches.Add($cmdletArray[$i..[math]::Min($i + 9, $cmdletArray.Length - 1)])
50+
$batches.Add($cmdletArray[$i..[math]::Min($i + 9, $cmdletArray.Length - 1)])
5151
}
5252

53-
$ReturnedData = @()
53+
$ReturnedData = [System.Collections.Generic.List[object]]::new()
5454
foreach ($batch in $batches) {
5555
$BatchBodyObj = @{
5656
requests = @()
@@ -85,13 +85,16 @@ function New-ExoBulkRequest {
8585
}
8686
$BatchBodyJson = ConvertTo-Json -InputObject $BatchBodyObj -Depth 10
8787
$Results = Invoke-RestMethod $BatchURL -ResponseHeadersVariable responseHeaders -Method POST -Body $BatchBodyJson -Headers $Headers -ContentType 'application/json; charset=utf-8'
88-
$ReturnedData = $ReturnedData + $Results.responses
88+
$ReturnedData.Add($Results.responses)
89+
8990
Write-Host "Batch #$($batches.IndexOf($batch) + 1) of $($batches.Count) processed"
9091
}
9192
} catch {
9293
# Error handling (omitted for brevity)
9394
}
9495

96+
Write-Information ($ReturnedHeaders | ConvertTo-Json -Depth 10)
97+
9598
# Process the returned data
9699
if ($ReturnWithCommand) {
97100
$FinalData = @{}

Modules/CIPPCore/Public/Set-CIPPGroupAuthentication.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ function Set-CIPPGroupAuthentication(
22
[string]$Headers,
33
[string]$GroupType,
44
[string]$Id,
5-
[string]$OnlyAllowInternalString,
5+
[bool]$OnlyAllowInternal,
66
[string]$TenantFilter,
77
[string]$APIName = 'Group Sender Authentication'
88
) {
99
try {
10-
$OnlyAllowInternal = if ($OnlyAllowInternalString -eq 'true') { 'true' } else { 'false' }
11-
$messageSuffix = if ($OnlyAllowInternal -eq 'true') { 'inside the organisation.' } else { 'inside and outside the organisation.' }
10+
$messageSuffix = if ($OnlyAllowInternal -eq $true) { 'inside the organisation.' } else { 'inside and outside the organisation.' }
1211

1312
if ($GroupType -eq 'Distribution List' -or $GroupType -eq 'Mail-Enabled Security') {
1413
New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-DistributionGroup' -cmdParams @{Identity = $Id; RequireSenderAuthenticationEnabled = $OnlyAllowInternal }

0 commit comments

Comments
 (0)