Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to Merge or Overwrite Bits in Add-VSTeamAccessControlEntry #515

Merged
merged 7 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .docs/Add-VSTeamAccessControlEntry.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ Bitmask for Deny Permissions
Type: Int
Required: True
```
### OverwriteMask

Switch to overwrite the mask values rather than merge them.

```yaml
Type: Switch
Required: False
```

<!-- #include "./params/projectName.md" -->

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 7.13.0

Merged [Pull Request](https://github.com/MethodsAndPractices/vsteam/pull/515) from [mrwalters1988](https://github.com/mrwalters1988) the following:

- feat: added parameter for Add-VSTeamAccessControlEntry to choose whether to merge the Bits or to Overwrite the bits.

## 7.12.0

Merged [Pull Request](https://github.com/MethodsAndPractices/vsteam/pull/506) from [Miguel Nieto](https://github.com/mnieto) the following:
Expand Down
13 changes: 8 additions & 5 deletions Source/Public/Add-VSTeamAccessControlEntry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,26 @@ function Add-VSTeamAccessControlEntry {

[Parameter(Mandatory = $true)]
[ValidateRange(0, [int]::MaxValue)]
[int] $DenyMask
[int] $DenyMask,

[Parameter(Mandatory = $false)]
[switch] $OverwriteMask = $false
)
process {

if ($AllowMask -eq 0 -and $DenyMask -eq 0) {
if ($AllowMask -eq 0 -and $DenyMask -eq 0 -and $OverwriteMask -eq $false) {
Write-Warning "Permission masks for Allow and Deny do not inlude any permission. No Permission will change!"
}

if ($SecurityNamespace) {
$SecurityNamespaceId = $SecurityNamespace.ID
}

$merge = !$OverwriteMask
$body =
@"
{
"token": "$Token",
"merge": true,
"merge": $merge,
"accessControlEntries": [
{
"descriptor": "$Descriptor",
Expand Down Expand Up @@ -78,4 +81,4 @@ function Add-VSTeamAccessControlEntry {

Write-Output $acl
}
}
}
2 changes: 1 addition & 1 deletion Source/VSTeam.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'VSTeam.psm1'

# Version number of this module.
ModuleVersion = '7.12.0'
ModuleVersion = '7.13.0'

# Supported PSEditions
CompatiblePSEditions = @('Core', 'Desktop')
Expand Down
25 changes: 25 additions & 0 deletions Tests/function/tests/Add-VSTeamAccessControlEntry.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,30 @@ Describe 'VSTeamAccessControlEntry' {
-AllowMask 12 `
-DenyMask 15 } | Should -Throw
}

It 'should handle OverwriteMask' {

## Act
Add-VSTeamAccessControlEntry -SecurityNamespaceId 5a27515b-ccd7-42c9-84f1-54c998f03866 `
-Descriptor abc `
-Token xyz `
-AllowMask 12 `
-DenyMask 15 `
-OverwriteMask

## Assert
Should -Invoke Invoke-RestMethod -Exactly -Times 1 -Scope It -ParameterFilter {
$Uri -like "https://dev.azure.com/test/_apis/accesscontrolentries/5a27515b-ccd7-42c9-84f1-54c998f03866*" -and
$Uri -like "*api-version=$(_getApiVersion Core)*" -and
$Body -like "*`"token`": `"xyz`",*" -and
$Body -like "*`"descriptor`": `"abc`",*" -and
$Body -like "*`"allow`": 12,*" -and
$Body -like "*`"deny`": 15,*" -and
$Body -like "*`"merge`": false,*" -and
$Method -eq "Post"
}

}

}
}