protected virtual void OnItemCreating(ItemEventArgs e) { EventHandler <ItemEventArgs> handler = base.Events[EventItemCreating] as EventHandler <ItemEventArgs>; if (handler != null) { handler.Invoke(this, e); } if (e.AffectedItem != null) { IDefinitionManager definitions = Engine.Definitions; ISecurityManager security = Engine.SecurityManager; ContentActivator activator = Engine.Resolve <ContentActivator>(); ItemDefinition parentDefinition = definitions.GetDefinition(parentItem); if (parentDefinition.IsChildAllowed(definitions, parentItem, parentDefinition)) { e.AffectedItem = Engine.Resolve <ContentActivator>().CreateInstance(parentItem.GetContentType(), parentItem); return; } foreach (ItemDefinition definition in definitions.GetAllowedChildren(parentItem, null).WhereAuthorized(security, HttpContext.Current.User, parentItem)) { e.AffectedItem = activator.CreateInstance(definition.ItemType, parentItem); return; } throw new N2.Definitions.NoItemAllowedException(parentItem); } }
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(); } }
public override ActionResult Index() { if ("Tests" != (string)RouteData.DataTokens["area"]) { throw new Exception("Incorrect area: " + RouteData.Values["area"]); } return(PartialView(definitions.GetAllowedChildren(CurrentPage, null).WhereAuthorized(security, User, CurrentPage))); }
public override ActionResult Index() { if ("Tests" != (string)RouteData.DataTokens["area"]) { throw new Exception("Incorrect area: " + RouteData.Values["area"]); } if (CurrentItem.IsPage) { return(View()); } else { return(PartialView("Partial", definitions.GetAllowedChildren(CurrentPage, null).WhereAuthorized(Engine.SecurityManager, User, CurrentPage))); } }
public override ActionResult Index() { if ("Tests" != (string)RouteData.DataTokens["area"]) { throw new Exception("Incorrect area: " + RouteData.Values["area"]); } ViewData["RemainingItems"] = remainingItems; if (CurrentItem.ShowEveryone || security.IsEditor(User)) { return(PartialView(definitions.GetAllowedChildren(CurrentPage, null).WhereAuthorized(security, User, CurrentPage))); } else { return(Content("")); } }
private void LoadAdd() { lblLocationTitle.DataBind(); txtTitle.Text = Selection.SelectedItem.Title; ddlTypes.DataSource = Definitions.GetAllowedChildren(Selection.SelectedItem, "", User) .SelectMany(d => { return(new [] { new { Value = d.Discriminator, Title = d.Title } }.Union(Templates.GetTemplates(d.ItemType).Select(t => new { Value = d.Discriminator + ":" + t.Name, Title = "* " + t.Title }))); }); ddlTypes.DataBind(); }
private void LoadAdd() { lblLocationTitle.DataBind(); txtTitle.Text = Selection.SelectedItem.Title; ddlTypes.DataSource = Definitions.GetAllowedChildren(Selection.SelectedItem, null) .WhereAuthorized(Engine.SecurityManager, User, Selection.SelectedItem) .SelectMany(d => { return(new [] { new { Value = d.Discriminator, Title = d.Title } }.Union(Engine.Resolve <ITemplateAggregator>().GetTemplates(d.ItemType).Select(t => new { Value = d.Discriminator + ":" + t.Name, Title = "* " + t.Title }))); }); ddlTypes.DataBind(); }