private string GetContentPath(IUmbracoEntity item)
        {
            if (item == null)
            {
                return("");
            }

            var path = string.Empty;

            if (item.ParentId > -1)
            {
                var parent = Services.EntityService.Get(item.ParentId);
                if (parent != null)
                {
                    path += GetContentPath(parent);
                }
            }

            if (!string.IsNullOrWhiteSpace(path))
            {
                return(path + " > " + item.Name);
            }

            return(item.Name);
        }
        /// <summary>
        /// Returns a collection of all menu items that can be on a content node
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected MenuItemCollection GetAllNodeMenuItems(IUmbracoEntity item)
        {
            var menu = new MenuItemCollection();

            AddActionNode <ActionNew>(item, menu, opensDialog: true);
            AddActionNode <ActionDelete>(item, menu, opensDialog: true);
            AddActionNode <ActionCreateBlueprintFromContent>(item, menu, opensDialog: true);
            AddActionNode <ActionMove>(item, menu, true, opensDialog: true);
            AddActionNode <ActionCopy>(item, menu, opensDialog: true);
            AddActionNode <ActionSort>(item, menu, true);
            AddActionNode <ActionAssignDomain>(item, menu, opensDialog: true);
            AddActionNode <ActionRights>(item, menu, opensDialog: true);
            AddActionNode <ActionProtect>(item, menu, true, opensDialog: true);

            if (EmailSender.CanSendRequiredEmail)
            {
                menu.Items.Add(new MenuItem("notify", Services.TextService)
                {
                    Icon            = "megaphone",
                    SeparatorBefore = true,
                    OpensDialog     = true
                });
            }

            if ((item is DocumentEntitySlim documentEntity && documentEntity.IsContainer) == false)
            {
                menu.Items.Add(new RefreshNode(Services.TextService, true));
            }

            return(menu);
        }
        private int GetTopNodeId(IUmbracoEntity entity)
        {
            int id;
            var parts = entity.Path.Split(Comma, StringSplitOptions.RemoveEmptyEntries);

            return(parts.Length >= 2 && int.TryParse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out id) ? id : 0);
        }
