Skip to content

Commit

Permalink
Merge pull request #13 from Readify/tags
Browse files Browse the repository at this point in the history
Add role assertions, ShouldProcess support, and autocomplete to tags
  • Loading branch information
RobFaie authored Feb 19, 2020
2 parents 284c179 + c5f106b commit 4ebc3b4
Show file tree
Hide file tree
Showing 5 changed files with 485 additions and 4 deletions.
11 changes: 8 additions & 3 deletions functions/Add-Tag.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

function Add-Tag {
[OutputType([PSCustomObject])]
[CmdletBinding(DefaultParameterSetName = 'Default')]
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High', DefaultParameterSetName = 'Default')]
Param (

# Unique Id of ticket to add tags to
Expand Down Expand Up @@ -37,6 +37,8 @@ function Add-Tag {
$Context = $null
)

Assert-IsAgent -Context $Context

switch ($PSCMDlet.ParameterSetName) {
'Ticket' {
$path = "/api/v2/tickets/$TicketId/tags.json"
Expand All @@ -55,7 +57,10 @@ function Add-Tag {
tags = $Tag
}

$result = Invoke-Method -Context $Context -Method 'Put' -Path $path -Body $body -Verbose:$VerbosePreference
$result

if ($PSCmdlet.ShouldProcess("$TicketId$OrganizationId$UserId", "Set Tags: $Tag")) {
$result = Invoke-Method -Context $Context -Method 'Put' -Path $path -Body $body -Verbose:$VerbosePreference
$result
}

}
14 changes: 14 additions & 0 deletions functions/Get-Tag.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ function Get-Tag {
[Int64]
$UserId,

# Partial Name for auto complete results
[Parameter(Mandatory = $true,
ParameterSetName = 'AutoComplete')]
[ValidateNotNullOrEmpty()]
[String]
$PartialName,

# Zendesk Connection Context from `Get-ZendeskConnection`
[Parameter(Mandatory = $false)]
[PSTypeName('ZendeskContext')]
[PSCustomObject]
$Context = $null
)

Assert-IsAgent -Context $Context

switch ($PSCMDlet.ParameterSetName) {
'Ticket' {
$path = "/api/v2/tickets/$TicketId/tags.json"
Expand All @@ -46,7 +55,12 @@ function Get-Tag {
$path = "/api/v2/users/$UserId/tags.json"
}

'AutoComplete' {
$path = "/api/v2/autocomplete/tags.json?name=$PartialName"
}

default {
Assert-IsAdmin -Context $Context
$path = '/api/v2/tags.json'
}
}
Expand Down
4 changes: 3 additions & 1 deletion functions/Remove-Tag.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ function Remove-Tag {
$Context = $null
)

Assert-IsAgent -Context $Context

switch ($PSCMDlet.ParameterSetName) {
'Ticket' {
$path = "/api/v2/tickets/$TicketId/tags.json"
Expand All @@ -56,7 +58,7 @@ function Remove-Tag {
tags = $Tag
}

if ($PSCmdlet.ShouldProcess("$Tag", 'Remove Tag')) {
if ($PSCmdlet.ShouldProcess("$TicketId$OrganizationId$UserId", "Set Tags: $Tag")) {
$result = Invoke-Method -Context $Context -Method 'Delete' -Path $path -Body $body -Verbose:$VerbosePreference
$result
}
Expand Down
2 changes: 2 additions & 0 deletions functions/Set-Tag.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ function Set-Tag {
$Context = $null
)

Assert-IsAgent -Context $Context

switch ($PSCMDlet.ParameterSetName) {
'Ticket' {
$path = "/api/v2/tickets/$TicketId/tags.json"
Expand Down
Loading

0 comments on commit 4ebc3b4

Please sign in to comment.