コード例 #1
0
        public override void DeleteEntity(OrganizationServiceContext context, string entitySet, Guid entityID)
        {
            var entity = GetServiceOperationEntityByID(context, entitySet, entityID);

            AssertCrmEntityChangeAccess(context, entity);

            CrmEntityInactiveInfo inactiveInfo;

            if (CrmEntityInactiveInfo.TryGetInfo(entity.LogicalName, out inactiveInfo))
            {
                context.SetState(inactiveInfo.InactiveState, inactiveInfo.InactiveStatus, entity);

                return;
            }

            if (entity.LogicalName == "adx_communityforum" || entity.LogicalName == "adx_event" || entity.LogicalName == "adx_shortcut")
            {
                context.DeleteObject(entity);

                context.SaveChanges();

                return;
            }

            throw new DataServiceException(403, "This operation cannot be performed entities of type {0}.".FormatWith(entity.LogicalName));
        }
コード例 #2
0
        public static Entity LookupFileByUrlPath(OrganizationServiceContext context, Entity website, string urlPath)
        {
            CrmEntityInactiveInfo inactiveInfo;

            var filter = CrmEntityInactiveInfo.TryGetInfo("adx_webfile", out inactiveInfo)
                                ? entity => !inactiveInfo.IsInactive(entity)
                                : new Func <Entity, bool>(entity => true);

            return(LookupFileByUrlPath(context, website, urlPath, filter));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        /// <summary>
        /// Searches for a adx_webpage that matches a given <paramref name="urlPath"/>.
        /// </summary>
        /// <param name="context">
        /// The <see cref="OrganizationServiceContext"/> to be used by the lookup operation for CRM data access.
        /// </param>
        /// <param name="website">The adx_website to which the search will be scoped.</param>
        /// <param name="urlPath">The URL path to match.</param>
        /// <returns>
        /// An adx_webpage <see cref="Entity"/> whose adx_partial URL, and those of its parent pages, matches <paramref name="urlPath"/>. If no
        /// match is found, this method will return null.
        /// </returns>
        public static UrlMappingResult <Entity> LookupPageByUrlPath(OrganizationServiceContext context, Entity website, string urlPath)
        {
            var applicationPath = GetApplicationPath(urlPath);

            CrmEntityInactiveInfo inactiveInfo;

            var filter = CrmEntityInactiveInfo.TryGetInfo("adx_webpage", out inactiveInfo)
                                ? entity => !inactiveInfo.IsInactive(entity)
                                : new Func <Entity, bool>(entity => true);

            return(LookupPageByUrlPath(context, website, applicationPath.PartialPath, filter));
        }
コード例 #5
0
        /// <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);
        }
        /// <summary>
        /// Service operation to soft-delete an entity. ("Soft" in that it may not actually delete the entity,
        /// but may instead change it to a different state, archive it, etc.)
        /// </summary>
        public virtual void DeleteEntity(OrganizationServiceContext context, string entitySet, Guid entityID)
        {
            var entity = GetServiceOperationEntityByID(context, entitySet, entityID);

            AssertCrmEntityChangeAccess(context, entity);

            CrmEntityInactiveInfo inactiveInfo;

            if (!CrmEntityInactiveInfo.TryGetInfo(entity.LogicalName, out inactiveInfo))
            {
                throw new DataServiceException(403, "This operation cannot be performed entities of type {0}.".FormatWith(entity.LogicalName));
            }

            context.SetState(inactiveInfo.InactiveState, inactiveInfo.InactiveStatus, entity);
        }
コード例 #7
0
        public override bool TryAssert(OrganizationServiceContext context, Entity entity, CrmEntityRight right)
        {
            if (entity == null || entity.Id == Guid.Empty)
            {
                return(false);
            }

            entity.AssertEntityName(_handledEntityNames);

            CrmEntityInactiveInfo inactiveInfo;

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

            var website = context.GetWebsite(entity);

            if (website == null)
            {
                return(false);
            }

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

            if (HttpContext.Current.User == null ||
                HttpContext.Current.User.Identity == null ||
                HttpContext.Current.User.Identity.Name == null ||
                !HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(false);
            }

            var roleName = context.GetSiteSettingValueByName(website, SiteSettingName);

            var result = !string.IsNullOrEmpty(roleName) && Roles.IsUserInRole(roleName);

            return(result);
        }
