/// <summary> /// Validate the organization access of users according to the role. /// </summary> /// <param name="_ds"></param> /// <returns></returns> private List <int> validateUsers(DataSet _ds) { List <int> users = new List <int>(); MRole role = new MRole(GetCtx(), Util.GetValueOfInt(_ds.Tables[0].Rows[0]["AD_Role_ID"]), null); bool isAllUser = false; // if access all organization if (role.IsAccessAllOrgs()) { isAllUser = true; } // if not access user organization access. if (!isAllUser && !role.IsUseUserOrgAccess()) { if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_Org_ID) FROm AD_Role_OrgAccess WHERE IsActive='Y' AND AD_Role_ID=" + role.GetAD_Role_ID() + " AND AD_Org_ID IN (" + _req.GetAD_Org_ID() + ",0)")) > 0) { isAllUser = true; } else { return(users); } } for (int i = 0; i < _ds.Tables[0].Rows.Count; i++) { if (isAllUser) { users.Add(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_User_ID"])); } else { if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_Org_ID) FROm AD_User_OrgAccess WHERE AD_User_ID=" + Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_User_ID"]) + " AND IsActive='Y' AND AD_Org_ID IN (" + _req.GetAD_Org_ID() + ",0)")) > 0) { users.Add(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["AD_User_ID"])); } } } return(users); }
/// <summary> /// Create New Role /// </summary> /// <param name="Name"></param> /// <param name="userLevel"></param> /// <param name="OrgID"></param> /// <returns></returns> public String AddNewRole(string Name, string userLevel, List <int> OrgID) { string info = ""; string msg; int AD_Role_Table_ID = Convert.ToInt32(DB.ExecuteScalar("SELECT AD_Table_ID FROM AD_Table WHERE TableName='AD_Role'", null, null)); try { string sql = @"SELECT AD_Column_ID,ColumnName, defaultvalue FROM AD_Column WHERE AD_Table_ID =" + AD_Role_Table_ID + @" AND isActive ='Y' AND defaultvalue IS NOT NULL"; DataSet ds = DB.ExecuteDataset(sql); // Get Default Values if (ds == null || ds.Tables[0].Rows.Count == 0) { return(VAdvantage.Utility.Msg.GetMsg(ctx, "DefaultValueNotFound")); } MRole role = new MRole(ctx, 0, null); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) // Setting Default Values { string value = ds.Tables[0].Rows[i]["DefaultValue"].ToString(); if (value.StartsWith("@")) { value = value.Substring(0, value.Length - 1); string columnName = value.Substring(value.IndexOf("@") + 1); value = ctx.GetContext(columnName); // get global context } role.Set_Value(ds.Tables[0].Rows[i]["ColumnName"].ToString(), value); } role.SetIsManual(true); role.SetName(Name); role.SetUserLevel(userLevel); if (role.Save()) { if (OrgID != null) { for (int i = 0; i < OrgID.Count; i++) // Assigning org access to role { MOrg org = new MOrg(ctx, OrgID[i], null); MRoleOrgAccess roles = new MRoleOrgAccess(org, role.GetAD_Role_ID()); roles.SetAD_Client_ID(ctx.GetAD_Client_ID()); roles.SetAD_Org_ID(OrgID[i]); roles.SetIsReadOnly(false); roles.Save(); } } } else { ValueNamePair ppE = VAdvantage.Logging.VLogger.RetrieveError(); if (ppE != null) { msg = ppE.GetValue(); info = ppE.GetName(); } } return(info); } catch (Exception ex) { return(ex.Message); } //rr.Set_Value( }
/// <summary> /// Get Users with Role /// </summary> /// <param name="role">role</param> /// <returns>array of users</returns> public static MUser[] GetWithRole(MRole role) { List <MUser> list = new List <MUser>(); String sql = "SELECT * FROM AD_User u " + "WHERE u.IsActive='Y'" + " AND EXISTS (SELECT * FROM AD_User_Roles ur " + "WHERE ur.AD_User_ID=u.AD_User_ID AND ur.AD_Role_ID=" + role.GetAD_Role_ID() + " AND ur.IsActive='Y')"; try { DataSet ds = DataBase.DB.ExecuteDataset(sql, null, null); if (ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { list.Add(new MUser(role.GetCtx(), dr, null)); } } } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } MUser[] retValue = new MUser[list.Count]; retValue = list.ToArray(); return(retValue); }
/// <summary> /// Create New Role /// </summary> /// <param name="Name"></param> /// <param name="userLevel"></param> /// <param name="OrgID"></param> /// <returns></returns> public bool AddNewRole(string Name, string userLevel, List <int> OrgID) { var retValue = false; int AD_Role_Table_ID = Convert.ToInt32(DB.ExecuteScalar("SELECT AD_Table_ID FROM AD_Table WHERE TableName='AD_Role'", null, null)); try { string sql = @"SELECT AD_Column_ID,ColumnName, defaultvalue FROM AD_Column WHERE AD_Table_ID =" + AD_Role_Table_ID + @" AND isActive ='Y' AND defaultvalue IS NOT NULL"; DataSet ds = DB.ExecuteDataset(sql); // Get Default Values if (ds == null || ds.Tables[0].Rows.Count == 0) { return(false); } MRole role = new MRole(ctx, 0, null); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) // Setting Default Values { string value = ds.Tables[0].Rows[i]["DefaultValue"].ToString(); if (value.StartsWith("@")) { value = value.Substring(0, value.Length - 1); string columnName = value.Substring(value.IndexOf("@") + 1); value = ctx.GetContext(columnName); // get global context } role.Set_Value(ds.Tables[0].Rows[i]["ColumnName"].ToString(), value); } role.SetIsManual(true); role.SetName(Name); role.SetUserLevel(userLevel); if (role.Save()) { if (OrgID != null) { for (int i = 0; i < OrgID.Count; i++) // Assigning org access to role { MOrg org = new MOrg(ctx, OrgID[i], null); MRoleOrgAccess roles = new MRoleOrgAccess(org, role.GetAD_Role_ID()); roles.SetAD_Client_ID(ctx.GetAD_Client_ID()); roles.SetAD_Org_ID(OrgID[i]); roles.SetIsReadOnly(false); roles.Save(); } retValue = true; } else { retValue = true; } } } catch { retValue = false; } //rr.Set_Value( return(retValue); }
/// <summary> /// Role Constructor /// </summary> /// <param name="role">role</param> /// <param name="AD_Org_ID">org</param> public MRoleOrgAccess(MRole role, int AD_Org_ID) : this(role.GetCtx(), 0, role.Get_TrxName()) { SetClientOrg(role.GetAD_Client_ID(), AD_Org_ID); SetAD_Role_ID(role.GetAD_Role_ID()); }