private IEnumerable <WebsiteNode> GetSiteNodes() { var siteNodes = new List <WebsiteNode>(); using (var cref = this.UmbracoContext.EnsureUmbracoContext()) { try { var cache = cref.UmbracoContext.Content; var sites = cache.GetAtRoot().Where(x => x.ContentType.Alias == "website"); foreach (var site in sites) { var siteNode = new WebsiteNode { WebsiteId = site.Id, WebsiteName = site.Name }; siteNodes.Add(siteNode); } } catch (Exception e) { siteNodes = new List <WebsiteNode>(); } } return(siteNodes); }
private static WebFileNode LookupFileByUrlPath(WebsiteNode website, string urlPath, ContextLanguageInfo languageContext, Func <WebFileNode, bool> predicate) { if (website.Id == Guid.Empty) { throw new NullReferenceException(string.Format("Unable to retrieve the Id of the website. {0}", "Lookup failed.")); } var urlWithoutWebsitePath = HttpUtility.UrlDecode(urlPath.TrimEnd('/')); string parentPath; string thisPath; if (ParseParentPath(urlWithoutWebsitePath, out parentPath, out thisPath)) { // Find the language-root web page because that's what web files hang off from. var parentFilterResult = LookupPageByUrlPath(website, parentPath, WebPageLookupOptions.RootOnly, languageContext); if (parentFilterResult.Node != null) { var file = parentFilterResult.Node.WebFiles.FirstOrDefault(f => predicate(f) && string.Equals(f.PartialUrl, thisPath, StringComparison.InvariantCultureIgnoreCase)); if (file != null) { ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, "LookupFILEByUrlPath Found"); return(file); } } } ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, "LookupFILEByUrlPath NULL"); return(null); }
private bool HasAdminPrivileges() { var contentMap = AdxstudioCrmConfigurationManager.CreateContentMapProvider(); var webSiteEntity = PortalContext.Current.Website; if (webSiteEntity == null) { return(false); } WebsiteNode webSite = null; contentMap.Using(map => map.TryGetValue(webSiteEntity, out webSite)); if (webSite == null) { return(false); } // Get names of current user roles var roleNames = Roles.GetRolesForUser(); // Select these role nodes var userRoles = webSite.WebRoles.Where(role => roleNames.Contains(role.Name)); // Select web site access permissions var permissions = userRoles.SelectMany(role => role.WebsiteAccesses); // Check if there is permission with all options active var hasAcccess = permissions.Any(p => p.ManageContentSnippets.Value && p.ManageSiteMarkers.Value && p.ManageWebLinkSets.Value && p.PreviewUnpublishedEntities.Value); return(hasAcccess); }
/// <summary> The belongs to website. </summary> /// <param name="website"> The website. </param> /// <param name="webRole"> The web role. </param> /// <returns> The <see cref="bool"/>. </returns> private static bool BelongsToWebsite(WebsiteNode website, WebRoleNode webRole) { if (website == null || webRole == null || webRole.Website == null) { return(false); } return(website.Id == webRole.Website.Id); }
public string GetPortalContextPath(ContentMap contentMap, WebsiteNode website, string path) { if (contentMap == null || website == null || path == null) { return(null); } var pathCache = HttpContext.Current != null ? HttpContext.Current.Items : null; var applicationPath = GetApplicationPathForSiteMarker(contentMap, website, pathCache); return(GetPortalContextPath(path, applicationPath)); }
public static WebFileNode LookupFileByUrlPath(WebsiteNode website, string urlPath, ContextLanguageInfo languageContext) { CrmEntityInactiveInfo inactiveInfo; var filter = CrmEntityInactiveInfo.TryGetInfo("adx_webfile", out inactiveInfo) ? file => !inactiveInfo.IsInactive(file.ToEntity()) : new Func <WebFileNode, bool>(entity => true); var result = LookupFileByUrlPath(website, urlPath, languageContext, filter); return(result); }
private bool TryAssertRightProperty(WebsiteNode site, Func <WebsiteAccessNode, bool?> selectFlag) { // If Roles are not enabled on the site, deny permission. if (!Roles.Enabled) { ADXTrace.Instance.TraceError(TraceCategory.Application, "Roles are not enabled for this application.Permission denied."); return(false); } var userRoles = this.GetUserRoles(); if (!userRoles.Any()) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, "No roles were found for the current user. Permission denied."); return(false); } var rules = site.WebsiteAccesses; // If no access permissions are defined for this site, deny permission. if (rules == null || !rules.Any()) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, "No website access permission rules were found for the current website. Permission denied."); return(false); } foreach (var rule in rules) { var ruleRoles = rule.WebRoles; if (ruleRoles == null) { continue; } var ruleRoleNames = ruleRoles.Select(role => role.Name); var roleIntersection = ruleRoleNames.Intersect(userRoles, StringComparer.InvariantCulture); // If the user is in any of the roles associated with the permission rule, and // the rightsPredicate evaluates to true for the given rule, grant permission. if (roleIntersection.Any() && selectFlag(rule).GetValueOrDefault()) { return(true); } } // If no permission rules meet the necessary conditions, deny permission. return(false); }
/// <summary> /// /// </summary> /// <param name="website"></param> /// <param name="urlPath"></param> /// <param name="getRootWebPage">Whether to get the Root version of a group of translated web pages where adx_isroot = true. /// This should only be set to true in specific cases where we are explicitly looking for the non-translated root page, /// ex: we're looking for a web file which only hangs off from root web pages, or the provided urlPath is from a SiteMapNode which is not language-aware so the url will be the root's. /// This does NOT refer to the website root "/" (aka Home) web page.</param> /// <returns></returns> public static UrlMappingResult <WebPageNode> LookupPageByUrlPath(WebsiteNode website, string urlPath, WebPageLookupOptions lookupOption, ContextLanguageInfo languageContext) { var applicationPath = UrlMapping.GetApplicationPath(urlPath); CrmEntityInactiveInfo inactiveInfo; var filter = CrmEntityInactiveInfo.TryGetInfo("adx_webpage", out inactiveInfo) ? page => !inactiveInfo.IsInactive(page.ToEntity()) : new Func <WebPageNode, bool>(entity => true); var result = LookupPageByUrlPath(website, applicationPath.PartialPath, lookupOption, languageContext, filter); return(result); }
protected CrmSiteMapNode GetNotFoundNode(ContentMap map, WebsiteNode site, IContentMapEntityUrlProvider urlProvider) { var notFoundPage = site.SiteMarkers.FirstOrDefault(sm => sm.Name == NotFoundPageSiteMarkerName); if (notFoundPage == null || notFoundPage.WebPage == null || notFoundPage.WebPage.IsReference) { return(null); } var languageInfo = HttpContext.Current.GetContextLanguageInfo(); var path = HttpContext.Current.Request.Path; var notFoundNode = languageInfo.FindLanguageSpecificWebPageNode(notFoundPage.WebPage, true); var isLanguageEnabled = languageInfo.IsCrmMultiLanguageEnabled; if (isLanguageEnabled) { var isPublished = languageInfo.ContextLanguage.IsPublished; var language = languageInfo.ContextLanguage.WebsiteLanguageNode.Name; if (isPublished && notFoundNode == null) { var root = this.RootNode as CrmSiteMapNode; if (null != root) { ADXTrace.Instance.TraceWarning(TraceCategory.Application, "Cannot find language specific web page for url"); var id = root.Entity.GetAttributeValue("adx_webpageid"); throw new HttpException((int)HttpStatusCode.NotFound, "Error ID - {0}. The Webpage you are looking for at {1} is not found in the {2} language. To display Page Not Found page localize it in {2} language.".FormatWith(id, path, language)); } } else if (!isPublished && notFoundNode != null) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Language not available for: {0}", language)); var id = notFoundNode.Id; throw new HttpException((int)HttpStatusCode.NotFound, "Error ID – {0} . {1} language is not available. Please ensure it is in published status.".FormatWith(id, language)); } else if (!isPublished) { throw new HttpException((int)HttpStatusCode.NotFound, "Not Found."); } } return(GetNode(map, notFoundNode, HttpStatusCode.NotFound, urlProvider)); }
public void HomeSiteMarkerNotFound(WebsiteNode website) { if (website == null) { return; } HomeSiteMarkerNotFound( website.Name, website.Id, this.PortalUrl, this.PortalVersion, this.ProductionOrTrial, this.SessionId, this.ElapsedTime()); MdmMetrics.CmsHomeSiteMarkerNotFoundMetric.LogValue(1); }
private bool TryGetWebsite(ContentMap map, out WebsiteNode site, out IContentMapEntityUrlProvider urlProvider) { urlProvider = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName).GetDependency <IContentMapEntityUrlProvider>(); if (urlProvider == null) { site = null; return(false); } var portal = PortalContext; var website = portal.Website; if (!map.TryGetValue(website, out site)) { return(false); } return(true); }
private IIndex CreateWebsiteResourceIndex(WebsiteNode site) { var fields = new FieldDefinitionCollection(); fields.AddOrUpdate(new FieldDefinition("lat", FieldDefinitionTypes.Double)); fields.AddOrUpdate(new FieldDefinition("lon", FieldDefinitionTypes.Double)); var index = new UmbracoContentIndex( Constants.Examine.ResourceIndexName + "-" + site.WebsiteName, this.CreateFileSystemLuceneDirectory(Constants.Examine.ResourceDirectory + "-" + site.WebsiteName), fields, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), this.ProfilingLogger, this.LanguageService, this.GetPublishedContentValueSetValidator(site.WebsiteId)); return(index); }
/// <summary> /// Setup Culture for localization and globalization of the application. /// </summary> /// <param name="website"></param> /// <param name="legacyWebsiteLcid">CrmWebsite.Language value, for backwards compatibility with legacy pre-Multi-Language CRM environments.</param> /// <param name="bundles"></param> /// <param name="registerAction"></param> private static void UseLocalizedBundles(Entity website, int legacyWebsiteLcid, IContentMapProvider contentMapProvider, BundleCollection bundles, Action <BundleCollection, CultureInfo> registerAction) { // For backward compatibility with pre-Multi-Language CRM environments. // At this point in code execution, PortalContext is not available yet, so check for existance of adx_defaultlanguage field to determine if this is legacy environment or not. if (!ContextLanguageInfo.IsCrmMultiLanguageEnabledInWebsite(website)) { if (legacyWebsiteLcid != 0) { CultureInfo culture = new CultureInfo(legacyWebsiteLcid); CultureInfo.DefaultThreadCurrentCulture = culture; CultureInfo.DefaultThreadCurrentUICulture = culture; registerAction(bundles, culture); } return; } // Note: for environments WITH multi-language, the CurrentCulture will be set by ContextLanguageInfo.BuildContextLanguageInfo(...) // Not able to use portal language context so getting language directly // (portal context depends on owin context which is accesible only per request, not on startup) WebsiteNode websiteNode = null; contentMapProvider.Using(contentMap => contentMap.TryGetValue(website, out websiteNode)); if (websiteNode == null) { registerAction(bundles, CultureInfo.CurrentCulture); } foreach (var websiteLanguage in websiteNode.WebsiteLanguages) { var portalLanguage = websiteLanguage.PortalLanguage; var culture = ContextLanguageInfo.GetCulture(portalLanguage.CrmLanguage ?? 0); registerAction(bundles, culture); } }
private ApplicationPath GetApplicationPathForSiteMarker(ContentMap contentMap, WebsiteNode website, IDictionary cache) { return(GetApplicationPathForSiteMarker(cache, () => { var siteMarkerNode = website.SiteMarkers .FirstOrDefault(e => string.Equals(e.Name, SiteMarker, StringComparison.Ordinal)); if (siteMarkerNode == null || siteMarkerNode.WebPage == null || siteMarkerNode.WebPage.IsReference) { return null; } var urlProvider = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName) .GetDependency <IContentMapEntityUrlProvider>(); try { return urlProvider.GetApplicationPath(contentMap, siteMarkerNode.WebPage); } catch (InvalidOperationException) { return null; } })); }
/// <summary> /// /// </summary> /// <param name="website"></param> /// <param name="urlPath"></param> /// <param name="getRootWebPage">Whether to get the Root version of a group of translated web pages where adx_isroot = true. /// This should only be set to true in specific cases where we are explicitly looking for the non-translated root page, /// ex: we're looking for a web file which only hangs off from root web pages. /// This does NOT refer to the root "/" web page (typically Home page).</param> /// <param name="predicate"></param> /// <returns></returns> private static UrlMappingResult <WebPageNode> LookupPageByUrlPath(WebsiteNode website, string urlPath, WebPageLookupOptions lookupOption, ContextLanguageInfo languageContext, Func <WebPageNode, bool> predicate) { if (website.Id == Guid.Empty) { throw new ArgumentException(string.Format("Unable to retrieve the Id of the website. {0}", string.Empty), "website"); } ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, "LookupPageByUrlPath ENTER URL"); var pages = website.WebPages.Where(predicate).ToArray(); // Use _pagePathRegex to extract the right-most path segment (child path), and the remaining left // part of the path (parent path), while enforcing that web page paths must end in a '/'. var pathMatch = UrlMapping._pagePathRegex.Match(urlPath); if (!pathMatch.Success) { // If we don't have a valid path match, still see if there is a page with the entire literal // path as its partial URL. (The previous iteration of this method has this behaviour, so we // maintain it here.) // NOTE: requests for web files (ex: .png, .css) and bad links all come here. var mappingResult = FilterResultsOnLanguage(pages, p => IsPartialUrlMatch(p, urlPath), lookupOption, languageContext); ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, string.Format("LookupPageByUrlPath (1)pathMatch.Fail URL {0}", mappingResult.Node == null ? "NULL" : "Found")); return(mappingResult); } var fullPath = pathMatch.Groups["full"].Value; var parentPath = pathMatch.Groups["parent"].Value; var childPath = pathMatch.Groups["child"].Value; // Check if we can find a page with the exact fullPath match. This may be a web page with a // partial URL that matches the entire path, but in the more common case, it will match the // root URL path "/". var fullPathMatchPageResult = FilterResultsOnLanguage(pages, p => IsPartialUrlMatch(p, fullPath), lookupOption, languageContext); if (fullPathMatchPageResult.Node != null) { ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, "LookupPageByUrlPath (2)fullPathMatchPage "); return(fullPathMatchPageResult); } // If we don't have non-empty parentPath and childPath, lookup fails. if (string.IsNullOrEmpty(parentPath) || string.IsNullOrEmpty(childPath)) { ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, "LookupPageByUrlPath (3)parent/child path null "); return(UrlMappingResult <WebPageNode> .MatchResult(null)); } // Look up the parent page, using the parent path. This will generally recurse until parentPath // is the root path "/", at which point fullPath will match the Home page and the recursion will // unwind. // Look for the "Root" (adx_isroot=true) web page because the parent-child relationships uses the Root web pages, not the translated Content web pages. // (Ignoring uniquence for parent page) var parentPageFilterResult = LookupPageByUrlPath(website, parentPath, WebPageLookupOptions.RootOnly, languageContext, predicate); // If we can't find a parent page, lookup fails. // Ignore IsUnique here, trying to find any possible match. if (parentPageFilterResult.Node == null) { ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, "LookupPageByUrlPath (4)parent page null "); return(parentPageFilterResult); } // Look for a partial URL match for childPath, among the children of the returned parent page. var result = FilterResultsOnLanguage(parentPageFilterResult.Node.WebPages, p => predicate(p) && IsPartialUrlMatch(p, childPath), lookupOption, languageContext); ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, string.Format("LookupPageByUrlPath (5)searchByParent {0}", result.Node == null ? "NULL" : "Found")); return(result); }
internal static string GetPortalContextPath(this RouteCollection routes, ContentMap contentMap, WebsiteNode website, string path) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Start: {0}", path)); var match = routes.OfTypeWithLock <IPortalContextRoute>() .Select(portalContextRoute => portalContextRoute.GetPortalContextPath(contentMap, website, path)) .FirstOrDefault(contextPath => contextPath != null); ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("End: {0}", path)); return(match); }
private static Entity ToWebsite(OrganizationServiceContext context, WebsiteNode node) { var website = node.AttachTo(context); return(website); }
private void LoadTree_Websites(string parentId, TreeNodeCollection parentNodeCollection) { // returns a reader with 4 fields: Title, Description, Id, HasChildren, HasChildLists using (System.Data.IDataReader oReader = _ExecContext.SPDatabase.GetWebsites(parentId)) { while (oReader.Read()) { string sTitle = oReader["Title"].ToString(); if (sTitle == null || sTitle.TrimEnd().Length == 0) sTitle = "(no title)"; string sUrl = oReader["FullUrl"].ToString(); string sId = oReader["Id"].ToString(); string sDesc = oReader["Description"].ToString(); if (parentId != null && parentId.Length > 0) sUrl = sUrl.Substring(sUrl.LastIndexOf("/")+1); WebsiteNode oNode = new WebsiteNode("/" + sUrl, sId, sTitle + "\r\n" + sDesc); parentNodeCollection.Add(oNode); if (Convert.ToBoolean(oReader["HasChildren"]) || Convert.ToBoolean(oReader["HasChildLists"])) oNode.Nodes.Add(new TreeNode("...")); } } }