Skip to content

Commit ee808d3

Browse files
authored
Merge pull request #227 from Resgrid/develop
Develop
2 parents 48552ac + 311d40d commit ee808d3

File tree

5 files changed

+1001
-776
lines changed

5 files changed

+1001
-776
lines changed

Web/Resgrid.Web.Services/Controllers/v4/CallFilesController.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,44 @@ public async Task<ActionResult> GetFile(string query)
130130
return File(attachment.Data, contentType);
131131
}
132132

133+
/// <summary>
134+
/// Get a users avatar from the Resgrid system based on their ID
135+
/// </summary>
136+
/// <param name="query">ID of the file</param>
137+
/// <returns></returns>
138+
[HttpHead("GetFile")]
139+
[AllowAnonymous]
140+
[ProducesResponseType(StatusCodes.Status200OK)]
141+
[ProducesResponseType(StatusCodes.Status404NotFound)]
142+
public async Task<ActionResult> GetFileHead(string query)
143+
{
144+
if (String.IsNullOrWhiteSpace(query))
145+
return NotFound();
146+
147+
var decodedQuery = Encoding.UTF8.GetString(Convert.FromBase64String(query));
148+
149+
var decryptedQuery = SymmetricEncryption.Decrypt(decodedQuery, Config.SystemBehaviorConfig.ExternalLinkUrlParamPassphrase);
150+
151+
var items = decryptedQuery.Split(char.Parse("|"));
152+
153+
if (String.IsNullOrWhiteSpace(items[0]) || items[0] == "0" || String.IsNullOrWhiteSpace(items[1]))
154+
return NotFound();
155+
156+
int departmentId = int.Parse(items[0].Trim());
157+
string id = items[1].Trim();
158+
159+
var attachment = await _callsService.GetCallAttachmentAsync(int.Parse(id));
160+
161+
if (attachment == null)
162+
return NotFound();
163+
164+
var call = await _callsService.GetCallByIdAsync(attachment.CallId);
165+
if (call.DepartmentId != departmentId)
166+
return Unauthorized();
167+
168+
return Ok();
169+
}
170+
133171
/// <summary>
134172
/// Attaches a file to a call
135173
/// </summary>

Web/Resgrid.Web.Services/Controllers/v4/ContactsController.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,53 @@ public async Task<ActionResult<ContactResult>> GetContactById(string contactId)
166166
return result;
167167
}
168168

