SenseNet.ContentRepository.GenericContent.GetAllowedChildTypeNames C# (CSharp) Method

GetAllowedChildTypeNames() public method

public GetAllowedChildTypeNames ( ) : IEnumerable
return IEnumerable
        public IEnumerable<string> GetAllowedChildTypeNames()
        {
            // in case of folders and pages inherit settings from parent
            if (this.NodeType.Name == "Folder" || this.NodeType.Name == "Page")
            {
                var parent = Parent as GenericContent;
                if (parent == null)
                    return ContentType.EmptyAllowedChildTypeNames;
                return parent.GetAllowedChildTypeNames();
            }

            // collect types set on local instance
            var names = new List<string>();        
            var hasLocalItems = false;
            foreach (var ct in this.AllowedChildTypes)
            {
                hasLocalItems = true; //-- Indicates that the local list has items. The length of list is not enough because the permission filters the list and if the filter skips all elements, the user gets the list that declared on the content type.
                if (ct.Security.HasPermission(PermissionType.See))
                    names.Add(ct.Name);
            }

            // SystemFolder and TrashBag allows every type if there is no setting on local instance
            var systemFolderName = "SystemFolder";
            if (!hasLocalItems && (this.NodeType.Name == systemFolderName || this.NodeType.Name == "TrashBag"))
                return new string[0];

            // SystemFolder can be created anywhere if the user has the necessary permissions on the CTD
            var systemFolderType = ContentType.GetByName(systemFolderName);
            if (systemFolderType.Security.HasPermission(PermissionType.See))
                if (!names.Contains(systemFolderName))
                    names.Add(systemFolderName);

            if (hasLocalItems)
                return names;

            // settings come from CTD if no local setting is present
            foreach (var ct in this.ContentType.AllowedChildTypes)
            {
                if (ct.Security.HasPermission(PermissionType.See))
                    if (!names.Contains(ct.Name))
                        names.Add(ct.Name);
            }

            return names;
        }
        public IEnumerable<ContentType> GetAllowedChildTypes()

Usage Example

Esempio n. 1
0
        //====================================================================== Helper methods

        private static void AssertRestoreContentType(GenericContent targetParent, Node node)
        {
            if (targetParent == null || node == null)
            {
                throw new ArgumentNullException();
            }

            if (!(targetParent is IFolder))
            {
                throw new RestoreException(RestoreResultType.ForbiddenContentType, targetParent.Path);
            }

            var ctNames = targetParent.GetAllowedChildTypeNames().ToArray();

            if (ctNames.Length > 0 && !ctNames.Any(ctName => ctName == node.NodeType.Name))
            {
                throw new RestoreException(RestoreResultType.ForbiddenContentType, targetParent.Path);
            }
        }
All Usage Examples Of SenseNet.ContentRepository.GenericContent::GetAllowedChildTypeNames