private void VerifyCanCancel(WorkOrder workOrder)
        {
            workOrder.VerifyCanCancel();

            if (!_currentUserService.HasAnyGroup(UserGroups.Agent, UserGroups.ContractManager, UserGroups.AuthorisationManager))
            {
                throw new UnauthorizedAccessException("Not Authorised to cancel jobs");
            }
        }
Exemplo n.º 2
0
        public static IQueryable <WorkOrder> RestrictContractor(this IQueryable <WorkOrder> source, ICurrentUserService userService)
        {
            if (userService.HasAnyGroup(UserGroups.AuthorisationManager, UserGroups.ContractManager, UserGroups.Agent, UserGroups.Service))
            {
                return(source);
            }

            var contractors = userService.GetContractors();

            if (contractors.Count > 0)
            {
                return(source.Where(wo => contractors.Contains(wo.AssignedToPrimary.ContractorReference) && wo.StatusCode != WorkStatusCode.PendingApproval));
            }

            if (userService.HasAnyGroup(UserGroups.Operative))
            {
                var userEmail = userService.GetUser().Email();
                return(source.Where(wo => wo.AssignedOperatives.Any(ao => ao.Email == userEmail)));
            }

            throw new UnauthorizedAccessException("Cannot access work orders");
        }
        private async Task <List <FilterOption> > GetContractors()
        {
            var liveContractors = await _scheduleOfRatesGateway.GetLiveContractors();

            var filterOptions = new List <FilterOption>(liveContractors.Select(c => new FilterOption {
                Key = c.ContractorReference, Description = c.ContractorName
            }));

            if (!_currentUserService.HasAnyGroup(UserGroups.Agent, UserGroups.AuthorisationManager, UserGroups.ContractManager))
            {
                var groups = _currentUserService.GetContractors();

                return(filterOptions.Where(fo => groups.Contains(fo.Key)).ToList());
            }

            return(filterOptions);
        }
Exemplo n.º 4
0
        public static bool UserCanAccess(this WorkOrder workOrder, ICurrentUserService userService)
        {
            if (userService.HasAnyGroup(UserGroups.Agent, UserGroups.ContractManager, UserGroups.AuthorisationManager, UserGroups.Service))
            {
                return(true);
            }

            var contractors = userService.GetContractors();

            if (contractors.Count > 0)
            {
                return(contractors.Contains(workOrder.AssignedToPrimary.ContractorReference) &&
                       workOrder.StatusCode != WorkStatusCode.PendingApproval);
            }

            if (workOrder.IsAssignedOperative(userService))
            {
                return(true);
            }

            return(false);
        }