Example #1
0
        protected virtual IEvent Select(Predicate <Entity> match)
        {
            var serviceContext = Dependencies.GetServiceContext();
            var website        = Dependencies.GetWebsite();

            var publishingStateAccessProvider = new PublishingStateAccessProvider(Dependencies.GetRequestContext().HttpContext);

            // Bulk-load all ad entities into cache.
            var allEntities = serviceContext.CreateQuery("adx_event")
                              .Where(e => e.GetAttributeValue <EntityReference>("adx_websiteid") == website)
                              .ToArray();

            var entity = allEntities.FirstOrDefault(e =>
                                                    match(e) &&
                                                    IsActive(e) &&
                                                    publishingStateAccessProvider.TryAssert(serviceContext, e));

            if (entity == null)
            {
                return(null);
            }

            var securityProvider = Dependencies.GetSecurityProvider();

            if (!securityProvider.TryAssert(serviceContext, entity, CrmEntityRight.Read))
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Forum={0}: Not Found", entity.Id));

                return(null);
            }

            var myevent = new Event(entity);

            return(myevent);
        }
        protected virtual IForum Select(Predicate <Entity> match)
        {
            var serviceContext = Dependencies.GetServiceContext();
            var website        = Dependencies.GetWebsite();

            var publishingStateAccessProvider = new PublishingStateAccessProvider(Dependencies.GetRequestContext().HttpContext);

            // Bulk-load all ad entities into cache.
            var fetch = new Fetch
            {
                Entity = new FetchEntity("adx_communityforum")
                {
                    Filters = new[]
                    {
                        new Filter
                        {
                            Conditions = new[] { new Condition("adx_websiteid", ConditionOperator.Equal, website.Id) }
                        }
                    }
                }
            };

            var allEntities = serviceContext.RetrieveMultiple(fetch).Entities;

            var entity = allEntities.FirstOrDefault(e =>
                                                    match(e) &&
                                                    IsActive(e) &&
                                                    publishingStateAccessProvider.TryAssert(serviceContext, e));

            if (entity == null)
            {
                return(null);
            }

            var securityProvider = Dependencies.GetSecurityProvider();

            if (!securityProvider.TryAssert(serviceContext, entity, CrmEntityRight.Read))
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Forum={0}: Not Found", entity.Id));

                return(null);
            }

            var viewEntity      = new PortalViewEntity(serviceContext, entity, securityProvider, Dependencies.GetUrlProvider());
            var forumInfo       = serviceContext.FetchForumInfo(entity.Id);
            var counterStrategy = Dependencies.GetCounterStrategy();

            var forum = new Forum(
                entity,
                viewEntity,
                forumInfo,
                // Only lazily get counts, because it's unlikely to be used in the common case.
                // SelectThreadCount and SelectPostCount will generally be used instead.
                () => counterStrategy.GetForumCounts(serviceContext, entity));

            return(forum);
        }
