Files
Umbraco-CMS/src/Umbraco.Web/Trees/MediaTreeController.cs

176 lines
7.1 KiB
C#
Raw Normal View History

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;
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;
using Umbraco.Core.Services.Implement;
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,
Constants.Applications.Packages,
2018-06-29 19:52:40 +02:00
Constants.Applications.Members)]
[Tree(Constants.Applications.Media, Constants.Trees.Media)]
[PluginController("UmbracoTrees")]
[CoreTree]
[SearchableTree("searchResultFormatter", "configureMediaResult", 20)]
2018-06-29 19:52:40 +02:00
public class MediaTreeController : ContentTreeControllerBase, ISearchableTree
{
private readonly UmbracoTreeSearcher _treeSearcher;
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)
{
_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
menu.DefaultMenuAlias = ActionNew.ActionAlias;
2018-06-29 19:52:40 +02: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)
{
menu.Items.Add(new RefreshNode(Services.TextService, true));
2018-06-29 19:52:40 +02:00
return menu;
}
// root actions
menu.Items.Add<ActionNew>(Services.TextService, opensDialog: true);
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;
}
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
if (!Security.CurrentUser.HasMediaPathAccess(item, Services.EntityService))
2018-06-29 19:52:40 +02: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
Merge remote-tracking branch 'origin/dev-v7' into temp8 # Conflicts: # build/NuSpecs/tools/Web.config.install.xdt # src/Umbraco.Core/Constants-Conventions.cs # src/Umbraco.Core/DatabaseContext.cs # src/Umbraco.Core/Models/Rdbms/LanguageDto.cs # src/Umbraco.Core/Models/Rdbms/RelationTypeDto.cs # src/Umbraco.Core/Persistence/Migrations/Initial/BaseDataCreation.cs # src/Umbraco.Core/Persistence/Repositories/MemberGroupRepository.cs # src/Umbraco.Core/PropertyEditors/PreValueField.cs # src/Umbraco.Core/PropertyEditors/SupportTagsAttribute.cs # src/Umbraco.Core/Services/FileService.cs # src/Umbraco.Core/Services/IFileService.cs # src/Umbraco.Core/Strategies/RelateOnTrashHandler.cs # src/Umbraco.Tests/App.config # src/Umbraco.Tests/Persistence/Repositories/RelationTypeRepositoryTest.cs # src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs # src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbcontentnodeinfo.directive.js # src/Umbraco.Web.UI.Client/src/common/directives/components/umbgridselector.directive.js # src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js # src/Umbraco.Web.UI.Client/src/less/belle.less # src/Umbraco.Web.UI.Client/src/less/components/application/umb-drawer.less # src/Umbraco.Web.UI.Client/src/less/components/umb-grid.less # src/Umbraco.Web.UI.Client/src/less/hacks.less # src/Umbraco.Web.UI.Client/src/less/property-editors.less # src/Umbraco.Web.UI.Client/src/less/variables.less # src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.controller.js # src/Umbraco.Web.UI.Client/src/views/common/drawers/help/help.html # src/Umbraco.Web.UI.Client/src/views/components/content/umb-content-node-info.html # src/Umbraco.Web.UI.Client/src/views/components/umb-grid-selector.html # src/Umbraco.Web.UI.Client/src/views/datatypes/datatype.edit.controller.js # src/Umbraco.Web.UI.Client/src/views/documenttypes/views/templates/templates.html # src/Umbraco.Web.UI.Client/src/views/media/move.html # src/Umbraco.Web.UI.Client/src/views/prevalueeditors/multivalues.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.prevalues.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/listview/listview.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/listview/listview.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/mediapicker/mediapicker.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/tags/tags.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/tags/tags.html # src/Umbraco.Web.UI/Views/Web.config # src/Umbraco.Web.UI/umbraco/Install/Views/Web.config # src/Umbraco.Web.UI/umbraco/config/lang/da.xml # src/Umbraco.Web.UI/umbraco/config/lang/en.xml # src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml # src/Umbraco.Web.UI/umbraco/config/lang/nl.xml # src/Umbraco.Web.UI/umbraco/config/lang/ru.xml # src/Umbraco.Web.UI/web.Template.Debug.config # src/Umbraco.Web.UI/web.Template.config # src/Umbraco.Web/Editors/TemplateController.cs # src/Umbraco.Web/Models/ContentEditing/ContentItemDisplay.cs # src/Umbraco.Web/Models/ContentEditing/PreValueFieldDisplay.cs # src/Umbraco.Web/PropertyEditors/ColorListPreValueEditor.cs # src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs # src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs # src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs # src/Umbraco.Web/PropertyEditors/ValueListPreValueEditor.cs # src/Umbraco.Web/PublishedContentExtensions.cs # src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs # src/Umbraco.Web/Trees/MediaTreeController.cs # src/umbraco.MacroEngines/Resources/Web.config # src/umbraco.cms/Actions/ActionRestore.cs # src/umbraco.editorControls/yesno/YesNoDataType.cs
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));
Merge remote-tracking branch 'origin/dev-v7' into temp8 # Conflicts: # build/NuSpecs/tools/Web.config.install.xdt # src/Umbraco.Core/Constants-Conventions.cs # src/Umbraco.Core/DatabaseContext.cs # src/Umbraco.Core/Models/Rdbms/LanguageDto.cs # src/Umbraco.Core/Models/Rdbms/RelationTypeDto.cs # src/Umbraco.Core/Persistence/Migrations/Initial/BaseDataCreation.cs # src/Umbraco.Core/Persistence/Repositories/MemberGroupRepository.cs # src/Umbraco.Core/PropertyEditors/PreValueField.cs # src/Umbraco.Core/PropertyEditors/SupportTagsAttribute.cs # src/Umbraco.Core/Services/FileService.cs # src/Umbraco.Core/Services/IFileService.cs # src/Umbraco.Core/Strategies/RelateOnTrashHandler.cs # src/Umbraco.Tests/App.config # src/Umbraco.Tests/Persistence/Repositories/RelationTypeRepositoryTest.cs # src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs # src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbcontentnodeinfo.directive.js # src/Umbraco.Web.UI.Client/src/common/directives/components/umbgridselector.directive.js # src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js # src/Umbraco.Web.UI.Client/src/less/belle.less # src/Umbraco.Web.UI.Client/src/less/components/application/umb-drawer.less # src/Umbraco.Web.UI.Client/src/less/components/umb-grid.less # src/Umbraco.Web.UI.Client/src/less/hacks.less # src/Umbraco.Web.UI.Client/src/less/property-editors.less # src/Umbraco.Web.UI.Client/src/less/variables.less # src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.controller.js # src/Umbraco.Web.UI.Client/src/views/common/drawers/help/help.html # src/Umbraco.Web.UI.Client/src/views/components/content/umb-content-node-info.html # src/Umbraco.Web.UI.Client/src/views/components/umb-grid-selector.html # src/Umbraco.Web.UI.Client/src/views/datatypes/datatype.edit.controller.js # src/Umbraco.Web.UI.Client/src/views/documenttypes/views/templates/templates.html # src/Umbraco.Web.UI.Client/src/views/media/move.html # src/Umbraco.Web.UI.Client/src/views/prevalueeditors/multivalues.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.prevalues.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/listview/listview.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/listview/listview.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/mediapicker/mediapicker.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/multipletextbox/multipletextbox.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/tags/tags.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/tags/tags.html # src/Umbraco.Web.UI/Views/Web.config # src/Umbraco.Web.UI/umbraco/Install/Views/Web.config # src/Umbraco.Web.UI/umbraco/config/lang/da.xml # src/Umbraco.Web.UI/umbraco/config/lang/en.xml # src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml # src/Umbraco.Web.UI/umbraco/config/lang/nl.xml # src/Umbraco.Web.UI/umbraco/config/lang/ru.xml # src/Umbraco.Web.UI/web.Template.Debug.config # src/Umbraco.Web.UI/web.Template.config # src/Umbraco.Web/Editors/TemplateController.cs # src/Umbraco.Web/Models/ContentEditing/ContentItemDisplay.cs # src/Umbraco.Web/Models/ContentEditing/PreValueFieldDisplay.cs # src/Umbraco.Web/PropertyEditors/ColorListPreValueEditor.cs # src/Umbraco.Web/PropertyEditors/ListViewPropertyEditor.cs # src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs # src/Umbraco.Web/PropertyEditors/TrueFalsePropertyEditor.cs # src/Umbraco.Web/PropertyEditors/ValueListPreValueEditor.cs # src/Umbraco.Web/PublishedContentExtensions.cs # src/Umbraco.Web/Trees/ApplicationTreeExtensions.cs # src/Umbraco.Web/Trees/MediaTreeController.cs # src/umbraco.MacroEngines/Resources/Web.config # src/umbraco.cms/Actions/ActionRestore.cs # src/umbraco.editorControls/yesno/YesNoDataType.cs
2018-07-30 21:31:35 +10:00
//set the default to create
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);
}
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
}
Merge remote-tracking branch 'origin/v7/dev' into v8/dev - Iniital commit (broken) # Conflicts: # build/NuSpecs/tools/Web.config.install.xdt # src/Umbraco.Core/Constants-DataTypes.cs # src/Umbraco.Core/Models/DataTypeDefinition.cs # src/Umbraco.Core/Models/DataTypeExtensions.cs # src/Umbraco.Core/Models/IDataTypeDefinition.cs # src/Umbraco.Core/Models/UmbracoEntity.cs # src/Umbraco.Core/Models/UserExtensions.cs # src/Umbraco.Core/Persistence/Factories/DataTypeDefinitionFactory.cs # src/Umbraco.Core/Persistence/Factories/UmbracoEntityFactory.cs # src/Umbraco.Core/Persistence/Migrations/Initial/BaseDataCreation.cs # src/Umbraco.Core/Persistence/Repositories/EntityRepository.cs # src/Umbraco.Core/Services/ContentService.cs # src/Umbraco.Core/Services/DataTypeService.cs # src/Umbraco.Core/Services/EntityService.cs # src/Umbraco.Core/Services/IContentService.cs # src/Umbraco.Core/Services/IDataTypeService.cs # src/Umbraco.Core/Services/IEntityService.cs # src/Umbraco.Core/Services/IRelationService.cs # src/Umbraco.Core/Services/Implement/RelationService.cs # src/Umbraco.Tests/Models/UmbracoEntityTests.cs # src/Umbraco.Tests/Plugins/PluginManagerTests.cs # src/Umbraco.Tests/Services/EntityServiceTests.cs # src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js # src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js # src/Umbraco.Web.UI.Client/src/common/resources/media.resource.js # src/Umbraco.Web.UI.Client/src/common/services/mediahelper.service.js # src/Umbraco.Web.UI.Client/src/common/services/search.service.js # src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js # src/Umbraco.Web.UI.Client/src/views/common/dialogs/linkpicker.controller.js # src/Umbraco.Web.UI.Client/src/views/common/dialogs/linkpicker.html # src/Umbraco.Web.UI.Client/src/views/common/dialogs/mediapicker.controller.js # src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.controller.js # src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/mediapicker/mediapicker.controller.js # src/Umbraco.Web.UI.Client/src/views/common/overlays/contentpicker/contentpicker.html # src/Umbraco.Web.UI.Client/src/views/common/overlays/linkpicker/linkpicker.controller.js # src/Umbraco.Web.UI.Client/src/views/common/overlays/linkpicker/linkpicker.html # src/Umbraco.Web.UI.Client/src/views/common/overlays/treepicker/treepicker.controller.js # src/Umbraco.Web.UI.Client/src/views/common/overlays/treepicker/treepicker.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/grid/editors/media.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/grid/editors/rte.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/mediapicker/mediapicker.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/multiurlpicker/multiurlpicker.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/relatedlinks/relatedlinks.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/rte.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/rte.prevalues.html # src/Umbraco.Web.UI/packages.config # src/Umbraco.Web.UI/web.Template.config # src/Umbraco.Web/Editors/ContentController.cs # src/Umbraco.Web/Editors/EntityController.cs # src/Umbraco.Web/Editors/MediaController.cs # src/Umbraco.Web/HtmlHelperRenderExtensions.cs # src/Umbraco.Web/Models/ContentEditing/ContentPropertyBasic.cs # src/Umbraco.Web/Models/Mapping/ContentPropertyBasicConverter.cs # src/Umbraco.Web/Models/Mapping/ContentPropertyDisplayConverter.cs # src/Umbraco.Web/Models/Mapping/ContentPropertyDtoConverter.cs # src/Umbraco.Web/Models/Mapping/ContentPropertyModelMapper.cs # src/Umbraco.Web/Models/Mapping/PreValueDisplayResolver.cs # src/Umbraco.Web/Mvc/RenderRouteHandler.cs # src/Umbraco.Web/PropertyEditors/ContentPicker2PropertyEditor.cs # src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs # src/Umbraco.Web/PropertyEditors/MediaPicker2PropertyEditor.cs # src/Umbraco.Web/PropertyEditors/MultiNodeTreePicker2PropertyEditor.cs # src/Umbraco.Web/PropertyEditors/MultiUrlPickerPropertyEditor.cs # src/Umbraco.Web/PropertyEditors/RelatedLinks2PropertyEditor.cs # src/Umbraco.Web/PropertyEditors/RichTextPreValueEditor.cs # src/Umbraco.Web/Search/UmbracoTreeSearcher.cs # src/Umbraco.Web/Security/UmbracoAntiForgeryAdditionalDataProvider.cs # src/Umbraco.Web/Trees/ContentTreeController.cs # src/Umbraco.Web/Trees/ContentTreeControllerBase.cs # src/Umbraco.Web/Trees/MediaTreeController.cs # src/Umbraco.Web/Trees/TreeControllerBase.cs # src/Umbraco.Web/Trees/TreeQueryStringParameters.cs # src/Umbraco.Web/UmbracoHelper.cs # src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForContentAttribute.cs # src/Umbraco.Web/WebBootManager.cs # src/Umbraco.Web/umbraco.presentation/umbraco/Trees/BaseMediaTree.cs # src/Umbraco.Web/umbraco.presentation/umbraco/Trees/BaseTree.cs # src/umbraco.cms/businesslogic/web/Access.cs
2019-06-28 13:03:36 +10:00
2018-06-29 19:52:40 +02:00
}
}