diff --git a/src/ZendeskApi_v2/Models/Requests/IndividualAttachmentResponse.cs b/src/ZendeskApi_v2/Models/Requests/IndividualAttachmentResponse.cs new file mode 100644 index 00000000..1e9a50b1 --- /dev/null +++ b/src/ZendeskApi_v2/Models/Requests/IndividualAttachmentResponse.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using ZendeskApi_v2.Models.Shared; + +namespace ZendeskApi_v2.Models.Requests +{ + public class IndividualAttachmentResponse + { + [JsonProperty("attachment")] + public Attachment Attachment { get; set; } + } +} diff --git a/src/ZendeskApi_v2/Requests/Attachments.cs b/src/ZendeskApi_v2/Requests/Attachments.cs index 19e2cf66..a869875b 100644 --- a/src/ZendeskApi_v2/Requests/Attachments.cs +++ b/src/ZendeskApi_v2/Requests/Attachments.cs @@ -11,6 +11,7 @@ #endif using ZendeskApi_v2.Extensions; using ZendeskApi_v2.Models.HelpCenter.Attachments; +using ZendeskApi_v2.Models.Requests; using ZendeskApi_v2.Models.Shared; namespace ZendeskApi_v2.Requests @@ -22,6 +23,7 @@ public interface IAttachments : ICore Upload UploadAttachment(ZenFile file, int? timeout = null); Upload UploadAttachments(IEnumerable files, int? timeout = null); bool DeleteUpload(Upload upload); + IndividualAttachmentResponse RedactCommentAttachment(long attachmentId, long ticketId, long commentId); #endif #if ASYNC @@ -37,7 +39,7 @@ public interface IAttachments : ICore Task UploadAttachmentsAsync(IEnumerable files, int? timeout = null); Task DeleteUploadAsync(Upload upload); Task DownloadAttachmentAsync(Attachment attachment); - + Task RedactCommentAttachmentAsync(long attachmentId, long ticketId, long commentId); #endif } @@ -104,6 +106,12 @@ public bool DeleteUpload(Upload upload) { return (upload?.Token == null ? false : GenericDelete($"/uploads/{upload.Token}.json")); } + + public IndividualAttachmentResponse RedactCommentAttachment(long attachmentId, long ticketId, long commentId) + { + var resource = $"/tickets/{ticketId}/comments/{commentId}/attachments/{attachmentId}/redact"; + return RunRequest(resource, RequestMethod.Put); + } #endif #if ASYNC @@ -175,6 +183,12 @@ public async Task DownloadAttachmentAsync(Attachment attachment) return file; } + public async Task RedactCommentAttachmentAsync(long attachmentId, long ticketId, long commentId) + { + var resource = $"/tickets/{ticketId}/comments/{commentId}/attachments/{attachmentId}/redact"; + return await RunRequestAsync(resource, RequestMethod.Put); + } + #endif diff --git a/test/ZendeskApi_v2.Test/AttachmentTests.cs b/test/ZendeskApi_v2.Test/AttachmentTests.cs index 251ac2eb..f9b91974 100644 --- a/test/ZendeskApi_v2.Test/AttachmentTests.cs +++ b/test/ZendeskApi_v2.Test/AttachmentTests.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using System.Net; namespace Tests { @@ -65,5 +66,44 @@ public async Task CanDowloadAttachment() Assert.That(api.Tickets.Delete(t1.Ticket.Id.Value), Is.True); Assert.That(api.Attachments.DeleteUpload(res)); } + + [Test] + public async Task CanRedactAttachment() + { + //This could probably be brought into a helper for above two tests perhaps + var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "testupload.txt"); + + var res = await api.Attachments.UploadAttachmentAsync(new ZenFile() + { + ContentType = "text/plain", + FileName = "testupload.txt", + FileData = File.ReadAllBytes(path) + }); + + var ticket = new Ticket() + { + Subject = "testing attachments", + Priority = TicketPriorities.Normal, + Comment = new Comment() + { + Body = "comments are required for attachments", + Public = true, + Uploads = new List() { res.Token } + }, + }; + + var t1 = await api.Tickets.CreateTicketAsync(ticket); + + var comments = api.Tickets.GetTicketComments(t1.Ticket.Id.Value); + + var attach = comments.Comments[0].Attachments[0]; + + var delRes = api.Attachments.RedactCommentAttachment(attach.Id, t1.Ticket.Id.Value, comments.Comments[0].Id.Value); + //Returned correct attachment + Assert.That(delRes.Attachment.Id, Is.EqualTo(attach.Id)); + + //Check the file has been replaced by redacted.txt + Assert.That(api.Tickets.GetTicketComments(t1.Ticket.Id.Value).Comments[0].Attachments[0].FileName, Is.EqualTo("redacted.txt")); + } } }