Skip to content

Commit a557f51

Browse files
fix: Change default assignment mode to append (KelvinTegelaar#2137)
Update the default assignment mode to 'append' for a less destructive default. Frontend PR: KelvinTegelaar/CIPP#6342
2 parents 2a86601 + b2985a6 commit a557f51

6 files changed

Lines changed: 134 additions & 4 deletions

File tree

Modules/CIPPCore/Public/Set-CIPPAssignedApplication.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function Set-CIPPAssignedApplication {
1010
$ApplicationId,
1111
$TenantFilter,
1212
$GroupIds,
13-
$AssignmentMode = 'replace',
13+
$AssignmentMode = 'append',
1414
$AssignmentDirection,
1515
$APIName = 'Assign Application',
1616
$Headers,

Modules/CIPPCore/Public/Set-CIPPAssignedPolicy.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Set-CIPPAssignedPolicy {
1515
$AssignmentFilterType = 'include',
1616
$GroupIds,
1717
$GroupNames,
18-
$AssignmentMode = 'replace',
18+
$AssignmentMode = 'append',
1919
$AssignmentDirection
2020
)
2121

Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/Endpoint/Applications/Invoke-ExecAssignApp.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function Invoke-ExecAssignApp {
3131
$Intent = if ([string]::IsNullOrWhiteSpace($Intent)) { 'Required' } else { $Intent }
3232

3333
if ([string]::IsNullOrWhiteSpace($AssignmentMode)) {
34-
$AssignmentMode = 'replace'
34+
$AssignmentMode = 'append'
3535
} else {
3636
$AssignmentMode = $AssignmentMode.ToLower()
3737
if ($AssignmentMode -notin @('replace', 'append')) {

Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/Endpoint/MEM/Invoke-ExecAssignPolicy.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function Invoke-ExecAssignPolicy {
4949

5050
# Validate and default AssignmentMode
5151
if ([string]::IsNullOrWhiteSpace($AssignmentMode)) {
52-
$AssignmentMode = 'replace'
52+
$AssignmentMode = 'append'
5353
}
5454

5555
$AssignTo = if ($AssignTo -ne 'on') { $AssignTo }
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Pester tests for Invoke-ExecAssignApp assignment mode defaults.
2+
3+
BeforeAll {
4+
$RepoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSCommandPath))
5+
$FunctionPath = Get-ChildItem -Path (Join-Path $RepoRoot 'Modules') -Recurse -Filter 'Invoke-ExecAssignApp.ps1' -File |
6+
Select-Object -First 1 -ExpandProperty FullName
7+
8+
([PSObject].Assembly.GetType('System.Management.Automation.TypeAccelerators')).GetMethod('Add').Invoke(
9+
$null, @('HttpStatusCode', [System.Net.HttpStatusCode]))
10+
11+
class HttpResponseContext {
12+
[int]$StatusCode
13+
[object]$Body
14+
}
15+
16+
function Set-CIPPAssignedApplication { param($ApplicationId, $TenantFilter, $Intent, $APIName, $Headers, $GroupName, $AssignmentMode) }
17+
18+
. $FunctionPath
19+
}
20+
21+
Describe 'Invoke-ExecAssignApp assignment mode' {
22+
BeforeEach {
23+
$script:assignmentMode = $null
24+
Mock -CommandName Set-CIPPAssignedApplication -MockWith {
25+
$script:assignmentMode = $AssignmentMode
26+
}
27+
}
28+
29+
It 'defaults omitted assignment mode to append' {
30+
$request = [pscustomobject]@{
31+
Params = @{ CIPPEndpoint = 'ExecAssignApp' }
32+
Headers = @{}
33+
Query = [pscustomobject]@{}
34+
Body = [pscustomobject]@{
35+
tenantFilter = 'contoso.onmicrosoft.com'
36+
ID = 'app-1'
37+
AppType = 'Win32Lob'
38+
AssignTo = 'AllDevices'
39+
}
40+
}
41+
42+
$response = Invoke-ExecAssignApp -Request $request -TriggerMetadata $null
43+
44+
$response.StatusCode | Should -Be ([System.Net.HttpStatusCode]::OK)
45+
$script:assignmentMode | Should -Be 'append'
46+
}
47+
48+
It 'preserves explicit replace mode' {
49+
$request = [pscustomobject]@{
50+
Params = @{ CIPPEndpoint = 'ExecAssignApp' }
51+
Headers = @{}
52+
Query = [pscustomobject]@{}
53+
Body = [pscustomobject]@{
54+
tenantFilter = 'contoso.onmicrosoft.com'
55+
ID = 'app-1'
56+
AppType = 'Win32Lob'
57+
AssignTo = 'AllDevices'
58+
assignmentMode = 'replace'
59+
}
60+
}
61+
62+
$null = Invoke-ExecAssignApp -Request $request -TriggerMetadata $null
63+
64+
$script:assignmentMode | Should -Be 'replace'
65+
}
66+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Pester tests for Invoke-ExecAssignPolicy assignment mode defaults.
2+
3+
BeforeAll {
4+
$RepoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSCommandPath))
5+
$FunctionPath = Get-ChildItem -Path (Join-Path $RepoRoot 'Modules') -Recurse -Filter 'Invoke-ExecAssignPolicy.ps1' -File |
6+
Select-Object -First 1 -ExpandProperty FullName
7+
8+
([PSObject].Assembly.GetType('System.Management.Automation.TypeAccelerators')).GetMethod('Add').Invoke(
9+
$null, @('HttpStatusCode', [System.Net.HttpStatusCode]))
10+
11+
class HttpResponseContext {
12+
[int]$StatusCode
13+
[object]$Body
14+
}
15+
16+
function Set-CIPPAssignedPolicy { param($PolicyId, $TenantFilter, $GroupName, $Type, $Headers, $AssignmentMode) }
17+
18+
. $FunctionPath
19+
}
20+
21+
Describe 'Invoke-ExecAssignPolicy assignment mode' {
22+
BeforeEach {
23+
$script:assignmentMode = $null
24+
Mock -CommandName Set-CIPPAssignedPolicy -MockWith {
25+
$script:assignmentMode = $AssignmentMode
26+
}
27+
}
28+
29+
It 'defaults omitted assignment mode to append' {
30+
$request = [pscustomobject]@{
31+
Params = @{ CIPPEndpoint = 'ExecAssignPolicy' }
32+
Headers = @{}
33+
Body = [pscustomobject]@{
34+
tenantFilter = 'contoso.onmicrosoft.com'
35+
ID = 'policy-1'
36+
Type = 'configurationPolicies'
37+
AssignTo = 'AllDevices'
38+
}
39+
}
40+
41+
$response = Invoke-ExecAssignPolicy -Request $request -TriggerMetadata $null
42+
43+
$response.StatusCode | Should -Be ([System.Net.HttpStatusCode]::OK)
44+
$script:assignmentMode | Should -Be 'append'
45+
}
46+
47+
It 'preserves explicit replace mode' {
48+
$request = [pscustomobject]@{
49+
Params = @{ CIPPEndpoint = 'ExecAssignPolicy' }
50+
Headers = @{}
51+
Body = [pscustomobject]@{
52+
tenantFilter = 'contoso.onmicrosoft.com'
53+
ID = 'policy-1'
54+
Type = 'configurationPolicies'
55+
AssignTo = 'AllDevices'
56+
assignmentMode = 'replace'
57+
}
58+
}
59+
60+
$null = Invoke-ExecAssignPolicy -Request $request -TriggerMetadata $null
61+
62+
$script:assignmentMode | Should -Be 'replace'
63+
}
64+
}

0 commit comments

Comments
 (0)