Esempio n. 1
0
        /// <summary>
        /// Determines whether Content Access Level are enabled or not,
        /// by checking entity existence and config's site setting
        /// </summary>
        /// <returns>True if config's site setting exists and is enabled</returns>
        public override bool IsEnabled()
        {
            if (this.calEntityMetadata == null)
            {
                try
                {
                    this.calEntityMetadata = ContentAccessProvider.GetEntityMetadata(this.Portal.ServiceContext, "adx_contentaccesslevel", EntityFilters.Entity);
                }
                catch
                {
                    return(false);
                }
            }

            return(base.IsEnabled());
        }
 /// <summary>
 /// Parameterized constructor for apply product filtering
 /// </summary>
 /// <param name="_contentAccessProvider"></param>
 public CategoryController(ContentAccessProvider _contentAccessProvider)
 {
     this.contentAccessProvider = _contentAccessProvider;
 }
Esempio n. 3
0
        /// <summary>
        /// Modify a fetch and add necessary link entity elements and filter conditions to satisfy record level security trimming based on the relationship definitions.
        /// </summary>
        /// <param name="serviceContext"><see cref="OrganizationServiceContext"/> to use</param>
        /// <param name="relationshipMetadata">Relationship metadata that defines relationship attributes</param>
        /// <param name="linkDetails"><see cref="ContentAccessProvider.LinkDetails"/> to use</param>
        /// <param name="fetch">Fetch to modify</param>
        /// <param name="link">Link to construct</param>
        /// <param name="filter">Filter to construct</param>
        /// <param name="contact">Associated Contact</param>
        /// <param name="account">Associated Account</param>
        /// <param name="addCondition">Construct Account/Contact relationship filter</param>
        /// <param name="linkEntityAliasGenerator">LinkEntityAliasGenerator to track and create Aliases</param>
        private static void BuildLinksAndFilter(OrganizationServiceContext serviceContext, ProductAccessProvider.RelationshipMetadata relationshipMetadata, LinkDetails linkDetails, Fetch fetch, Link link, Filter filter, EntityReference contact, EntityReference account, bool addCondition, LinkEntityAliasGenerator linkEntityAliasGenerator)
        {
            var  alias   = linkEntityAliasGenerator.CreateUniqueAlias(relationshipMetadata.Entity2LogicalName);
            Link newLink = null;


            if (relationshipMetadata.RelationshipType == ProductAccessProvider.RelationshipType.ManyToManyRelationship)
            {
                var    intersectLinkEntityName = relationshipMetadata.IntersectEntityName;
                string linkTargetFromAttribute;
                string linkTargetToAttribute;
                string linkIntersectFromAttribute;
                string linkIntersectToAttribute;
                if (relationshipMetadata.Entity1LogicalName == relationshipMetadata.Entity2LogicalName)
                {
                    linkIntersectFromAttribute = relationshipMetadata.Entity2IntersectAttribute;
                    linkIntersectToAttribute   = relationshipMetadata.Entity1PrimaryIdAttribute;
                    linkTargetFromAttribute    = relationshipMetadata.Entity1PrimaryIdAttribute;
                    linkTargetToAttribute      = relationshipMetadata.Entity1IntersectAttribute;
                }
                else
                {
                    linkIntersectFromAttribute   =
                        linkIntersectToAttribute = relationshipMetadata.Entity1LogicalName == linkDetails.Entity1Name
                            ? relationshipMetadata.Entity1IntersectAttribute
                            : relationshipMetadata.Entity2IntersectAttribute;
                    linkTargetFromAttribute   =
                        linkTargetToAttribute = relationshipMetadata.Entity2LogicalName == linkDetails.Entity2Name
                            ? relationshipMetadata.Entity2IntersectAttribute
                            : relationshipMetadata.Entity1IntersectAttribute;
                }

                newLink = new Link
                {
                    Name          = intersectLinkEntityName,
                    FromAttribute = linkIntersectFromAttribute,
                    ToAttribute   = linkIntersectToAttribute,
                    Intersect     = true,
                    Visible       = false,
                    Type          = JoinOperator.LeftOuter,
                    Links         = new List <Link>
                    {
                        new Link
                        {
                            Name          = relationshipMetadata.Entity2LogicalName,
                            FromAttribute = linkTargetFromAttribute,
                            ToAttribute   = linkTargetToAttribute,
                            Alias         = alias,
                            Type          = JoinOperator.LeftOuter
                        }
                    }
                };
            }
            else if (relationshipMetadata.RelationshipType == ProductAccessProvider.RelationshipType.ManyToOneRelationship)
            {
                var linkFromAttribute = relationshipMetadata.ReferencedEntity == relationshipMetadata.Entity2LogicalName
                    ? relationshipMetadata.ReferencedAttribute
                    : relationshipMetadata.ReferencingAttribute;

                var linkToAttribute = relationshipMetadata.ReferencedEntity == relationshipMetadata.Entity2LogicalName
                    ? relationshipMetadata.ReferencingAttribute
                    : relationshipMetadata.ReferencedAttribute;

                newLink = new Link
                {
                    Name          = relationshipMetadata.Entity2LogicalName,
                    FromAttribute = linkFromAttribute,
                    ToAttribute   = linkToAttribute,
                    Type          = JoinOperator.LeftOuter,
                    Alias         = alias
                };
            }
            else if (relationshipMetadata.RelationshipType == ProductAccessProvider.RelationshipType.OneToManyRelationship)
            {
                var linkFromAttribute = relationshipMetadata.ReferencedEntity == relationshipMetadata.Entity2LogicalName
                    ? relationshipMetadata.ReferencedAttribute
                    : relationshipMetadata.ReferencingAttribute;

                var linkToAttribute = relationshipMetadata.ReferencedEntity == relationshipMetadata.Entity2LogicalName
                    ? relationshipMetadata.ReferencingAttribute
                    : relationshipMetadata.ReferencedAttribute;

                newLink = new Link
                {
                    Name          = relationshipMetadata.Entity2LogicalName,
                    FromAttribute = linkFromAttribute,
                    ToAttribute   = linkToAttribute,
                    Type          = JoinOperator.LeftOuter,
                    Alias         = alias
                };
            }
            else
            {
                throw new ApplicationException(string.Format("Retrieve relationship request failed for relationship name {0}", linkDetails.RelationshipName));
            }

            ContentAccessProvider.AddLink(link, newLink);


            if (addCondition) // Only add the condition if we are at the end of the chain
            {
                var condition = new Condition {
                    Attribute = relationshipMetadata.Entity2PrimaryIdAttribute
                };

                if (linkDetails.Scope.HasValue && linkDetails.Scope.Value == OwningCustomerType.Contact)
                {
                    condition.EntityName = alias;
                    condition.Operator   = ConditionOperator.Equal;
                    condition.Value      = contact.Id;
                }
                else if (linkDetails.Scope.HasValue && linkDetails.Scope.Value == OwningCustomerType.Account)
                {
                    condition.EntityName = alias;
                    condition.Operator   = ConditionOperator.Equal;
                    condition.Value      = account.Id;
                }
                else
                {
                    condition.EntityName = alias;
                    condition.Operator   = ConditionOperator.NotNull;
                }

                filter.Conditions.Add(condition);
            }

            fetch.Distinct = true;
        }
 /// <summary>
 /// Default contstructor to initialize property
 /// </summary>
 public CategoryController()
 {
     this.contentAccessProvider = new ProductAccessProvider();
 }