Ejemplo n.º 4
0
    /// <summary>
    ///     Returns a collection of all menu items that can be on a content node
    /// </summary>
    /// <param name="item"></param>
    /// <returns></returns>
    protected MenuItemCollection GetAllNodeMenuItems(IUmbracoEntity item)
    {
        MenuItemCollection menu = _menuItemCollectionFactory.Create();

        AddActionNode <ActionNew>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionDelete>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionCreateBlueprintFromContent>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionMove>(item, menu, hasSeparator: true, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionCopy>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionSort>(item, menu, hasSeparator: true, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionAssignDomain>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionRights>(item, menu, opensDialog: true, useLegacyIcon: false);
        AddActionNode <ActionProtect>(item, menu, hasSeparator: true, opensDialog: true, useLegacyIcon: false);

        if (_emailSender.CanSendRequiredEmail())
        {
            menu.Items.Add(new MenuItem("notify", LocalizedTextService)
            {
                Icon            = "icon-megaphone",
                SeparatorBefore = true,
                OpensDialog     = true,
                UseLegacyIcon   = false
            });
        }

        if ((item is DocumentEntitySlim documentEntity && documentEntity.IsContainer) == false)
        {
            menu.Items.Add(new RefreshNode(LocalizedTextService, true));
        }

        return(menu);
    }
        /// <summary>
        /// Returns a collection of all menu items that can be on a content node
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected MenuItemCollection GetAllNodeMenuItems(IUmbracoEntity item)
        {
            var menu = _menuItemCollectionFactory.Create();

            AddActionNode <ActionNew>(item, menu, opensDialog: true);
            AddActionNode <ActionDelete>(item, menu, opensDialog: true);
            AddActionNode <ActionCreateBlueprintFromContent>(item, menu, opensDialog: true);
            AddActionNode <ActionMove>(item, menu, true, opensDialog: true);
            AddActionNode <ActionCopy>(item, menu, opensDialog: true);
            AddActionNode <ActionSort>(item, menu, true, opensDialog: true);
            AddActionNode <ActionAssignDomain>(item, menu, opensDialog: true);
            AddActionNode <ActionRights>(item, menu, opensDialog: true);
            AddActionNode <ActionProtect>(item, menu, true, opensDialog: true);

            if (_emailSender.CanSendRequiredEmail())
            {
                AddActionNode <ActionNotify>(item, menu, true, opensDialog: true);
            }

            if ((item is DocumentEntitySlim documentEntity && documentEntity.IsContainer) == false)
            {
                menu.Items.Add(new RefreshNode(LocalizedTextService, true));
            }

            return(menu);
        }
        /// <summary>
        /// Creates a tree node for a content item based on an UmbracoEntity
        /// </summary>
        /// <param name="e"></param>
        /// <param name="parentId"></param>
        /// <param name="queryStrings"></param>
        /// <returns></returns>
        protected override TreeNode GetSingleTreeNode(IUmbracoEntity e, string parentId, FormDataCollection queryStrings)
        {
            var entity = (UmbracoEntity)e;

            //Special check to see if it ia a container, if so then we'll hide children.
            var isContainer = e.IsContainer(); // && (queryStrings.Get("isDialog") != "true");

            var node = CreateTreeNode(
                e.Id.ToInvariantString(),
                parentId,
                queryStrings,
                e.Name,
                entity.ContentTypeIcon,
                entity.HasChildren && (isContainer == false));

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

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

            return(node);
        }
Ejemplo n.º 7
0
        public ContentAccess CheckPermissions(
            IUmbracoEntity entity,
            IUser user,
            IReadOnlyList <char> permissionsToCheck)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (entity == null)
            {
                return(ContentAccess.NotFound);
            }

            var hasPathAccess = user.HasContentPathAccess(entity, _entityService, _appCaches);

            if (hasPathAccess == false)
            {
                return(ContentAccess.Denied);
            }

            if (permissionsToCheck == null || permissionsToCheck.Count == 0)
            {
                return(ContentAccess.Granted);
            }

            //get the implicit/inherited permissions for the user for this path
            return(CheckPermissionsPath(entity.Path, user, permissionsToCheck)
                ? ContentAccess.Granted
                : ContentAccess.Denied);
        }
        /// <summary>
        /// Relates two objects that are based on the <see cref="IUmbracoEntity"/> interface.
        /// </summary>
        /// <param name="parent">Parent entity</param>
        /// <param name="child">Child entity</param>
        /// <param name="relationType">The type of relation to create</param>
        /// <returns>The created <see cref="Relation"/></returns>
        public IRelation Relate(IUmbracoEntity parent, IUmbracoEntity child, IRelationType relationType)
        {
            //Ensure that the RelationType has an indentity before using it to relate two entities
            if (relationType.HasIdentity == false)
            {
                Save(relationType);
            }

            var relation = new Relation(parent.Id, child.Id, relationType);

            using (var uow = UowProvider.GetUnitOfWork())
            {
                var repository    = RepositoryFactory.CreateRelationRepository(uow);
                var saveEventArgs = new SaveEventArgs <IRelation>(relation);
                if (uow.Events.DispatchCancelable(SavingRelation, this, saveEventArgs))
                {
                    uow.Commit();
                    return(relation);
                }

                repository.AddOrUpdate(relation);
                uow.Commit();
                saveEventArgs.CanCancel = false;
                uow.Events.Dispatch(SavedRelation, this, saveEventArgs);
                return(relation);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns a collection of all menu items that can be on a content node
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected MenuItemCollection GetAllNodeMenuItems(IUmbracoEntity item)
        {
            var menu = new MenuItemCollection();

            menu.Items.Add <ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
            menu.Items.Add <ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias));

            menu.Items.Add <ActionCreateBlueprintFromContent>(ui.Text("actions", ActionCreateBlueprintFromContent.Instance.Alias));

            //need to ensure some of these are converted to the legacy system - until we upgrade them all to be angularized.
            menu.Items.Add <ActionMove>(ui.Text("actions", ActionMove.Instance.Alias), true);
            menu.Items.Add <ActionCopy>(ui.Text("actions", ActionCopy.Instance.Alias));
            menu.Items.Add <ActionChangeDocType>(ui.Text("actions", ActionChangeDocType.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");

            menu.Items.Add <ActionSort>(ui.Text("actions", ActionSort.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");

            menu.Items.Add <ActionRollback>(ui.Text("actions", ActionRollback.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add <ActionAudit>(ui.Text("actions", ActionAudit.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add <ActionPublish>(ui.Text("actions", ActionPublish.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add <ActionToPublish>(ui.Text("actions", ActionToPublish.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add <ActionAssignDomain>(ui.Text("actions", ActionAssignDomain.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add <ActionRights>(ui.Text("actions", ActionRights.Instance.Alias), true);
            menu.Items.Add <ActionProtect>(ui.Text("actions", ActionProtect.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");

            menu.Items.Add <ActionNotify>(ui.Text("actions", ActionNotify.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add <ActionSendToTranslate>(ui.Text("actions", ActionSendToTranslate.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");

            menu.Items.Add <RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true);

            return(menu);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Relates two objects that are based on the <see cref="IUmbracoEntity"/> interface.
        /// </summary>
        /// <param name="parent">Parent entity</param>
        /// <param name="child">Child entity</param>
        /// <param name="relationType">The type of relation to create</param>
        /// <returns>The created <see cref="Relation"/></returns>
        public IRelation Relate(IUmbracoEntity parent, IUmbracoEntity child, IRelationType relationType)
        {
            //Ensure that the RelationType has an indentity before using it to relate two entities
            if (relationType.HasIdentity == false)
            {
                Save(relationType);
            }

            var relation = new Relation(parent.Id, child.Id, relationType);

            if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs <IRelation>(relation), this))
            {
                return(relation);
            }

            var uow = UowProvider.GetUnitOfWork();

            using (var repository = RepositoryFactory.CreateRelationRepository(uow))
            {
                repository.AddOrUpdate(relation);
                uow.Commit();
            }

            SavedRelation.RaiseEvent(new SaveEventArgs <IRelation>(relation, false), this);
            return(relation);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Relates two objects that are based on the <see cref="IUmbracoEntity"/> interface.
        /// </summary>
        /// <param name="parent">Parent entity</param>
        /// <param name="child">Child entity</param>
        /// <param name="relationTypeAlias">Alias of the type of relation to create</param>
        /// <returns>The created <see cref="Relation"/></returns>
        public IRelation Relate(IUmbracoEntity parent, IUmbracoEntity child, string relationTypeAlias)
        {
            var relationType = GetRelationTypeByAlias(relationTypeAlias);

            if (relationType == null || string.IsNullOrEmpty(relationType.Alias))
            {
                throw new ArgumentNullException(string.Format("No RelationType with Alias '{0}' exists.", relationTypeAlias));
            }

            var relation = new Relation(parent.Id, child.Id, relationType);

            if (SavingRelation.IsRaisedEventCancelled(new SaveEventArgs <IRelation>(relation), this))
            {
                return(relation);
            }

            var uow = UowProvider.GetUnitOfWork();

            using (var repository = RepositoryFactory.CreateRelationRepository(uow))
            {
                repository.AddOrUpdate(relation);
                uow.Commit();
            }

            SavedRelation.RaiseEvent(new SaveEventArgs <IRelation>(relation, false), this);
            return(relation);
        }
        /// <summary>
        /// Returns a <see cref="TreeNode"/> for the <see cref="IUmbracoEntity"/> and
        /// attaches some meta data to the node if the user doesn't have start node access to it when in dialog mode
        /// </summary>
        /// <param name="e"></param>
        /// <param name="parentId"></param>
        /// <param name="queryStrings"></param>
        /// <returns></returns>
        internal TreeNode GetSingleTreeNodeWithAccessCheck(IUmbracoEntity e, string parentId, FormDataCollection queryStrings,
                                                           int[] startNodeIds, string[] startNodePaths, bool ignoreUserStartNodes)
        {
            bool hasPathAccess;
            var  entityIsAncestorOfStartNodes = UserExtensions.IsInBranchOfStartNode(e.Path, startNodeIds, startNodePaths, out hasPathAccess);

            if (ignoreUserStartNodes == false && entityIsAncestorOfStartNodes == false)
            {
                return(null);
            }

            var treeNode = GetSingleTreeNode(e, parentId, queryStrings);

            if (treeNode == null)
            {
                //this means that the user has NO access to this node via permissions! They at least need to have browse permissions to see
                //the node so we need to return null;
                return(null);
            }
            if (ignoreUserStartNodes == false && hasPathAccess == false)
            {
                treeNode.AdditionalData["noAccess"] = true;
            }
            return(treeNode);
        }
        /// <summary>
        /// Returns a collection of all menu items that can be on a content node
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected MenuItemCollection GetAllNodeMenuItems(IUmbracoEntity item)
        {
            var menu = new MenuItemCollection();

            AddActionNode <ActionNew>(item, menu, opensDialog: true);
            AddActionNode <ActionDelete>(item, menu, opensDialog: true);
            AddActionNode <ActionCreateBlueprintFromContent>(item, menu, opensDialog: true);
            AddActionNode <ActionMove>(item, menu, true, opensDialog: true);
            AddActionNode <ActionCopy>(item, menu, opensDialog: true);
            AddActionNode <ActionSort>(item, menu, true);
            AddActionNode <ActionAssignDomain>(item, menu, opensDialog: true);
            AddActionNode <ActionRights>(item, menu, opensDialog: true);
            //fixme - conver this editor to angular
            AddActionNode <ActionProtect>(item, menu, true, convert: true, opensDialog: true);

            menu.Items.Add(new MenuItem("notify", Services.TextService)
            {
                Icon            = "megaphone",
                SeperatorBefore = true,
                OpensDialog     = true
            });

            menu.Items.Add(new RefreshNode(Services.TextService, true));

            return(menu);
        }
Ejemplo n.º 14
0
        internal void ConvertLegacyMenuItem(IUmbracoEntity item, string nodeType, string currentSection)
        {
            // try to get a URL/title from the legacy action,
            // in some edge cases, item can be null so we'll just convert those to "-1" and "" for id and name since these edge cases don't need that.
            var attempt = LegacyTreeDataConverter.GetUrlAndTitleFromLegacyAction(Action,
                                                                                 item == null ? "-1" : item.Id.ToInvariantString(),
                                                                                 nodeType,
                                                                                 item == null ? "" : item.Name, currentSection);

            if (attempt)
            {
                var action = attempt.Result;
                LaunchDialogUrl(action.Url, action.DialogTitle);
            }
            else
            {
                // if that doesn't work, try to get the legacy confirm view
                var attempt2 = LegacyTreeDataConverter.GetLegacyConfirmView(Action);
                if (attempt2)
                {
                    var view        = attempt2.Result;
                    var textService = Current.Services.TextService;
                    LaunchDialogView(view, textService.Localize("defaultdialogs/confirmdelete") + " '" + (item == null ? "" : item.Name) + "' ?");
                }
            }
        }
        /// <summary>
        /// Relates two objects that are based on the <see cref="IUmbracoEntity"/> interface.
        /// </summary>
        /// <param name="parent">Parent entity</param>
        /// <param name="child">Child entity</param>
        /// <param name="relationTypeAlias">Alias of the type of relation to create</param>
        /// <returns>The created <see cref="Relation"/></returns>
        public IRelation Relate(IUmbracoEntity parent, IUmbracoEntity child, string relationTypeAlias)
        {
            var relationType = GetRelationTypeByAlias(relationTypeAlias);

            if (relationType == null || string.IsNullOrEmpty(relationType.Alias))
            {
                throw new ArgumentNullException(string.Format("No RelationType with Alias '{0}' exists.", relationTypeAlias));
            }

            var relation = new Relation(parent.Id, child.Id, relationType);

            using (var uow = UowProvider.GetUnitOfWork())
            {
                var saveEventArgs = new SaveEventArgs <IRelation>(relation);
                if (uow.Events.DispatchCancelable(SavingRelation, this, saveEventArgs))
                {
                    uow.Commit();
                    return(relation);
                }
                var repository = RepositoryFactory.CreateRelationRepository(uow);
                repository.AddOrUpdate(relation);
                uow.Commit();
                saveEventArgs.CanCancel = false;
                uow.Events.Dispatch(SavedRelation, this, saveEventArgs);
                return(relation);
            }
        }
Ejemplo n.º 16
0
    /// <summary>
    ///     Does a quick check on the entity's set path to ensure that it's valid and consistent
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    public static bool ValidatePath(this IUmbracoEntity entity)
    {
        // don't validate if it's empty and it has no id
        if (entity.HasIdentity == false && entity.Path.IsNullOrWhiteSpace())
        {
            return(true);
        }

        if (entity.Path.IsNullOrWhiteSpace())
        {
            return(false);
        }

        var pathParts = entity.Path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries);

        if (pathParts.Length < 2)
        {
            // a path cannot be less than 2 parts, at a minimum it must be root (-1) and it's own id
            return(false);
        }

        if (entity.ParentId != default && pathParts[^ 2] != entity.ParentId.ToInvariantString())
        {
            // the 2nd last id in the path must be it's parent id
            return(false);
        }

        return(true);
    }
        private int GetTopNodeId(IUmbracoEntity entity)
        {
            int id;
            var parts = entity.Path.Split(Comma, StringSplitOptions.RemoveEmptyEntries);

            return(parts.Length >= 2 && int.TryParse(parts[1], out id) ? id : 0);
        }
Ejemplo n.º 18
0
 public static void ClearIndexingStatus(this IUmbracoEntity entity)
 {
     if (entity.AdditionalData.ContainsKey(Key))
     {
         entity.AdditionalData.Remove(Key);
     }
 }
Ejemplo n.º 19
0
 internal Media(IUmbracoEntity entity, bool noSetup = true)
     : base(entity)
 {
     if (noSetup == false)
     {
         setupNode();
     }
 }
 /// <summary>
 /// Returns true or false if the current user has access to the node based on the user's allowed start node (path) access
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="queryStrings"></param>
 /// <returns></returns>
 protected bool HasPathAccess(IUmbracoEntity entity, FormDataCollection queryStrings)
 {
     if (entity == null)
     {
         return(false);
     }
     return(Security.CurrentUser.HasPathAccess(entity, Services.EntityService, RecycleBinId));
 }
Ejemplo n.º 21
0
 public static bool HasContentPathAccess(this IUser user, IUmbracoEntity entity, IEntityService entityService, AppCaches appCaches)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     return(ContentPermissions.HasPathAccess(entity.Path, user.CalculateContentStartNodeIds(entityService, appCaches), Constants.System.RecycleBinContent));
 }
Ejemplo n.º 22
0
 public static IndexingStatus GetIndexingStatus(this IUmbracoEntity entity)
 {
     if (!entity.AdditionalData.ContainsKey(Key))
     {
         entity.AdditionalData.Add(Key, new IndexingStatus());
     }
     return(entity.AdditionalData[Key] as IndexingStatus);
 }
Ejemplo n.º 23
0
 protected override string GetItemFileName(IUmbracoEntity item, bool useGuid)
 {
     if (useGuid)
     {
         return(item.Key.ToString());
     }
     return(item.Name.ToSafeAlias());
 }
        /// <summary>
        /// Helper method to create tree nodes and automatically generate the json url + UDI
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="entityObjectType"></param>
        /// <param name="parentId"></param>
        /// <param name="queryStrings"></param>
        /// <param name="icon"></param>
        /// <param name="hasChildren"></param>
        /// <returns></returns>
        public TreeNode CreateTreeNode(IUmbracoEntity entity, Guid entityObjectType, string parentId, FormDataCollection queryStrings, string icon, bool hasChildren)
        {
            var treeNode = CreateTreeNode(entity.Id.ToInvariantString(), parentId, queryStrings, entity.Name, icon);

            treeNode.Udi         = Udi.Create(UmbracoObjectTypesExtensions.GetUdiType(entityObjectType), entity.Key);
            treeNode.HasChildren = hasChildren;
            return(treeNode);
        }
 public static object GetAdditionalDataValueIgnoreCase(this IUmbracoEntity entity, string key, object defaultVal)
 {
     if (entity.AdditionalData.ContainsKeyIgnoreCase(key) == false)
     {
         return(defaultVal);
     }
     return(entity.AdditionalData.GetValueIgnoreCase(key, defaultVal));
 }
Ejemplo n.º 26
0
 internal static bool HasMediaPathAccess(this IUser user, IUmbracoEntity entity, IEntityService entityService)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     return(ContentPermissionsHelper.HasPathAccess(entity.Path, user.CalculateMediaStartNodeIds(entityService), Constants.System.RecycleBinMedia));
 }
 internal static void SendNotification(this INotificationService service, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext)
 {
     if (umbracoContext == null)
     {
         LogHelper.Warn(typeof(NotificationServiceExtensions), "Cannot send notifications, there is no current UmbracoContext");
         return;
     }
     service.SendNotification(entity, action, umbracoContext, umbracoContext.Application);
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Checks if the user has access to the specified node and permissions set
        /// </summary>
        /// <param name="nodeId"></param>
        /// <param name="user"></param>
        /// <param name="userService"></param>
        /// <param name="entityService"></param>
        /// <param name="entity">The <see cref="IUmbracoEntity"/> item resolved if one was found for the id</param>
        /// <param name="permissionsToCheck"></param>
        /// <returns></returns>
        public ContentAccess CheckPermissions(
            int nodeId,
            IUser user,
            out IUmbracoEntity entity,
            IReadOnlyList <char> permissionsToCheck = null)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (permissionsToCheck == null)
            {
                permissionsToCheck = Array.Empty <char>();
            }

            bool?hasPathAccess = null;

            entity = null;

            if (nodeId == Constants.System.Root)
            {
                hasPathAccess = user.HasContentRootAccess(_entityService, _appCaches);
            }
            else if (nodeId == Constants.System.RecycleBinContent)
            {
                hasPathAccess = user.HasContentBinAccess(_entityService, _appCaches);
            }

            if (hasPathAccess.HasValue)
            {
                return(hasPathAccess.Value ? ContentAccess.Granted : ContentAccess.Denied);
            }

            entity = _entityService.Get(nodeId, UmbracoObjectTypes.Document);
            if (entity == null)
            {
                return(ContentAccess.NotFound);
            }
            hasPathAccess = user.HasContentPathAccess(entity, _entityService, _appCaches);

            if (hasPathAccess == false)
            {
                return(ContentAccess.Denied);
            }

            if (permissionsToCheck == null || permissionsToCheck.Count == 0)
            {
                return(ContentAccess.Granted);
            }

            //get the implicit/inherited permissions for the user for this path
            return(CheckPermissionsPath(entity.Path, user, permissionsToCheck)
                ? ContentAccess.Granted
                : ContentAccess.Denied);
        }
 /// <summary>
 /// Returns true or false if the current user has access to the node based on the user's allowed start node (path) access
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="queryStrings"></param>
 /// <returns></returns>
 protected bool HasPathAccess(IUmbracoEntity entity, FormCollection queryStrings)
 {
     if (entity == null)
     {
         return(false);
     }
     return(RecycleBinId == Constants.System.RecycleBinContent
         ? _backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser.HasContentPathAccess(entity, _entityService, _appCaches)
         : _backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser.HasMediaPathAccess(entity, _entityService, _appCaches));
 }
 /// <summary>
 /// Returns true or false if the current user has access to the node based on the user's allowed start node (path) access
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="queryStrings"></param>
 /// <returns></returns>
 protected bool HasPathAccess(IUmbracoEntity entity, FormDataCollection queryStrings)
 {
     if (entity == null)
     {
         return(false);
     }
     return(RecycleBinId == Constants.System.RecycleBinContent
         ? Security.CurrentUser.HasContentPathAccess(entity, Services.EntityService)
         : Security.CurrentUser.HasMediaPathAccess(entity, Services.EntityService));
 }
Ejemplo n.º 31
0
        private string GetPath(IUmbracoEntity item)
        {
            var path = item.Name;
            if (item.ParentId != -1)
            {
                var parent = _entityService.Get(item.ParentId);
                if (parent != null)
                {
                    path = GetPath(parent) + @"\" + path;
                }
            }

            return path;
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Creates a tree node for a content item based on an UmbracoEntity
        /// </summary>
        /// <param name="e"></param>
        /// <param name="parentId"></param>
        /// <param name="queryStrings"></param>
        /// <returns></returns>
        protected override TreeNode GetSingleTreeNode(IUmbracoEntity e, string parentId, FormDataCollection queryStrings)
        {
            var entity = (UmbracoEntity)e;

            //Special check to see if it ia a container, if so then we'll hide children.
            var isContainer = entity.AdditionalData.ContainsKey("IsContainer")
                && entity.AdditionalData["IsContainer"] is bool
                && (bool)entity.AdditionalData["IsContainer"];

            var node = CreateTreeNode(
                e.Id.ToInvariantString(),
                parentId,
                queryStrings,
                e.Name,
                entity.ContentTypeIcon,
                entity.HasChildren && (isContainer == false));

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

            if (isContainer)
                node.SetContainerStyle();

            return node;
        }
        /// <summary>
        /// Returns a collection of all menu items that can be on a content node
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected MenuItemCollection GetAllNodeMenuItems(IUmbracoEntity item)
        {
            var menu = new MenuItemCollection();
            menu.Items.Add<ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
            menu.Items.Add<ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias));
            
            //need to ensure some of these are converted to the legacy system - until we upgrade them all to be angularized.
            menu.Items.Add<ActionMove>(ui.Text("actions", ActionMove.Instance.Alias), true);
            menu.Items.Add<ActionCopy>(ui.Text("actions", ActionCopy.Instance.Alias));

            menu.Items.Add<ActionSort>(ui.Text("actions", ActionSort.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");

            menu.Items.Add<ActionRollback>(ui.Text("actions", ActionRollback.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add<ActionPublish>(ui.Text("actions", ActionPublish.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add<ActionToPublish>(ui.Text("actions", ActionToPublish.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add<ActionAssignDomain>(ui.Text("actions", ActionAssignDomain.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add<ActionRights>(ui.Text("actions", ActionRights.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add<ActionProtect>(ui.Text("actions", ActionProtect.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");
            
            menu.Items.Add<ActionNotify>(ui.Text("actions", ActionNotify.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");
            menu.Items.Add<ActionSendToTranslate>(ui.Text("actions", ActionSendToTranslate.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");

            menu.Items.Add<RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true);

            return menu;
        }
 protected abstract TreeNode GetSingleTreeNode(IUmbracoEntity e, string parentId, FormDataCollection queryStrings);
 /// <summary>
 /// Determins if the user has access to view the node/document
 /// </summary>
 /// <param name="doc">The Document to check permissions against</param>
 /// <param name="allowedUserOptions">A list of MenuItems that the user has permissions to execute on the current document</param>
 /// <remarks>By default the user must have Browse permissions to see the node in the Content tree</remarks>
 /// <returns></returns>        
 internal bool CanUserAccessNode(IUmbracoEntity doc, IEnumerable<MenuItem> allowedUserOptions)
 {
     return allowedUserOptions.Select(x => x.Action).OfType<ActionBrowse>().Any();
 }
        internal IEnumerable<MenuItem> GetAllowedUserMenuItemsForNode(IUmbracoEntity dd)
        {
            var actions = global::umbraco.BusinessLogic.Actions.Action.FromString(UmbracoUser.GetPermissions(dd.Path));

            // A user is allowed to delete their own stuff
            if (dd.CreatorId == UmbracoUser.Id && actions.Contains(ActionDelete.Instance) == false)
                actions.Add(ActionDelete.Instance);

            return actions.Select(x => new MenuItem(x));
        }
Ejemplo n.º 37
0
        internal void ConvertLegacyMenuItem(IUmbracoEntity item, string nodeType, string currentSection)
        {
            //First try to get a URL/title from the legacy action,
            // if that doesn't work, try to get the legacy confirm view

            //in some edge cases, item can be null so we'll just convert those to "-1" and "" for id and name since these edge cases don't need that.
            Attempt
                .Try(LegacyTreeDataConverter.GetUrlAndTitleFromLegacyAction(Action,
                                                                            item == null ? "-1" : item.Id.ToInvariantString(),
                                                                            nodeType,
                                                                            item == null ? "" : item.Name, currentSection),
                     action => LaunchDialogUrl(action.Url, action.DialogTitle))
                .OnFailure(() => LegacyTreeDataConverter.GetLegacyConfirmView(Action, currentSection),
                           view => LaunchDialogView(
                               view,
                               ui.GetText("defaultdialogs", "confirmdelete") + " '" + item.Name + "' ?"));
        } 
 private string GetFullPath(IUmbracoEntity entity)
 {
     var content = entity as IContent;
     var ancestorsPath = "";
     if (content != null)
         ancestorsPath = String.Join(" " + configuration.BreadcrumbSeparator + " ", content.Ancestors().Select(x => x.Name));
     return String.Format("{0} {1} {2}", ancestorsPath, configuration.BreadcrumbSeparator, entity.Name);
 }
Ejemplo n.º 39
0
 protected internal Content(IUmbracoEntity entity) : base(entity) { }
        /// <summary>
        /// Creates a tree node for a content item based on an UmbracoEntity
        /// </summary>
        /// <param name="e"></param>
        /// <param name="parentId"></param>
        /// <param name="queryStrings"></param>
        /// <returns></returns>
        protected override TreeNode GetSingleTreeNode(IUmbracoEntity e, string parentId, FormDataCollection queryStrings)
        {
            var entity = (UmbracoEntity) e;

            var allowedUserOptions = GetAllowedUserMenuItemsForNode(e);
            if (CanUserAccessNode(e, allowedUserOptions))
            {

                //Special check to see if it ia a container, if so then we'll hide children.
                var isContainer = e.AdditionalData.ContainsKey("IsContainer")
                    && e.AdditionalData["IsContainer"] is bool
                    && (bool)e.AdditionalData["IsContainer"];

                var node = CreateTreeNode(
                    e.Id.ToInvariantString(),
                    parentId,
                    queryStrings,
                    e.Name,
                    entity.ContentTypeIcon,
                    entity.HasChildren && (isContainer == false));

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

                if (isContainer)
                    node.SetContainerStyle();

                if (entity.IsPublished == false)
                    node.SetNotPublishedStyle();

                if (entity.HasPendingChanges)
                    node.SetHasUnpublishedVersionStyle();

                if (Access.IsProtected(e.Id, e.Path))
                    node.SetProtectedStyle();

                return node;
            }

            return null;
        }
        private Node GenerateJsonForTree(IUmbracoEntity content)
        {
            var children = Services.EntityService.GetChildren(content.Id);
            var isFolder = children.Any();

            var temp = new Node
            {
                title = content.Name,
                key = content.Id.ToString(),
                folder = isFolder,
                lazy = isFolder
            };

            return temp;
        }
Ejemplo n.º 42
0
 /// <summary>
 /// Internal initialization of a legacy Document object using the new IUmbracoEntity object
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="noSetup"></param>
 internal Document(IUmbracoEntity entity, bool noSetup = true) : base(entity)
 {
     if(noSetup == false)
         setupNode();
 }
Ejemplo n.º 43
0
        /// <summary>
        /// Relates two objects that are based on the <see cref="IUmbracoEntity"/> interface.
        /// </summary>
        /// <param name="parent">Parent entity</param>
        /// <param name="child">Child entity</param>
        /// <param name="relationType">The type of relation to create</param>
        /// <returns>The created <see cref="Relation"/></returns>
        public Relation Relate(IUmbracoEntity parent, IUmbracoEntity child, RelationType relationType)
        {
            //Ensure that the RelationType has an indentity before using it to relate two entities
            if(relationType.HasIdentity == false)
                Save(relationType);

            var relation = new Relation(parent.Id, child.Id, relationType);
            var uow = _uowProvider.GetUnitOfWork();
            using (var repository = _repositoryFactory.CreateRelationRepository(uow))
            {
                repository.AddOrUpdate(relation);
                uow.Commit();

                return relation;
            }
        }
Ejemplo n.º 44
0
        /// <summary>
        /// Relates two objects that are based on the <see cref="IUmbracoEntity"/> interface.
        /// </summary>
        /// <param name="parent">Parent entity</param>
        /// <param name="child">Child entity</param>
        /// <param name="relationTypeAlias">Alias of the type of relation to create</param>
        /// <returns>The created <see cref="Relation"/></returns>
        public Relation Relate(IUmbracoEntity parent, IUmbracoEntity child, string relationTypeAlias)
        {
            var relationType = GetRelationTypeByAlias(relationTypeAlias);
            if(relationType == null || string.IsNullOrEmpty(relationType.Alias))
                throw new ArgumentNullException(string.Format("No RelationType with Alias '{0}' exists.", relationTypeAlias));

            var relation = new Relation(parent.Id, child.Id, relationType);
            var uow = _uowProvider.GetUnitOfWork();
            using (var repository = _repositoryFactory.CreateRelationRepository(uow))
            {
                repository.AddOrUpdate(relation);
                uow.Commit();

                return relation;
            }
        }