Skip to content

Commit ff2c227

Browse files
committed
CU-3w8z67w Working on the Contacts system.
1 parent 3d232a7 commit ff2c227

File tree

22 files changed

+1191
-61
lines changed

22 files changed

+1191
-61
lines changed

Core/Resgrid.Config/TelemetryConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
public static class TelemetryConfig
44
{
55
public static string Exporter = "";
6+
7+
public static string PostHogUrl = "";
8+
public static string PostHogApiKey = "";
69
}
710
}

Core/Resgrid.Localization/Areas/User/Contacts/Contacts.en.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,4 +471,16 @@
471471
<data name="SaveNote" xml:space="preserve">
472472
<value>Add Note</value>
473473
</data>
474+
<data name="FilterBy" xml:space="preserve">
475+
<value>Filter By</value>
476+
</data>
477+
<data name="LoadingNotes" xml:space="preserve">
478+
<value>Loading Notes</value>
479+
</data>
480+
<data name="SearchNotes" xml:space="preserve">
481+
<value>Search Notes</value>
482+
</data>
483+
<data name="EditContact" xml:space="preserve">
484+
<value>Edit Contact</value>
485+
</data>
474486
</root>

Core/Resgrid.Model/Repositories/ICallsRepository.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,13 @@ public interface ICallsRepository: IRepository<Call>
7171
/// <param name="departmentId">The department identifier.</param>
7272
/// <returns>Task&lt;IEnumerable&lt;Call&gt;&gt;.</returns>
7373
Task<IEnumerable<Call>> GetAllNonDispatchedScheduledCallsByDepartmentIdAsync(int departmentId);
74+
75+
/// <summary>
76+
/// Gets all calls by department and contact asynchronous.
77+
/// </summary>
78+
/// <param name="contactId">The contact identifier.</param>
79+
/// <param name="departmentId">The department identifier.</param>
80+
/// <returns>Task&lt;IEnumerable&lt;Call&gt;&gt;.</returns>
81+
Task<IEnumerable<Call>> GetAllCallsByContactIdAsync(string contactId, int departmentId);
7482
}
7583
}

Core/Resgrid.Model/Services/IAuthorizationService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,5 +322,9 @@ public interface IAuthorizationService
322322
Task<bool> CanUserDeleteContactNoteTypeAsync(string userId, string contactNoteTypeId);
323323

324324
Task<bool> CanUserEditContactNoteTypeAsync(string userId, string contactNoteTypeId);
325+
326+
Task<bool> CanUserDeleteContactAsync(string userId, int departmentId);
327+
328+
Task<bool> CanUserAddOrEditContactAsync(string userId, int departmentId);
325329
}
326330
}

Core/Resgrid.Model/Services/ICallsService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,5 +408,7 @@ Task<bool> ClearGroupForDispatchesAsync(int departmentGroupId,
408408
Task<List<CallReference>> GetChildCallsForCallAsync(int callId);
409409

410410
Task<bool> DeleteCallReferenceAsync(CallReference callReference, CancellationToken cancellationToken = default(CancellationToken));
411+
412+
Task<List<Call>> GetCallsByContactIdAsync(string contactId, int departmentId);
411413
}
412414
}

Core/Resgrid.Model/Services/IContactsService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ public interface IContactsService
2525
Task<bool> DoesContactNoteTypeAlreadyExistAsync(int departmentId, string noteTypeText);
2626
Task<bool> DeleteContactNoteTypeAsync(ContactNoteType type, CancellationToken cancellationToken = default(CancellationToken));
2727
Task<ContactNote> SaveContactNoteAsync(ContactNote note, CancellationToken cancellationToken = default(CancellationToken));
28+
Task<bool> DeleteContactAsync(string contactId, string userId, int departmentId, string ipAddress, string userAgent, CancellationToken cancellationToken = default(CancellationToken));
2829
}
2930
}

