Skip to content

Commit

Permalink
Merge pull request #260 from pierce-m/ticket-comment-redaction
Browse files Browse the repository at this point in the history
Add ticket comment redaction
  • Loading branch information
nukosuke authored Feb 16, 2023
2 parents c5a8eb7 + 5acdf46 commit 2be7899
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fixture/PUT/redact_ticket_comment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"comment": {
"attachments": [],
"author_id": 123,
"id": 123,
"plain_body": "My ID number is ▇▇▇▇!",
"public": true,
"type": "Comment"
}
}
20 changes: 20 additions & 0 deletions zendesk/ticket_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ type TicketComment struct {
Via *Via `json:"via,omitempty"`
}

// RedactTicketCommentRequest contains the body of the RedactTicketComment PUT request
type RedactTicketCommentRequest struct {
TicketID int64 `json:"ticket_id"` // Required
HTMLBody string `json:"html_body,omitempty"`
ExternalAttachmentUrls []string `json:"external_attachment_urls,omitempty"`
}

// NewPublicTicketComment generates and returns a new TicketComment
func NewPublicTicketComment(body string, authorID int64) TicketComment {
public := true
Expand Down Expand Up @@ -111,3 +118,16 @@ func (z *Client) MakeCommentPrivate(ctx context.Context, ticketID int64, ticketC
_, err := z.put(ctx, path, nil)
return err
}

// RedactTicketComment permanently removes words, strings, or attachments from a ticket comment
//
// ref: https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/#redact-ticket-comment-in-agent-workspace
func (z *Client) RedactTicketComment(
ctx context.Context,
ticketCommentID int64,
body RedactTicketCommentRequest,
) error {
path := fmt.Sprintf("/api/v2/comment_redactions/%d.json", ticketCommentID)
_, err := z.put(ctx, path, body)
return err
}
15 changes: 15 additions & 0 deletions zendesk/ticket_comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,18 @@ func TestMakeCommentPrivate(t *testing.T) {
})
}
}

func TestRedactTicketComment(t *testing.T) {
mockAPI := newMockAPI(http.MethodPut, "redact_ticket_comment.json")
client := newTestClient(mockAPI)
defer mockAPI.Close()

err := client.RedactTicketComment(ctx, 123, RedactTicketCommentRequest{
TicketID: 100,
HTMLBody: "<div class=\"zd-comment\" dir=\"auto\">My ID number is <redact>847564</redact>!</div>",
})

if err != nil {
t.Fatalf("Failed to redact ticket comment: %s", err)
}
}

0 comments on commit 2be7899

Please sign in to comment.