2018-06-29 19:52:40 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
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.Entities;
|
|
|
|
|
|
using Umbraco.Core.Services;
|
2018-10-29 17:27:33 +11:00
|
|
|
|
using Umbraco.Web.Actions;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
using Umbraco.Web.Models.Trees;
|
|
|
|
|
|
using Umbraco.Web.Mvc;
|
|
|
|
|
|
using Umbraco.Web.WebApi.Filters;
|
|
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
|
|
|
|
|
using Umbraco.Web.Search;
|
|
|
|
|
|
using Constants = Umbraco.Core.Constants;
|
2018-11-19 17:54:36 +11:00
|
|
|
|
using Umbraco.Core.Services.Implement;
|
2019-10-15 00:07:44 +11:00
|
|
|
|
using Umbraco.Core.Cache;
|
|
|
|
|
|
using Umbraco.Core.Configuration;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
|
using Umbraco.Core.Persistence;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Trees
|
|
|
|
|
|
{
|
|
|
|
|
|
//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,
|
2018-10-05 11:09:33 +02:00
|
|
|
|
Constants.Applications.Packages,
|
2018-06-29 19:52:40 +02:00
|
|
|
|
Constants.Applications.Members)]
|
|
|
|
|
|
[Tree(Constants.Applications.Media, Constants.Trees.Media)]
|
|
|
|
|
|
[PluginController("UmbracoTrees")]
|
|
|
|
|
|
[CoreTree]
|
2019-05-31 20:29:00 +02:00
|
|
|
|
[SearchableTree("searchResultFormatter", "configureMediaResult", 20)]
|
2018-06-29 19:52:40 +02:00
|
|
|
|
public class MediaTreeController : ContentTreeControllerBase, ISearchableTree
|
|
|
|
|
|
{
|
2018-12-03 22:10:56 +11:00
|
|
|
|
private readonly UmbracoTreeSearcher _treeSearcher;
|
|
|
|
|
|
|
2019-10-15 00:07:44 +11:00
|
|
|
|
public MediaTreeController(UmbracoTreeSearcher treeSearcher, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper)
|
2018-12-03 22:10:56 +11:00
|
|
|
|
{
|
|
|
|
|
|
_treeSearcher = treeSearcher;
|
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
|
|
protected override int RecycleBinId => Constants.System.RecycleBinMedia;
|
|
|
|
|
|
|
|
|
|
|
|
protected override bool RecycleBinSmells => Services.MediaService.RecycleBinSmells();
|
|
|
|
|
|
|
|
|
|
|
|
private int[] _userStartNodes;
|
|
|
|
|
|
protected override int[] UserStartNodes
|
|
|
|
|
|
=> _userStartNodes ?? (_userStartNodes = Security.CurrentUser.CalculateMediaStartNodeIds(Services.EntityService));
|
|
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
|
protected override TreeNode GetSingleTreeNode(IEntitySlim entity, string parentId, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var node = CreateTreeNode(
|
|
|
|
|
|
entity,
|
|
|
|
|
|
Constants.ObjectTypes.Media,
|
|
|
|
|
|
parentId,
|
|
|
|
|
|
queryStrings,
|
2018-12-19 18:01:36 +01:00
|
|
|
|
entity.HasChildren);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
|
|
// entity is either a container, or a media
|
2018-12-19 18:01:36 +01:00
|
|
|
|
if (entity.IsContainer)
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
node.SetContainerStyle();
|
|
|
|
|
|
node.AdditionalData.Add("isContainer", true);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var contentEntity = (IContentEntitySlim) entity;
|
|
|
|
|
|
node.AdditionalData.Add("contentType", contentEntity.ContentTypeAlias);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var menu = new MenuItemCollection();
|
|
|
|
|
|
|
|
|
|
|
|
//set the default
|
2018-10-29 17:27:33 +11:00
|
|
|
|
menu.DefaultMenuAlias = ActionNew.ActionAlias;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2019-03-29 12:06:23 +00:00
|
|
|
|
if (id == Constants.System.RootString)
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
// if the user's start node is not the root then the only menu item to display is refresh
|
|
|
|
|
|
if (UserStartNodes.Contains(Constants.System.Root) == false)
|
|
|
|
|
|
{
|
2018-10-29 17:27:33 +11:00
|
|
|
|
menu.Items.Add(new RefreshNode(Services.TextService, true));
|
2018-06-29 19:52:40 +02:00
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// root actions
|
2018-10-30 00:34:43 +11:00
|
|
|
|
menu.Items.Add<ActionNew>(Services.TextService, opensDialog: true);
|
2018-10-29 17:27:33 +11:00
|
|
|
|
menu.Items.Add<ActionSort>(Services.TextService, true);
|
|
|
|
|
|
menu.Items.Add(new RefreshNode(Services.TextService, true));
|
2018-06-29 19:52:40 +02:00
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-29 17:27:33 +11:00
|
|
|
|
if (int.TryParse(id, out var iid) == false)
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
|
|
|
|
}
|
|
|
|
|
|
var item = Services.EntityService.Get(iid, UmbracoObjectTypes.Media);
|
|
|
|
|
|
if (item == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//if the user has no path access for this node, all they can do is refresh
|
2018-11-15 15:24:09 +11:00
|
|
|
|
if (!Security.CurrentUser.HasMediaPathAccess(item, Services.EntityService))
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
2018-10-29 17:27:33 +11:00
|
|
|
|
menu.Items.Add(new RefreshNode(Services.TextService, true));
|
2018-06-29 19:52:40 +02:00
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-21 13:48:59 +11:00
|
|
|
|
|
|
|
|
|
|
//if the media item is in the recycle bin, we don't have a default menu and we need to show a limited menu
|
2018-06-29 19:52:40 +02:00
|
|
|
|
if (item.Path.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Contains(RecycleBinId.ToInvariantString()))
|
|
|
|
|
|
{
|
2018-12-21 13:48:59 +11:00
|
|
|
|
menu.Items.Add<ActionRestore>(Services.TextService, opensDialog: true);
|
|
|
|
|
|
menu.Items.Add<ActionMove>(Services.TextService, opensDialog: true);
|
|
|
|
|
|
menu.Items.Add<ActionDelete>(Services.TextService, opensDialog: true);
|
|
|
|
|
|
menu.Items.Add(new RefreshNode(Services.TextService, true));
|
|
|
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
|
menu.DefaultMenuAlias = null;
|
2018-12-21 13:48:59 +11:00
|
|
|
|
|
2018-07-30 21:31:35 +10:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-12-21 13:48:59 +11:00
|
|
|
|
//return a normal node menu:
|
|
|
|
|
|
menu.Items.Add<ActionNew>(Services.TextService, opensDialog: true);
|
|
|
|
|
|
menu.Items.Add<ActionMove>(Services.TextService, opensDialog: true);
|
|
|
|
|
|
menu.Items.Add<ActionDelete>(Services.TextService, opensDialog: true);
|
|
|
|
|
|
menu.Items.Add<ActionSort>(Services.TextService);
|
|
|
|
|
|
menu.Items.Add(new RefreshNode(Services.TextService, true));
|
|
|
|
|
|
|
2018-07-30 21:31:35 +10:00
|
|
|
|
//set the default to create
|
2018-10-29 17:27:33 +11:00
|
|
|
|
menu.DefaultMenuAlias = ActionNew.ActionAlias;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override UmbracoObjectTypes UmbracoObjectType => UmbracoObjectTypes.Media;
|
|
|
|
|
|
|
|
|
|
|
|
/// <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 entity = GetEntityFromId(id);
|
|
|
|
|
|
|
|
|
|
|
|
return HasPathAccess(entity, queryStrings);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-04 14:25:37 +11:00
|
|
|
|
public IEnumerable<SearchResultEntity> Search(string query, int pageSize, long pageIndex, out long totalFound, string searchFrom = null)
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
2019-06-13 23:47:48 +10:00
|
|
|
|
return _treeSearcher.ExamineSearch(query, UmbracoEntityTypes.Media, pageSize, pageIndex, out totalFound, searchFrom);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
}
|
2019-06-28 13:03:36 +10:00
|
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|