Skip to content

Commit 4b03379

Browse files
committed
fix logic for checking existing group membership
1 parent 360dadc commit 4b03379

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Tenant/Invoke-EditTenant.ps1

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

3-
Function Invoke-EditTenant {
3+
function Invoke-EditTenant {
44
<#
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
@@ -11,8 +11,9 @@ Function Invoke-EditTenant {
1111
param($Request, $TriggerMetadata)
1212

1313
$APIName = $Request.Params.CIPPEndpoint
14+
$Headers = $Request.Headers
1415

15-
Write-LogMessage -headers $Request.Headers -API $APINAME -message 'Accessed this API' -Sev 'Debug'
16+
Write-LogMessage -headers $Headers -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1617

1718
$customerId = $Request.Body.customerId
1819
$tenantAlias = $Request.Body.tenantAlias
@@ -46,9 +47,9 @@ Function Invoke-EditTenant {
4647
}
4748

4849
# Update tenant groups
49-
$CurrentMembers = Get-CIPPAzDataTableEntity @GroupMembersTable -Filter "customerId eq '$customerId'"
50+
$CurrentGroupMemberships = Get-CIPPAzDataTableEntity @GroupMembersTable -Filter "customerId eq '$customerId'"
5051
foreach ($Group in $tenantGroups) {
51-
$GroupEntity = $CurrentMembers | Where-Object { $_.GroupId -eq $Group.groupId }
52+
$GroupEntity = $CurrentGroupMemberships | Where-Object { $_.GroupId -eq $Group.groupId }
5253
if (!$GroupEntity) {
5354
$GroupEntity = @{
5455
PartitionKey = 'Member'
@@ -61,8 +62,8 @@ Function Invoke-EditTenant {
6162
}
6263

6364
# Remove any groups that are no longer selected
64-
foreach ($Group in $CurrentMembers) {
65-
if ($tenantGroups -notcontains $Group.GroupId) {
65+
foreach ($Group in $CurrentGroupMemberships) {
66+
if ($tenantGroups.GroupId -notcontains $Group.GroupId) {
6667
Remove-AzDataTableEntity @GroupMembersTable -Entity $Group
6768
}
6869
}
@@ -76,7 +77,7 @@ Function Invoke-EditTenant {
7677
Body = $response
7778
})
7879
} catch {
79-
Write-LogMessage -headers $Request.Headers -tenant $customerId -API $APINAME -message "Edit Tenant failed. The error is: $($_.Exception.Message)" -Sev 'Error'
80+
Write-LogMessage -headers $Headers -tenant $customerId -API $APINAME -message "Edit Tenant failed. The error is: $($_.Exception.Message)" -Sev 'Error'
8081
$response = @{
8182
state = 'error'
8283
resultText = $_.Exception.Message

0 commit comments

Comments
 (0)