Ejemplo n.º 1
0
        protected async Task <(bool isValid, ContactResponse contact)> SecurityCheckAndGetContact(Guid contactId)
        {
            RequestingUser = await GetRequestingContact();

            UserToBeDisplayed = await ContactsApiClient.GetById(contactId);

            return(RequestingUser.OrganisationId == UserToBeDisplayed.OrganisationId, UserToBeDisplayed);
        }
Ejemplo n.º 2
0
        private async Task <RegisterViewAndEditUserViewModel> GetUserViewModel(Guid contactId)
        {
            var contact = await _contactsApiClient.GetById(contactId);

            var organisation = await _organisationsApiClient.Get(contact.OrganisationId.Value);

            var vm = Mapper.Map <RegisterViewAndEditUserViewModel>(contact);

            vm.EndPointAssessorOrganisationId = organisation.EndPointAssessorOrganisationId;
            vm.AssignedPrivileges             = await _contactsApiClient.GetContactPrivileges(contact.Id);

            vm.AllPrivilegeTypes = await _contactsApiClient.GetPrivileges();

            return(vm);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AccessDenied()
        {
            if (TempData.Keys.Contains(nameof(PrivilegeAuthorizationDeniedContext)))
            {
                var deniedContext = JsonConvert
                                    .DeserializeObject <PrivilegeAuthorizationDeniedContext>(TempData[nameof(PrivilegeAuthorizationDeniedContext)]
                                                                                             .ToString());

                var userId = Guid.Parse(User.FindFirst("UserId").Value);
                var user   = await _contactsApiClient.GetById(userId);

                OrganisationResponse organisation = null;
                try
                {
                    organisation = await _organisationsApiClient.GetOrganisationByUserId(userId);
                }
                catch (Exception ex)
                {
                    _logger.LogWarning(ex.Message, ex);
                    if (user.OrganisationId == null && user.Status == ContactStatus.Live)
                    {
                        return(RedirectToAction("Index", "OrganisationSearch"));
                    }
                }

                if (user.OrganisationId != null && user.Status == ContactStatus.InvitePending)
                {
                    return(RedirectToAction("InvitePending", "Home"));
                }

                if (organisation != null && organisation.Status == OrganisationStatus.Applying ||
                    organisation.Status == OrganisationStatus.New)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }

                var privilege = (await _contactsApiClient.GetPrivileges()).Single(p => p.Id == deniedContext.PrivilegeId);

                var usersPrivileges = await _contactsApiClient.GetContactPrivileges(userId);

                return(View("~/Views/Account/AccessDeniedForPrivilege.cshtml", new AccessDeniedViewModel
                {
                    Title = privilege.UserPrivilege,
                    Rights = privilege.PrivilegeData.Rights,
                    PrivilegeId = deniedContext.PrivilegeId,
                    ContactId = userId,
                    UserHasUserManagement = usersPrivileges.Any(up => up.Privilege.Key == Privileges.ManageUsers),
                    ReturnController = deniedContext.Controller,
                    ReturnAction = deniedContext.Action,
                    IsUsersOrganisationLive = organisation?.Status == OrganisationStatus.Live
                }));
            }
            else if (TempData.Keys.Contains("UnavailableFeatureContext"))
            {
                return(View("~/Views/Account/UnavailableFeature.cshtml"));
            }

            return(View());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Invited(Guid contactId)
        {
            var contact = await _contactsApiClient.GetById(contactId);

            var organisation = await _organisationsApiClient.GetOrganisationByUserId(contactId);

            return(View("~/Views/ManageUsers/InviteUser/Invited.cshtml", new InvitedViewModel {
                Email = contact.Email, Organisation = organisation.EndPointAssessorName
            }));
        }