private TabPermissionCollection CreateTabPermissions() { TabPermissionCollection returnCollection = new TabPermissionCollection(); PermissionController pc = new PermissionController(); var viewPermission = pc.GetPermissionByCodeAndKey("SYSTEM_TAB", "VIEW").ToList <PermissionInfo>(); var editPermission = pc.GetPermissionByCodeAndKey("SYSTEM_TAB", "EDIT").ToList <PermissionInfo>(); int adminRoleId = PortalSettings.AdministratorRoleId; TabPermissionInfo objViewPermission = new TabPermissionInfo(viewPermission[0]); objViewPermission.TabID = PortalSettings.ActiveTab.TabID; objViewPermission.RoleID = PortalSettings.AdministratorRoleId; objViewPermission.RoleName = PortalSettings.AdministratorRoleName; objViewPermission.AllowAccess = true; objViewPermission.UserID = Null.NullInteger; objViewPermission.DisplayName = ""; returnCollection.Add(objViewPermission, true); TabPermissionInfo objEditPermission = new TabPermissionInfo(editPermission[0]); objEditPermission.TabID = PortalSettings.ActiveTab.TabID; objEditPermission.RoleID = PortalSettings.AdministratorRoleId; objEditPermission.RoleName = PortalSettings.AdministratorRoleName; objEditPermission.AllowAccess = true; objEditPermission.UserID = Null.NullInteger; objEditPermission.DisplayName = ""; returnCollection.Add(objEditPermission, true); return(returnCollection); }
private string SetPageViewRights(TabInfo oTab, string RoleName) { RoleController oRoleC = new RoleController(); RoleInfo oRole = oRoleC.GetRoleByName(PortalSettings.PortalId, RoleName); if (oRole != null) { TabController oTabC = new TabController(); TabPermissionInfo infPerm = new TabPermissionInfo(); PermissionProvider permProv = new PermissionProvider(); int RoleId = 0; infPerm.AllowAccess = true; infPerm.RoleID = oRole.RoleID; infPerm.RoleName = RoleName; infPerm.TabID = oTab.TabID; infPerm.PermissionID = 3; // View // Change its permissions TabPermissionCollection Perm = oTab.TabPermissions; Perm.Add(infPerm, true); // true if checkForDuplicates // Save the permissions permProv.SaveTabPermissions(oTab); return(string.Format("Page {0}: role {1} View Rights Set <br />", oTab.TabName, RoleName)); } else { return(string.Format("Role {0} does not exist <br />", RoleName)); } }
protected override void AddPermission(PermissionInfo permission, int roleId, string roleName, int userId, string displayName, bool allowAccess) { var objPermission = new TabPermissionInfo(permission); objPermission.TabID = TabID; objPermission.RoleID = roleId; objPermission.RoleName = roleName; objPermission.AllowAccess = allowAccess; objPermission.UserID = userId; objPermission.DisplayName = displayName; _TabPermissions.Add(objPermission, true); //Clear Permission List _PermissionsList = null; }
/// ----------------------------------------------------------------------------- /// <summary> /// Load the ViewState /// </summary> /// <param name="savedState">The saved state</param> /// <history> /// [cnurse] 01/12/2006 Created /// </history> /// ----------------------------------------------------------------------------- protected override void LoadViewState(object savedState) { if (savedState != null) { //Load State from the array of objects that was saved with SaveViewState. var myState = (object[])savedState; //Load Base Controls ViewState if (myState[0] != null) { base.LoadViewState(myState[0]); } //Load TabId if (myState[1] != null) { TabID = Convert.ToInt32(myState[1]); } //Load TabPermissions if (myState[2] != null) { _TabPermissions = new TabPermissionCollection(); string state = Convert.ToString(myState[2]); if (!String.IsNullOrEmpty(state)) { //First Break the String into individual Keys string[] permissionKeys = state.Split(new[] { "##" }, StringSplitOptions.None); foreach (string key in permissionKeys) { string[] Settings = key.Split('|'); _TabPermissions.Add(ParseKeys(Settings)); } } } } }
/// <summary> /// Updates a Permission /// </summary> /// <param name="permission">The permission being updated</param> /// <param name="roleid">The id of the role</param> /// <param name="roleName">The name of the role</param> /// <param name="allowAccess">The value of the permission</param> protected override void UpdatePermission(PermissionInfo permission, int roleid, string roleName, bool allowAccess) { bool isMatch = false; TabPermissionInfo objPermission; int permissionId = permission.PermissionID; //Search TabPermission Collection for the permission to Update foreach (TabPermissionInfo tempLoopVar_objPermission in TabPermissions) { objPermission = tempLoopVar_objPermission; if (objPermission.PermissionID == permissionId && objPermission.RoleID == roleid) { //TabPermission is in collection if (!allowAccess) { //Remove from collection as we only keep AllowAccess permissions TabPermissions.Remove(objPermission); } isMatch = true; break; } } //TabPermission not found so add new if (!isMatch && allowAccess) { objPermission = new TabPermissionInfo(); objPermission.PermissionID = permissionId; objPermission.RoleName = roleName; objPermission.RoleID = roleid; objPermission.AllowAccess = allowAccess; objPermission.TabID = TabID; TabPermissions.Add(objPermission); } }
/// ----------------------------------------------------------------------------- /// <summary> /// Load the ViewState /// </summary> /// <param name="savedState">The saved state</param> /// ----------------------------------------------------------------------------- protected override void LoadViewState(object savedState) { if (savedState != null) { //Load State from the array of objects that was saved with SaveViewState. var myState = (object[])savedState; //Load Base Controls ViewState if (myState[0] != null) { base.LoadViewState(myState[0]); } //Load TabId if (myState[1] != null) { TabID = Convert.ToInt32(myState[1]); } //Load TabPermissions if (myState[2] != null) { _TabPermissions = new TabPermissionCollection(); string state = Convert.ToString(myState[2]); if (!String.IsNullOrEmpty(state)) { //First Break the String into individual Keys string[] permissionKeys = state.Split(new[] { "##" }, StringSplitOptions.None); foreach (string key in permissionKeys) { string[] Settings = key.Split('|'); _TabPermissions.Add(ParseKeys(Settings)); } } } } }