예제 #1
0
        public async Task ApprovalWorksForStaffWithoutEmail()
        {
            var setup  = _sf.SetupLeaveRequest(p => { p.Staff.Email = null; });
            var result = await _leaveService.ApproveLeaveRequest(setup.request.Id, setup.supervisor.Id);

            result.notified.ShouldBeFalse();
            result.requester.Id.ShouldBe(setup.requester.Id);
        }
예제 #2
0
        public Task <ActionResult> Approve(Guid leaveRequestId)
        {
            var personId = User.PersonId();

            if (personId == null)
            {
                throw new UnauthorizedAccessException(
                          "Logged in user must be connected to a person, talk to HR about this issue");
            }
            LeaveRequest leaveRequest = null;

            return(TryExecute <Func <Guid> >(MyPolicies.peopleEdit,
                                             () =>
            {
                leaveRequest = _leaveService.GetById(leaveRequestId);
                return leaveRequest?.PersonId ??
                throw new UserError("Unable to find leave request, it may have been deleted");
            },
                                             async() =>
            {
                //lambda above may not be called, so we need to fetch the request if not
                leaveRequest = leaveRequest ?? _leaveService.GetById(leaveRequestId);
                var(_, requester, notified) =
                    await _leaveService.ApproveLeaveRequest(leaveRequest, personId.Value);
                if (notified)
                {
                    return this.ShowFrontendMessage(
                        $"Leave request approved{Environment.NewLine}{requester.PreferredName ?? requester.FirstName} has been notified");
                }

                return this.ShowFrontendMessage(
                    $"Leave request approved{Environment.NewLine}{requester.PreferredName ?? requester.FirstName} does not have an email and has not been notified");
            }));
        }
예제 #3
0
        public IActionResult Approve(Guid leaveRequestId)
        {
            //todo validate that logged in user is HR/ADMIN or is the supervisor of the person who created the leave request
            var personId = User.PersonId();

            if (personId == null)
            {
                throw new UnauthorizedAccessException(
                          "Logged in user must be connected to a person, talk to HR about this issue");
            }
            _leaveService.ApproveLeaveRequest(leaveRequestId, personId.Value);
            return(this.ShowFrontendMessage("Leave request approved"));
        }