Ejemplo n.º 1
0
        public List <ComputerWithImage> SearchComputersForUser(int userId, int limit, string searchString = "")
        {
            var userServices = new UserServices();

            if (limit == 0)
            {
                limit = int.MaxValue;
            }
            if (userServices.GetUser(userId).Membership == "Administrator")
            {
                return(SearchComputers(searchString, limit));
            }

            var user = userServices.GetUser(userId);

            if (user.GroupManagementEnabled == 0)
            {
                return(SearchComputers(searchString, limit));
            }

            var listOfComputers   = new List <ComputerWithImage>();
            var userManagedGroups = userServices.GetUserGroupManagements(userId);

            foreach (var managedGroup in userManagedGroups)
            {
                listOfComputers.AddRange(new GroupServices().GetGroupMembersWithImages(managedGroup.GroupId,
                                                                                       searchString));
            }

            return(listOfComputers);
        }
Ejemplo n.º 2
0
        public string ComputerCountUser(int userId)
        {
            var userServices = new UserServices();

            if (userServices.GetUser(userId).Membership == "Administrator")
            {
                return(TotalCount());
            }

            var user = userServices.GetUser(userId);

            if (user.GroupManagementEnabled == 0)
            {
                return(TotalCount());
            }

            var userManagedGroups = userServices.GetUserGroupManagements(userId);
            var computerCount     = 0;

            foreach (var managedGroup in userManagedGroups)
            {
                computerCount += Convert.ToInt32(new GroupServices().GetGroupMemberCount(managedGroup.GroupId));
            }
            return(computerCount.ToString());
        }
Ejemplo n.º 3
0
        public string ConsoleLogin(string username, string password, string task, string ip)
        {
            log.Info("Console Login Request Received: " + username + " " + password + " " + task + " " + ip);
            var result = new Dictionary <string, string>();

            var validationResult = GlobalLogin(username, password, "Console");

            if (!validationResult.Success)
            {
                log.Info("Console Login Request Failed");
                result.Add("valid", "false");
                result.Add("user_id", "");
                result.Add("user_token", "");
            }
            else
            {
                log.Info("Console Login Request Succeeded");
                var cloneDeployUser = _userServices.GetUser(username);
                result.Add("valid", "true");
                result.Add("user_id", cloneDeployUser.Id.ToString());
                result.Add("user_token", cloneDeployUser.Token);
            }

            return(JsonConvert.SerializeObject(result));
        }
Ejemplo n.º 4
0
 public AuthorizationServices(int userId, string requiredRight)
 {
     _userServices      = new UserServices();
     _cloneDeployUser   = _userServices.GetUser(userId);
     _currentUserRights = _userServices.GetUserRights(userId).Select(right => right.Right).ToList();
     _requiredRight     = requiredRight;
 }
Ejemplo n.º 5
0
        public ActionResultDTO CheckApprovalAndChecksum(ImageEntity image, int userId)
        {
            var actionResult = new ActionResultDTO();

            if (image == null)
            {
                actionResult.Success      = false;
                actionResult.ErrorMessage = "Image Does Not Exist";
                return(actionResult);
            }

            if (image.Enabled == 0)
            {
                actionResult.Success      = false;
                actionResult.ErrorMessage = "Image Is Not Enabled";
                return(actionResult);
            }

            if (SettingServices.GetSettingValue(SettingStrings.RequireImageApproval).ToLower() == "true")
            {
                var user = _userServices.GetUser(userId);
                if (user.Membership != "Administrator") //administrators don't need image approval
                {
                    if (!Convert.ToBoolean(image.Approved))
                    {
                        actionResult.Success      = false;
                        actionResult.ErrorMessage = "Image Has Not Been Approved";
                        return(actionResult);
                    }
                }
            }

            actionResult.Success = true;
            return(actionResult);
        }
Ejemplo n.º 6
0
        public string GroupCountUser(int userId)
        {
            var userServices = new UserServices();

            if (userServices.GetUser(userId).Membership == "Administrator")
            {
                return(TotalCount());
            }

            var user = userServices.GetUser(userId);

            if (user.GroupManagementEnabled == 1)
            {
                var userManagedGroups = userServices.GetUserGroupManagements(userId);
                return(userManagedGroups.Count.ToString());
            }
            return(TotalCount());
        }
Ejemplo n.º 7
0
        public List <GroupWithImage> SearchGroupsForUser(int userId, string searchString = "")
        {
            var userServices = new UserServices();

            if (userServices.GetUser(userId).Membership == "Administrator")
            {
                return(SearchGroups(searchString));
            }

            var user = userServices.GetUser(userId);

            if (user.GroupManagementEnabled == 0)
            {
                return(SearchGroups(searchString));
            }

            var userManagedGroups = userServices.GetUserGroupManagements(userId);

            return
                (userManagedGroups.Select(
                     groupManagement => _uow.GroupRepository.GetGroupWithImage(searchString, groupManagement.GroupId))
                 .Where(@group => @group != null)
                 .ToList());
        }