Example #3
0
            private bool InnerTryAssert(OrganizationServiceContext context, Entity entity, CrmEntityRight right, CrmEntityCacheDependencyTrace dependencies)
            {
                if (entity == null)
                {
                    return(false);
                }

                if (right == CrmEntityRight.Read && (!_publishedDatesAccessProvider.TryAssert(context, entity) || !_publishingStateAccessProvider.TryAssert(context, entity)))
                {
                    // We let the date and state access providers handle their own caching logic, so we signal any
                    // caching providers above this one to not cache this result.
                    dependencies.IsCacheable = false;

                    return(false);
                }

                dependencies.AddEntityDependency(entity);

                var entityName = entity.LogicalName;

                CrmEntityInactiveInfo inactiveInfo;

                if (CrmEntityInactiveInfo.TryGetInfo(entityName, out inactiveInfo) && inactiveInfo.IsInactive(entity))
                {
                    return(false);
                }

                if (entityName == "adx_webpage")
                {
                    return(TestWebPage(context, entity, right, dependencies));
                }

                if (entityName == "feedback")
                {
                    return(TestFeedback(context, entity, right, dependencies));
                }

                if (entityName == "adx_event")
                {
                    return(TestEvent(context, entity, right, dependencies));
                }

                if (entityName == "adx_eventschedule")
                {
                    return(TestEventSchedule(context, entity, right, dependencies));
                }

                if ((entityName == "adx_eventspeaker" || entityName == "adx_eventsponsor") && right == CrmEntityRight.Read)
                {
                    return(true);
                }

                if (entityName == "adx_communityforum")
                {
                    return(TestForum(context, entity, right, dependencies));
                }

                if (entityName == "adx_communityforumthread")
                {
                    return(TestForumThread(context, entity, right, dependencies));
                }

                if (entityName == "adx_communityforumpost")
                {
                    return(TestForumPost(context, entity, right, dependencies));
                }

                if (entityName == "adx_communityforumannouncement")
                {
                    return(TestForumAnnouncement(context, entity, right, dependencies));
                }

                if (entityName == "adx_forumthreadtype")
                {
                    return(right == CrmEntityRight.Read);
                }

                if ((entityName == "adx_pagetemplate" || entityName == "adx_publishingstate" || "adx_websitelanguage" == entityName) && right == CrmEntityRight.Read)
                {
                    return(true);
                }

                if (entityName == "adx_webfile")
                {
                    return(TestWebFile(context, entity, right, dependencies));
                }

                if (entityName == "adx_contentsnippet" || entityName == "adx_weblinkset" || entityName == "adx_weblink" || entityName == "adx_sitemarker")
                {
                    return(TestWebsiteAccessPermission(context, entity, right, dependencies));
                }

                if (entityName == "adx_shortcut")
                {
                    return(TestShortcut(context, entity, right, dependencies));
                }

                if (entityName == "adx_blog")
                {
                    return(TestBlog(context, entity, right, dependencies));
                }

                if (entityName == "adx_blogpost")
                {
                    return(TestBlogPost(context, entity, right, dependencies));
                }

                if (entityName == "adx_ideaforum")
                {
                    return(TestIdeaForum(context, entity, right, dependencies));
                }

                if (entityName == "adx_idea")
                {
                    return(TestIdea(context, entity, right, dependencies));
                }

                if (entityName == "adx_ideacomment")
                {
                    return(TestIdeaComment(context, entity, right, dependencies));
                }

                if (entityName == "adx_ideavote")
                {
                    return(TestIdeaVote(context, entity, right, dependencies));
                }

                if (entityName == "adx_issueforum")
                {
                    return(TestIssueForum(context, entity, right, dependencies));
                }

                if (entityName == "adx_issue")
                {
                    return(TestIssue(context, entity, right, dependencies));
                }

                if (entityName == "adx_issuecomment")
                {
                    return(TestIssueComment(context, entity, right, dependencies));
                }

                if (entityName == "adx_adplacement" || entityName == "adx_ad")
                {
                    return(right == CrmEntityRight.Read);
                }

                if (entityName == "email")
                {
                    return(right == CrmEntityRight.Read);
                }

                if (entityName == "incident" && right == CrmEntityRight.Read)
                {
                    return(IsPublicCase(entity));
                }

                if (IsPortalKbArticle(entity))
                {
                    return(right == CrmEntityRight.Read);
                }

                if (IsPublicKnowledgeArticle(entity))
                {
                    return(right == CrmEntityRight.Read);
                }

                if (IsCategory(entity))
                {
                    return(right == CrmEntityRight.Read);
                }

                if (IsAnnotation(entity))
                {
                    return(right == CrmEntityRight.Read);
                }

                // To allow note attachments to be read by the customer to which the order or quote belongs.
                if (entityName == "salesorder" || entityName == "quote")
                {
                    var customerid    = entity.GetAttributeValue <EntityReference>("customerid");
                    var portalContext = PortalCrmConfigurationManager.CreatePortalContext(PortalName);

                    return(right == CrmEntityRight.Read &&
                           customerid != null &&
                           portalContext != null &&
                           portalContext.User != null &&
                           customerid.Equals(portalContext.User.ToEntityReference()));
                }

                if (TestServiceRequest(context, entity))
                {
                    return(right == CrmEntityRight.Read);
                }

                Entity parentPermit;

                if (TryGetParentPermit(context, entity, out parentPermit))
                {
                    return(TestParentPermit(context, parentPermit, right));
                }

                return(false);
            }