public/api-v1-objects/New-ConfluenceOperation.ps1

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
function New-ConfluenceOperation {
    [CmdletBinding()]
    param (
        # The operation
        [Parameter(Mandatory,Position=0,ValueFromPipelineByPropertyName)]
        [ValidateSet("administer", "copy", "create", "delete", "export", "move", "purge",
                     "purge_version", "read", "restore", "update", "use")]
        [string]
        $Operation,

        # The target type
        [Parameter(Mandatory,Position=1,ValueFromPipelineByPropertyName)]
        [ValidateSet("page", "blogpost", "comment", "attachment", "space")]
        [string]
        $TargetType,

        # The context in which the operation will be used (enables validation)
        [Parameter(Position=2,ValueFromPipelineByPropertyName)]
        [ValidateSet("SpacePermission")]
        [string]
        $Context="SpacePermission"
    )
    begin {
        $results = @()
    }
    process {
        switch ($Context) {
            "SpacePermission" { 
                if (@("create","read","delete","export","administer") -notcontains $Operation) {throw "Invalid Operation: Context $context does not have operation $Operation"}
                if ((@("create","delete") -contains $Operation) -and (@("page", "blogpost", "comment", "attachment") -notcontains $TargetType)) {throw "Invalid Operation: Context $context does not have TargetType $TargetType for operation $Operation"}
                if ((@("read","export","administer") -contains $Operation) -and ($TargetType -ne "space")) {throw "Invalid Operation: Context $context does not have TargetType $TargetType for operation $Operation"}
            }
            Default {}
        }

        $results += [pscustomobject]@{
            operation = $Operation
            targetType = $TargetType
        }
    }
    end {
        $results
    }
}