/// <summary> /// Gets a list of pages that the user is entitled to view. /// </summary> /// <param name="sessionData">The session data.</param> /// <param name="product">The product.</param> /// <param name="applicationId">State of the application.</param> /// <returns> /// A list of pages that the user is entitled to view. /// </returns> public PageList GetAuthorisedPages(SessionData sessionData, ProductDefinition product, string applicationId) { User user = this.userManager.GetUserById(sessionData.UserId); SecureSession secureSession = new SecureSession(sessionData.DeserializationSource, sessionData.SessionId, user); RoleList roles = this.DataAccess.GetRoleList(); Application app = string.IsNullOrWhiteSpace(applicationId) ? this.CreateApplicationSecure(sessionData, product.Id, false, product.Version).Application : this.GetApplication(applicationId); PageList allPages = product.FormDefinition.Pages; ControlList allControls = allPages.AllControls; List<PageAccess> pagesAccess = this.entitlementProvider.GetPagesAccess(secureSession, app, allPages, roles, product.Version); PageList accessiblePages = new PageList(); bool receiptPageExists = pagesAccess.Any(p => p.Id == 999); foreach (var page in allPages) { if (!receiptPageExists && page.PageType == PageType.Receipt) { accessiblePages.Add(page); } var entitlement = pagesAccess.FirstOrDefault(e => e.Id == page.PageId); if (entitlement != null) { if (entitlement.AccessLevel >= AccessLevel.Read) { accessiblePages.Add(page); } } } List<ControlAccess> controlsAccess = this.entitlementProvider.GetControlsAccess(secureSession, app, accessiblePages.AllControls, roles, product.Version); this.RemoveInaccessibleControls(accessiblePages, controlsAccess); this.FillControlReferences(accessiblePages, allControls); return accessiblePages; }
/// <summary>Finds all internal wikilinks in page text, excluding interwiki /// links, links to sister projects, categories, embedded images and links in /// image descriptions.</summary> /// <returns>Returns the PageList object, in which page titles are the wikilinks, /// found in text.</returns> public PageList GetLinks() { MatchCollection matches = Site.wikiLinkRE.Matches(text); StringCollection exclLinks = new StringCollection(); exclLinks.AddRange(GetInterWikiLinks()); exclLinks.AddRange(GetSisterWikiLinks(true)); string str; int fragmentPosition; PageList pl = new PageList(site); for (int i = 0; i < matches.Count; i++) { str = matches[i].Groups[1].Value; if (str.StartsWith(site.namespaces["6"] + ":", true, site.langCulture) || str.StartsWith(Site.wikiNSpaces["6"] + ":", true, site.langCulture) || str.StartsWith(site.namespaces["14"] + ":", true, site.langCulture) || str.StartsWith(Site.wikiNSpaces["14"] + ":", true, site.langCulture)) continue; str = str.TrimStart(':'); if (exclLinks.Contains(str)) continue; fragmentPosition = str.IndexOf("#"); if (fragmentPosition != -1) str = str.Substring(0, fragmentPosition); pl.Add(new Page(site, str)); } return pl; }
/// <summary> /// Exclude page controls and data for all pages except for the requested page. /// If the requested page has a summary control. All controls data for other pages will be returned (none will be removed). /// </summary> /// <param name="pageId">The page id passed from the client, which holds special meaning.</param> /// <param name="pages">The list of all pages for the form.</param> /// <returns>The page list to use.</returns> /// <remarks> /// When <paramref name="pageId"/> is <see langword="null"/>, then the return value is all <paramref name="pages"/>. /// When <paramref name="pageId"/> is -1, then the return value is the first page in <paramref name="pages"/>. /// Otherwise the return value is the page that with an id matching <paramref name="pageId"/>. /// </remarks> private PageList RemoveUnecessaryControlsData(int? pageId, PageList pages) { Page currentPage = null; currentPage = !pageId.HasValue || pageId.Value == -1 ? pages[0] : pages.FindByPageId(pageId.Value); if (currentPage == null) { return pages; } if (PageHasSummaryControl(currentPage)) { var summaryControl = currentPage.Controls.FindAllRecursive<SummaryControl>().First(); if (!summaryControl.IncludedControls.All) { foreach (var page in pages) { if (page == currentPage) { continue; } var controls = page.Controls.Where(c => summaryControl.IncludedControls.Controls.Contains(c.Name)); page.Controls = new ControlList(controls); } } } else { pages.Clear(); pages.Add(currentPage); } return pages; }