Ejemplo n.º 1
0
        public static bool AllowableAction(SubmissionAction action, Enrollee enrollee, bool asAdmin)
        {
            enrollee.ThrowIfNull(nameof(enrollee));
            if (enrollee.CurrentStatus == null)
            {
                throw new ArgumentException("Enrollee must have a CurrentStatus", nameof(enrollee));
            }

            var status = enrollee.CurrentStatus.GetStatusType();

            return((status, action) switch
            {
                (StatusType.Editable, SubmissionAction.LockProfile) => asAdmin,
                (StatusType.Editable, SubmissionAction.DeclineProfile) => asAdmin,

                (StatusType.UnderReview, SubmissionAction.Approve) => asAdmin,
                (StatusType.UnderReview, SubmissionAction.EnableEditing) => asAdmin,
                (StatusType.UnderReview, SubmissionAction.LockProfile) => asAdmin,
                (StatusType.UnderReview, SubmissionAction.DeclineProfile) => asAdmin,
                (StatusType.UnderReview, SubmissionAction.RerunRules) => asAdmin,

                (StatusType.RequiresToa, SubmissionAction.AcceptToa) => !asAdmin,
                (StatusType.RequiresToa, SubmissionAction.DeclineToa) => !asAdmin,
                (StatusType.RequiresToa, SubmissionAction.EnableEditing) => asAdmin,
                (StatusType.RequiresToa, SubmissionAction.LockProfile) => asAdmin,
                (StatusType.RequiresToa, SubmissionAction.DeclineProfile) => asAdmin,

                (StatusType.Locked, SubmissionAction.EnableEditing) => asAdmin,
                (StatusType.Locked, SubmissionAction.DeclineProfile) => asAdmin,

                (StatusType.Declined, SubmissionAction.EnableEditing) => asAdmin,

                _ => false
            });
Ejemplo n.º 2
0
        /// <summary>
        /// Performs a submission action on an Enrollee.
        /// Returns true if the Action was successfully performed.
        /// </summary>
        public async Task <bool> PerformSubmissionActionAsync(int enrolleeId, SubmissionAction action, bool isAdmin, object additionalParameters = null)
        {
            var enrollee = await _context.Enrollees
                           .Include(e => e.PhysicalAddress)
                           .Include(e => e.MailingAddress)
                           .Include(e => e.EnrolmentStatuses)
                           .ThenInclude(es => es.Status)
                           .Include(e => e.EnrolmentStatuses)
                           .ThenInclude(es => es.EnrolmentStatusReasons)
                           .ThenInclude(esr => esr.StatusReason)
                           .Include(e => e.Certifications)
                           .ThenInclude(cer => cer.College)
                           .Include(e => e.Certifications)
                           .ThenInclude(l => l.License)
                           .SingleOrDefaultAsync(e => e.Id == enrolleeId);

            var allowed = new SubmissionStateEngine().AllowableAction(action, enrollee, isAdmin);

            if (!allowed)
            {
                return(false);
            }

            return(await HandleSubmissionActionAsync(action, enrollee, additionalParameters));
        }
Ejemplo n.º 3
0
        public void TestAllowableActions_Declined(SubmissionAction action, bool asAdmin)
        {
            // Arrange
            var enrollee = EnrolleeWithCurrentStatus(StatusType.Declined);
            var expected = (action == SubmissionAction.EnableEditing && asAdmin);

            // Act
            var allowed = SubmissionStateEngine.AllowableAction(action, enrollee, asAdmin);

            // Assert
            Assert.Equal(expected, allowed);
        }
Ejemplo n.º 4
0
        public void TestAllowableActions_Editable(SubmissionAction action, bool asAdmin)
        {
            // Arrange
            var enrollee = EnrolleeWithCurrentStatus(StatusType.Editable);
            var expected = (action == SubmissionAction.LockProfile && asAdmin) ||
                           (action == SubmissionAction.DeclineProfile && asAdmin);

            // Act
            var allowed = SubmissionStateEngine.AllowableAction(action, enrollee, asAdmin);

            // Assert
            Assert.Equal(expected, allowed);
        }
        public bool AllowableAction(SubmissionAction action, Enrollee enrollee, bool asAdmin)
        {
            _actionAllowed = false;

            var machine = InitBuilder()
                          .WithInitialState(FromEnrollee(enrollee))
                          .Build()
                          .CreatePassiveStateMachine();

            machine.Start();
            machine.Fire(action, asAdmin);

            return(_actionAllowed);
        }
Ejemplo n.º 6
0
        public void TestAllowableActions_RequiresToa(SubmissionAction action, bool asAdmin)
        {
            // Arrange
            var enrollee = EnrolleeWithCurrentStatus(StatusType.RequiresToa);
            var expected = (action == SubmissionAction.AcceptToa && !asAdmin) ||
                           (action == SubmissionAction.DeclineToa && !asAdmin) ||
                           (action == SubmissionAction.EnableEditing && asAdmin) ||
                           (action == SubmissionAction.LockProfile && asAdmin) ||
                           (action == SubmissionAction.DeclineProfile && asAdmin);

            // Act
            var allowed = SubmissionStateEngine.AllowableAction(action, enrollee, asAdmin);

            // Assert
            Assert.Equal(expected, allowed);
        }
Ejemplo n.º 7
0
        public void TestAllowableActions_UnderReview(SubmissionAction action, bool asAdmin)
        {
            // Arrange
            var enrollee = EnrolleeWithCurrentStatus(StatusType.UnderReview);
            var expected = (action == SubmissionAction.Approve && asAdmin) ||
                           (action == SubmissionAction.EnableEditing && asAdmin) ||
                           (action == SubmissionAction.LockProfile && asAdmin) ||
                           (action == SubmissionAction.DeclineProfile && asAdmin) ||
                           (action == SubmissionAction.RerunRules && asAdmin);

            // Act
            var allowed = SubmissionStateEngine.AllowableAction(action, enrollee, asAdmin);

            // Assert
            Assert.Equal(expected, allowed);
        }
Ejemplo n.º 8
0
        private async Task <bool> HandleSubmissionActionAsync(SubmissionAction action, Enrollee enrollee, object additionalParameters)
        {
            switch (action)
            {
            case SubmissionAction.Approve:
                await ApproveApplicationAsync(enrollee);

                break;

            case SubmissionAction.AcceptToa:
                return(await AcceptToaAsync(enrollee, additionalParameters));

            case SubmissionAction.DeclineToa:
                await DeclineToaAsync(enrollee);

                break;

            case SubmissionAction.EnableEditing:
                await EnableEditingAsync(enrollee);

                break;

            case SubmissionAction.LockProfile:
                await LockProfileAsync(enrollee);

                break;

            case SubmissionAction.DeclineProfile:
                await DeclineProfileAsync(enrollee);

                break;

            case SubmissionAction.RerunRules:
                await RerunRulesAsync(enrollee);

                break;

            default:
                throw new InvalidOperationException($"Action {action} is not recognized in {nameof(HandleSubmissionActionAsync)}");
            }

            return(true);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Performs a submission action on an Enrollee.
        /// </summary>
        /// <exception cref="Prime.Services.SubmissionService.InvalidActionException"> Thrown when the action is invalid on the given Enrollee due to current state or admin access </exception>
        public async Task PerformSubmissionActionAsync(int enrolleeId, SubmissionAction action, bool isAdmin)
        {
            var enrollee = await _context.Enrollees
                           .Include(e => e.PhysicalAddress)
                           .Include(e => e.MailingAddress)
                           .Include(e => e.EnrolmentStatuses)
                           .ThenInclude(es => es.Status)
                           .Include(e => e.EnrolmentStatuses)
                           .ThenInclude(es => es.EnrolmentStatusReasons)
                           .ThenInclude(esr => esr.StatusReason)
                           .Include(e => e.Certifications)
                           .ThenInclude(cer => cer.College)
                           .Include(e => e.Certifications)
                           .ThenInclude(l => l.License)
                           .SingleOrDefaultAsync(e => e.Id == enrolleeId);

            var stateMachine = new SubmissionStateMachine(enrollee, this);

            await stateMachine.PerformAction(action, isAdmin);
        }
        public async Task <ActionResult <EnrolleeViewModel> > SubmissionAction(int enrolleeId, SubmissionAction submissionAction, [FromQuery] Guid?documentGuid = null)
        {
            var record = await _enrolleeService.GetPermissionsRecordAsync(enrolleeId);

            if (record == null)
            {
                return(NotFound(ApiResponse.Message($"Enrollee not found with id {enrolleeId}")));
            }
            if (!record.EditableBy(User))
            {
                return(Forbid());
            }

            var success = await _submissionService.PerformSubmissionActionAsync(enrolleeId, submissionAction, User.IsAdmin(), documentGuid);

            if (!success)
            {
                this.ModelState.AddModelError("Enrollee.CurrentStatus", "Action could not be performed.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            var enrollee = await _enrolleeService.GetEnrolleeAsync(enrolleeId);

            return(Ok(ApiResponse.Result(enrollee)));
        }
Ejemplo n.º 11
0
        public async Task <ActionResult <Enrollee> > SubmissionAction(int enrolleeId, SubmissionAction submissionAction)
        {
            var enrollee = await _enrolleeService.GetEnrolleeAsync(enrolleeId);

            if (enrollee == null)
            {
                return(NotFound(ApiResponse.Message($"Enrollee not found with id {enrolleeId}.")));
            }
            if (!User.CanEdit(enrollee))
            {
                return(Forbid());
            }

            try
            {
                await _submissionService.PerformSubmissionActionAsync(enrolleeId, submissionAction, User.IsAdmin());

                enrollee = await _enrolleeService.GetEnrolleeAsync(enrolleeId);

                return(Ok(ApiResponse.Result(enrollee)));
            }
            catch (SubmissionService.InvalidActionException)
            {
                this.ModelState.AddModelError("Enrollee.CurrentStatus", $"Action could not be performed.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
        }
Ejemplo n.º 12
0
 public async Task PerformAction(SubmissionAction action, bool isAdmin)
 {
     await _machine.Fire(action, isAdmin);
 }