2013-08-12 15:06:12 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
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-10-08 12:38:27 +11:00
|
|
|
|
using Umbraco.Web.Models.Trees;
|
2013-08-16 17:25:52 +10:00
|
|
|
|
using Umbraco.Web.Mvc;
|
2013-11-20 14:18:03 +11:00
|
|
|
|
using Umbraco.Web.WebApi.Filters;
|
2016-03-17 15:28:46 +01:00
|
|
|
|
using Umbraco.Web._Legacy.Actions;
|
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-11-20 14:18:03 +11:00
|
|
|
|
//We will not allow the tree to render unless the user has access to any of the sections that the tree gets rendered
|
|
|
|
|
|
// this is not ideal but until we change permissions to be tree based (not section) there's not much else we can do here.
|
|
|
|
|
|
[UmbracoApplicationAuthorize(
|
|
|
|
|
|
Constants.Applications.Content,
|
|
|
|
|
|
Constants.Applications.Media,
|
|
|
|
|
|
Constants.Applications.Users,
|
|
|
|
|
|
Constants.Applications.Settings,
|
|
|
|
|
|
Constants.Applications.Developer,
|
|
|
|
|
|
Constants.Applications.Members)]
|
2015-09-28 08:54:00 +02:00
|
|
|
|
[Tree(Constants.Applications.Content, Constants.Trees.Content)]
|
2013-08-16 17:25:52 +10:00
|
|
|
|
[PluginController("UmbracoTrees")]
|
2013-10-03 11:25:26 +10:00
|
|
|
|
[CoreTree]
|
2013-08-12 15:06:12 +02:00
|
|
|
|
public class ContentTreeController : ContentTreeControllerBase
|
|
|
|
|
|
{
|
2013-12-12 14:10:03 +11:00
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
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
|
|
|
|
}
|
2016-03-15 16:39:17 +01:00
|
|
|
|
node.Name = Services.TextService.Localize("sections/"+ Constants.Trees.Content);
|
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; }
|
|
|
|
|
|
}
|
2014-09-23 16:50:05 +10:00
|
|
|
|
|
2013-12-12 13:27:33 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates a tree node for a content item based on an UmbracoEntity
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
/// <param name="parentId"></param>
|
|
|
|
|
|
/// <param name="queryStrings"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2013-12-12 14:10:03 +11:00
|
|
|
|
protected override TreeNode GetSingleTreeNode(IUmbracoEntity e, string parentId, FormDataCollection queryStrings)
|
2013-12-12 13:27:33 +11:00
|
|
|
|
{
|
2013-12-12 14:10:03 +11:00
|
|
|
|
var entity = (UmbracoEntity) e;
|
|
|
|
|
|
|
2013-12-12 13:27:33 +11:00
|
|
|
|
var allowedUserOptions = GetAllowedUserMenuItemsForNode(e);
|
|
|
|
|
|
if (CanUserAccessNode(e, allowedUserOptions))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//Special check to see if it ia a container, if so then we'll hide children.
|
2014-01-28 15:49:04 +01:00
|
|
|
|
var isContainer = e.IsContainer(); // && (queryStrings.Get("isDialog") != "true");
|
2013-12-12 13:27:33 +11:00
|
|
|
|
|
|
|
|
|
|
var node = CreateTreeNode(
|
|
|
|
|
|
e.Id.ToInvariantString(),
|
|
|
|
|
|
parentId,
|
|
|
|
|
|
queryStrings,
|
|
|
|
|
|
e.Name,
|
2013-12-12 14:10:03 +11:00
|
|
|
|
entity.ContentTypeIcon,
|
|
|
|
|
|
entity.HasChildren && (isContainer == false));
|
2013-12-12 13:27:33 +11:00
|
|
|
|
|
2013-12-12 14:10:03 +11:00
|
|
|
|
node.AdditionalData.Add("contentType", entity.ContentTypeAlias);
|
2013-12-12 13:27:33 +11:00
|
|
|
|
|
|
|
|
|
|
if (isContainer)
|
2014-10-08 14:26:18 +11:00
|
|
|
|
{
|
|
|
|
|
|
node.AdditionalData.Add("isContainer", true);
|
2013-12-12 13:27:33 +11:00
|
|
|
|
node.SetContainerStyle();
|
2014-10-08 14:26:18 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-12-12 13:27:33 +11:00
|
|
|
|
|
2013-12-12 14:10:03 +11:00
|
|
|
|
if (entity.IsPublished == false)
|
2013-12-12 13:27:33 +11:00
|
|
|
|
node.SetNotPublishedStyle();
|
|
|
|
|
|
|
2013-12-12 14:10:03 +11:00
|
|
|
|
if (entity.HasPendingChanges)
|
2013-12-12 13:27:33 +11:00
|
|
|
|
node.SetHasUnpublishedVersionStyle();
|
|
|
|
|
|
|
2015-01-28 19:46:05 +11:00
|
|
|
|
if (Services.PublicAccessService.IsProtected(e.Path))
|
2013-12-12 13:27:33 +11:00
|
|
|
|
node.SetProtectedStyle();
|
|
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
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
|
2016-03-16 17:52:08 +01:00
|
|
|
|
var permission = Services.UserService.GetPermissions(Security.CurrentUser, Constants.System.Root).First();
|
2016-03-17 15:28:46 +01:00
|
|
|
|
var nodeActions = global::Umbraco.Web._Legacy.Actions.Action.FromEntityPermission(permission)
|
2016-03-16 17:52:08 +01:00
|
|
|
|
.Select(x => new MenuItem(x));
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
|
|
|
|
|
//these two are the standard items
|
2016-03-15 16:58:13 +01:00
|
|
|
|
menu.Items.Add<ActionNew>(Services.TextService.Localize("actions", ActionNew.Instance.Alias));
|
|
|
|
|
|
menu.Items.Add<ActionSort>(Services.TextService.Localize("actions", ActionSort.Instance.Alias), 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-10-03 15:05:48 +10:00
|
|
|
|
if (menu.Items.Any())
|
2013-08-12 15:06:12 +02:00
|
|
|
|
{
|
2013-10-03 15:05:48 +10:00
|
|
|
|
menu.Items.Last().SeperatorBefore = true;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// add default actions for *all* users
|
2016-03-15 16:58:13 +01:00
|
|
|
|
menu.Items.Add<ActionRePublish>(Services.TextService.Localize("actions", ActionRePublish.Instance.Alias)).ConvertLegacyMenuItem(null, "content", "content");
|
|
|
|
|
|
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true);
|
2013-10-02 20:00:01 +10:00
|
|
|
|
|
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);
|
|
|
|
|
|
|
2013-10-24 16:54:17 +11:00
|
|
|
|
//if the media item is in the recycle bin, don't have a default menu, just show the regular menu
|
|
|
|
|
|
if (item.Path.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Contains(RecycleBinId.ToInvariantString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
nodeMenu.DefaultMenuAlias = null;
|
2016-03-15 16:58:13 +01:00
|
|
|
|
nodeMenu.Items.Insert(2, new MenuItem(ActionRestore.Instance, Services.TextService.Localize("actions", ActionRestore.Instance.Alias)));
|
2013-10-24 16:54:17 +11:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//set the default to create
|
|
|
|
|
|
nodeMenu.DefaultMenuAlias = ActionNew.Instance.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-11-19 12:28:50 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns true or false if the current user has access to the node based on the user's allowed start node (path) access
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
/// <param name="queryStrings"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
protected override bool HasPathAccess(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var content = Services.ContentService.GetById(int.Parse(id));
|
|
|
|
|
|
if (content == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return Security.CurrentUser.HasPathAccess(content);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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();
|
2016-03-15 16:58:13 +01:00
|
|
|
|
menu.Items.Add<ActionNew>(Services.TextService.Localize("actions", ActionNew.Instance.Alias));
|
|
|
|
|
|
menu.Items.Add<ActionDelete>(Services.TextService.Localize("actions", ActionDelete.Instance.Alias));
|
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.
|
2016-03-15 16:58:13 +01:00
|
|
|
|
menu.Items.Add<ActionMove>(Services.TextService.Localize("actions", ActionMove.Instance.Alias), true);
|
|
|
|
|
|
menu.Items.Add<ActionCopy>(Services.TextService.Localize("actions", ActionCopy.Instance.Alias));
|
|
|
|
|
|
menu.Items.Add<ActionChangeDocType>(Services.TextService.Localize("actions", ActionChangeDocType.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
|
|
|
|
|
|
menu.Items.Add<ActionSort>(Services.TextService.Localize("actions", ActionSort.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
|
|
|
|
|
|
menu.Items.Add<ActionRollback>(Services.TextService.Localize("actions", ActionRollback.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.Items.Add<ActionAudit>(Services.TextService.Localize("actions", ActionAudit.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.Items.Add<ActionPublish>(Services.TextService.Localize("actions", ActionPublish.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.Items.Add<ActionToPublish>(Services.TextService.Localize("actions", ActionToPublish.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.Items.Add<ActionAssignDomain>(Services.TextService.Localize("actions", ActionAssignDomain.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.Items.Add<ActionRights>(Services.TextService.Localize("actions", ActionRights.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.Items.Add<ActionProtect>(Services.TextService.Localize("actions", ActionProtect.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");
|
2013-11-05 09:38:54 +11:00
|
|
|
|
|
2016-03-15 16:58:13 +01:00
|
|
|
|
menu.Items.Add<ActionNotify>(Services.TextService.Localize("actions", ActionNotify.Instance.Alias), true).ConvertLegacyMenuItem(item, "content", "content");
|
|
|
|
|
|
menu.Items.Add<ActionSendToTranslate>(Services.TextService.Localize("actions", ActionSendToTranslate.Instance.Alias)).ConvertLegacyMenuItem(item, "content", "content");
|
2013-10-03 15:05:48 +10:00
|
|
|
|
|
2016-03-15 16:58:13 +01:00
|
|
|
|
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2013-07-30 13:29:05 +10:00
|
|
|
|
}
|