2013-09-03 12:27:48 +10:00
|
|
|
|
using System;
|
2017-09-12 16:22:16 +02:00
|
|
|
|
using System.Collections.Generic;
|
2013-09-03 12:27:48 +10:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
using System.Net.Http.Formatting;
|
2013-09-03 12:27:48 +10:00
|
|
|
|
using System.Web.Http;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
2018-01-15 11:32:30 +01:00
|
|
|
|
using Umbraco.Core.Models.Entities;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
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;
|
2017-09-12 16:22:16 +02:00
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
|
|
|
|
|
using Umbraco.Web.Search;
|
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.Settings,
|
|
|
|
|
|
Constants.Applications.Developer,
|
|
|
|
|
|
Constants.Applications.Members)]
|
2015-09-28 08:54:00 +02:00
|
|
|
|
[Tree(Constants.Applications.Media, Constants.Trees.Media)]
|
2013-08-16 17:25:52 +10:00
|
|
|
|
[PluginController("UmbracoTrees")]
|
2013-10-03 11:25:26 +10:00
|
|
|
|
[CoreTree]
|
2017-09-12 16:22:16 +02:00
|
|
|
|
[SearchableTree("searchResultFormatter", "configureMediaResult")]
|
|
|
|
|
|
public class MediaTreeController : ContentTreeControllerBase, ISearchableTree
|
2013-08-12 15:06:12 +02:00
|
|
|
|
{
|
2017-09-12 16:22:16 +02:00
|
|
|
|
private readonly UmbracoTreeSearcher _treeSearcher = new UmbracoTreeSearcher();
|
2017-09-23 10:08:18 +02:00
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
protected override int RecycleBinId => Constants.System.RecycleBinMedia;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
protected override bool RecycleBinSmells => Services.MediaService.RecycleBinSmells();
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
2017-09-12 16:22:16 +02:00
|
|
|
|
private int[] _userStartNodes;
|
|
|
|
|
|
protected override int[] UserStartNodes
|
|
|
|
|
|
=> _userStartNodes ?? (_userStartNodes = Security.CurrentUser.CalculateMediaStartNodeIds(Services.EntityService));
|
2013-10-01 16:38:10 +10:00
|
|
|
|
|
2013-12-12 14:10:03 +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>
|
2018-01-15 11:32:30 +01:00
|
|
|
|
protected override TreeNode GetSingleTreeNode(IEntitySlim entity, string parentId, FormDataCollection queryStrings)
|
2013-12-12 14:10:03 +11:00
|
|
|
|
{
|
|
|
|
|
|
//Special check to see if it ia a container, if so then we'll hide children.
|
2018-01-15 11:32:30 +01:00
|
|
|
|
var isContainer = entity.IsContainer; // && (queryStrings.Get("isDialog") != "true");
|
2013-11-15 16:19:46 +11:00
|
|
|
|
|
2013-12-12 14:10:03 +11:00
|
|
|
|
var node = CreateTreeNode(
|
2017-05-12 14:49:44 +02:00
|
|
|
|
entity,
|
2017-09-19 18:19:05 +02:00
|
|
|
|
Constants.ObjectTypes.Media,
|
2013-12-12 14:10:03 +11:00
|
|
|
|
parentId,
|
|
|
|
|
|
queryStrings,
|
2018-01-15 11:32:30 +01:00
|
|
|
|
entity.HasChildren && !isContainer);
|
2013-11-15 16:19:46 +11:00
|
|
|
|
|
2018-01-15 11:32:30 +01:00
|
|
|
|
// entity is either a container, or a media
|
2013-12-12 14:10:03 +11:00
|
|
|
|
if (isContainer)
|
2014-10-09 00:04:25 +11:00
|
|
|
|
{
|
2013-12-12 14:10:03 +11:00
|
|
|
|
node.SetContainerStyle();
|
2014-10-09 00:04:25 +11:00
|
|
|
|
node.AdditionalData.Add("isContainer", true);
|
|
|
|
|
|
}
|
2018-01-15 11:32:30 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var contentEntity = (IContentEntitySlim) entity;
|
|
|
|
|
|
node.AdditionalData.Add("contentType", contentEntity.ContentTypeAlias);
|
|
|
|
|
|
}
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
2013-12-12 14:10:03 +11:00
|
|
|
|
return node;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var menu = new MenuItemCollection();
|
|
|
|
|
|
|
2013-09-26 15:55:38 +10:00
|
|
|
|
//set the default
|
|
|
|
|
|
menu.DefaultMenuAlias = ActionNew.Instance.Alias;
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
if (id == Constants.System.Root.ToInvariantString())
|
|
|
|
|
|
{
|
2017-09-19 15:51:47 +02:00
|
|
|
|
// if the user's start node is not the root then the only menu item to display is refresh
|
2017-09-12 16:22:16 +02:00
|
|
|
|
if (UserStartNodes.Contains(Constants.System.Root) == false)
|
2013-10-01 16:38:10 +10:00
|
|
|
|
{
|
2017-09-19 15:51:47 +02:00
|
|
|
|
menu.Items.Add<RefreshNode, ActionRefresh>(
|
|
|
|
|
|
Services.TextService.Localize(string.Concat("actions/", ActionRefresh.Instance.Alias)),
|
|
|
|
|
|
true);
|
2013-10-01 16:38:10 +10:00
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-01 19:06:08 +02:00
|
|
|
|
// root actions
|
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, "media", "media");
|
|
|
|
|
|
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-03 12:27:48 +10:00
|
|
|
|
int iid;
|
|
|
|
|
|
if (int.TryParse(id, out iid) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
|
|
|
|
}
|
|
|
|
|
|
var item = Services.EntityService.Get(iid, UmbracoObjectTypes.Media);
|
|
|
|
|
|
if (item == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
|
|
|
|
}
|
2017-09-19 15:51:47 +02:00
|
|
|
|
|
|
|
|
|
|
//if the user has no path access for this node, all they can do is refresh
|
|
|
|
|
|
if (Security.CurrentUser.HasPathAccess(item, Services.EntityService, RecycleBinId) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
menu.Items.Add<RefreshNode, ActionRefresh>(
|
|
|
|
|
|
Services.TextService.Localize(string.Concat("actions/", ActionRefresh.Instance.Alias)),
|
|
|
|
|
|
true);
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
//return a normal node menu:
|
2016-03-15 16:58:13 +01:00
|
|
|
|
menu.Items.Add<ActionNew>(Services.TextService.Localize("actions", ActionNew.Instance.Alias));
|
|
|
|
|
|
menu.Items.Add<ActionMove>(Services.TextService.Localize("actions", ActionMove.Instance.Alias));
|
|
|
|
|
|
menu.Items.Add<ActionDelete>(Services.TextService.Localize("actions", ActionDelete.Instance.Alias));
|
|
|
|
|
|
menu.Items.Add<ActionSort>(Services.TextService.Localize("actions", ActionSort.Instance.Alias)).ConvertLegacyMenuItem(item, "media", "media");
|
|
|
|
|
|
menu.Items.Add<ActionRefresh>(Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true);
|
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()))
|
|
|
|
|
|
{
|
|
|
|
|
|
menu.DefaultMenuAlias = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
protected override UmbracoObjectTypes UmbracoObjectType => UmbracoObjectTypes.Media;
|
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)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var entity = GetEntityFromId(id);
|
|
|
|
|
|
|
2017-09-19 15:51:47 +02:00
|
|
|
|
return HasPathAccess(entity, queryStrings);
|
2017-09-12 16:22:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<SearchResultItem> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _treeSearcher.ExamineSearch(Umbraco, query, UmbracoEntityTypes.Media, pageSize, pageIndex, out totalFound, searchFrom);
|
2013-11-19 12:28:50 +11:00
|
|
|
|
}
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|