File: permissions.ps1

package info (click to toggle)
azure-devops-cli-extension 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,384 kB
  • sloc: python: 160,782; xml: 198; makefile: 56; sh: 51
file content (66 lines) | stat: -rw-r--r-- 2,378 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
. (Join-Path $PSScriptRoot ..\Utils\permissionsHelper.ps1)

function get_token{
    param(
        [String]$iterationsNodeID,
        [String]$rootIterationID,
        [String]$childIterationID
    )
    $rootStr = 'vstfs:///Classification/Node/'
    $tokenStr = ''
    if($iterationsNodeID)
    {
        $tokenStr = $rootStr + $iterationsNodeID
        if($rootIterationID)
        {
            $tokenStr = $tokenStr + ':' + $rootStr + $rootIterationID
            if($childIterationID)
            {
                $tokenStr = $tokenStr + ':' + $rootStr + $childIterationID
            }
            return $tokenStr
        }
    }
    else {
        return $null
    }
}

function setPermissions{
    param(
        [String]$org,
        [String]$subject,
        [String]$tokenStr,
        [Int]$allowBit,
        [Int]$denyBit
    )
    # boards iterations namespace id
    $namespaceId = 'bf7bfa03-b2b7-47db-8113-fa2e002cc5b1'
    
    $aclList = az devops security permission list --org $org --subject $subject --id $namespaceId -o json | ConvertFrom-Json
    foreach($acl in $aclList){
        if ($($acl.token) -contains $tokenStr)
        {
            # Show permissions
            $displayPermissions = az devops security permission show --org $org --id $namespaceId --subject $subject --token $tokenStr -o json | ConvertFrom-Json
            Write-Host "`nCurrent iterations related permissions for admin group :"
            displayPermissions -permissionsResponse $displayPermissions

            # Update permissions
            if($allowBit)
            {
                $updatePermissions = az devops security permission update --org $org --id $namespaceId --subject $subject --token $tokenStr --allow-bit $allowBit -o json | ConvertFrom-Json    
            }

            if($denyBit)
            {
                $updatePermissions = az devops security permission update --org $org --id $namespaceId --subject $subject --token $tokenStr --deny-bit $denyBit -o json | ConvertFrom-Json    
            }
            
            $displayPermissions = az devops security permission show --org $org --id $namespaceId --subject $subject --token $tokenStr -o json | ConvertFrom-Json
            Write-Host "Updated iterations related permissions for admin group :"
            displayPermissions -permissionsResponse $displayPermissions
        }
    }
}