Skip to content

Commit 989f4f3

Browse files
authored
Merge pull request #556 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 4d14a55 + b50c4bb commit 989f4f3

File tree

9 files changed

+71
-21
lines changed

9 files changed

+71
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function Invoke-ListScheduledItems {
4848
}
4949

5050
if ($SearchTitle) {
51-
$Tasks | Where-Object { $_.Name -like $SearchTitle }
51+
$Tasks = $Tasks | Where-Object { $_.Name -like $SearchTitle }
5252
}
5353

5454
$AllowedTenants = Test-CIPPAccess -Request $Request -TenantList

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Conditional/Invoke-ExecCAExclusion.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function Invoke-ExecCAExclusion {
5454
}
5555

5656
if ($Policy.conditions.users.excludeGroups -notcontains $GroupId) {
57-
Set-CIPPCAExclusion -TenantFilter $TenantFilter -ExclusionType 'Add' -PolicyId $PolicyId -Groups @{ value = @($GroupId); addedFields = @{ displayName = @("CIPP-Vacation-$($Policy.displayName)") } } -Headers $Headers
57+
Set-CIPPCAExclusion -TenantFilter $TenantFilter -ExclusionType 'Add' -PolicyId $PolicyId -Groups @{ value = @($GroupId); addedFields = @{ displayName = @("Vacation Exclusion - $($Policy.displayName)") } } -Headers $Headers
5858
}
5959

