2013-08-12 15:06:12 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Net.Http.Formatting;
|
|
|
|
|
|
using System.Web.Http;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Core.Models.EntityBase;
|
|
|
|
|
|
using Umbraco.Core.Services;
|
2013-08-16 17:25:52 +10:00
|
|
|
|
using Umbraco.Web.Mvc;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
using Umbraco.Web.Trees.Menu;
|
|
|
|
|
|
using umbraco;
|
|
|
|
|
|
using umbraco.BusinessLogic.Actions;
|
|
|
|
|
|
using umbraco.businesslogic;
|
|
|
|
|
|
using umbraco.interfaces;
|
2013-08-16 17:25:52 +10:00
|
|
|
|
using Constants = Umbraco.Core.Constants;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Trees
|
|
|
|
|
|
{
|
2013-09-04 17:36:05 +10:00
|
|
|
|
[LegacyBaseTree(typeof(loadContent))]
|
2013-08-12 15:06:12 +02:00
|
|
|
|
[Tree(Constants.Applications.Content, Constants.Trees.Content, "Content")]
|
2013-08-16 17:25:52 +10:00
|
|
|
|
[PluginController("UmbracoTrees")]
|
2013-08-12 15:06:12 +02:00
|
|
|
|
public class ContentTreeController : ContentTreeControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
protected override TreeNode CreateRootNode(FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
2013-10-01 16:38:10 +10:00
|
|
|
|
var node = base.CreateRootNode(queryStrings);
|
|
|
|
|
|
//if the user's start node is not default, then ensure the root doesn't have a menu
|
2013-09-26 14:28:18 +10:00
|
|
|
|
if (Security.CurrentUser.StartContentId != Constants.System.Root)
|
2013-08-12 15:06:12 +02:00
|
|
|
|
{
|
2013-10-01 16:38:10 +10:00
|
|
|
|
node.MenuUrl = "";
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
2013-09-04 17:36:05 +10:00
|
|
|
|
return node;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override int RecycleBinId
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return Constants.System.RecycleBinContent; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override bool RecycleBinSmells
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return Services.ContentService.RecycleBinSmells(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-01 16:38:10 +10:00
|
|
|
|
protected override int UserStartNode
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return Security.CurrentUser.StartContentId; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
protected override TreeNodeCollection PerformGetTreeNodes(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var entities = GetChildEntities(id);
|
|
|
|
|
|
|
|
|
|
|
|
var nodes = new TreeNodeCollection();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var entity in entities)
|
|
|
|
|
|
{
|
|
|
|
|
|
var e = (UmbracoEntity)entity;
|
2013-09-19 10:38:37 +02:00
|
|
|
|
|
2013-09-26 15:55:38 +10:00
|
|
|
|
var allowedUserOptions = GetAllowedUserMenuItemsForNode(e);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
if (CanUserAccessNode(e, allowedUserOptions))
|
2013-10-01 21:12:32 +10:00
|
|
|
|
{
|
2013-09-19 10:38:37 +02:00
|
|
|
|
var hasChildren = e.HasChildren;
|
2013-10-01 21:12:32 +10:00
|
|
|
|
|
|
|
|
|
|
//Special check to see if it ia a container, if so then we'll hide children.
|
|
|
|
|
|
if (entity.AdditionalData["IsContainer"] is bool && (bool) entity.AdditionalData["IsContainer"])
|
|
|
|
|
|
{
|
2013-09-19 10:38:37 +02:00
|
|
|
|
hasChildren = false;
|
2013-10-01 21:12:32 +10:00
|
|
|
|
}
|
2013-09-19 10:38:37 +02:00
|
|
|
|
|
2013-09-04 17:36:05 +10:00
|
|
|
|
var node = CreateTreeNode(
|
2013-08-12 15:06:12 +02:00
|
|
|
|
e.Id.ToInvariantString(),
|
|
|
|
|
|
queryStrings,
|
|
|
|
|
|
e.Name,
|
|
|
|
|
|
e.ContentTypeIcon,
|
2013-09-19 10:38:37 +02:00
|
|
|
|
hasChildren);
|
2013-09-04 17:36:05 +10:00
|
|
|
|
|
|
|
|
|
|
nodes.Add(node);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return nodes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (id == Constants.System.Root.ToInvariantString())
|
|
|
|
|
|
{
|
2013-09-26 15:55:38 +10:00
|
|
|
|
var menu = new MenuItemCollection();
|
|
|
|
|
|
|
2013-10-01 16:38:10 +10:00
|
|
|
|
//if the user's start node is not the root then ensure the root menu is empty/doesn't exist
|
|
|
|
|
|
if (Security.CurrentUser.StartContentId != Constants.System.Root)
|
|
|
|
|
|
{
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-26 15:55:38 +10:00
|
|
|
|
//set the default to create
|
|
|
|
|
|
menu.DefaultMenuAlias = ActionNew.Instance.Alias;
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
// we need to get the default permissions as you can't set permissions on the very root node
|
2013-10-01 16:38:10 +10:00
|
|
|
|
//TODO: Use the new services to get permissions
|
2013-08-12 15:06:12 +02:00
|
|
|
|
var nodeActions = global::umbraco.BusinessLogic.Actions.Action.FromString(
|
|
|
|
|
|
UmbracoUser.GetPermissions(Constants.System.Root.ToInvariantString()))
|
|
|
|
|
|
.Select(x => new MenuItem(x));
|
|
|
|
|
|
|
|
|
|
|
|
//these two are the standard items
|
|
|
|
|
|
menu.AddMenuItem<ActionNew>();
|
2013-10-02 00:11:10 +02:00
|
|
|
|
menu.AddMenuItem<ActionSort>(true).ConvertLegacyMenuItem(null, "content", "content");
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
|
|
|
|
|
//filter the standard items
|
2013-09-26 15:55:38 +10:00
|
|
|
|
FilterUserAllowedMenuItems(menu, nodeActions);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
2013-09-26 15:55:38 +10:00
|
|
|
|
if (menu.MenuItems.Any())
|
2013-08-12 15:06:12 +02:00
|
|
|
|
{
|
2013-09-26 15:55:38 +10:00
|
|
|
|
menu.MenuItems.Last().SeperatorBefore = true;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// add default actions for *all* users
|
2013-09-26 15:55:38 +10:00
|
|
|
|
menu.AddMenuItem<ActionRePublish>().ConvertLegacyMenuItem(null, "content", "content");
|
|
|
|
|
|
menu.AddMenuItem<RefreshNode, ActionRefresh>(true);
|
2013-10-01 12:32:27 +02:00
|
|
|
|
|
|
|
|
|
|
foreach (var menuItem in menu.MenuItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
menuItem.Name = ui.Text("actions", menuItem.Alias);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-26 15:55:38 +10:00
|
|
|
|
return menu;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-26 15:55:38 +10:00
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
//return a normal node menu:
|
|
|
|
|
|
int iid;
|
|
|
|
|
|
if (int.TryParse(id, out iid) == false)
|
|
|
|
|
|
{
|
2013-09-03 12:27:48 +10:00
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
var item = Services.EntityService.Get(iid, UmbracoObjectTypes.Document);
|
|
|
|
|
|
if (item == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-26 15:55:38 +10:00
|
|
|
|
var nodeMenu = GetAllNodeMenuItems(item);
|
|
|
|
|
|
var allowedMenuItems = GetAllowedUserMenuItemsForNode(item);
|
|
|
|
|
|
|
|
|
|
|
|
FilterUserAllowedMenuItems(nodeMenu, allowedMenuItems);
|
|
|
|
|
|
|
|
|
|
|
|
//set the default to create
|
|
|
|
|
|
nodeMenu.DefaultMenuAlias = ActionNew.Instance.Alias;
|
|
|
|
|
|
|
2013-10-01 12:32:27 +02:00
|
|
|
|
foreach (var menuItem in nodeMenu.MenuItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
menuItem.Name = ui.Text("actions", menuItem.Alias);
|
|
|
|
|
|
}
|
2013-09-26 15:55:38 +10:00
|
|
|
|
return nodeMenu;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override UmbracoObjectTypes UmbracoObjectType
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return UmbracoObjectTypes.Document; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-26 15:55:38 +10:00
|
|
|
|
/// <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)
|
2013-08-12 15:06:12 +02:00
|
|
|
|
{
|
|
|
|
|
|
var menu = new MenuItemCollection();
|
|
|
|
|
|
menu.AddMenuItem<ActionNew>();
|
|
|
|
|
|
menu.AddMenuItem<ActionDelete>(true);
|
2013-09-03 12:27:48 +10:00
|
|
|
|
|
|
|
|
|
|
//need to ensure some of these are converted to the legacy system - until we upgrade them all to be angularized.
|
2013-10-01 00:54:46 +02:00
|
|
|
|
menu.AddMenuItem<ActionMove>(true);
|
2013-10-02 00:11:10 +02:00
|
|
|
|
menu.AddMenuItem<ActionCopy>();
|
2013-09-03 12:27:48 +10:00
|
|
|
|
|
2013-10-01 00:54:46 +02:00
|
|
|
|
menu.AddMenuItem<ActionSort>(true).ConvertLegacyMenuItem(item, "content", "content");
|
2013-09-03 12:27:48 +10:00
|
|
|
|
|
|
|
|
|
|
menu.AddMenuItem<ActionRollback>().ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.AddMenuItem<ActionPublish>(true).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.AddMenuItem<ActionToPublish>().ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.AddMenuItem<ActionAssignDomain>().ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.AddMenuItem<ActionRights>().ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.AddMenuItem<ActionProtect>(true).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.AddMenuItem<ActionUnPublish>(true).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.AddMenuItem<ActionNotify>(true).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.AddMenuItem<ActionSendToTranslate>().ConvertLegacyMenuItem(item, "content", "content");
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
2013-08-20 17:25:17 +10:00
|
|
|
|
menu.AddMenuItem<RefreshNode, ActionRefresh>(true);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2013-07-30 13:29:05 +10:00
|
|
|
|
}
|