Exemple #1
0
        public void IsChildTypeAllowedWorksAsExpected()
        {
            ItemDefinition parentDefinition = engine.Definitions.GetDefinition(typeof(ItemWithDetails));

            Assert.That(parentDefinition.GetAllowedChildren(engine.Definitions, null).Contains(engine.Definitions.GetDefinition(typeof(ItemInZone1Or2))));
            Assert.That(!parentDefinition.GetAllowedChildren(engine.Definitions, null).Contains(engine.Definitions.GetDefinition(typeof(SideshowItem))));
        }
        public void RestrictChildrenAttribute_AllowsChildren_WithCorrectTemplateName()
        {
            var rca = new RestrictChildrenAttribute(typeof(DefinitionOppressedChild))
            {
                TemplateNames = new[] { "Wide" }
            };

            rca.Refine(parentDefinition, new List <ItemDefinition>());

            var allowedChildren = parentDefinition.GetAllowedChildren(definitions, new DefinitionControllingParent()).ToList();

            Assert.That(allowedChildren.Single().ItemType, Is.EqualTo(typeof(DefinitionOppressedChild)));
        }
Exemple #3
0
        public void Item_WithoutTheInterface_IsntAllowed()
        {
            ItemDefinition menuDefinition     = definitions.GetDefinition(typeof(DefinitionMenuItem));
            ItemDefinition textPageDefinition = definitions.GetDefinition(typeof(DefinitionTextItem));

            Assert.That(!textPageDefinition.GetAllowedChildren(definitions, null).Contains(menuDefinition));
        }
Exemple #4
0
        public void Interfaces_CanBeUsedToConstrainAllowedTypes()
        {
            ItemDefinition menuDefinition      = definitions.GetDefinition(typeof(DefinitionMenuItem));        // RestrictParents: ILeftColumnlPage
            ItemDefinition startPageDefinition = definitions.GetDefinition(typeof(DefinitionStartPage));       // RestrictParents: None, implements ILeftColumnlPage

            Assert.That(startPageDefinition.GetAllowedChildren(definitions, null).Contains(menuDefinition));
        }
Exemple #5
0
        private void LoadAllowedTypes()
        {
            int allowedChildrenCount = ParentItemDefinition.GetAllowedChildren(Definitions, Selection.SelectedItem).Count();
            IList <ItemDefinition> allowedChildren = Definitions.GetAllowedChildren(Selection.SelectedItem, ZoneName)
                                                     .WhereAuthorized(Engine.SecurityManager, User, Selection.SelectedItem)
                                                     .ToList();

            if (!IsAuthorized(Permission.Write))
            {
                cvPermission.IsValid = false;
                return;
            }

            if (allowedChildrenCount == 0)
            {
                Title = string.Format(GetLocalResourceString("NewPage.Title.NoneAllowed", "No item is allowed below an item of type \"{0}\""), ParentItemDefinition.Title);
            }
            else if (allowedChildrenCount == 1 && allowedChildren.Count == 1)
            {
                Response.Redirect(GetEditUrl(allowedChildren[0]));
            }
            else
            {
                Title = string.Format(GetLocalResourceString("NewPage.Title.Select", "Select type of item below \"{0}\""), ActualItem.Title);

                var top  = allowedChildren.OrderByDescending(d => d.NumberOfItems).ThenBy(d => d.SortOrder).Take(1).ToList();
                var rest = allowedChildren.Except(top).ToList();

                AvailableDefinitions = top.Union(rest).ToList();
            }
        }
Exemple #6
0
        public void AllowedChildrenAreCorrect()
        {
            ItemDefinition definition = engine.Definitions.GetDefinition(typeof(ItemWithDetails));

            Assert.IsNotNull(definition);
            Assert.That(definition.GetAllowedChildren(engine.Definitions, null).Contains(engine.Definitions.GetDefinition(typeof(ItemInZone1Or2))));
        }
Exemple #7
0
        /// <summary>Retrieves allowed item definitions.</summary>
        /// <param name="parentItem">The parent item.</param>
        /// <param name="user">The user to restrict access for.</param>
        /// <returns>Item definitions allowed by zone, parent restrictions and security.</returns>
        public virtual IEnumerable <ItemDefinition> GetAllowedDefinitions(ContentItem parentItem, IPrincipal user)
        {
            ItemDefinition containerDefinition = Definitions.GetDefinition(parentItem);

            foreach (ItemDefinition childDefinition in containerDefinition.GetAllowedChildren(Definitions, parentItem))
            {
                if (childDefinition.Enabled && childDefinition.IsAuthorized(user) && childDefinition.AllowedIn != N2.Integrity.AllowedZones.None)
                {
                    yield return(childDefinition);
                }
            }
        }
Exemple #8
0
        public void ValidateRootDefinition()
        {
            ItemDefinition rootDefinition      = engine.Definitions.GetDefinition(typeof(Definitions.IntegrityRoot));
            ItemDefinition startPageDefinition = engine.Definitions.GetDefinition(typeof(Definitions.IntegrityStartPage));

            Assert.That(rootDefinition.GetAllowedChildren(engine.Definitions, null).Contains(startPageDefinition));
            //EnumerableAssert.Contains(rootDefinition.AllowedChildren, startPageDefinition);
            Assert.IsNull(rootDefinition.AuthorizedRoles);
            Assert.AreEqual(0, rootDefinition.AvailableZones.Count);
            Assert.AreEqual(0, rootDefinition.Containers.Count);
            Assert.IsEmpty(rootDefinition.Description);
            Assert.AreEqual(typeof(Definitions.IntegrityRoot).Name, rootDefinition.Discriminator);
            Assert.That(rootDefinition.Displayables.Count, Is.EqualTo(17));
            Assert.AreEqual(0, rootDefinition.Editables.Count);
            EnumerableAssert.Contains(engine.Definitions.GetAllowedChildren(new Definitions.IntegrityRoot(), null, null), startPageDefinition);
            Assert.AreEqual(0, rootDefinition.Editables.Count);
            Assert.AreEqual(0, rootDefinition.GetModifiers("Title").Count);
            Assert.AreEqual(0, rootDefinition.EditableModifiers.Count);
            Assert.AreEqual(0, rootDefinition.SortOrder);
            Assert.AreEqual(typeof(Definitions.IntegrityRoot).Name, rootDefinition.Title);
        }
Exemple #9
0
        protected IList <ItemDefinition> AllowedChildren(object dataItem)
        {
            ItemDefinition d = dataItem as ItemDefinition;

            return(d.GetAllowedChildren(N2.Context.Current.Definitions, Activator.CreateInstance(d.ItemType) as ContentItem).ToList());
        }