Skip to content

Commit

Permalink
Added support for SuppressNoteAddedNotifications via AddNote entities…
Browse files Browse the repository at this point in the history
… that support notes
  • Loading branch information
klaasvandeweerdt committed Jan 28, 2023
1 parent 6fe1b9a commit 1694249
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 3 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions Source/Sdk4me.Tests/RequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Note> notes = client.Requests.GetNotes(request, "*");
Assert.IsNotNull(notes);
Assert.IsInstanceOfType(notes, typeof(List<Note>));
Expand Down
2 changes: 0 additions & 2 deletions Source/Sdk4me.Tests/ServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Sdk4me.Tests
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Sdk4me/Entities/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
91 changes: 91 additions & 0 deletions Source/Sdk4me/Entities/NoteCreate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Sdk4me
{
/// <summary>
/// A 4me note creation object.
/// </summary>
public class NoteCreate : BaseItem
{
private List<AttachmentReference> attachments;
private bool _internal;
private bool suppressNoteAddedNotifications;
private string text = string.Empty;

#region Attachment

/// <summary>
/// Write-only. Add a reference to an uploaded note attachment. Use <see cref="Attachment"/> to get the existing attachments.
/// </summary>
/// <param name="key">The attachment key.</param>
/// <param name="fileSize">The attachment file size.</param>
/// <param name="inline">True if this an in-line attachment; otherwise false.</param>
public void ReferenceAttachment(string key, long fileSize, bool inline = false)
{
if (attachments == null)
attachments = new List<AttachmentReference>();

attachments.Add(new AttachmentReference()
{
Key = key,
FileSize = fileSize,
Inline = inline
});

base.PropertySerializationCollection.Add("attachments");
}

[JsonProperty("attachments"), Sdk4meIgnoreInFieldSelection()]
internal List<AttachmentReference> Attachments
{
get => attachments;
}

#endregion

#region Internal

/// <summary>
/// <para>True when the note is internal; otherwise false.</para>
/// <br>Public notes belong to the account in which the author’s person record is registered.</br>
/// <br>Internal notes belong to the account in which specialists are allowed to see the internal note.</br>
/// </summary>
[JsonProperty("internal")]
internal bool Internal
{
get => _internal;
set => _internal = SetValue("internal", _internal, value);
}

#endregion

#region Suppress note added notifications

/// <summary>
/// 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.
/// </summary>
[JsonProperty("suppress_note_added_notifications")]
public bool SuppressNoteAddedNotifications
{
get => suppressNoteAddedNotifications;
set => suppressNoteAddedNotifications = SetValue("suppress_note_added_notifications", suppressNoteAddedNotifications, value);
}

#endregion

#region Text

/// <summary>
/// Required text (max 64KB), default: <see cref="string.Empty"/>.
/// </summary>
[JsonProperty("text")]
public string Text
{
get => text;
set => text = SetValue("text", text, value);
}

#endregion
}
}
11 changes: 11 additions & 0 deletions Source/Sdk4me/Handlers/ProblemHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ public List<Note> GetNotes(Problem problem, params string[] fieldNames)
return GetChildHandler<Note>(problem, "notes", SortOrder.None).Get(fieldNames);
}

/// <summary>
/// Add a note to a problem.
/// </summary>
/// <param name="problem">The problem.</param>
/// <param name="item">The note to add.</param>
public void AddNote(Problem problem, NoteCreate item)
{
BaseItem retval = GetChildHandler<NoteCreate>(problem, "notes", SortOrder.None).Insert(item);
item.ID = retval.ID;
}

#endregion

#region Requests
Expand Down
11 changes: 11 additions & 0 deletions Source/Sdk4me/Handlers/ProjectHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ public List<Note> GetNotes(Project project, params string[] fieldNames)
return GetChildHandler<Note>(project, "notes", SortOrder.None).Get(fieldNames);
}

/// <summary>
/// Add a note to a project.
/// </summary>
/// <param name="project">The project.</param>
/// <param name="item">The note to add.</param>
public void AddNote(Project project, NoteCreate item)
{
BaseItem retval = GetChildHandler<NoteCreate>(project, "notes", SortOrder.None).Insert(item);
item.ID = retval.ID;
}

#endregion

