Skip to content

Commit 8418991

Browse files
authored
Merge pull request #668 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 169f302 + df13333 commit 8418991

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function Invoke-ListTenantGroups {
1111
param($Request, $TriggerMetadata)
1212

1313
$groupFilter = $Request.Query.groupId ?? $Request.Body.groupId
14-
$TenantGroups = (Get-TenantGroups -GroupId $groupFilter) ?? @()
14+
$TenantGroups = (Get-TenantGroups -GroupId $groupFilter -SkipCache) ?? @()
1515
$Body = @{ Results = @($TenantGroups) }
1616

1717
return ([HttpResponseContext]@{

Modules/CIPPCore/Public/TenantGroups/Get-TenantGroups.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ function Get-TenantGroups {
3030
param(
3131
[string]$GroupId,
3232
[string]$TenantFilter,
33-
[switch]$Dynamic
33+
[switch]$Dynamic,
34+
[switch]$SkipCache
3435
)
3536
$CacheKey = "$GroupId|$TenantFilter|$($Dynamic.IsPresent)"
3637

37-
if ($script:TenantGroupsResultCache.ContainsKey($CacheKey)) {
38+
if ($SkipCache) {
39+
Write-Verbose "Skipping cache for: $CacheKey"
40+
} elseif ($script:TenantGroupsResultCache.ContainsKey($CacheKey)) {
3841
Write-Verbose "Returning cached result for: $CacheKey"
3942
return $script:TenantGroupsResultCache[$CacheKey]
4043
}
@@ -47,7 +50,7 @@ function Get-TenantGroups {
4750
}
4851

4952
# Load table data into cache if not already loaded
50-
if (-not $script:TenantGroupsCache.Groups -or -not $script:TenantGroupsCache.Members) {
53+
if (-not $script:TenantGroupsCache.Groups -or -not $script:TenantGroupsCache.Members -or $SkipCache) {
5154
Write-Verbose 'Loading TenantGroups and TenantGroupMembers tables into cache'
5255

5356
$GroupTable = Get-CippTable -tablename 'TenantGroups'

Modules/CIPPCore/Public/TenantGroups/Update-CIPPDynamicTenantGroups.ps1

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,34 @@ function Update-CIPPDynamicTenantGroups {
9696
}
9797
}
9898
'tenantGroupMember' {
99-
# Get members of the referenced tenant group
100-
$ReferencedGroupId = $Value.value
101-
if ($Operator -eq 'in') {
102-
"`$_.customerId -in `$script:TenantGroupMembersCache['$ReferencedGroupId']"
99+
# Get members of the referenced tenant group(s)
100+
if ($Operator -in @('in', 'notin')) {
101+
# Handle array of group IDs
102+
$ReferencedGroupIds = @($Value.value)
103+
104+
# Collect all unique member customerIds from all referenced groups
105+
$AllMembers = [System.Collections.Generic.HashSet[string]]::new()
106+
foreach ($GroupId in $ReferencedGroupIds) {
107+
if ($script:TenantGroupMembersCache.ContainsKey($GroupId)) {
108+
foreach ($MemberId in $script:TenantGroupMembersCache[$GroupId]) {
109+
[void]$AllMembers.Add($MemberId)
110+
}
111+
}
112+
}
113+
114+
# Convert to array string for condition
115+
$MemberArray = $AllMembers | ForEach-Object { "'$_'" }
116+
$MemberArrayString = $MemberArray -join ', '
117+
118+
if ($Operator -eq 'in') {
119+
"`$_.customerId -in @($MemberArrayString)"
120+
} else {
121+
"`$_.customerId -notin @($MemberArrayString)"
122+
}
103123
} else {
104-
"`$_.customerId -notin `$script:TenantGroupMembersCache['$ReferencedGroupId']"
124+
# Single value with other operators
125+
$ReferencedGroupId = $Value.value
126+
"`$_.customerId -$Operator `$script:TenantGroupMembersCache['$ReferencedGroupId']"
105127
}
106128
}
107129
'customVariable' {

0 commit comments

Comments
 (0)