Beispiel #1
0
        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 <IActionResult> GetOrganisationForContact(Guid userId)
        {
            var organisation = await _organisationQueryRepository.GetOrganisationByContactId(userId);

            if (organisation == null)
            {
                throw new ResourceNotFoundException(userId.ToString());
            }

            return(Ok(Mapper.Map <Organisation, OrganisationResponse>(organisation)));
        }