コード例 #8
0
        protected override void ProcessRequest(HttpContext context, ICmsEntityServiceProvider serviceProvider, Guid portalScopeId, IPortalContext portal, OrganizationServiceContext serviceContext, Entity entity, CmsEntityMetadata entityMetadata, ICrmEntitySecurityProvider security)
        {
            if (!(IsRequestMethod(context.Request, "POST") || IsRequestMethod(context.Request, "DELETE")))
            {
                throw new CmsEntityServiceException(HttpStatusCode.MethodNotAllowed, "Request method {0} not allowed for this resource.".FormatWith(context.Request.HttpMethod));
            }

            CrmEntityInactiveInfo inactiveInfo;

            if (CrmEntityInactiveInfo.TryGetInfo(entity.LogicalName, out inactiveInfo))
            {
                serviceContext.SetState(inactiveInfo.InactiveState, inactiveInfo.InactiveStatus, entity);

                WriteNoContentResponse(context.Response);

                return;
            }

            if (entity.LogicalName == "adx_communityforumthread")
            {
                var forum = entity.GetRelatedEntity(serviceContext, new Relationship("adx_communityforum_communityforumthread"));

                if (forum != null)
                {
                    var forumDataAdapter = new ForumDataAdapter(
                        forum.ToEntityReference(),
                        new PortalConfigurationDataAdapterDependencies(portalName: PortalName, requestContext: context.Request.RequestContext));

                    forumDataAdapter.DeleteThread(entity.ToEntityReference());

                    WriteNoContentResponse(context.Response);

                    if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage))
                    {
                        PortalFeatureTrace.TraceInstance.LogFeatureUsage(FeatureTraceCategory.Forum, HttpContext.Current, "delete_forumthread", 1, entity.ToEntityReference(), "delete");
                    }

                    return;
                }
            }

            if (entity.LogicalName == "adx_communityforumpost")
            {
                var forumThread = entity.GetRelatedEntity(serviceContext, new Relationship("adx_communityforumthread_communityforumpost"));

                if (forumThread != null)
                {
                    var forumThreadDataAdapter = new ForumThreadDataAdapter(
                        forumThread.ToEntityReference(),
                        new PortalConfigurationDataAdapterDependencies(portalName: PortalName, requestContext: context.Request.RequestContext));

                    forumThreadDataAdapter.DeletePost(entity.ToEntityReference());

                    WriteNoContentResponse(context.Response);

                    if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage))
                    {
                        PortalFeatureTrace.TraceInstance.LogFeatureUsage(FeatureTraceCategory.Forum, HttpContext.Current, "delete_forumpost", 1, entity.ToEntityReference(), "delete");
                    }

                    return;
                }
            }

            serviceContext.DeleteObject(entity);
            serviceContext.SaveChanges();

            WriteNoContentResponse(context.Response);

            if (FeatureCheckHelper.IsFeatureEnabled(FeatureNames.TelemetryFeatureUsage))
            {
                PortalFeatureTrace.TraceInstance.LogFeatureUsage(FeatureTraceCategory.Blog, HttpContext.Current, "delete_blogpost", 1, entity.ToEntityReference(), "delete");
            }
        }
コード例 #9
0
ファイル: RmCommand.cs プロジェクト: ITLec/Dynamics-365-XEP
        private static List <Tuple <string, string> > RemoveFiles(ICommandContext commandContext)
        {
            var errors = new List <Tuple <string, string> >();

            var targetHashes = (commandContext.Parameters["targets[]"] ?? string.Empty).Split(',');

            if (!targetHashes.Any())
            {
                return(errors);
            }

            var portal              = commandContext.CreatePortalContext();
            var website             = portal.Website.ToEntityReference();
            var security            = commandContext.CreateSecurityProvider();
            var dataServiceProvider = commandContext.CreateDependencyProvider().GetDependency <ICmsDataServiceProvider>();

            foreach (var targetHash in targetHashes)
            {
                var serviceContext = commandContext.CreateServiceContext();

                Entity target;

                if (!TryGetTargetEntity(serviceContext, targetHash, website, out target))
                {
                    errors.Add(new Tuple <string, string>(targetHash, ResourceManager.GetString("Unable_To_Retrieve_Target_Entity_For_Given_Hash_Error")));

                    continue;
                }

                try
                {
                    OrganizationServiceContextInfo serviceContextInfo;
                    EntitySetInfo entitySetInfo;

                    if (dataServiceProvider != null &&
                        OrganizationServiceContextInfo.TryGet(serviceContext.GetType(), out serviceContextInfo) &&
                        serviceContextInfo.EntitySetsByEntityLogicalName.TryGetValue(target.LogicalName, out entitySetInfo))
                    {
                        dataServiceProvider.DeleteEntity(serviceContext, entitySetInfo.Property.Name, target.Id);
                    }
                    else
                    {
                        if (!security.TryAssert(serviceContext, target, CrmEntityRight.Change))
                        {
                            errors.Add(new Tuple <string, string>(GetDisplayName(target), ResourceManager.GetString("Delete_Permission_Denied_For_Target_Entity_Error")));

                            continue;
                        }

                        CrmEntityInactiveInfo inactiveInfo;

                        if (CrmEntityInactiveInfo.TryGetInfo(target.LogicalName, out inactiveInfo))
                        {
                            serviceContext.SetState(inactiveInfo.InactiveState, inactiveInfo.InactiveStatus, target);
                        }
                        else
                        {
                            serviceContext.DeleteObject(target);
                            serviceContext.SaveChanges();
                        }
                    }
                }
                catch (Exception e)
                {
                    ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("{0} {1}", ResourceManager.GetString("Deleting_File_Exception"), e.ToString()));
                    errors.Add(new Tuple <string, string>(GetDisplayName(target), e.Message));
                }
            }

            return(errors);
        }
コード例 #10
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);
            }