private static void AddCustomPagesToMenu(FirmaSession currentFirmaSession, FirmaMenuItem menuType, LtInfoMenuItem topLevelMenu, string menuGroupName) { MultiTenantHelpers.GetCustomPages(menuType).ForEach(x => { var isVisible = new CustomPageViewFeature().HasPermission(currentFirmaSession, x).HasPermission; if (isVisible) { // var customPageUrl = null; switch (menuType.ToEnum) { case FirmaMenuItemEnum.About: topLevelMenu.AddMenuItem(LtInfoMenuItem.MakeItem(new SitkaRoute <CustomPageController>(c => c.About(x.CustomPageVanityUrl)), currentFirmaSession, x.CustomPageDisplayName, menuGroupName)); break; case FirmaMenuItemEnum.Projects: topLevelMenu.AddMenuItem(LtInfoMenuItem.MakeItem(new SitkaRoute <CustomPageController>(c => c.Project(x.CustomPageVanityUrl)), currentFirmaSession, x.CustomPageDisplayName, menuGroupName)); break; case FirmaMenuItemEnum.ProgramInfo: topLevelMenu.AddMenuItem(LtInfoMenuItem.MakeItem(new SitkaRoute <CustomPageController>(c => c.ProgramInfo(x.CustomPageVanityUrl)), currentFirmaSession, x.CustomPageDisplayName, menuGroupName)); break; case FirmaMenuItemEnum.Results: topLevelMenu.AddMenuItem(LtInfoMenuItem.MakeItem(new SitkaRoute <CustomPageController>(c => c.Results(x.CustomPageVanityUrl)), currentFirmaSession, x.CustomPageDisplayName, menuGroupName)); break; default: topLevelMenu.AddMenuItem(LtInfoMenuItem.MakeItem(new SitkaRoute <CustomPageController>(c => c.About(x.CustomPageVanityUrl)), currentFirmaSession, x.CustomPageDisplayName, menuGroupName)); break; } } }); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var validationResults = new List <ValidationResult>(); var existingCustomPages = MultiTenantHelpers.GetCustomPages(); if (!CustomPageModelExtensions.IsDisplayNameUnique(existingCustomPages, CustomPageDisplayName, CustomPageID)) { validationResults.Add(new SitkaValidationResult <EditViewModel, string>("Custom Page with the provided Display Name already exists.", x => x.CustomPageDisplayName)); } if (!string.IsNullOrWhiteSpace(CustomPageVanityUrl)) { if (!new Regex("^[a-zA-Z0-9]*$").IsMatch(CustomPageVanityUrl)) { validationResults.Add(new SitkaValidationResult <EditViewModel, string>("Vanity Url must not contain any special characters or spaces.", x => x.CustomPageVanityUrl)); } else if (!CustomPageModelExtensions.IsVanityUrlUnique(existingCustomPages, CustomPageVanityUrl, CustomPageID)) { validationResults.Add(new SitkaValidationResult <EditViewModel, string>("An Custom Page with the provided Vanity Url already exists.", x => x.CustomPageVanityUrl)); } } return(validationResults); }
public ActionResult ViewCustomPage(string route, string vanityUrl) { var customPage = MultiTenantHelpers.GetCustomPages() .SingleOrDefault(x => string.Equals(x.CustomPageVanityUrl, vanityUrl, StringComparison.OrdinalIgnoreCase)); if (vanityUrl.IsEmpty() || customPage == null) { // Search engines sometimes have stale routes; we re-map for them. // (This is really fairly coddled, but it could benefit humans too, theoretically.) string remappedVanityUrl = null; switch (vanityUrl) { case "MeetingsAndNotes": remappedVanityUrl = "MeetingNotes"; break; case "AboutClackamasPartnership": remappedVanityUrl = "About"; break; } // If we found a remapping, redirect permanently to it if (remappedVanityUrl != null) { return(RedirectToAction(new SitkaRoute <CustomPageController>(x => x.ViewCustomPage(route, remappedVanityUrl)))); } // Otherwise, we just redirect to the site's main page, and put up a warning in case this was actually a human doing the navigation. SetWarningForDisplay($"Could not find vanity URL /{route}: \"{vanityUrl}\""); return(RedirectToAction(new SitkaRoute <HomeController>(x => x.Index()))); // Since we either return the requested vanity URL, OR redirect to SOMETHING, search engines should // stop bashing their heads eventually here. } new CustomPageViewFeature().DemandPermission(CurrentFirmaSession, customPage); var hasPermission = new CustomPageManageFeature().HasPermission(CurrentFirmaSession, customPage).HasPermission; var viewData = new DisplayPageContentViewData(CurrentFirmaSession, customPage, hasPermission); return(RazorView <DisplayPageContent, DisplayPageContentViewData>(viewData)); }