Beispiel #1
0
        public CmsEntityMetadata(OrganizationServiceContext serviceContext, string logicalName)
        {
            if (serviceContext == null)
            {
                throw new ArgumentNullException("serviceContext");
            }

            if (string.IsNullOrWhiteSpace(logicalName))
            {
                throw new ArgumentException("Value can't be null or whitespace.", "logicalName");
            }

            _entityMetadata = new Lazy <EntityMetadata>(() => GetEntityMetadata(serviceContext, logicalName));

            PrimaryIdAttribute     = _entityMetadata.Value.PrimaryIdAttribute;
            _attributeLogicalNames = new HashSet <string>(_entityMetadata.Value.Attributes.Select(a => a.LogicalName));
            _relationships         = new Dictionary <Relationship, CmsEntityRelationshipInfo>();

            foreach (var relationshipMetadata in _entityMetadata.Value.ManyToOneRelationships)
            {
                var relationship = new Relationship(relationshipMetadata.SchemaName)
                {
                    PrimaryEntityRole = relationshipMetadata.ReferencedEntity == relationshipMetadata.ReferencingEntity
                                                ? new EntityRole?(EntityRole.Referencing)
                                                : null
                };

                _relationships[relationship] = new CmsEntityRelationshipInfo(relationship, false, relationshipMetadata.ReferencedEntity, relationshipMetadata.ReferencingEntity);
            }

            foreach (var relationshipMetadata in _entityMetadata.Value.OneToManyRelationships)
            {
                var relationship = new Relationship(relationshipMetadata.SchemaName)
                {
                    PrimaryEntityRole = relationshipMetadata.ReferencedEntity == relationshipMetadata.ReferencingEntity
                                                ? new EntityRole?(EntityRole.Referenced)
                                                : null
                };

                _relationships[relationship] = new CmsEntityRelationshipInfo(relationship, true, relationshipMetadata.ReferencedEntity, relationshipMetadata.ReferencingEntity);
            }

            LogicalName = logicalName;
        }
        protected virtual void AssertRequestEntitySecurity(IPortalContext portal, OrganizationServiceContext serviceContext, Entity entity, ICrmEntitySecurityProvider security, IWebsiteAccessPermissionProvider websiteAccess, CmsEntityRelationshipInfo relationshipInfo)
        {
            if (!entity.ToEntityReference().Equals(portal.Website.ToEntityReference()))
            {
                return;
            }

            var otherEntity = relationshipInfo.IsCollection
                                ? relationshipInfo.ReferencingEntity
                                : relationshipInfo.ReferencedEntity;

            if (string.Equals(otherEntity, "adx_contentsnippet", StringComparison.OrdinalIgnoreCase))
            {
                if (!websiteAccess.TryAssert(serviceContext, WebsiteRight.ManageContentSnippets))
                {
                    throw new CmsEntityServiceException(HttpStatusCode.Forbidden, "Manage Content Snippets permission denied.");
                }

                return;
            }

            if (string.Equals(otherEntity, "adx_sitemarker", StringComparison.OrdinalIgnoreCase))
            {
                if (!websiteAccess.TryAssert(serviceContext, WebsiteRight.ManageSiteMarkers))
                {
                    throw new CmsEntityServiceException(HttpStatusCode.Forbidden, "Manage Site Markers permission denied.");
                }

                return;
            }

            if (string.Equals(otherEntity, "adx_weblinkset", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(otherEntity, "adx_weblink", StringComparison.OrdinalIgnoreCase))
            {
                if (!websiteAccess.TryAssert(serviceContext, WebsiteRight.ManageWebLinkSets))
                {
                    throw new CmsEntityServiceException(HttpStatusCode.Forbidden, "Manage Web Link Sets permission denied.");
                }

                return;
            }

            base.AssertRequestEntitySecurity(portal, serviceContext, entity, security);
        }
Beispiel #3
0
 public bool TryGetRelationshipInfo(Relationship relationship, out CmsEntityRelationshipInfo relationshipInfo)
 {
     return(_relationships.TryGetValue(relationship, out relationshipInfo));
 }