#region Phases
Expand Down
11 changes: 11 additions & 0 deletions Source/Sdk4me/Handlers/ProjectTaskHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ public List<Note> GetNotes(ProjectTask projectTask, params string[] fieldNames)
return GetChildHandler<Note>(projectTask, "notes", SortOrder.None).Get(fieldNames);
}

/// <summary>
/// Add a note to a project task.
/// </summary>
/// <param name="projectTask">The project task.</param>
/// <param name="item">The note to add.</param>
public void AddNote(ProjectTask projectTask, NoteCreate item)
{
BaseItem retval = GetChildHandler<NoteCreate>(projectTask, "notes", SortOrder.None).Insert(item);
item.ID = retval.ID;
}

#endregion

#region Predecessors
Expand Down
11 changes: 11 additions & 0 deletions Source/Sdk4me/Handlers/ReleaseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public List<Note> GetNotes(Release release, params string[] fieldNames)
return GetChildHandler<Note>(release, "notes", SortOrder.None).Get(fieldNames);
}

/// <summary>
/// Add a note to a release.
/// </summary>
/// <param name="release">The release.</param>
/// <param name="item">The note to add.</param>
public void AddNote(Release release, NoteCreate item)
{
BaseItem retval = GetChildHandler<NoteCreate>(release, "notes", SortOrder.None).Insert(item);
item.ID = retval.ID;
}

#endregion

#region Workflows
Expand Down
15 changes: 15 additions & 0 deletions Source/Sdk4me/Handlers/RequestHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Sdk4me.Extensions;
using System;
using System.Collections.Generic;
using System.Net;

namespace Sdk4me
{
Expand Down Expand Up @@ -150,6 +152,19 @@ public List<Note> GetNotes(PredefinedRequestNoteFilter filter, Request request,
return GetChildHandler<Note>(request, $"notes/{filter.To4meString()}", SortOrder.None).Get(fieldNames);
}

/// <summary>
/// Add a note to a request.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="item">The note to add.</param>
/// <param name="internal">True if this in an internal note; otherwise false.</param>
public void AddNote(Request request, NoteCreate item, bool @internal = false)
{
item.Internal = @internal;
BaseItem retval = GetChildHandler<NoteCreate>(request, "notes", SortOrder.None).Insert(item);
item.ID = retval.ID;
}

#endregion

#region Satisfaction
Expand Down
11 changes: 11 additions & 0 deletions Source/Sdk4me/Handlers/RiskHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ public List<Note> GetNotes(Risk risk, params string[] fieldNames)
return GetChildHandler<Note>(risk, "notes", SortOrder.None).Get(fieldNames);
}

/// <summary>
/// Add a note to a risk.
/// </summary>
/// <param name="risk">The risk.</param>
/// <param name="item">The note to add.</param>
public void AddNote(Risk risk, NoteCreate item)
{
BaseItem retval = GetChildHandler<NoteCreate>(risk, "notes", SortOrder.None).Insert(item);
item.ID = retval.ID;
}

#endregion

#region Organizations
Expand Down
11 changes: 11 additions & 0 deletions Source/Sdk4me/Handlers/TaskHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ public List<Note> GetNotes(Task task, params string[] fieldNames)
return GetChildHandler<Note>(task, "notes", SortOrder.None).Get(fieldNames);
}

/// <summary>
/// Add a note to a task.
/// </summary>
/// <param name="task">The task.</param>
/// <param name="item">The note to add.</param>
public void AddNote(Task task, NoteCreate item)
{
BaseItem retval = GetChildHandler<NoteCreate>(task, "notes", SortOrder.None).Insert(item);
item.ID = retval.ID;
}

#endregion

#region Predecessors
Expand Down
11 changes: 11 additions & 0 deletions Source/Sdk4me/Handlers/WorkflowHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ public List<Note> GetNotes(Workflow workflow, params string[] fieldNames)
return GetChildHandler<Note>(workflow, "notes", SortOrder.None).Get(fieldNames);
}

/// <summary>
/// Add a note to a workflow.
/// </summary>
/// <param name="workflow">The workflow.</param>
/// <param name="item">The note to add.</param>
public void AddNote(Workflow workflow, NoteCreate item)
{
BaseItem retval = GetChildHandler<NoteCreate>(workflow, "notes", SortOrder.None).Insert(item);
item.ID = retval.ID;
}

#endregion

#region Tasks
Expand Down

0 comments on commit 1694249

Please sign in to comment.