/// <summary> /// Retrieves an entitycollection with all the systemactionright-role combinations currently defined for the role specified /// </summary> /// <param name="roleID">The role which system action rights should be retrieved.</param> /// <returns>filled collection with entities of type RoleSystemActionRightEntity</returns> public static RoleSystemActionRightCollection GetSystemActionRightRolesForRole(int roleID) { RoleSystemActionRightCollection toReturn = new RoleSystemActionRightCollection(); toReturn.GetMulti((RoleSystemActionRightFields.RoleID == roleID)); return(toReturn); }
/// <summary> /// Deletes the given role from the system. /// </summary> /// <param name="roleID">ID of role to delete</param> /// <returns>true if succeeded, false otherwise</returns> public static bool DeleteRole(int roleID) { RoleEntity toDelete = SecurityGuiHelper.GetRole(roleID); if (toDelete == null) { // not found return(false); } Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteRole"); try { // remove the role - forum - action right entities ForumRoleForumActionRightCollection forumRoleActionRights = new ForumRoleForumActionRightCollection(); trans.Add(forumRoleActionRights); forumRoleActionRights.DeleteMulti(ForumRoleForumActionRightFields.RoleID == roleID); // Remove role-audit action entities RoleAuditActionCollection roleAuditActions = new RoleAuditActionCollection(); trans.Add(roleAuditActions); roleAuditActions.DeleteMulti(RoleAuditActionFields.RoleID == roleID); // remove Role - systemright entities RoleSystemActionRightCollection roleSystemRights = new RoleSystemActionRightCollection(); trans.Add(roleSystemRights); roleSystemRights.DeleteMulti(RoleSystemActionRightFields.RoleID == roleID); // remove Role - user entities RoleUserCollection roleUsers = new RoleUserCollection(); trans.Add(roleUsers); roleUsers.DeleteMulti(RoleUserFields.RoleID == roleID); // delete the actual role trans.Add(toDelete); toDelete.Delete(); trans.Commit(); return(true); } catch { // error occured, rollback trans.Rollback(); throw; } finally { trans.Dispose(); } }
private void Page_Load(object sender, System.EventArgs e) { // If the user doesn't have any access rights to management stuff, the user should // be redirected to the default of the global system. if (!SessionAdapter.HasSystemActionRights()) { // doesn't have system rights. redirect. Response.Redirect("../Default.aspx", true); } // Check if the user has the right systemright if (!SessionAdapter.HasSystemActionRight(ActionRights.SecurityManagement)) { // no, redirect to admin default page, since the user HAS access to the admin menu. Response.Redirect("Default.aspx", true); } _roleID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["RoleID"]); if (!Page.IsPostBack) { // get the role and show the description RoleEntity role = SecurityGuiHelper.GetRole(_roleID); if (role != null) { tbxRoleDescription.Text = role.RoleDescription; } // get the system rights ActionRightCollection systemActionRights = SecurityGuiHelper.GetAllSystemActionRights(); cblSystemRights.DataSource = systemActionRights; cblSystemRights.DataTextField = "ActionRightDescription"; cblSystemRights.DataValueField = "ActionRightID"; cblSystemRights.DataBind(); // get the action rights set for this role RoleSystemActionRightCollection systemActionRightRoleCombinations = SecurityGuiHelper.GetSystemActionRightRolesForRole(_roleID); // check the checkboxes in the cblSystemRights list if the value matches a row in the datatable foreach (RoleSystemActionRightEntity currentEntity in systemActionRightRoleCombinations) { cblSystemRights.Items.FindByValue(currentEntity.ActionRightID.ToString()).Selected = true; } } }
/// <summary> /// Modifies the given role: it resets the system action rights for the given role to the given set of action rights and it modifies /// the role description for the given role. If the user specified a role description that is already available, false will be returned to signal /// that the save failed. /// </summary> /// <param name="actionRightIDs">The action rights.</param> /// <param name="roleID">The role ID.</param> /// <param name="roleDescription">The role description.</param> /// <returns>true if succeeded, false otherwise</returns> public static bool ModifyRole(List <int> actionRightIDs, int roleID, string roleDescription) { // read the existing role entity from the database. RoleEntity roleToModify = new RoleEntity(roleID); if (roleToModify.IsNew) { // not found return(false); } // check if the description is different. If so, we've to check if the new roledescription is already present. If so, we'll // abort the save if (roleToModify.RoleDescription != roleDescription) { if (CheckIfRoleDescriptionIsPresent(roleDescription)) { // new description, is already present, fail return(false); } } // all set. We're going to delete all Role - SystemAction Rights combinations first, as we're going to re-insert them later on. // We'll use a transaction to be able to roll back all our changes if something fails. Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "ModifyRole"); try { RoleSystemActionRightCollection roleActionRights = new RoleSystemActionRightCollection(); // add this collection to the transaction so all actions executed through this collection will be inside the transaction trans.Add(roleActionRights); // delete all role-systemactionright combinations directly from the database, by issuing a direct delete on the database, using a filter // on roleid roleActionRights.DeleteMulti(RoleSystemActionRightFields.RoleID == roleID); // add new role-systemactionright entities which we'll save to the database after that foreach (int actionRightID in actionRightIDs) { RoleSystemActionRightEntity toAdd = new RoleSystemActionRightEntity(); toAdd.ActionRightID = actionRightID; toAdd.RoleID = roleID; roleActionRights.Add(toAdd); } // save the new entities to the database roleActionRights.SaveMulti(); // we'll now save the role and the role description, if it's changed. Otherwise the save action will be a no-op. // add it to the transaction trans.Add(roleToModify); roleToModify.RoleDescription = roleDescription; roleToModify.Save(); // all done, commit the transaction trans.Commit(); return(true); } catch { // failed, roll back transaction. trans.Rollback(); throw; } finally { trans.Dispose(); } }
/// <summary> /// Modifies the given role: it resets the system action rights for the given role to the given set of action rights and it modifies /// the role description for the given role. If the user specified a role description that is already available, false will be returned to signal /// that the save failed. /// </summary> /// <param name="actionRightIDs">The action rights.</param> /// <param name="roleID">The role ID.</param> /// <param name="roleDescription">The role description.</param> /// <returns>true if succeeded, false otherwise</returns> public static bool ModifyRole(List<int> actionRightIDs, int roleID, string roleDescription) { // read the existing role entity from the database. RoleEntity roleToModify = new RoleEntity(roleID); if(roleToModify.IsNew) { // not found return false; } // check if the description is different. If so, we've to check if the new roledescription is already present. If so, we'll // abort the save if(roleToModify.RoleDescription != roleDescription) { if(CheckIfRoleDescriptionIsPresent(roleDescription)) { // new description, is already present, fail return false; } } // all set. We're going to delete all Role - SystemAction Rights combinations first, as we're going to re-insert them later on. // We'll use a transaction to be able to roll back all our changes if something fails. Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "ModifyRole"); try { RoleSystemActionRightCollection roleActionRights = new RoleSystemActionRightCollection(); // add this collection to the transaction so all actions executed through this collection will be inside the transaction trans.Add(roleActionRights); // delete all role-systemactionright combinations directly from the database, by issuing a direct delete on the database, using a filter // on roleid roleActionRights.DeleteMulti(RoleSystemActionRightFields.RoleID == roleID); // add new role-systemactionright entities which we'll save to the database after that foreach(int actionRightID in actionRightIDs) { RoleSystemActionRightEntity toAdd = new RoleSystemActionRightEntity(); toAdd.ActionRightID = actionRightID; toAdd.RoleID = roleID; roleActionRights.Add(toAdd); } // save the new entities to the database roleActionRights.SaveMulti(); // we'll now save the role and the role description, if it's changed. Otherwise the save action will be a no-op. // add it to the transaction trans.Add(roleToModify); roleToModify.RoleDescription = roleDescription; roleToModify.Save(); // all done, commit the transaction trans.Commit(); return true; } catch { // failed, roll back transaction. trans.Rollback(); throw; } finally { trans.Dispose(); } }
/// <summary> /// Deletes the given role from the system. /// </summary> /// <param name="roleID">ID of role to delete</param> /// <returns>true if succeeded, false otherwise</returns> public static bool DeleteRole(int roleID) { RoleEntity toDelete = SecurityGuiHelper.GetRole(roleID); if(toDelete == null) { // not found return false; } Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteRole"); try { // remove the role - forum - action right entities ForumRoleForumActionRightCollection forumRoleActionRights = new ForumRoleForumActionRightCollection(); trans.Add(forumRoleActionRights); forumRoleActionRights.DeleteMulti(ForumRoleForumActionRightFields.RoleID == roleID); // Remove role-audit action entities RoleAuditActionCollection roleAuditActions = new RoleAuditActionCollection(); trans.Add(roleAuditActions); roleAuditActions.DeleteMulti(RoleAuditActionFields.RoleID == roleID); // remove Role - systemright entities RoleSystemActionRightCollection roleSystemRights = new RoleSystemActionRightCollection(); trans.Add(roleSystemRights); roleSystemRights.DeleteMulti(RoleSystemActionRightFields.RoleID == roleID); // remove Role - user entities RoleUserCollection roleUsers = new RoleUserCollection(); trans.Add(roleUsers); roleUsers.DeleteMulti(RoleUserFields.RoleID == roleID); // delete the actual role trans.Add(toDelete); toDelete.Delete(); trans.Commit(); return true; } catch { // error occured, rollback trans.Rollback(); throw; } finally { trans.Dispose(); } }