/// <summary> /// Handles the Load event of the AdminPage control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void AdminPageLoad([NotNull] object sender, [NotNull] EventArgs e) { if (!this.IsPostBack) { this.CreatePageLinks(); } // not admins are forbidden if (!this.PageContext.IsAdmin) { YafBuildLink.AccessDenied(); } // host admins are not checked if (this.PageContext.IsHostAdmin) { return; } // Load the page access list. var dt = LegacyDb.adminpageaccess_list( this.PageContext.PageUserID, this.PageContext.ForumPageType.ToString().ToLowerInvariant()); // Check access rights to the page. if (!this.PageContext.ForumPageType.ToString().IsSet() || dt == null || dt.Rows.Count <= 0) { YafBuildLink.RedirectInfoPage(InfoMessage.HostAdminPermissionsAreRequired); } }
/* Methods */ /// <summary> /// The bind data. /// </summary> private void BindData() { bool found = false; if (this.Request.QueryString.GetFirstOrDefault("u") != null) { // Load the page access list. DataTable dt = LegacyDb.adminpageaccess_list( this.Request.QueryString.GetFirstOrDefault("u"), null); // Get admin pages by page prefixes. var listPages = Enum.GetNames(typeof(ForumPages)).Where( e => e.IndexOf("admin_", System.StringComparison.Ordinal) >= 0); // Initialize list with a helper class. var adminPageAccesses = new List <AdminPageAccess>(); // Protected hostadmin pages var hostPages = new[] { "admin_boards", "admin_hostsettings", "admin_pageaccesslist", "admin_pageaccessedit", "admin_eventloggroups", "admin_eventloggroupaccess" }; // Iterate thru all admin pages foreach (var listPage in listPages.ToList()) { if (dt != null && dt.Rows.Cast <DataRow>().Any(dr => dr["PageName"].ToString() == listPage && hostPages.All(s => s != dr["PageName"].ToString()))) { found = true; adminPageAccesses.Add(new AdminPageAccess { UserId = this.Request.QueryString.GetFirstOrDefault("u").ToType <int>(), PageName = listPage, ReadAccess = true }); } // If it doesn't contain page for the user add it. if (!found && hostPages.All(s => s != listPage)) { adminPageAccesses.Add(new AdminPageAccess { UserId = this.Request.QueryString.GetFirstOrDefault("u").ToType <int>(), PageName = listPage, ReadAccess = false }); } // Reset flag in the end of the outer loop found = false; } this.UserName.Text = this.HtmlEncode(this.Get <IUserDisplayName>().GetName(this.Request.QueryString.GetFirstOrDefault("u").ToType <int>())); // get admin pages list with access flags. this.AccessList.DataSource = adminPageAccesses.AsEnumerable(); } this.DataBind(); }
/// <summary> /// Render the Admin Menu Items /// </summary> /// <param name="writer"> /// The writer. /// </param> private void RenderAccordian([NotNull] HtmlTextWriter writer) { bool show = false; IEnumerable <DataRow> dt = !this.PageContext.IsHostAdmin ? LegacyDb.adminpageaccess_list(this.PageContext.PageUserID, null).AsEnumerable().ToList() : null; // build menu... foreach (var value in this.GetMenuSections()) { // add items.. No items in menu - continue if (!value.YafMenuItem.Any()) { show = false; continue; } // add items.. No items in menu - continue if ((dt == null || !dt.Any()) && !this.PageContext.IsHostAdmin) { show = false; continue; } // Check access rights to the page. Double check will be next to hide categories. if (!this.PageContext.IsHostAdmin) { if (value.YafMenuItem.Any(va => dt.Any() && va.ForumPage.IsSet() && dt.Any(row => va.ForumPage == row["PageName"].ToString()))) { show = true; } } // If a candidate entry was found ar this is a host admin if (show || this.PageContext.IsHostAdmin) { IEnumerable <YafMenuYafMenuSectionYafMenuItem> g; // no need to check access rights for host admin if (this.PageContext.IsHostAdmin) { g = value.YafMenuItem; } else { g = value.YafMenuItem.Where(va => dt.Any(row => dt.Any() && va.ForumPage.IsSet() && va.ForumPage == row["PageName"].ToString())); } var ret = (this.BuildUrlList(g)); if (!ret.IsSet()) { continue; } writer.WriteLine(@"<h3><a href=""#"">{0}</a></h3>".FormatWith(this.GetText("ADMINMENU", value.Tag))); writer.WriteLine(ret); } show = false; } }
/// <summary> /// Render the Admin Menu Items /// </summary> /// <param name="writer"> /// The writer. /// </param> private void RenderAccordian([NotNull] HtmlTextWriter writer) { var show = false; IEnumerable <DataRow> dt = !this.PageContext.IsHostAdmin ? LegacyDb.adminpageaccess_list(this.PageContext.PageUserID, null) .AsEnumerable() .ToList() : null; // build menu... foreach (var value in this.GetMenuSections()) { // add items.. No items in menu - continue if (!value.YafMenuItem.Any()) { show = false; continue; } // add items.. No items in menu - continue if ((dt == null || !dt.Any()) && !this.PageContext.IsHostAdmin) { show = false; continue; } // Check access rights to the page. Double check will be next to hide categories. if (!this.PageContext.IsHostAdmin) { if ( value.YafMenuItem.Any( va => dt.Any() && va.ForumPage.IsSet() && dt.Any(row => va.ForumPage == row["PageName"].ToString()))) { show = true; } } // If a candidate entry was found ar this is a host admin if (show || this.PageContext.IsHostAdmin) { IEnumerable <YafMenuYafMenuSectionYafMenuItem> g; // no need to check access rights for host admin if (this.PageContext.IsHostAdmin) { g = value.YafMenuItem; } else { g = value.YafMenuItem.Where( va => dt.Any( row => dt.Any() && va.ForumPage.IsSet() && va.ForumPage == row["PageName"].ToString())); } // Highlight the Current Page bool highlightPage; var ret = this.BuildUrlList(out highlightPage, g, value.Tag); if (!ret.IsSet()) { continue; } var activeClass = string.Empty; if (highlightPage) { activeClass = " class=\"active\""; } writer.WriteLine( @"<li{3}><a aria-expanded=""{4}"" href=""#{2}""{3}><i class=""fa fa-{1} fa-fw""></i> {0}<span class=""fa arrow""></span></a>" .FormatWith( this.GetText("ADMINMENU", value.Tag), value.Icon, value.Tag, activeClass, highlightPage.ToString().ToLower())); writer.WriteLine(ret); } show = false; } }