Ejemplo n.º 1
0
        /// <summary>
        /// This method adds the groups to a list of users
        /// </summary>
        /// <param name="ado"></param>
        /// <param name="users"></param>
        /// <returns></returns>
        internal void MergeGroupsToUsers(ADO ado, ref ADO_readerOutput resultUsers)
        {
            GroupAccount_ADO adoGroupAccount = new GroupAccount_ADO();

            //cycle through each user in the list and get the group data
            if (resultUsers.hasData)
            {
                foreach (var user in resultUsers.data)
                {
                    GroupAccount_DTO_Read gpAccDto = new GroupAccount_DTO_Read();
                    gpAccDto.CcnUsername = user.CcnUsername;

                    //Get the group data for the user
                    ADO_readerOutput resultGroups = adoGroupAccount.Read(ado, gpAccDto);
                    if (resultGroups.hasData)
                    {
                        user.UserGroups = new List <GroupAccount_DTO>();
                        foreach (var group in resultGroups.data)
                        {// add the new data to the output
                            GroupAccount_DTO groupAccountDTO = new GroupAccount_DTO();
                            groupAccountDTO.GrpName        = group.GrpName;
                            groupAccountDTO.GrpCode        = group.GrpCode;
                            groupAccountDTO.GccApproveFlag = group.GccApproveFlag;
                            // add group to the user
                            user.UserGroups.Add(groupAccountDTO);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get a list of GroupAccounts for a CcnUsername
        /// </summary>
        /// <param name="ccnUsername"></param>
        /// <returns></returns>
        private List <GroupAccount_DTO> getGroupMembership(string ccnUsername)
        {
            GroupAccount_ADO      gaAdo   = new GroupAccount_ADO();
            GroupAccount_DTO_Read dtoRead = new GroupAccount_DTO_Read();

            dtoRead.CcnUsername = ccnUsername;
            dynamic result = gaAdo.Read(Ado, dtoRead);
            List <GroupAccount_DTO> groupAccountList = new List <GroupAccount_DTO>();

            foreach (dynamic groupAccount in result.data)
            {
                GroupAccount_DTO resultDTO = new GroupAccount_DTO(groupAccount);
                groupAccountList.Add(resultDTO);
            }

            return(groupAccountList);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads Group Account data (TM_GROUP_ACCOUNT table)
        /// Both the GroupID and CcnUsername parameters are optional
        /// If no parameters are sent, all data is returned
        /// If just the GroupId parameter is sent then all user/group combinations for that group are returned
        /// If just the CcnUsername parameter is sent then all user/group combinations for that user are returned
        /// If both parameters are sent, then the user/group combination for that user and group are returned (if it exists)
        /// </summary>
        /// <param name="ado"></param>
        /// <param name="groupAccount"></param>
        /// <returns></returns>
        internal ADO_readerOutput Read(ADO ado, GroupAccount_DTO_Read groupAccount)
        {
            ADO_readerOutput output = new ADO_readerOutput();

            List <ADO_inputParams> paramList = new List <ADO_inputParams>();

            if (!string.IsNullOrEmpty(groupAccount.CcnUsername))
            {
                paramList.Add(new ADO_inputParams()
                {
                    name = "@CcnUsername", value = groupAccount.CcnUsername
                });
            }
            if (!string.IsNullOrEmpty(groupAccount.GrpCode))
            {
                paramList.Add(new ADO_inputParams()
                {
                    name = "@GrpCode", value = groupAccount.GrpCode
                });
            }

            //Call the stored procedure
            output = ado.ExecuteReaderProcedure("Security_GroupAccount_Read", paramList);

            //Read the result of the call to the database
            if (output.hasData)
            {
                Log.Instance.Debug("Data found");
            }
            else
            {
                //No data found
                Log.Instance.Debug("No data found");
            }

            //return the list of entities that have been found
            return(output);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            //A power user may not delete an Administrator
            if (IsPowerUser() && IsAdministrator(DTO.CcnUsername))
            {
                Log.Instance.Debug("A power user may not delete an Administrator");
                Response.error = Label.Get("error.privilege");
                return(false);
            }

            //You can't delete yourself
            if (DTO.CcnUsername.Equals(SamAccountName))
            {
                Log.Instance.Debug("A user may not delete themselves");
                Response.error = Label.Get("error.delete");
                return(false);
            }

            var adoAccount = new Account_ADO();

            //There must always be at least one administrator in the system. If this delete would leave no administrator then the request must be refused.
            if (IsAdministrator(DTO.CcnUsername))
            {
                if (!adoAccount.EnoughPrivilegesInAccounts(Ado, Resources.Constants.C_SECURITY_PRIVILEGE_ADMINISTRATOR))
                {
                    Log.Instance.Debug("There are insufficient Administrators in the Account table to proceed with this delete.");
                    Response.error = Label.Get("error.delete");
                    return(false);
                }
            }

            //We also need to delete user membership of any groups
            GroupAccount_ADO      gaAdo = new GroupAccount_ADO();
            GroupAccount_DTO_Read gaDto = new GroupAccount_DTO_Read();

            gaDto.CcnUsername = DTO.CcnUsername;
            ADO_readerOutput groupAccountList = gaAdo.Read(Ado, gaDto);

            if (groupAccountList.hasData)
            {
                foreach (dynamic res in groupAccountList.data)
                {
                    GroupAccount_DTO_Delete dtoDelete = new GroupAccount_DTO_Delete();
                    dtoDelete.CcnUsername = DTO.CcnUsername;
                    dtoDelete.GrpCode     = res.GrpCode;
                    gaAdo.Delete(Ado, dtoDelete, SamAccountName);
                }
            }

            //attempting to delete. The number of entities deleted are passed to the entitiesDeleted variable (this is 1 for a successful delete)
            int nDeleted = adoAccount.Delete(Ado, DTO, SamAccountName);

            if (nDeleted == 0)
            {
                Log.Instance.Debug("adoAccount.Delete - can't delete Account");
                Response.error = Label.Get("error.delete");
                return(false);
            }

            //If this user is cached then we must remove the cache entry as well
            MemCacheD.Remove_BSO <dynamic>("PxStat.Security", "Account_API", "ReadCurrentAccesss", DTO.CcnUsername);

            Response.data = JSONRPC.success;
            return(true);
        }