Core/Resgrid.Services/AuthorizationService.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,5 +1401,36 @@ public async Task<bool> CanUserEditContactNoteTypeAsync(string userId, string co
14011401

14021402
return false;
14031403
}
1404+
1405+
public async Task<bool> CanUserDeleteContactAsync(string userId, int departmentId)
1406+
{
1407+
var permission = await _permissionsService.GetPermissionByDepartmentTypeAsync(departmentId, PermissionTypes.ContactDelete);
1408+
1409+
bool isGroupAdmin = false;
1410+
var group = await _departmentGroupsService.GetGroupForUserAsync(userId, departmentId);
1411+
var roles = await _personnelRolesService.GetRolesForUserAsync(userId, departmentId);
1412+
var department = await _departmentsService.GetDepartmentByIdAsync(departmentId);
1413+
1414+
if (group != null)
1415+
isGroupAdmin = group.IsUserGroupAdmin(userId);
1416+
1417+
return _permissionsService.IsUserAllowed(permission, department.IsUserAnAdmin(userId), isGroupAdmin, roles);
1418+
}
1419+
1420+
public async Task<bool> CanUserAddOrEditContactAsync(string userId, int departmentId)
1421+
{
1422+
var permission = await _permissionsService.GetPermissionByDepartmentTypeAsync(departmentId, PermissionTypes.ContactEdit);
1423+
1424+
bool isGroupAdmin = false;
1425+
var group = await _departmentGroupsService.GetGroupForUserAsync(userId, departmentId);
1426+
var roles = await _personnelRolesService.GetRolesForUserAsync(userId, departmentId);
1427+
var department = await _departmentsService.GetDepartmentByIdAsync(departmentId);
1428+
1429+
if (group != null)
1430+
isGroupAdmin = group.IsUserGroupAdmin(userId);
1431+
1432+
return _permissionsService.IsUserAllowed(permission, department.IsUserAnAdmin(userId), isGroupAdmin, roles);
1433+
}
1434+
14041435
}
14051436
}

Core/Resgrid.Services/CallsService.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class CallsService : ICallsService
4040
private readonly IGeoLocationProvider _geoLocationProvider;
4141
private readonly IDepartmentsService _departmentsService;
4242
private readonly ICallReferencesRepository _callReferencesRepository;
43+
private readonly ICallContactsRepository _callContactsRepository;
4344

4445
public CallsService(ICallsRepository callsRepository, ICommunicationService communicationService,
4546
ICallDispatchesRepository callDispatchesRepository, ICallTypesRepository callTypesRepository, ICallEmailFactory callEmailFactory,
@@ -48,7 +49,7 @@ public CallsService(ICallsRepository callsRepository, ICommunicationService comm
4849
ICallDispatchUnitRepository callDispatchUnitRepository, ICallDispatchRoleRepository callDispatchRoleRepository,
4950
IDepartmentCallPriorityRepository departmentCallPriorityRepository, IShortenUrlProvider shortenUrlProvider,
5051
ICallProtocolsRepository callProtocolsRepository, IGeoLocationProvider geoLocationProvider, IDepartmentsService departmentsService,
51-
ICallReferencesRepository callReferencesRepository)
52+
ICallReferencesRepository callReferencesRepository, ICallContactsRepository callContactsRepository)
5253
{
5354
_callsRepository = callsRepository;
5455
_communicationService = communicationService;
@@ -67,6 +68,7 @@ public CallsService(ICallsRepository callsRepository, ICommunicationService comm
6768
_geoLocationProvider = geoLocationProvider;
6869
_departmentsService = departmentsService;
6970
_callReferencesRepository = callReferencesRepository;
71+
_callContactsRepository = callContactsRepository;
7072
}
7173

7274
public async Task<Call> SaveCallAsync(Call call, CancellationToken cancellationToken = default(CancellationToken))
@@ -893,5 +895,15 @@ public async Task<string> CallPriorityToColorAsync(int priority, int departmentI
893895
return "#008000";
894896
}
895897
}
898+
899+
public async Task<List<Call>> GetCallsByContactIdAsync(string contactId, int departmentId)
900+
{
901+
var calls = await _callsRepository.GetAllCallsByContactIdAsync(contactId, departmentId);
902+
903+
if (calls != null && calls.Any())
904+
return calls.ToList();
905+
906+
return new List<Call>();
907+
}
896908
}
897909
}

Core/Resgrid.Services/ContactsService.cs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
using Resgrid.Model;
1+
using System;
2+
using Resgrid.Model;
23
using Resgrid.Model.Repositories;
34
using Resgrid.Model.Services;
45
using System.Collections.Generic;
56
using System.Linq;
67
using System.Threading;
78
using System.Threading.Tasks;
9+
using Resgrid.Framework;
10+
using Resgrid.Model.Events;
11+
using Resgrid.Model.Providers;
812

913
namespace Resgrid.Services
1014
{
@@ -15,20 +19,23 @@ public class ContactsService : IContactsService
1519
private readonly IContactNotesRepository _contactNotesRepository;
1620
private readonly IContactNoteTypesRepository _contactNoteTypesRepository;
1721
private readonly IContactAssociationsRepository _contactAssociationsRepository;
22+
private readonly IEventAggregator _eventAggregator;
1823

1924
public ContactsService(IContactsRepository contactsRepository, IContactNotesRepository contactNotesRepository,
20-
IContactCategoryRepository contactCategoryRepository,
21-
IContactNoteTypesRepository contactNoteTypesRepository, IContactAssociationsRepository contactAssociationsRepository)
25+
IContactCategoryRepository contactCategoryRepository, IContactNoteTypesRepository contactNoteTypesRepository,
26+
IContactAssociationsRepository contactAssociationsRepository, IEventAggregator eventAggregator)
2227
{
2328
_contactsRepository = contactsRepository;
2429
_contactCategoryRepository = contactCategoryRepository;
2530
_contactNotesRepository = contactNotesRepository;
2631
_contactNoteTypesRepository = contactNoteTypesRepository;
2732
_contactAssociationsRepository = contactAssociationsRepository;
33+
_eventAggregator = eventAggregator;
2834
}
2935

3036
public async Task<List<Contact>> GetAllContactsForDepartmentAsync(int departmentId)
3137
{
38+
var contactsResult = new List<Contact>();
3239
var contacts = await _contactsRepository.GetAllByDepartmentIdAsync(departmentId);
3340
var categories = await _contactCategoryRepository.GetAllByDepartmentIdAsync(departmentId);
3441

@@ -37,11 +44,16 @@ public async Task<List<Contact>> GetAllContactsForDepartmentAsync(int department
3744

3845
foreach (var contact in contacts)
3946
{
47+
if (contact.IsDeleted)
48+
continue;
49+
4050
if (categories != null && categories.Any())
4151
contact.Category = categories.FirstOrDefault(x => x.ContactCategoryId == contact.ContactCategoryId);
52+
53+
contactsResult.Add(contact);
4254
}
4355

44-
return contacts.ToList();
56+
return contactsResult;
4557
}
4658

4759
public async Task<List<ContactCategory>> GetContactCategoriesForDepartmentAsync(int departmentId)
@@ -156,5 +168,30 @@ public async Task<bool> DoesContactNoteTypeAlreadyExistAsync(int departmentId, s
156168
return await _contactNotesRepository.SaveOrUpdateAsync(note, cancellationToken);
157169
}
158170

171+
public async Task<bool> DeleteContactAsync(string contactId, string userId, int departmentId, string ipAddress, string userAgent, CancellationToken cancellationToken = default(CancellationToken))
172+
{
173+
var auditEvent = new AuditEvent();
174+
auditEvent.DepartmentId = departmentId;
175+
auditEvent.UserId = userId;
176+
auditEvent.Type = AuditLogTypes.ContactRemoved;
177+
auditEvent.Successful = true;
178+
auditEvent.IpAddress = ipAddress;
179+
auditEvent.ServerName = Environment.MachineName;
180+
auditEvent.UserAgent = userAgent;
181+
182+
var contact = await _contactsRepository.GetByIdAsync(contactId);
183+
auditEvent.Before = contact.CloneJsonToString();
184+
185+
contact.IsDeleted = true;
186+
contact.EditedByUserId = userId;
187+
contact.EditedOn = DateTime.UtcNow;
188+
189+
await SaveContactAsync(contact, cancellationToken);
190+
191+
auditEvent.After = contact.CloneJsonToString();
192+
_eventAggregator.SendMessage<AuditEvent>(auditEvent);
193+
194+
return true;
195+
}
159196
}
160197
}

Repositories/Resgrid.Repositories.DataRepository/CallsRepository.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,48 @@ public async Task<IEnumerable<Call>> GetAllNonDispatchedScheduledCallsByDepartme
362362
}
363363
}
364364

365+
public async Task<IEnumerable<Call>> GetAllCallsByContactIdAsync(string contactId, int departmentId)
366+
{
367+
try
368+
{
369+
var selectFunction = new Func<DbConnection, Task<IEnumerable<Call>>>(async x =>
370+
{
371+
var dynamicParameters = new DynamicParametersExtension();
372+
dynamicParameters.Add("ContactId", contactId);
373+
dynamicParameters.Add("DepartmentId", departmentId);
374+
375+
var query = _queryFactory.GetQuery<SelectCallsByContactQuery>();
376+
377+
return await x.QueryAsync<Call>(sql: query,
378+
param: dynamicParameters,
379+
transaction: _unitOfWork.Transaction);
380+
});
381+
382+
DbConnection conn = null;
383+
if (_unitOfWork?.Connection == null)
384+
{
385+
using (conn = _connectionProvider.Create())
386+
{
387+
await conn.OpenAsync();
388+
389+
return await selectFunction(conn);
390+
}
391+
}
392+
else
393+
{
394+
conn = _unitOfWork.CreateOrGetConnection();
395+
396+
return await selectFunction(conn);
397+
}
398+
}
399+
catch (Exception ex)
400+
{
401+
Logging.LogException(ex);
402+
403+
throw;
404+
}
405+
}
406+
365407
public void CleanUpCallDispatchAudio()
366408
{
367409
//var lastestDate = DateTime.UtcNow.AddDays(-14);

0 commit comments

Comments
 (0)