169+
/// <summary>
170+
/// Gets all the Notes for a Contact by the contact id
171+
/// </summary>
172+
/// <returns></returns>
173+
[HttpGet("GetContactNotesByContactId")]
174+
[ProducesResponseType(StatusCodes.Status200OK)]
175+
[Authorize(Policy = ResgridResources.Contacts_View)]
176+
public async Task<ActionResult<ContactNotesResult>> GetContactNotesByContactId(string contactId)
177+
{
178+
var result = new ContactNotesResult();
179+
180+
var contact = await _contactsService.GetContactByIdAsync(contactId);
181+
var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId);
182+
183+
if (contact != null && contact.DepartmentId == DepartmentId)
184+
{
185+
var contactNotes = await _contactsService.GetContactNotesByContactIdAsync(contactId, Int32.MaxValue, false);
186+
187+
foreach (var contactNote in contactNotes)
188+
{
189+
var addedOnPerson = await _userProfileService.GetProfileByUserIdAsync(contactNote.AddedByUserId);
190+
UserProfile editedPerson = null;
191+
192+
if (!String.IsNullOrWhiteSpace(contactNote.EditedByUserId))
193+
editedPerson = await _userProfileService.GetProfileByUserIdAsync(contactNote.EditedByUserId);
194+
195+
ContactNoteType noteType = null;
196+
if (!String.IsNullOrWhiteSpace(contactNote.ContactNoteTypeId))
197+
noteType = await _contactsService.GetContactNoteTypeByIdAsync(contactNote.ContactNoteTypeId);
198+
199+
result.Data.Add(ConvertContactNoteData(contactNote, noteType, department, addedOnPerson, editedPerson));
200+
}
201+
202+
result.PageSize = contactNotes.Count;
203+
result.Status = ResponseHelper.Success;
204+
}
205+
else
206+
{
207+
result.PageSize = 0;
208+
result.Status = ResponseHelper.NotFound;
209+
}
210+
211+
ResponseHelper.PopulateV4ResponseData(result);
212+
213+
return result;
214+
}
215+
169216
public static ContactCategoryResultData ConvertCategoryData(ContactCategory category, Department department, UserProfile addedProfile, UserProfile editedProfile)
170217
{
171218
var cat = new ContactCategoryResultData();
@@ -246,5 +293,44 @@ public static ContactResultData ConvertContactData(Contact contact, Department d
246293

247294
return con;
248295
}
296+
297+
public static ContactNoteResultData ConvertContactNoteData(ContactNote contactNote, ContactNoteType contactNoteType, Department department, UserProfile addedProfile, UserProfile editedProfile)
298+
{
299+
var conNote = new ContactNoteResultData();
300+
conNote.ContactId = contactNote.ContactId;
301+
conNote.ContactNoteId = contactNote.ContactNoteId;
302+
conNote.ContactNoteTypeId = contactNote.ContactNoteTypeId;
303+
conNote.Note = contactNote.Note;
304+
conNote.ShouldAlert = contactNote.ShouldAlert;
305+
conNote.Visibility = contactNote.Visibility;
306+
307+
if (contactNoteType != null)
308+
{
309+
conNote.ContactNoteTypeId = contactNoteType.ContactNoteTypeId;
310+
conNote.NoteType = contactNoteType.Name;
311+
}
312+
313+
if (contactNote.ExpiresOn.HasValue)
314+
{
315+
conNote.ExpiresOnUtc = contactNote.ExpiresOn;
316+
conNote.ExpiresOn = contactNote.ExpiresOn.Value.FormatForDepartment(department);
317+
}
318+
319+
conNote.IsDeleted = contactNote.IsDeleted;
320+
conNote.AddedOnUtc = contactNote.AddedOn;
321+
conNote.AddedOn = contactNote.AddedOn.FormatForDepartment(department);
322+
conNote.AddedByUserId = contactNote.AddedByUserId;
323+
conNote.AddedByName = addedProfile.FullName.AsFirstNameLastName;
324+
325+
if (contactNote.EditedOn.HasValue)
326+
{
327+
conNote.EditedOnUtc = contactNote.EditedOn;
328+
conNote.EditedOn = contactNote.EditedOn.Value.FormatForDepartment(department);
329+
conNote.EditedByUserId = contactNote.EditedByUserId;
330+
conNote.EditedByName = editedProfile.FullName.AsFirstNameLastName;
331+
}
332+
333+
return conNote;
334+
}
249335
}
250336
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using Resgrid.Web.Services.Models.v4.CallTypes;
3+
using System.Collections.Generic;
4+
using Humanizer;
5+
6+
namespace Resgrid.Web.Services.Models.v4.Contacts
7+
{
8+
/// <summary>
9+
/// Gets the notes for a contact
10+
/// </summary>
11+
public class ContactNotesResult : StandardApiResponseV4Base
12+
{
13+
/// <summary>
14+
/// Response Data
15+
/// </summary>
16+
public List<ContactNoteResultData> Data { get; set; }
17+
18+
/// <summary>
19+
/// Default constructor
20+
/// </summary>
21+
public ContactNotesResult()
22+
{
23+
Data = new List<ContactNoteResultData>();
24+
}
25+
}
26+
27+
/// <summary>
28+
/// A contact note
29+
/// </summary>
30+
public class ContactNoteResultData
31+
{
32+
public string ContactNoteId { get; set; }
33+
34+
public string ContactId { get; set; }
35+
36+
public string ContactNoteTypeId { get; set; }
37+
38+
public string Note { get; set; }
39+
40+
public string NoteType { get; set; }
41+
42+
public bool ShouldAlert { get; set; }
43+
44+
public int Visibility { get; set; } // 0 Internal, 1 Visible to Client
45+
46+
public DateTime? ExpiresOnUtc { get; set; }
47+
48+
public string ExpiresOn { get; set; }
49+
50+
public bool IsDeleted { get; set; }
51+
52+
public DateTime AddedOnUtc { get; set; }
53+
54+
public string AddedOn { get; set; }
55+
56+
public string AddedByUserId { get; set; }
57+
58+
public string AddedByName { get; set; }
59+
60+
public DateTime? EditedOnUtc { get; set; }
61+
62+
public string EditedOn { get; set; }
63+
64+
public string EditedByUserId { get; set; }
65+
66+
public string EditedByName { get; set; }
67+
}
68+
}

Web/Resgrid.Web.Services/Resgrid.Web.Services.xml

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)