/// <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); } } } } }
/// <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); }
/// <summary> /// Execute /// </summary> /// <returns></returns> protected override bool Execute() { //Validation of parameters and user have been successful. We may now proceed to read from the database var adoGroupAccount = new GroupAccount_ADO(); //GroupAccounts are returned as an ADO result ADO_readerOutput result = adoGroupAccount.Read(Ado, DTO); if (!result.hasData) { return(false); } else { ActiveDirectory_ADO adAdo = new Security.ActiveDirectory_ADO(); adAdo.MergeAdToUsers(ref result); } Response.data = result.data; return(true); }
/// <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); }