public UserStartNodes GetById(int userId)
        {
            StartNodeCollection startNodes     = StartNodeRepository.GetCachedStartNodesByUserId(userId, ApplicationContext, DatabaseContext);
            UserStartNodes      userStartNodes = new UserStartNodes();

            userStartNodes.UserId  = userId;
            userStartNodes.Content = (startNodes.Content != null) ? string.Join(",", startNodes.Content) : "";
            userStartNodes.Media   = (startNodes.Media != null) ? string.Join(",", startNodes.Media) : "";

            return(userStartNodes);
        }
Пример #2
0
        public static void RenderContentStartNodes(int userId, TreeControllerBase sender, TreeNodesRenderingEventArgs e)
        {
            StartNodeCollection startNodes = StartNodeRepository.GetCachedStartNodesByUserId(userId, sender.ApplicationContext, sender.DatabaseContext);

            if (startNodes.Content == null)
            {
                return;
            }

            if (startNodes.Content.Any())
            {
                // Remove default start nodes
                e.Nodes.Clear();

                IEnumerable <IUmbracoEntity> startNodesEntities = sender.Services.EntityService.GetAll(Umbraco.Core.Models.UmbracoObjectTypes.Document, startNodes.Content);

                // Feels like a lot of duct tape. A lot taken from:
                // https://github.com/umbraco/Umbraco-CMS/blob/5397f2c53acbdeb0805e1fe39fda938f571d295a/src/Umbraco.Web/Trees/ContentTreeController.cs#L75
                foreach (IUmbracoEntity startNodeEntity in startNodesEntities)
                {
                    UmbracoEntity entity = (UmbracoEntity)startNodeEntity;

                    // Not as safe as the approach in core
                    // https://github.com/umbraco/Umbraco-CMS/blob/5397f2c53acbdeb0805e1fe39fda938f571d295a/src/Umbraco.Core/Models/UmbracoEntityExtensions.cs#L34
                    bool isContainer = (entity.AdditionalData.ContainsKey("IsContainer") && entity.AdditionalData["IsContainer"].ToString() == "True");

                    TreeNode node = sender.CreateTreeNode(
                        startNodeEntity.Id.ToInvariantString(),
                        "-1",
                        e.QueryStrings,
                        startNodeEntity.Name,
                        entity.ContentTypeIcon,
                        entity.HasChildren && (isContainer == false)
                        );

                    AddQueryStringsToAdditionalData(node, e.QueryStrings);

                    if (e.QueryStrings.Get("isDialog") == "true")
                    {
                        node.RoutePath = "#";
                    }

                    // TODO: How should we order nodes?

                    e.Nodes.Add(node);
                }
            }
        }
Пример #3
0
        private Task <HttpResponseMessage> RemoveInaccessibleNodesFromSearchResults(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            IUser user = ContextHelpers.EnsureUmbracoContext().Security.CurrentUser;
            StartNodeCollection startNodes = StartNodeRepository.GetCachedStartNodesByUserId(user.Id);

            if (user.UserType.Alias == "admin")
            {
                return(base.SendAsync(request, cancellationToken));
            }

            return(base.SendAsync(request, cancellationToken)
                   .ContinueWith(task =>
            {
                HttpResponseMessage response = task.Result;
                if (!response.IsSuccessStatusCode)
                {
                    return response;
                }
                try
                {
                    HttpContent data = response.Content;
                    ObjectContent dataContent = ((ObjectContent)(data));
                    IEnumerable <EntityTypeSearchResult> entities = dataContent.Value as IEnumerable <EntityTypeSearchResult>;

                    EntityTypeSearchResult contentResults = entities.FirstOrDefault(e => e.EntityType == "Document");
                    EntityTypeSearchResult mediaResults = entities.FirstOrDefault(e => e.EntityType == "Media");

                    if (startNodes.Content != null && contentResults.Results.Any())
                    {
                        contentResults.Results = contentResults.Results.Where(e => PathContainsAStartNode(e.Path, startNodes.Content));
                    }

                    if (startNodes.Media != null && mediaResults.Results.Any())
                    {
                        mediaResults.Results = mediaResults.Results.Where(e => PathContainsAStartNode(e.Path, startNodes.Media));
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error <WebApiHandler>("Could not remove inaccessible nodes from search results.", ex);
                }
                return response;
            }
                                 ));
        }
Пример #4
0
        public static void RenderMediaStartNodes(int userId, TreeControllerBase sender, TreeNodesRenderingEventArgs e)
        {
            StartNodeCollection startNodes = StartNodeRepository.GetCachedStartNodesByUserId(userId, sender.ApplicationContext, sender.DatabaseContext);

            if (startNodes.Media == null)
            {
                return;
            }

            if (startNodes.Media.Any())
            {
                // Remove default start nodes
                e.Nodes.Clear();
                IEnumerable <IUmbracoEntity> startNodesEntities = sender.Services.EntityService.GetAll(Umbraco.Core.Models.UmbracoObjectTypes.Media, startNodes.Media);

                foreach (IUmbracoEntity startNodeEntity in startNodesEntities)
                {
                    UmbracoEntity entity = (UmbracoEntity)startNodeEntity;

                    bool isContainer = (entity.AdditionalData.ContainsKey("IsContainer") && entity.AdditionalData["IsContainer"].ToString() == "True");

                    TreeNode node = sender.CreateTreeNode(
                        startNodeEntity.Id.ToInvariantString(),
                        "-1",
                        e.QueryStrings,
                        startNodeEntity.Name,
                        entity.ContentTypeIcon,
                        entity.HasChildren && (isContainer == false)
                        );

                    node.AdditionalData.Add("contentType", entity.ContentTypeAlias);

                    if (isContainer)
                    {
                        node.SetContainerStyle();
                        node.AdditionalData.Add("isContainer", true);
                    }

                    // TODO: How should we order nodes?

                    e.Nodes.Add(node);
                }
            }
        }