Skip to content
Merged
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
38 changes: 38 additions & 0 deletions Web/Resgrid.Web.Services/Controllers/v4/CallFilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,44 @@ public async Task<ActionResult> GetFile(string query)
return File(attachment.Data, contentType);
}

/// <summary>
/// Get a users avatar from the Resgrid system based on their ID
/// </summary>
/// <param name="query">ID of the file</param>
/// <returns></returns>
[HttpHead("GetFile")]
[AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult> GetFileHead(string query)
{
if (String.IsNullOrWhiteSpace(query))
return NotFound();

var decodedQuery = Encoding.UTF8.GetString(Convert.FromBase64String(query));

var decryptedQuery = SymmetricEncryption.Decrypt(decodedQuery, Config.SystemBehaviorConfig.ExternalLinkUrlParamPassphrase);

var items = decryptedQuery.Split(char.Parse("|"));

if (String.IsNullOrWhiteSpace(items[0]) || items[0] == "0" || String.IsNullOrWhiteSpace(items[1]))
return NotFound();

int departmentId = int.Parse(items[0].Trim());
string id = items[1].Trim();

var attachment = await _callsService.GetCallAttachmentAsync(int.Parse(id));

if (attachment == null)
return NotFound();

var call = await _callsService.GetCallByIdAsync(attachment.CallId);
if (call.DepartmentId != departmentId)
return Unauthorized();

return Ok();
}

/// <summary>
/// Attaches a file to a call
/// </summary>
Expand Down
86 changes: 86 additions & 0 deletions Web/Resgrid.Web.Services/Controllers/v4/ContactsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,53 @@ public async Task<ActionResult<ContactResult>> GetContactById(string contactId)
return result;
}

/// <summary>
/// Gets all the Notes for a Contact by the contact id
/// </summary>
/// <returns></returns>
[HttpGet("GetContactNotesByContactId")]
[ProducesResponseType(StatusCodes.Status200OK)]
[Authorize(Policy = ResgridResources.Contacts_View)]
public async Task<ActionResult<ContactNotesResult>> GetContactNotesByContactId(string contactId)
{
var result = new ContactNotesResult();

var contact = await _contactsService.GetContactByIdAsync(contactId);
var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId);

if (contact != null && contact.DepartmentId == DepartmentId)
{
var contactNotes = await _contactsService.GetContactNotesByContactIdAsync(contactId, Int32.MaxValue, false);

foreach (var contactNote in contactNotes)
{
var addedOnPerson = await _userProfileService.GetProfileByUserIdAsync(contactNote.AddedByUserId);
UserProfile editedPerson = null;

if (!String.IsNullOrWhiteSpace(contactNote.EditedByUserId))
editedPerson = await _userProfileService.GetProfileByUserIdAsync(contactNote.EditedByUserId);

ContactNoteType noteType = null;
if (!String.IsNullOrWhiteSpace(contactNote.ContactNoteTypeId))
noteType = await _contactsService.GetContactNoteTypeByIdAsync(contactNote.ContactNoteTypeId);

result.Data.Add(ConvertContactNoteData(contactNote, noteType, department, addedOnPerson, editedPerson));
}

result.PageSize = contactNotes.Count;
result.Status = ResponseHelper.Success;
}
else
{
result.PageSize = 0;
result.Status = ResponseHelper.NotFound;
}

ResponseHelper.PopulateV4ResponseData(result);

return result;
}

public static ContactCategoryResultData ConvertCategoryData(ContactCategory category, Department department, UserProfile addedProfile, UserProfile editedProfile)
{
var cat = new ContactCategoryResultData();
Expand Down Expand Up @@ -246,5 +293,44 @@ public static ContactResultData ConvertContactData(Contact contact, Department d

return con;
}

public static ContactNoteResultData ConvertContactNoteData(ContactNote contactNote, ContactNoteType contactNoteType, Department department, UserProfile addedProfile, UserProfile editedProfile)
{
var conNote = new ContactNoteResultData();
conNote.ContactId = contactNote.ContactId;
conNote.ContactNoteId = contactNote.ContactNoteId;
conNote.ContactNoteTypeId = contactNote.ContactNoteTypeId;
conNote.Note = contactNote.Note;
conNote.ShouldAlert = contactNote.ShouldAlert;
conNote.Visibility = contactNote.Visibility;

if (contactNoteType != null)
{
conNote.ContactNoteTypeId = contactNoteType.ContactNoteTypeId;
conNote.NoteType = contactNoteType.Name;
}

if (contactNote.ExpiresOn.HasValue)
{
conNote.ExpiresOnUtc = contactNote.ExpiresOn;
conNote.ExpiresOn = contactNote.ExpiresOn.Value.FormatForDepartment(department);
}

conNote.IsDeleted = contactNote.IsDeleted;
conNote.AddedOnUtc = contactNote.AddedOn;
conNote.AddedOn = contactNote.AddedOn.FormatForDepartment(department);
conNote.AddedByUserId = contactNote.AddedByUserId;
conNote.AddedByName = addedProfile.FullName.AsFirstNameLastName;

if (contactNote.EditedOn.HasValue)
{
conNote.EditedOnUtc = contactNote.EditedOn;
conNote.EditedOn = contactNote.EditedOn.Value.FormatForDepartment(department);
conNote.EditedByUserId = contactNote.EditedByUserId;
conNote.EditedByName = editedProfile.FullName.AsFirstNameLastName;
}

return conNote;
}
}
}
68 changes: 68 additions & 0 deletions Web/Resgrid.Web.Services/Models/v4/Contacts/ContactNotesResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using Resgrid.Web.Services.Models.v4.CallTypes;
using System.Collections.Generic;
using Humanizer;

namespace Resgrid.Web.Services.Models.v4.Contacts
{
/// <summary>
/// Gets the notes for a contact
/// </summary>
public class ContactNotesResult : StandardApiResponseV4Base
{
/// <summary>
/// Response Data
/// </summary>
public List<ContactNoteResultData> Data { get; set; }

/// <summary>
/// Default constructor
/// </summary>
public ContactNotesResult()
{
Data = new List<ContactNoteResultData>();
}
}

/// <summary>
/// A contact note
/// </summary>
public class ContactNoteResultData
{
public string ContactNoteId { get; set; }

public string ContactId { get; set; }

public string ContactNoteTypeId { get; set; }

public string Note { get; set; }

public string NoteType { get; set; }

public bool ShouldAlert { get; set; }

public int Visibility { get; set; } // 0 Internal, 1 Visible to Client

public DateTime? ExpiresOnUtc { get; set; }

public string ExpiresOn { get; set; }

public bool IsDeleted { get; set; }

public DateTime AddedOnUtc { get; set; }

public string AddedOn { get; set; }

public string AddedByUserId { get; set; }

public string AddedByName { get; set; }

public DateTime? EditedOnUtc { get; set; }

public string EditedOn { get; set; }

public string EditedByUserId { get; set; }

public string EditedByName { get; set; }
}
}
33 changes: 33 additions & 0 deletions Web/Resgrid.Web.Services/Resgrid.Web.Services.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading