public async Task <Unit> Handle(NotifyUserManagementUsersRequest message, CancellationToken cancellationToken) { const string epaoUserApproveRequestTemplate = "EPAOUserApproveRequest"; var emailTemplate = await _eMailTemplateQueryRepository.GetEmailTemplate(epaoUserApproveRequestTemplate); var organisation = await _organisationQueryRepository.Get(message.EndPointAssessorOrganisationId); var contactsWithUserManagementPrivilege = (await _contactQueryRepository.GetAllContactsIncludePrivileges(organisation.EndPointAssessorOrganisationId)) .Where(c => c.ContactsPrivileges.Any(cp => cp.Privilege.Key == Privileges.ManageUsers && cp.Contact.Status == ContactStatus.Live)).ToList(); foreach (var contact in contactsWithUserManagementPrivilege) { await _mediator.Send(new SendEmailRequest(contact.Email, emailTemplate, new { Contact = contact.DisplayName, username = message.DisplayName, ServiceName = "Apprenticeship assessment service", LoginLink = message.ServiceLink, ServiceTeam = "Apprenticeship assessment service team", Organisation = organisation.EndPointAssessorName }), cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(RequestForPrivilegeRequest message, CancellationToken cancellationToken) { var privilege = (await _contactQueryRepository.GetAllPrivileges()).Single(p => p.Id == message.PrivilegeId); var requestingContact = await _contactQueryRepository.GetContactById(message.ContactId); var organisation = await _organisationQueryRepository.GetOrganisationByContactId(message.ContactId); var contactsWithUserManagementPrivilege = (await _contactQueryRepository.GetAllContactsIncludePrivileges(organisation.EndPointAssessorOrganisationId)) .Where(c => c.ContactsPrivileges.Any(cp => cp.Privilege.Key == Privileges.ManageUsers && cp.Contact.Status == ContactStatus.Live)).ToList(); if (RequestingUserHasUserManagementPrivilege(contactsWithUserManagementPrivilege, requestingContact)) { await _contactRepository.AddPrivilege(requestingContact.Id, message.PrivilegeId); } else { var emailTemplate = await _mediator.Send(new GetEmailTemplateRequest { TemplateName = "EPAOPermissionsRequested" }, cancellationToken); contactsWithUserManagementPrivilege.ForEach(async contact => { await _mediator.Send(new SendEmailRequest(contact.Email, emailTemplate, new { ServiceName = "Apprenticeship assessment service", Contact = contact.DisplayName, Username = requestingContact.DisplayName, Permission = privilege.UserPrivilege, ServiceTeam = "Apprenticeship assessment service team", LoginLink = _config.ServiceLink })); }); } return(Unit.Value); }
public async Task <List <ContactIncludePrivilegesResponse> > Handle(GetAllContactsIncludePrivilegesRequest request, CancellationToken cancellationToken) { var response = new List <ContactIncludePrivilegesResponse>(); var results = await _contactQueryRepository.GetAllContactsIncludePrivileges(request.EndPointAssessorOrganisationId, request.WithUser); if (results == null) { return(response); } foreach (var result in results) { var contactsWithPrivilegesResponse = new ContactIncludePrivilegesResponse { Contact = Mapper.Map <ContactResponse>(result) }; contactsWithPrivilegesResponse.Contact.Status = result.Status == ContactStatus.Live ? ContactStatus.Active : result.Status; foreach (var role in result.ContactsPrivileges) { contactsWithPrivilegesResponse.Privileges.Add(new PrivilegeResponse { UserPrivilege = role.Privilege?.UserPrivilege, Key = role.Privilege?.Key }); } response.Add(contactsWithPrivilegesResponse); } return(response); }