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

ticket comment redact #305

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions fixture/PUT/redact_ticket_comment_string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"comment": {
"author_id": 1,
"id": 35436,
"plain_body": "My social security number is ▇▇▇▇!",
"type": "Comment"
}
}
19 changes: 19 additions & 0 deletions zendesk/ticket_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,22 @@ func (z *Client) RedactTicketComment(
_, err := z.put(ctx, path, body)
return err
}

// RedactTicketCommentStringRequest contains the body of the RedactTicketCommentString PUT request
type RedactTicketCommentStringRequest struct {
Text string `json:"text"`
}

// RedactTicketCommentString permanently removes words, or strings from a ticket comment
//
// ref: https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/#redact-string-in-comment
func (z *Client) RedactTicketCommentString(
ctx context.Context,
ticketID int64,
ticketCommentID int64,
body RedactTicketCommentStringRequest,
) error {
path := fmt.Sprintf("/api/v2/tickets/%d/comments/%d/redact", ticketID, ticketCommentID)
_, err := z.put(ctx, path, body)
return err
}
14 changes: 14 additions & 0 deletions zendesk/ticket_comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,17 @@ func TestRedactTicketComment(t *testing.T) {
t.Fatalf("Failed to redact ticket comment: %s", err)
}
}

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

err := client.RedactTicketCommentString(ctx, 456, 123, RedactTicketCommentStringRequest{
Text: "My social security number is 847564!",
})

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