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-09-04 17:36:05 +10:00
|
|
|
|
TreeNode node;
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
//if the user's start node is not default, then return their start node as the root node.
|
|
|
|
|
|
if (UmbracoUser.StartNodeId != Constants.System.Root)
|
|
|
|
|
|
{
|
|
|
|
|
|
var currApp = queryStrings.GetValue<string>(TreeQueryStringParameters.Application);
|
|
|
|
|
|
var userRoot = Services.EntityService.Get(UmbracoUser.StartNodeId, UmbracoObjectTypes.Document);
|
|
|
|
|
|
if (userRoot == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-04 17:36:05 +10:00
|
|
|
|
node = new TreeNode(
|
2013-08-12 15:06:12 +02:00
|
|
|
|
userRoot.Id.ToInvariantString(),
|
|
|
|
|
|
"", //root nodes aren't expandable, no need to lookup the child nodes url
|
|
|
|
|
|
Url.GetMenuUrl(GetType(), userRoot.Id.ToInvariantString(), queryStrings))
|
2013-09-04 17:36:05 +10:00
|
|
|
|
{
|
|
|
|
|
|
HasChildren = true,
|
|
|
|
|
|
RoutePath = currApp,
|
|
|
|
|
|
Title = userRoot.Name
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
2013-09-04 17:36:05 +10:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
node = base.CreateRootNode(queryStrings);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-04 17:36:05 +10:00
|
|
|
|
//InjectLegacyTreeCompatibility(node, queryStrings);
|
|
|
|
|
|
|
|
|
|
|
|
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(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-08-12 15:06:12 +02:00
|
|
|
|
var allowedUserOptions = GetUserMenuItemsForNode(e);
|
|
|
|
|
|
if (CanUserAccessNode(e, allowedUserOptions))
|
|
|
|
|
|
{
|
2013-09-19 10:38:37 +02:00
|
|
|
|
//TODO: if the node is of a specific type, don't list its children
|
|
|
|
|
|
//this is to enable the list view on the editor
|
|
|
|
|
|
|
|
|
|
|
|
//for WIP I'm just checking against a hardcoded value
|
|
|
|
|
|
var hasChildren = e.HasChildren;
|
|
|
|
|
|
if (e.ContentTypeAlias == "umbNewsArea")
|
|
|
|
|
|
hasChildren = false;
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
//InjectLegacyTreeCompatibility(node, queryStrings);
|
|
|
|
|
|
|
|
|
|
|
|
nodes.Add(node);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return nodes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var menu = new MenuItemCollection();
|
|
|
|
|
|
|
|
|
|
|
|
if (id == Constants.System.Root.ToInvariantString())
|
|
|
|
|
|
{
|
|
|
|
|
|
// we need to get the default permissions as you can't set permissions on the very root node
|
|
|
|
|
|
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>();
|
|
|
|
|
|
menu.AddMenuItem<ActionSort>();
|
|
|
|
|
|
|
|
|
|
|
|
//filter the standard items
|
|
|
|
|
|
var allowedMenu = GetUserAllowedMenuItems(menu, nodeActions);
|
|
|
|
|
|
|
|
|
|
|
|
if (allowedMenu.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
allowedMenu.Last().SeperatorBefore = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// add default actions for *all* users
|
2013-09-26 13:03:09 +10:00
|
|
|
|
allowedMenu.AddMenuItem<ActionRePublish>().ConvertLegacyMenuItem(null, "content", "content");
|
2013-08-20 17:25:17 +10:00
|
|
|
|
allowedMenu.AddMenuItem<RefreshNode, ActionRefresh>(true);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
return allowedMenu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return GetUserAllowedMenuItems(
|
2013-09-03 12:27:48 +10:00
|
|
|
|
CreateAllowedActions(item),
|
2013-08-12 15:06:12 +02:00
|
|
|
|
GetUserMenuItemsForNode(item));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override UmbracoObjectTypes UmbracoObjectType
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return UmbracoObjectTypes.Document; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-03 12:27:48 +10:00
|
|
|
|
protected IEnumerable<MenuItem> CreateAllowedActions(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.
|
|
|
|
|
|
menu.AddMenuItem<ActionMove>(true).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.AddMenuItem<ActionCopy>().ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
menu.AddMenuItem<ActionSort>(true);
|
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-09-04 17:36:05 +10:00
|
|
|
|
///// <summary>
|
|
|
|
|
|
///// This is required so that the legacy tree dialog pickers and the legacy TreeControl.ascx stuff works with these new trees.
|
|
|
|
|
|
///// </summary>
|
|
|
|
|
|
///// <param name="node"></param>
|
|
|
|
|
|
///// <param name="queryStrings"></param>
|
|
|
|
|
|
///// <remarks>
|
|
|
|
|
|
///// NOTE: That if developers create brand new trees using webapi controllers then they'll need to manually make it
|
|
|
|
|
|
///// compatible with the legacy tree pickers, 99.9% of the time devs won't be doing that and once we make the new tree
|
|
|
|
|
|
///// pickers and devs update their apps to be angularized it won't matter
|
|
|
|
|
|
///// </remarks>
|
|
|
|
|
|
//private void InjectLegacyTreeCompatibility(TreeNode node, FormDataCollection queryStrings)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// if (IsDialog(queryStrings))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// node.AdditionalData["legacyDialogAction"] = "javascript:openContent(" + node.NodeId + ");";
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
|
|
|
|
|
}
|
2013-07-30 13:29:05 +10:00
|
|
|
|
}
|