public void AuthorizeCore_GivenUserIsNotAdministrator_UserShouldBeDirectedToUnauthorizedView()
        {
            A.CallTo(() => _userRoleProvider.CurrentUserInAdministratorRole()).Returns(false);

            _authorizeAdministratorAttribute = new AuthorizeAdministratorAttribute(_userRoleProvider);
            _authorizeAdministratorAttribute.OnAuthorization(_filterContext);

            var result = _filterContext.Result as RedirectToRouteResult;

            AssertPersonRoute(result);
        }
Example #2
0
        public void BuildPatientSearchViewModel_GivenUserIsNotAnAdministrator_CanEditShouldBeFalse()
        {
            A.CallTo(() => _userRoleProvider.CurrentUserInAdministratorRole()).Returns(false);

            var patients = new Patients()
            {
                Items = new List <Patient>()
            };

            var result = _builder.BuildPatientSearchViewModel(patients);

            result.CanEdit.Should().BeFalse();
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var assessmentId = GetAssessmentId(filterContext);

            var assessment = _assessmentHelper.GetAssessment(assessmentId);

            if (assessment == null)
            {
                RedirectResult(filterContext);
                return;
            }

            if (assessment.StatusId != (int)AssessmentStatusEnum.Complete)
            {
                RedirectResult(filterContext);
                return;
            }

            if (NotCurrentUserIsAssessor(assessment) && !_userRoleProvider.CurrentUserInAdministratorRole())
            {
                RedirectResult(filterContext);
                return;
            }

            base.OnActionExecuting(filterContext);
        }
Example #4
0
        public void OnActionExecuting_GivenAssessmentIsNotCompleteAndIsAssignedToAnotherUserAndUserIsNotAdministrator_UserShouldBeRedirectedToPatientSearch()
        {
            var filterContext = GetActionExecutingContext(Guid.NewGuid());

            var assessment = new Assessment()
            {
                AssessorDomainName = "*****@*****.**"
            };

            A.CallTo(() => _userRoleProvider.CurrentUserInAdministratorRole()).Returns(false);
            A.CallTo(() => _userPrincipalProvider.CurrentUserName).Returns("*****@*****.**");
            A.CallTo(() => _assessmentHelper.GetAssessment(A <Guid> ._)).Returns(assessment);

            _assessmentInProgressActionFilter.OnActionExecuting(filterContext);

            AssertPatientSearch(filterContext);
        }
Example #5
0
        public PatientSearchViewModel BuildPatientSearchViewModel(Patients patients)
        {
            if (patients == null)
            {
                throw new ArgumentNullException("patients");
            }

            var viewModel = new PatientSearchViewModel
            {
                Items = patients.Items.Select(Mapper.Map <Patient, PatientViewModel>),
                ClinicalIdDescription = _clinicalSystemIdDescriptionProvider.GetDescription(),
                CanEdit = _userRoleProvider.CurrentUserInAdministratorRole()
            };

            return(viewModel);
        }
Example #6
0
        public void BuildAssessmentListViewModel_GivenAssessmentIsCompleteAndAssessorIsAssignedAssessor_CanViewPdfShouldBeTrue()
        {
            var assessments = new Assessments()
            {
                Items = new List <Assessment>()
                {
                    new Assessment()
                    {
                        Stage1DecisionToBeMade = Stage1DecisionToBeMade,
                        StatusId           = (int)AssessmentStatusEnum.Complete,
                        AssessorDomainName = AssessorDomainName
                    }
                }
            };

            A.CallTo(() => _userRoleProvider.CurrentUserInAdministratorRole()).Returns(false);
            A.CallTo(() => _userPrincipalProvider.CurrentUserName).Returns(AssessorDomainName);

            var result = _builder.BuildAssessmentListViewModel(Guid.NewGuid(), assessments);

            result.Items.First().CanViewPdf.Should().BeTrue();
        }
 protected override bool AuthorizeCore(HttpContextBase httpContext)
 {
     return(_userRoleProvider.CurrentUserInAdministratorRole());
 }
 private bool AssignedAssessorOrAdmin(Assessment assessment)
 {
     return(assessment.AssessorDomainName == _userPrincipalProvider.CurrentUserName ||
            _userRoleProvider.CurrentUserInAdministratorRole());
 }