Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ticket comment attachment redaction #268

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}