Skip to content

Commit

Permalink
Add support for ticket comment attachment redaction
Browse files Browse the repository at this point in the history
  • Loading branch information
pierce-m committed Mar 1, 2023
1 parent b3a7d08 commit 9719686
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fixture/PUT/redact_ticket_comment_attachment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"attachment": {
"content_type": "application/binary",
"content_url": "https://company.zendesk.com/attachments/myfile.dat",
"file_name": "myfile.dat",
"id": 498483,
"size": 2532,
"thumbnails": [],
"url": "https://company.zendesk.com/api/v2/attachments/498483.json"
}
}
8 changes: 8 additions & 0 deletions zendesk/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,11 @@ func (z *Client) GetAttachment(ctx context.Context, id int64) (Attachment, error

return result.Attachment, nil
}

// RedactCommentAttachment deletes an attachment with attachmentID on comment with commentID for ticket with ticketID
// https://developer.zendesk.com/api-reference/ticketing/tickets/ticket-attachments/#redact-comment-attachment
func (z *Client) RedactCommentAttachment(ctx context.Context, ticketID, commentID, attachmentID int64) error {
path := fmt.Sprintf("/api/v2/tickets/%d/comments/%d/attachments/%d/redact", ticketID, commentID, attachmentID)
_, err := z.put(ctx, path, nil)
return err
}
12 changes: 12 additions & 0 deletions zendesk/attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,15 @@ func TestGetAttachment(t *testing.T) {
t.Fatalf("Returned attachment does not have the expected ID %d. Attachment id is %d", expectedID, attachment.ID)
}
}

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

err := client.RedactCommentAttachment(ctx, 123, 456, 789)

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

0 comments on commit 9719686

Please sign in to comment.