public PageDrop(IPortalLiquidContext portalLiquidContext, IPortalViewEntity viewEntity, SiteMapNodeDrop siteMapNode) : base(portalLiquidContext, viewEntity) { if (siteMapNode == null) { throw new ArgumentNullException("siteMapNode"); } SiteMapNode = siteMapNode; var current = HttpContext.Current; var contextLanguageInfo = portalLiquidContext.ContextLanguageInfo; if (!contextLanguageInfo.IsCrmMultiLanguageEnabled) { this._availableLanguages = new Lazy <LanguageDrop[]>(() => new LanguageDrop[0]); this._languages = new Lazy <LanguageDrop[]>(() => new LanguageDrop[0]); } else { var previewPermission = new PreviewPermission(PortalContext.Current.ServiceContext, PortalContext.Current.Website); if (previewPermission.IsEnabledAndPermitted) { this._availableLanguages = new Lazy <LanguageDrop[]>(() => contextLanguageInfo.GetWebPageWebsiteLanguages(viewEntity.EntityReference, current).Select(websiteLanguage => new LanguageDrop(this, websiteLanguage)).ToArray()); this._languages = new Lazy <LanguageDrop[]>(() => contextLanguageInfo.ActiveWebsiteLanguages.Select(websiteLanguage => new LanguageDrop(this, websiteLanguage)).ToArray()); } else { this._availableLanguages = new Lazy <LanguageDrop[]>(() => contextLanguageInfo.GetWebPageWebsiteLanguages(viewEntity.EntityReference, current).Where(lang => lang.IsPublished).Select(websiteLanguage => new LanguageDrop(this, websiteLanguage)).ToArray()); this._languages = new Lazy <LanguageDrop[]>(() => contextLanguageInfo.ActiveWebsiteLanguages.Where(lang => lang.IsPublished).Select(websiteLanguage => new LanguageDrop(this, websiteLanguage)).ToArray()); } } this._isPageless = new Lazy <bool>(() => CrmSiteMapProvider.IsPageless(current)); }
public override CrmEntitySecurityCacheInfo GetCacheInfo(OrganizationServiceContext context, Entity entity, CrmEntityRight right) { if (entity == null || entity.Id == null) { return(new UncacheableCrmEntitySecurityCacheInfo()); } try { var website = context.GetWebsite(entity); if (website == null) { return(new UncacheableCrmEntitySecurityCacheInfo()); } var previewPermission = new PreviewPermission(context, website); var variedSecurityContextKey = "{0}:preview={1}".FormatWith(SecurityContextKey, previewPermission.IsEnabled); return(new CrmEntitySecurityCacheInfo(entity, right, variedSecurityContextKey)); } catch { return(new UncacheableCrmEntitySecurityCacheInfo()); } }
private static bool UserCanPreview(OrganizationServiceContext context, Entity entity) { var website = context.GetWebsite(entity); if (website == null) { return(false); } var preview = new PreviewPermission(context, website); return(preview.IsEnabledAndPermitted); }
public WebsiteDrop(IPortalLiquidContext portalLiquidContext, IPortalViewEntity viewEntity, IDataAdapterDependencies dependencies) : base(portalLiquidContext, viewEntity) { _dependencies = dependencies; _eventAggregationDataAdapter = new WebsiteEventDataAdapter(_dependencies); _events = new Lazy <EventDrop[]>(() => _eventAggregationDataAdapter.SelectEvents().Select(e => new EventDrop(this, _dependencies, new Event(e))).ToArray(), LazyThreadSafetyMode.None); var blogDependencies = new PortalConfigurationDataAdapterDependencies(); _blogAggregationDataAdapter = new WebsiteBlogAggregationDataAdapter(blogDependencies); var urlProvider = blogDependencies.GetUrlProvider(); var serviceContext = dependencies.GetServiceContext(); _blogs = new Lazy <BlogDrop[]>(() => _blogAggregationDataAdapter.SelectBlogs() .Select(e => new BlogDrop(this, blogDependencies, new Blog(e.Entity, urlProvider.GetApplicationPath(serviceContext, e.Entity)))) .ToArray(), LazyThreadSafetyMode.None); var contextLanguageInfo = portalLiquidContext.ContextLanguageInfo; if (!contextLanguageInfo.IsCrmMultiLanguageEnabled) { this._languages = new Lazy <LanguageDrop[]>(() => new LanguageDrop[0]); // Initialize _languages as an empty collection. } else { var previewPermission = new PreviewPermission(PortalContext.Current.ServiceContext, PortalContext.Current.Website); if (previewPermission.IsEnabledAndPermitted) { this._languages = new Lazy <LanguageDrop[]>(() => contextLanguageInfo.ActiveWebsiteLanguages.Select(websiteLanguage => new LanguageDrop(this, websiteLanguage)).ToArray()); } else { this._languages = new Lazy <LanguageDrop[]>(() => contextLanguageInfo.ActiveWebsiteLanguages.Where(lang => lang.IsPublished).Select(websiteLanguage => new LanguageDrop(this, websiteLanguage)).ToArray()); } this.SelectedLanguage = new LanguageDrop(this, contextLanguageInfo.ContextLanguage); } }
protected virtual void AddEntityMetadata(ICmsEntityEditingMetadataContainer container, EntityReference entityReference, IPortalContext portal, bool addSiteMapNodeMetadata, string portalName = null, string entityDisplayName = null) { if (container == null) { throw new ArgumentNullException("container"); } if (entityReference == null) { throw new ArgumentNullException("entityReference"); } if (portal == null) { throw new ArgumentNullException("portal"); } container.AddLabel(entityDisplayName ?? entityReference.Name); container.AddAttribute("data-xrm-base", VirtualPathUtility.ToAbsolute("~/xrm-adx/")); container.AddAttribute("data-logicalname", entityReference.LogicalName); container.AddAttribute("data-id", entityReference.Id.ToString()); AddRouteServiceReferenceAttribute(container, "data-parentoptions", "CmsParent_GetParentOptions", new { __portalScopeId__ = portal.Website.Id }); container.AddAttribute("data-parentoptions-uritemplate", VirtualPathUtility.ToAbsolute(CmsParentController.GetAppRelativePathTemplate(portal.Website.Id, "LogicalName", "Id"))); portalName = portalName ?? PortalName; var serviceContext = PortalCrmConfigurationManager.CreateServiceContext(portalName); var entity = GetEntity(serviceContext, entityReference); AddEntityTemplateServiceReference(container, portal, entityReference); AddFileBrowserServiceReference(container, portal, FileBrowserDirectoryEntityNames.Contains(entity.LogicalName)); if (entityReference.LogicalName == "adx_weblinkset") { // Output the service reference for the web link set itself. AddEntityServiceReference(container, portal, entityReference, entityDisplayName ?? entity.GetAttributeValue <string>("adx_name")); // Output the service reference for the child web links of the set. AddEntityRelationshipServiceReference(container, portal, entityReference, new Relationship("adx_weblinkset_weblink")); AddEntityRelationshipServiceReference(container, portal, entityReference, new Relationship("adx_weblinkset_weblink"), "xrm-entity-{0}-update-ref"); AddEntityDeleteServiceReferenceTemplate(container, portal, "adx_weblink"); // Output the service reference and schema map for site web pages (required to create new web links). AddEntitySetServiceReference(container, portal, "adx_webpage"); // Output the service reference and schema map for site publishing states (required to create new web links). AddEntitySetServiceReference(container, portal, "adx_publishingstate"); return; } var allEntities = GetEntityDictionary(serviceContext); AddEntityServiceReference(container, portal, entityReference); AddEntityUrlServiceReference(container, portal, entityReference); // If the entity is deletable, add a service reference for delete of the entity. if (DeletableEntityNames.Contains(entityReference.LogicalName)) { AddEntityDeleteServiceReference(container, portal, entityReference); } if (FileAttachmentEntityNames.Contains(entityReference.LogicalName)) { AddEntityFileAttachmentServiceReference(container, portal, entityReference); } // Add the service references on which the creation of various entities are dependent. foreach (var dependencyEntityName in DependencyEntityNames) { AddEntitySetServiceReference(container, portal, dependencyEntityName); } // Add the service reference URI Templates for the notes associated with given entity types. foreach (var fileAttachmentEntity in FileAttachmentEntityNames) { AddEntityFileAttachmentServiceReferenceTemplate(container, portal, fileAttachmentEntity); } // Add the service reference URI Templates for getting URLs for specific entity types. foreach (var urlEntityName in UrlEntityNames.Where(entityName => EntityNameExistsInSchema(entityName, allEntities))) { AddEntityUrlServiceReferenceTemplate(container, portal, urlEntityName); } IEnumerable <Relationship> childRelationships; if (ChildRelationshipsByEntityName.TryGetValue(entityReference.LogicalName, out childRelationships)) { foreach (var relationship in childRelationships.Where(relationship => RelationshipExistsInSchema(relationship, allEntities))) { AddEntityRelationshipServiceReference(container, portal, entityReference, relationship); } } var previewPermission = new PreviewPermission(portal.ServiceContext, portal.Website); if (previewPermission.IsPermitted) { container.AddPreviewPermittedMetadata(); } Relationship parentalRelationship; // Output the URL path of parent entity to the DOM (mostly to be read if the entity is deleted--the user // will then be redirected to the parent). if (ParentalRelationshipsByEntityName.TryGetValue(entityReference.LogicalName, out parentalRelationship)) { var parent = entity.GetRelatedEntity(serviceContext, parentalRelationship); var urlProvider = PortalCrmConfigurationManager.CreateDependencyProvider(portalName).GetDependency <IEntityUrlProvider>(); var parentPath = urlProvider.GetApplicationPath(serviceContext, parent ?? entity); if (parentPath != null) { AddServiceReference(container, parentPath.AbsolutePath, "xrm-adx-entity-parent-url-ref"); } } // Output the sitemarkers of the current web page into the DOM. if (entityReference.LogicalName == "adx_webpage") { foreach (var siteMarker in entity.GetRelatedEntities(serviceContext, "adx_webpage_sitemarker")) { container.AddSiteMarkerMetadata(entityReference.LogicalName, siteMarker.GetAttributeValue <string>("adx_name")); } if (EntityNameExistsInSchema("adx_communityforum", allEntities)) { AddEntitySetServiceReference(container, portal, "adx_communityforum"); } if (EntityNameExistsInSchema("adx_event", allEntities)) { AddEntitySetServiceReference(container, portal, "adx_event"); } if (EntityNameExistsInSchema("adx_entityform", allEntities)) { AddEntitySetServiceReference(container, portal, "adx_entityform"); } if (EntityNameExistsInSchema("adx_entitylist", allEntities)) { AddEntitySetServiceReference(container, portal, "adx_entitylist"); } if (EntityNameExistsInSchema("adx_webform", allEntities)) { AddEntitySetServiceReference(container, portal, "adx_webform"); } if (EntityNameExistsInSchema("adx_weblinkset", allEntities)) { AddEntitySetServiceReference(container, portal, "adx_weblinkset"); } AddEntitySetServiceReference(container, portal, "adx_webpage"); AddEntitySetServiceReference(container, portal, "adx_webfile"); AddPublishingStateSetServiceReference(container, portal); AddPicklistMetadata(container, serviceContext, "adx_webpage", "adx_feedbackpolicy"); AddEntityRelationshipServiceReferenceTemplate(container, portal, "adx_webpage", "adx_webpage_navigation_weblinkset".ToRelationship()); if (entity.GetAttributeValue <EntityReference>("adx_parentpageid") == null && string.Equals(entity.GetAttributeValue <string>("adx_partialurl"), "/", StringComparison.OrdinalIgnoreCase)) { container.AddAttribute("data-root", "true"); } var langContext = HttpContext.Current.GetContextLanguageInfo(); // For multi language portals, add root webpage id to the dom if (langContext.IsCrmMultiLanguageEnabled) { //add language information container.AddAttribute("data-languagename", langContext.ContextLanguage.Name); container.AddAttribute("data-languageid", langContext.ContextLanguage.EntityReference.Id.ToString()); var rootPageReference = portal.Entity.GetAttributeValue <EntityReference>("adx_rootwebpageid"); if (rootPageReference != null) { container.AddAttribute("data-rootwebpageid", rootPageReference.Id.ToString()); } else { ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Root page for current content page is null, id ={0}", entityReference.Id)); } } } if (entityReference.LogicalName == "adx_event") { AddPicklistMetadata(container, serviceContext, "adx_eventschedule", "adx_recurrence"); AddPicklistMetadata(container, serviceContext, "adx_eventschedule", "adx_week"); } if (addSiteMapNodeMetadata && SiteMapChildEntitiesByEntityName.ContainsKey(entityReference.LogicalName)) { container.AddCssClass("xrm-editable-sitemapchildren"); AddEntityChildrenServiceReference(container, portal, entityReference, "xrm-entity-ref-sitemapchildren", GetEntityName(entity)); AddSiteMapNodeMetadata(container, entityReference, portal, portalName); } if (entityReference.LogicalName == "adx_blog" || entityReference.LogicalName == "adx_webpage") { AddPicklistMetadata(container, serviceContext, "adx_blog", "adx_commentpolicy"); } if (entityReference.LogicalName == "adx_blog" || entityReference.LogicalName == "adx_blogpost") { AddPicklistMetadata(container, serviceContext, "adx_blogpost", "adx_commentpolicy"); var tags = GetWebsiteTags(portal, serviceContext); AddTagMetadata(container, "adx_blogpost", tags); } if (entityReference.LogicalName == "adx_communityforumthread") { AddEntitySetServiceReference(container, portal, "adx_forumthreadtype"); var tags = GetWebsiteTags(portal, serviceContext); AddTagMetadata(container, "adx_communityforumthread", tags); } AddPicklistMetadata(container, serviceContext, "adx_webfile", "adx_contentdisposition"); AddEntitySetServiceReference(container, portal, "subject"); }
public override void AddEntityMetadata(string portalName, IEditableCrmEntityControl control, Control container, Entity entity) { if (control == null || container == null || entity == null) { return; } var serviceContext = PortalCrmConfigurationManager.CreateServiceContext(portalName); var portalContext = PortalCrmConfigurationManager.CreatePortalContext(portalName); var metadata = ((RetrieveEntityResponse)serviceContext.Execute(new RetrieveEntityRequest { EntityFilters = EntityFilters.Entity, LogicalName = entity.LogicalName })).EntityMetadata; var refetchedEntity = serviceContext.CreateQuery(entity.LogicalName).FirstOrDefault(e => e.GetAttributeValue <Guid>(metadata.PrimaryIdAttribute) == entity.Id); if (entity.LogicalName == "adx_weblinkset") { // Output the service reference for the web link set itself. AddEntityServiceReference(control, entity, entity.GetAttributeValue <string>("adx_name"), container); // Output the service reference for the child web links of the set. AddEntityAssocationSetServiceReferenceForWebLinkSet(control, entity, "adx_weblinkset_weblink".ToRelationship(), container); AddEntityAssocationSetServiceReference(portalName, control, entity, "adx_weblinkset_weblink".ToRelationship(), container, "xrm-entity-{0}-update-ref"); AddEntitySetSchemaMap(control, "adx_weblink", container); // Output the service reference and schema map for site web pages (required to create new web links). AddEntitySetServiceReference(control, "adx_webpage", container); AddEntitySetSchemaMap(control, "adx_webpage", container); string weblinkDeleteUriTemplate; if (TryGetCrmEntityDeleteDataServiceUriTemplate(control, "adx_weblink", out weblinkDeleteUriTemplate)) { AddServiceReference(control, weblinkDeleteUriTemplate, "xrm-uri-template xrm-entity-adx_weblink-delete-ref", container); } // Output the service reference and schema map for site publishing states (required to create new web links). AddEntitySetServiceReference(control, "adx_publishingstate", container); AddEntitySetSchemaMap(control, "adx_publishingstate", container); } else { string serviceUri; if (!TryGetDataServiceEntityUri(control, entity, out serviceUri)) { return; } // Add the service reference to the bound entity. container.Controls.Add(new HyperLink { CssClass = "xrm-entity-ref", NavigateUrl = VirtualPathUtility.ToAbsolute(serviceUri), Text = string.Empty }); string entityUrlServiceUri; // Add the service reference for getting the URL of the bound entity. if (TryGetCrmEntityUrlDataServiceUri(control, entity, out entityUrlServiceUri)) { AddServiceReference(control, entityUrlServiceUri, "xrm-entity-url-ref", container, "GetEntityUrl"); } var crmEntityName = entity.LogicalName; AddEntitySetSchemaMap(control, crmEntityName, container); // If the entity is "deletable", add a service reference for soft-delete of the entity. if (DeletableEntityNames.Contains(crmEntityName)) { string deleteServiceUri; if (TryGetCrmEntityDeleteDataServiceUri(control, entity, out deleteServiceUri)) { AddServiceReference(control, deleteServiceUri, "xrm-entity-delete-ref", container); } } if (FileAttachmentEntityNames.Contains(crmEntityName)) { string fileAttachmentServiceUri; if (TryGetCrmEntityFileAttachmentDataServiceUri(control, entity, out fileAttachmentServiceUri)) { AddServiceReference(control, fileAttachmentServiceUri, "xrm-entity-attachment-ref", container); } } // Add the service references on which the creation of various entities are dependent. foreach (var dependencyEntityName in DependencyEntityNames) { AddEntitySetServiceReference(control, dependencyEntityName, container); AddEntitySetSchemaMap(control, dependencyEntityName, container); } // Add the service reference URI Templates for the notes associated with given entity types. foreach (var fileAttachmentEntity in FileAttachmentEntityNames) { string uriTemplate; if (TryGetCrmEntityFileAttachmentDataServiceUriTemplate(control, fileAttachmentEntity, out uriTemplate)) { AddServiceReference(control, uriTemplate, "xrm-uri-template xrm-entity-{0}-attachment-ref".FormatWith(fileAttachmentEntity), container); } } // Add the service reference URI Templates for getting URLs for specific entity types. foreach (var urlEntityName in UrlEntityNames) { string uriTemplate; if (TryGetCrmEntityUrlDataServiceUriTemplate(control, urlEntityName, out uriTemplate)) { AddServiceReference(control, uriTemplate, "xrm-uri-template xrm-entity-{0}-url-ref".FormatWith(urlEntityName), container, "GetEntityUrl"); } } IEnumerable <Relationship> childAssociations; if (ChildAssociationsByEntityName.TryGetValue(crmEntityName, out childAssociations)) { foreach (var childAssociation in childAssociations) { AddEntityAssocationSetServiceReference(portalName, control, entity, childAssociation, container); } } Relationship parentalRelationship2; // Output the URL path of parent entity to the DOM (mostly to be read if the entity is deleted--the user // will then be redirected to the parent). if (_parentalRelationshipsByEntityName.TryGetValue(crmEntityName, out parentalRelationship2)) { var parent = refetchedEntity.GetRelatedEntity(serviceContext, parentalRelationship2); var urlProvider = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName).GetDependency <IEntityUrlProvider>(); var parentPath = urlProvider.GetApplicationPath(serviceContext, parent ?? refetchedEntity); if (parentPath != null) { AddServiceReference(control, parentPath.AbsolutePath, "xrm-entity-parent-url-ref", container); } } // Output the sitemarkers of the current web page into the DOM. if (crmEntityName == "adx_webpage") { foreach (var siteMarker in refetchedEntity.GetRelatedEntities(serviceContext, "adx_webpage_sitemarker")) { var siteMarkerRef = new HtmlGenericControl("span"); siteMarkerRef.Attributes["class"] = "xrm-entity-adx_webpage_sitemarker"; siteMarkerRef.Attributes["title"] = siteMarker.GetAttributeValue <string>("adx_name"); container.Controls.Add(siteMarkerRef); } AddEntitySetSchemaMap(control, "adx_webfile", container); EntitySetInfo entitySetInfo; if (OrganizationServiceContextInfo.TryGet(GetCrmDataContextType(), "adx_communityforum", out entitySetInfo)) { AddEntitySetSchemaMap(control, "adx_communityforum", container); AddEntitySetServiceReference(control, "adx_communityforum", container); } if (OrganizationServiceContextInfo.TryGet(GetCrmDataContextType(), "adx_event", out entitySetInfo)) { AddEntitySetSchemaMap(control, "adx_event", container); AddEntitySetServiceReference(control, "adx_event", container); } AddEntitySetSchemaMap(control, "adx_shortcut", container); AddEntitySetServiceReference(control, "adx_webpage", container); AddEntitySetServiceReference(control, "adx_webfile", container); AddPublishingTransitionSetServiceReference(control, container); } if (entity.LogicalName == "adx_event") { AddEntitySetSchemaMap(control, "adx_eventschedule", container); AddPicklistMetadata(serviceContext, control, "adx_eventschedule", "adx_recurrence", container); } } var previewPermission = new PreviewPermission(portalContext.ServiceContext, portalContext.Website); if (previewPermission.IsPermitted) { var previewPermittedMetadata = new HtmlGenericControl("span"); previewPermittedMetadata.Attributes["class"] = "xrm-preview-permitted"; previewPermittedMetadata.Attributes["style"] = "display:none;"; container.Controls.Add(previewPermittedMetadata); } Relationship parentalRelationship; // Output the URL path of parent entity to the DOM (mostly to be read if the entity is deleted--the user // will then be redirected to the parent). if (_parentalRelationshipsByEntityName.TryGetValue(entity.LogicalName, out parentalRelationship)) { var parent = refetchedEntity.GetRelatedEntity(serviceContext, parentalRelationship); var urlProvider = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName).GetDependency <IEntityUrlProvider>(); var parentPath = urlProvider.GetApplicationPath(serviceContext, parent ?? refetchedEntity); if (parentPath != null) { AddServiceReference(control, parentPath.AbsolutePath, "xrm-adx-entity-parent-url-ref", container); } } }