6060
$PolicyName = $Policy.displayName

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,15 @@ function Invoke-ExecUpdateDriftDeviation {
8787
if ($Deviation.status -eq 'deniedDelete') {
8888
$Policy = $Deviation.receivedValue | ConvertFrom-Json -ErrorAction SilentlyContinue
8989
Write-Host "Policy is $($Policy)"
90-
$URLName = Get-CIPPURLName -Template $Policy
90+
if ($Deviation.standardName -like '*ConditionalAccessTemplates*') {
91+
$URLName = 'identity/conditionalAccess/policies'
92+
} else {
93+
$URLName = Get-CIPPURLName -Template $Policy
94+
}
95+
$ID = $Policy.ID
9196
if ($Policy -and $URLName) {
92-
Write-Host "Going to delete Policy with ID $($policy.ID) Deviation Name is $($Deviation.standardName)"
93-
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/$($URLName)/$($policy.id)" -type DELETE -tenant $TenantFilter
97+
Write-Host "Going to delete Policy with ID $($Policy.ID) Deviation Name is $($Deviation.standardName)"
98+
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/$($URLName)/$($ID)" -type DELETE -tenant $TenantFilter
9499
"Deleted Policy $($ID)"
95100
Write-LogMessage -tenant $TenantFilter -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Deleted Policy with ID $($ID)" -Sev 'Info'
96101
} else {

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ExecCommunityRepo.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,14 @@ function Invoke-ExecCommunityRepo {
172172
Write-Host 'Found a migration table, getting contents'
173173
$MigrationTable = (Get-GitHubFileContents -FullName $FullName -Branch $Branch -Path $MigrationTable.path).content | ConvertFrom-Json
174174
}
175+
176+
$NamedLocations = $Files | Where-Object { $_.name -match 'ALLOWED COUNTRIES' }
177+
$LocationData = foreach ($Location in $NamedLocations) {
178+
(Get-GitHubFileContents -FullName $TemplateSettings.templateRepo.value -Branch $TemplateSettings.templateRepoBranch.value -Path $Location.path).content | ConvertFrom-Json
179+
}
175180
}
176-
Import-CommunityTemplate -Template $Content -SHA $Template.sha -MigrationTable $MigrationTable
181+
Import-CommunityTemplate -Template $Content -SHA $Template.sha -MigrationTable $MigrationTable -LocationData $LocationData
182+
177183
$Results = @{
178184
resultText = 'Template imported'
179185
state = 'success'

Modules/CIPPCore/Public/New-CIPPCAPolicy.ps1

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,19 @@ function New-CIPPCAPolicy {
123123
if (!$locations) { continue }
124124
foreach ($location in $locations) {
125125
if (!$location.displayName) { continue }
126-
$CheckExististing = New-GraphGETRequest -uri 'https://graph.microsoft.com/beta/identity/conditionalAccess/namedLocations' -tenantid $TenantFilter -asApp $true
127-
if ($Location.displayName -in $CheckExististing.displayName) {
126+
$CheckExisting = New-GraphGETRequest -uri 'https://graph.microsoft.com/beta/identity/conditionalAccess/namedLocations' -tenantid $TenantFilter -asApp $true
127+
if ($Location.displayName -in $CheckExisting.displayName) {
128128
[pscustomobject]@{
129-
id = ($CheckExististing | Where-Object -Property displayName -EQ $Location.displayName).id
130-
name = ($CheckExististing | Where-Object -Property displayName -EQ $Location.displayName).displayName
129+
id = ($CheckExisting | Where-Object -Property displayName -EQ $Location.displayName).id
130+
name = ($CheckExisting | Where-Object -Property displayName -EQ $Location.displayName).displayName
131+
templateId = $location.id
131132
}
132133
Write-LogMessage -Headers $User -API $APINAME -message "Matched a CA policy with the existing Named Location: $($location.displayName)" -Sev 'Info'
133134

134135
} else {
135136
if ($location.countriesAndRegions) { $location.countriesAndRegions = @($location.countriesAndRegions) }
137+
$location | Select-Object * -ExcludeProperty id
138+
Remove-ODataProperties -Object $location
136139
$Body = ConvertTo-Json -InputObject $Location
137140
$GraphRequest = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/identity/conditionalAccess/namedLocations' -body $body -Type POST -tenantid $tenantfilter -asApp $true
138141
$retryCount = 0
@@ -151,19 +154,21 @@ function New-CIPPCAPolicy {
151154
}
152155
}
153156
}
157+
Write-Information 'Location Lookup Table:'
158+
Write-Information ($LocationLookupTable | ConvertTo-Json -Depth 10)
154159

155160
foreach ($location in $JSONobj.conditions.locations.includeLocations) {
156-
Write-Information "Replacing named location - $location"
157-
$lookup = $LocationLookupTable | Where-Object -Property name -EQ $location
158-
Write-Information "Found $lookup"
161+
$lookup = $LocationLookupTable | Where-Object { $_.name -eq $location -or $_.displayName -eq $location -or $_.templateId -eq $location }
159162
if (!$lookup) { continue }
163+
Write-Information "Replacing named location - $location"
160164
$index = [array]::IndexOf($JSONobj.conditions.locations.includeLocations, $location)
161165
$JSONobj.conditions.locations.includeLocations[$index] = $lookup.id
162166
}
163167

164168
foreach ($location in $JSONobj.conditions.locations.excludeLocations) {
165-
$lookup = $LocationLookupTable | Where-Object -Property name -EQ $location
169+
$lookup = $LocationLookupTable | Where-Object { $_.name -eq $location -or $_.displayName -eq $location -or $_.templateId -eq $location }
166170
if (!$lookup) { continue }
171+
Write-Information "Replacing named location - $location"
167172
$index = [array]::IndexOf($JSONobj.conditions.locations.excludeLocations, $location)
168173
$JSONobj.conditions.locations.excludeLocations[$index] = $lookup.id
169174
}

Modules/CIPPCore/Public/New-CIPPGroup.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,15 @@ function New-CIPPGroup {
167167
GroupType = $NormalizedGroupType
168168
Email = if ($NeedsEmail) { $Email } else { $null }
169169
}
170-
170+
if ($GroupObject.subscribeMembers) {
171+
#Waiting for group to become available in Exo.
172+
Start-Sleep -Seconds 10
173+
$SubParams = @{
174+
Identity = $GraphRequest.id
175+
'autoSubscribeNewMembers' = $true
176+
}
177+
$null = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Set-UnifiedGroup' -cmdParams $SubParams
178+
}
171179
} else {
172180
# Handle Exchange Online groups (Distribution, DynamicDistribution)
173181

Modules/CIPPCore/Public/New-CIPPTemplateRun.ps1

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,30 @@ function New-CIPPTemplateRun {
3939
if ($MigrationTable) {
4040
$MigrationTable = (Get-GitHubFileContents -FullName $TemplateSettings.templateRepo.value -Branch $TemplateSettings.templateRepoBranch.value -Path $MigrationTable.path).content | ConvertFrom-Json
4141
}
42+
$NamedLocations = $Files | Where-Object { $_.name -match 'ALLOWED COUNTRIES' }
43+
$LocationData = foreach ($Location in $NamedLocations) {
44+
(Get-GitHubFileContents -FullName $TemplateSettings.templateRepo.value -Branch $TemplateSettings.templateRepoBranch.value -Path $Location.path).content | ConvertFrom-Json
45+
}
46+
4247
foreach ($File in $Files) {
43-
if ($File.name -eq 'MigrationTable' -or $file.name -eq 'ALLOWED COUNTRIES') { continue }
44-
$ExistingTemplate = $ExistingTemplates | Where-Object { (![string]::IsNullOrEmpty($_.displayName) -and (Get-SanitizedFilename -filename $_.displayName) -eq $File.name) -or (![string]::IsNullOrEmpty($_.templateName) -and (Get-SanitizedFilename -filename $_.templateName) -eq $File.name ) -and ![string]::IsNullOrEmpty($_.SHA) } | Select-Object -First 1
48+
if ($File.name -eq 'MigrationTable' -or $file.name -match 'ALLOWED COUNTRIES') { continue }
49+
Write-Information "Processing template file $($File.name) - Sanitized as $(Get-SanitizedFilename -filename $File.name)"
50+
$ExistingTemplate = $ExistingTemplates | Where-Object { (![string]::IsNullOrEmpty($_.displayName) -and (Get-SanitizedFilename -filename $_.displayName) -eq (Get-SanitizedFilename -filename $File.name)) -or (![string]::IsNullOrEmpty($_.templateName) -and (Get-SanitizedFilename -filename $_.templateName) -eq (Get-SanitizedFilename -filename $File.name) ) -and ![string]::IsNullOrEmpty($_.SHA) } | Select-Object -First 1
4551

4652
$UpdateNeeded = $false
4753
if ($ExistingTemplate -and $ExistingTemplate.SHA -ne $File.sha) {
4854
$Name = $ExistingTemplate.displayName ?? $ExistingTemplate.templateName
4955
Write-Information "Existing template $($Name) found, but SHA is different. Updating template."
5056
$UpdateNeeded = $true
5157
"Template $($Name) needs to be updated as the SHA is different"
52-
} else {
58+
} elseif ($ExistingTemplate -and $ExistingTemplate.SHA -eq $File.sha) {
5359
Write-Information "Existing template $($File.name) found, but SHA is the same. No update needed."
5460
"Template $($File.name) found, but SHA is the same. No update needed."
5561
}
5662

5763
if (!$ExistingTemplate -or $UpdateNeeded) {
5864
$Template = (Get-GitHubFileContents -FullName $TemplateSettings.templateRepo.value -Branch $TemplateSettings.templateRepoBranch.value -Path $File.path).content | ConvertFrom-Json
59-
Import-CommunityTemplate -Template $Template -SHA $File.sha -MigrationTable $MigrationTable
65+
Import-CommunityTemplate -Template $Template -SHA $File.sha -MigrationTable $MigrationTable -LocationData $LocationData
6066
if ($UpdateNeeded) {
6167
Write-Information "Template $($File.name) needs to be updated as the SHA is different"
6268
"Template $($File.name) updated"
@@ -69,6 +75,7 @@ function New-CIPPTemplateRun {
6975
} catch {
7076
$Message = "Failed to get data from community repo $($TemplateSettings.templateRepo.value). Error: $($_.Exception.Message)"
7177
Write-LogMessage -API 'Community Repo' -tenant $TenantFilter -message $Message -sev Error
78+
Write-Information $_.InvocationInfo.PositionMessage
7279
return "Failed to get data from community repo $($TemplateSettings.templateRepo.value). Error: $($_.Exception.Message)"
7380
}
7481
} else {

Modules/CIPPCore/Public/Tools/Import-CommunityTemplate.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function Import-CommunityTemplate {
88
$Template,
99
$SHA,
1010
$MigrationTable,
11+
$LocationData,
1112
[switch]$Force
1213
)
1314

@@ -104,13 +105,29 @@ function Import-CommunityTemplate {
104105
$id = $Template.id
105106
$Template = $Template | Select-Object * -ExcludeProperty lastModifiedDateTime, 'assignments', '#microsoft*', '*@odata.navigationLink', '*@odata.associationLink', '*@odata.context', 'ScopeTagIds', 'supportsScopeTags', 'createdDateTime', '@odata.id', '@odata.editLink', '*odata.type', '[email protected]', createdDateTime, '[email protected]'
106107
Remove-ODataProperties -Object $Template
108+
109+
$LocationInfo = [system.collections.generic.list[object]]::new()
110+
if ($LocationData) {
111+
$LocationData | ForEach-Object {
112+
if ($Template.conditions.locations.includeLocations -contains $_.id -or $Template.conditions.locations.excludeLocations -contains $_.id) {
113+
Write-Information "Adding location info for location ID $($_.id)"
114+
$LocationInfo.Add($_)
115+
}
116+
}
117+
if ($LocationInfo.Count -gt 0) {
118+
$Template | Add-Member -MemberType NoteProperty -Name LocationInfo -Value $LocationInfo -Force
119+
}
120+
}
121+
107122
$RawJson = ConvertTo-Json -InputObject $Template -Depth 100 -Compress
108123
#Replace the ids with the displayname by using the migration table, this is a simple find and replace each instance in the JSON.
109124
$MigrationTable.objects | ForEach-Object {
110125
if ($RawJson -match $_.ID) {
111126
$RawJson = $RawJson.Replace($_.ID, $($_.DisplayName))
112127
}
113128
}
129+
130+
114131
$entity = @{
115132
JSON = "$RawJson"
116133
PartitionKey = 'CATemplate'

Modules/CippExtensions/Public/GitHub/Invoke-GitHubApiRequest.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function Invoke-GitHubApiRequest {
1313

1414
$Table = Get-CIPPTable -TableName Extensionsconfig
1515
$ExtensionConfig = (Get-CIPPAzDataTableEntity @Table).config
16-
if (Test-Json -Json $ExtensionConfig) {
16+
if ($ExtensionConfig -and (Test-Json -Json $ExtensionConfig)) {
1717
$Configuration = ($ExtensionConfig | ConvertFrom-Json).GitHub
1818
} else {
1919
$Configuration = @{ Enabled = $false }
@@ -64,6 +64,8 @@ function Invoke-GitHubApiRequest {
6464
Body = $Body
6565
Accept = $Accept
6666
}
67-
(Invoke-RestMethod -Uri 'https://cippy.azurewebsites.net/api/ExecGitHubAction' -Method POST -Body ($Action | ConvertTo-Json -Depth 10) -ContentType 'application/json').Results
67+
$Body = $Action | ConvertTo-Json -Depth 10
68+
69+
(Invoke-RestMethod -Uri 'https://cippy.azurewebsites.net/api/ExecGitHubAction' -Method POST -Body $Body -ContentType 'application/json').Results
6870
}
6971
}

0 commit comments

Comments
 (0)