/// <summary> /// Gets the PERMISIONS of a user, for all subviews of a view /// That method makes two things: /// 1. Calls CmpSecurityDB::GetPermissionsByUser to get all registers in USR_PERMISSIONS /// (for the specified user and view). /// 2. Get all subviews of the view, and foreach subview that IS not in the USR_PERMISSIONS /// table, adds it to the DataTable returned with null value /// The DataTable returned has ALWAYS, ALL the subviews of the specified view. /// </summary> /// <param name="user">ID of the User (USERS.USR_ID)</param> /// <param name="view">ID of the view (VIEWS.VIE_ID)</param> /// <returns>DataTable with permisions (exe, del, upd, ins)</returns> public static DataTable GetPermissionsByUser(int user, int view) { CmpSecurityDB csdb = new CmpSecurityDB(); CmpViewsElementsDB cvedb = new CmpViewsElementsDB(); // Step 1: Get data of USR_PERMISSIONS DataTable dtUserPermissions = csdb.GetPermissionsByUser(user, view); // Step 2: Get all subviews of a view DataTable dtSubViews = cvedb.GetData(new string[] { "VELE_VIE_ID", "VELE_ELEMENTNUMBER, VELE_DESCSHORT" }, "VELE_VIE_ID = @VIEWS_ELEMENTS.VELE_VIE_ID@", null, new object[] { view }); // Step 3: Merge the results... // Foreach subview search it in the table of permissioins and if does not appear // insert a new row with null ('not set' values). foreach (DataRow dr in dtSubViews.Rows) { DataRow[] selectResult = dtUserPermissions.Select("UPER_VELE_ELEMENTNUMBER = " + dr["VELE_ELEMENTNUMBER"]); if (selectResult == null || selectResult.Length == 0) { DataRow nrow = dtUserPermissions.NewRow(); nrow["UPER_USR_ID"] = user; nrow["VELE_DESCSHORT"] = dr["VELE_DESCSHORT"]; nrow["UPER_VELE_VIE_ID"] = view; nrow["UPER_VELE_ELEMENTNUMBER"] = dr["VELE_ELEMENTNUMBER"]; nrow["UPER_INSALLOWED"] = DBNull.Value; nrow["UPER_DELALLOWED"] = DBNull.Value; nrow["UPER_UPDALLOWED"] = DBNull.Value; nrow["UPER_EXEALLOWED"] = DBNull.Value; dtUserPermissions.Rows.Add(nrow); } } // don't accept changes because we want that rows to be with 'added' state // so it will be included in the table when user saves return(dtUserPermissions); }
/// <summary> /// Returns a DataSet with 2 tables containing /// Table 1: All views and roles associated to them /// Table 2: All roles /// </summary> /// <returns></returns> public static DataSet ViewsAssignedToRoles() { CmpSecurityDB cmpSec = new CmpSecurityDB(); DataSet ds = new DataSet(); // Adds a table with relations between roles and views DataTable dt = cmpSec.GetViewsAssignedToRoles(); ds.Tables.Add(dt); // Adds a table with all roles CmpRolesDB cmpRol = new CmpRolesDB(); dt = cmpRol.GetData(); ds.Tables.Add(dt); ds.Relations.Add("RolViews", ds.Tables["ROLES"].Columns["ROL_ID"], ds.Tables["ViewsAllowed"].Columns["RACC_ROL_ID"]); return(ds); }
/// <summary> /// Gets all views allowed by a specified user /// Note: A view is allowed to a user if and only if: /// 1. USR_ACCESS.UACC_ALLOWED is 1 for the view and user /// OR /// 2a. USR_ACCESS.UACC_ALLOWED is null for the view and user /// AND /// 2b. ROL_ACCESS.RACC_ALLOWED is 1 for the view and user's role /// </summary> /// <param name="userid">Id of the user</param> /// <returns>DataTable with ONLY one column (VIE_ID) with all views allowed by the user</returns> public static DataTable GetViewsAllowedByUser(int userid) { CmpSecurityDB cdb = new CmpSecurityDB(); CmpUsuarioDB udb = new CmpUsuarioDB(); // STEP 1: Get the role of the user int roleid = udb.GetUserRole(userid); // STEP 2: Get all the views associated by the role DataTable dtViewsByRole = cdb.GetViewsByRole(roleid); // STEP 3: Get all views associated by the user DataTable dtViewsAllowedByUser = cdb.GetViewsByUser(userid, true); // STEP 4: Get all views denied by the user DataTable dtViewsDeniedByUser = cdb.GetViewsByUser(userid, false); // STEP 5: Join all the current info in a new DataTable and return it... DataTable dtRet = new DataTable("ViewsByUser"); dtRet.Columns.Add(new DataColumn("VIE_ID", Type.GetType("System.Int32"))); dtRet.Columns.Add(new DataColumn("VIE_LIT_ID", Type.GetType("System.Int32"))); // 5.1 All views allowed by user are allowed foreach (DataRow dr in dtViewsAllowedByUser.Rows) { DataRow nrow = dtRet.NewRow(); nrow["VIE_ID"] = dr["UACC_VIE_ID"]; nrow["VIE_LIT_ID"] = dr["VIE_LIT_ID"]; dtRet.Rows.Add(nrow); } // 5.2 All views allowed by role AND not denied by user are also added foreach (DataRow dr in dtViewsByRole.Rows) { string vieid = dr["RACC_VIE_ID"].ToString(); DataRow[] draSelected = dtViewsDeniedByUser.Select("UACC_VIE_ID = " + vieid); if (draSelected != null && draSelected.Length > 0) { // 5.2.1 The view was not denied by the user... DataRow[] draSelected2 = dtRet.Select("VIE_ID = " + vieid); if (draSelected2 != null && draSelected2.Length > 0) { // 5.2.2 ... and was not previously added in dtRet, so we can add it DataRow nrow = dtRet.NewRow(); nrow["VIE_ID"] = dr["RACC_VIE_ID"]; nrow["VIE_LIT_ID"] = dr["VIE_LIT_ID"]; dtRet.Rows.Add(nrow); } } } dtRet.AcceptChanges(); return(dtRet); }
private void BuildUserMenu() { _usrMenu = new MenuInfo(); DataTable t = new CmpSecurityDB().GetMenuByRoleUser(_rolId, _usrId); foreach (DataRow dr in t.Rows) { MenuInfo.ModuleItem item = new MenuInfo.ModuleItem(); item.ViewLitId = Convert.ToInt32(dr["VIE_LIT_ID"]); item.ViewUrl = dr["VIE_URL"].ToString(); item.VieId = Convert.ToInt32(dr["VIE_ID"]); item.ModOrderId = Convert.ToInt32(dr["MOD_ORDER"]); item.ItemOrderId = Convert.ToInt32(dr["VMOD_ORDER"]); item.ViewImage = dr["VIE_IMAGE"] != DBNull.Value ? dr["VIE_IMAGE"].ToString() : null; // We don't use mod image to build menu //string smodimg = dr["MOD_IMAGE"] != DBNull.Value ? dr["MOD_IMAGE"].ToString() : null; // Items don't have icon now. //_usrMenu.AddItem (dr["MOD_DESCSHORT"].ToString(), smodimg,Convert.ToInt32(dr["MOD_LIT_ID"]),item); _usrMenu.AddItem(dr["MOD_DESCSHORT"].ToString(), "", Convert.ToInt32(dr["MOD_LIT_ID"]), item); } }