From 1694249e756d2a972adbf9a8340810534241dd89 Mon Sep 17 00:00:00 2001 From: Klaas Vandeweerdt Date: Sat, 28 Jan 2023 01:14:53 +0100 Subject: [PATCH] Added support for SuppressNoteAddedNotifications via AddNote entities that support notes --- README.md | 14 +++ Source/Sdk4me.Tests/RequestTest.cs | 5 ++ Source/Sdk4me.Tests/ServiceTest.cs | 2 - Source/Sdk4me/Entities/Note.cs | 2 +- Source/Sdk4me/Entities/NoteCreate.cs | 91 ++++++++++++++++++++ Source/Sdk4me/Handlers/ProblemHandler.cs | 11 +++ Source/Sdk4me/Handlers/ProjectHandler.cs | 11 +++ Source/Sdk4me/Handlers/ProjectTaskHandler.cs | 11 +++ Source/Sdk4me/Handlers/ReleaseHandler.cs | 11 +++ Source/Sdk4me/Handlers/RequestHandler.cs | 15 ++++ Source/Sdk4me/Handlers/RiskHandler.cs | 11 +++ Source/Sdk4me/Handlers/TaskHandler.cs | 11 +++ Source/Sdk4me/Handlers/WorkflowHandler.cs | 11 +++ 13 files changed, 203 insertions(+), 3 deletions(-) create mode 100644 Source/Sdk4me/Entities/NoteCreate.cs diff --git a/README.md b/README.md index 75d0cb1..261e8be 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,20 @@ request = client.Requests.Update(request); ``` The client will add a note with an attachment to the request. +  +```csharp +Request task = client.Tasks.Get(123); +client.Tasks.UploadAttachment(".\\HelloWorld.txt", "text/plain", out string key, out long size); +NoteCreate newNote = new NoteCreate() +{ + Text = "Hello World", + SuppressNoteAddedNotifications = true +}; +newNote.ReferenceAttachment(key, size, false); +client.Tasks.AddNote(task, newNote); +``` +The client will add an note with an attachment to the request suppressing the note add notification. +   ```csharp Service service = client.Services.Get(123); diff --git a/Source/Sdk4me.Tests/RequestTest.cs b/Source/Sdk4me.Tests/RequestTest.cs index 1e5c9b3..b7ce4a1 100644 --- a/Source/Sdk4me.Tests/RequestTest.cs +++ b/Source/Sdk4me.Tests/RequestTest.cs @@ -19,6 +19,11 @@ public void Get() Request request = client.Requests.Get(70454); Trace.WriteLine($"Continue relation tests on request: #{request.ID}"); + client.Requests.AddNote(request, new NoteCreate() + { + Text = "A new note", + }, true); + List notes = client.Requests.GetNotes(request, "*"); Assert.IsNotNull(notes); Assert.IsInstanceOfType(notes, typeof(List)); diff --git a/Source/Sdk4me.Tests/ServiceTest.cs b/Source/Sdk4me.Tests/ServiceTest.cs index f4eff3a..3c10666 100644 --- a/Source/Sdk4me.Tests/ServiceTest.cs +++ b/Source/Sdk4me.Tests/ServiceTest.cs @@ -1,7 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; using System.Collections.Generic; -using System.Diagnostics; namespace Sdk4me.Tests { diff --git a/Source/Sdk4me/Entities/Note.cs b/Source/Sdk4me/Entities/Note.cs index 18dc7e8..cda93ee 100644 --- a/Source/Sdk4me/Entities/Note.cs +++ b/Source/Sdk4me/Entities/Note.cs @@ -14,7 +14,7 @@ public class Note : BaseItem private AccountReference internalAccount; private NoteMedium medium; private Person person; - private string text; + private string text = string.Empty; #region Updated at (override) diff --git a/Source/Sdk4me/Entities/NoteCreate.cs b/Source/Sdk4me/Entities/NoteCreate.cs new file mode 100644 index 0000000..086ac0e --- /dev/null +++ b/Source/Sdk4me/Entities/NoteCreate.cs @@ -0,0 +1,91 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Sdk4me +{ + /// + /// A 4me note creation object. + /// + public class NoteCreate : BaseItem + { + private List attachments; + private bool _internal; + private bool suppressNoteAddedNotifications; + private string text = string.Empty; + + #region Attachment + + /// + /// Write-only. Add a reference to an uploaded note attachment. Use to get the existing attachments. + /// + /// The attachment key. + /// The attachment file size. + /// True if this an in-line attachment; otherwise false. + public void ReferenceAttachment(string key, long fileSize, bool inline = false) + { + if (attachments == null) + attachments = new List(); + + attachments.Add(new AttachmentReference() + { + Key = key, + FileSize = fileSize, + Inline = inline + }); + + base.PropertySerializationCollection.Add("attachments"); + } + + [JsonProperty("attachments"), Sdk4meIgnoreInFieldSelection()] + internal List Attachments + { + get => attachments; + } + + #endregion + + #region Internal + + /// + /// True when the note is internal; otherwise false. + ///
Public notes belong to the account in which the author’s person record is registered.
+ ///
Internal notes belong to the account in which specialists are allowed to see the internal note.
+ ///
+ [JsonProperty("internal")] + internal bool Internal + { + get => _internal; + set => _internal = SetValue("internal", _internal, value); + } + + #endregion + + #region Suppress note added notifications + + /// + /// Set to the value true to suppress the ‘Note Added’ notifications from being created. Other notifications, such as ‘Watchlist Item Updated’ and ‘Person Mentioned’, will still be created if applicable. + /// + [JsonProperty("suppress_note_added_notifications")] + public bool SuppressNoteAddedNotifications + { + get => suppressNoteAddedNotifications; + set => suppressNoteAddedNotifications = SetValue("suppress_note_added_notifications", suppressNoteAddedNotifications, value); + } + + #endregion + + #region Text + + /// + /// Required text (max 64KB), default: . + /// + [JsonProperty("text")] + public string Text + { + get => text; + set => text = SetValue("text", text, value); + } + + #endregion + } +} diff --git a/Source/Sdk4me/Handlers/ProblemHandler.cs b/Source/Sdk4me/Handlers/ProblemHandler.cs index 055a0c3..868cc2f 100644 --- a/Source/Sdk4me/Handlers/ProblemHandler.cs +++ b/Source/Sdk4me/Handlers/ProblemHandler.cs @@ -108,6 +108,17 @@ public List GetNotes(Problem problem, params string[] fieldNames) return GetChildHandler(problem, "notes", SortOrder.None).Get(fieldNames); } + /// + /// Add a note to a problem. + /// + /// The problem. + /// The note to add. + public void AddNote(Problem problem, NoteCreate item) + { + BaseItem retval = GetChildHandler(problem, "notes", SortOrder.None).Insert(item); + item.ID = retval.ID; + } + #endregion #region Requests diff --git a/Source/Sdk4me/Handlers/ProjectHandler.cs b/Source/Sdk4me/Handlers/ProjectHandler.cs index 7a63475..8766eaa 100644 --- a/Source/Sdk4me/Handlers/ProjectHandler.cs +++ b/Source/Sdk4me/Handlers/ProjectHandler.cs @@ -96,6 +96,17 @@ public List GetNotes(Project project, params string[] fieldNames) return GetChildHandler(project, "notes", SortOrder.None).Get(fieldNames); } + /// + /// Add a note to a project. + /// + /// The project. + /// The note to add. + public void AddNote(Project project, NoteCreate item) + { + BaseItem retval = GetChildHandler(project, "notes", SortOrder.None).Insert(item); + item.ID = retval.ID; + } + #endregion #region Phases diff --git a/Source/Sdk4me/Handlers/ProjectTaskHandler.cs b/Source/Sdk4me/Handlers/ProjectTaskHandler.cs index 881359b..859bbbe 100644 --- a/Source/Sdk4me/Handlers/ProjectTaskHandler.cs +++ b/Source/Sdk4me/Handlers/ProjectTaskHandler.cs @@ -105,6 +105,17 @@ public List GetNotes(ProjectTask projectTask, params string[] fieldNames) return GetChildHandler(projectTask, "notes", SortOrder.None).Get(fieldNames); } + /// + /// Add a note to a project task. + /// + /// The project task. + /// The note to add. + public void AddNote(ProjectTask projectTask, NoteCreate item) + { + BaseItem retval = GetChildHandler(projectTask, "notes", SortOrder.None).Insert(item); + item.ID = retval.ID; + } + #endregion #region Predecessors diff --git a/Source/Sdk4me/Handlers/ReleaseHandler.cs b/Source/Sdk4me/Handlers/ReleaseHandler.cs index 9beede7..1fced96 100644 --- a/Source/Sdk4me/Handlers/ReleaseHandler.cs +++ b/Source/Sdk4me/Handlers/ReleaseHandler.cs @@ -49,6 +49,17 @@ public List GetNotes(Release release, params string[] fieldNames) return GetChildHandler(release, "notes", SortOrder.None).Get(fieldNames); } + /// + /// Add a note to a release. + /// + /// The release. + /// The note to add. + public void AddNote(Release release, NoteCreate item) + { + BaseItem retval = GetChildHandler(release, "notes", SortOrder.None).Insert(item); + item.ID = retval.ID; + } + #endregion #region Workflows diff --git a/Source/Sdk4me/Handlers/RequestHandler.cs b/Source/Sdk4me/Handlers/RequestHandler.cs index f7fc9f8..1bb862f 100644 --- a/Source/Sdk4me/Handlers/RequestHandler.cs +++ b/Source/Sdk4me/Handlers/RequestHandler.cs @@ -1,5 +1,7 @@ using Sdk4me.Extensions; +using System; using System.Collections.Generic; +using System.Net; namespace Sdk4me { @@ -150,6 +152,19 @@ public List GetNotes(PredefinedRequestNoteFilter filter, Request request, return GetChildHandler(request, $"notes/{filter.To4meString()}", SortOrder.None).Get(fieldNames); } + /// + /// Add a note to a request. + /// + /// The request. + /// The note to add. + /// True if this in an internal note; otherwise false. + public void AddNote(Request request, NoteCreate item, bool @internal = false) + { + item.Internal = @internal; + BaseItem retval = GetChildHandler(request, "notes", SortOrder.None).Insert(item); + item.ID = retval.ID; + } + #endregion #region Satisfaction diff --git a/Source/Sdk4me/Handlers/RiskHandler.cs b/Source/Sdk4me/Handlers/RiskHandler.cs index 2c43c1a..1d822a1 100644 --- a/Source/Sdk4me/Handlers/RiskHandler.cs +++ b/Source/Sdk4me/Handlers/RiskHandler.cs @@ -50,6 +50,17 @@ public List GetNotes(Risk risk, params string[] fieldNames) return GetChildHandler(risk, "notes", SortOrder.None).Get(fieldNames); } + /// + /// Add a note to a risk. + /// + /// The risk. + /// The note to add. + public void AddNote(Risk risk, NoteCreate item) + { + BaseItem retval = GetChildHandler(risk, "notes", SortOrder.None).Insert(item); + item.ID = retval.ID; + } + #endregion #region Organizations diff --git a/Source/Sdk4me/Handlers/TaskHandler.cs b/Source/Sdk4me/Handlers/TaskHandler.cs index 273494b..fe5fa80 100644 --- a/Source/Sdk4me/Handlers/TaskHandler.cs +++ b/Source/Sdk4me/Handlers/TaskHandler.cs @@ -166,6 +166,17 @@ public List GetNotes(Task task, params string[] fieldNames) return GetChildHandler(task, "notes", SortOrder.None).Get(fieldNames); } + /// + /// Add a note to a task. + /// + /// The task. + /// The note to add. + public void AddNote(Task task, NoteCreate item) + { + BaseItem retval = GetChildHandler(task, "notes", SortOrder.None).Insert(item); + item.ID = retval.ID; + } + #endregion #region Predecessors diff --git a/Source/Sdk4me/Handlers/WorkflowHandler.cs b/Source/Sdk4me/Handlers/WorkflowHandler.cs index 2db9f2c..af3bb52 100644 --- a/Source/Sdk4me/Handlers/WorkflowHandler.cs +++ b/Source/Sdk4me/Handlers/WorkflowHandler.cs @@ -225,6 +225,17 @@ public List GetNotes(Workflow workflow, params string[] fieldNames) return GetChildHandler(workflow, "notes", SortOrder.None).Get(fieldNames); } + /// + /// Add a note to a workflow. + /// + /// The workflow. + /// The note to add. + public void AddNote(Workflow workflow, NoteCreate item) + { + BaseItem retval = GetChildHandler(workflow, "notes", SortOrder.None).Insert(item); + item.ID = retval.ID; + } + #endregion #region Tasks