2021-09-15 13:40:08 +02:00
|
|
|
using System.Globalization;
|
2021-01-14 19:41:32 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-06-09 07:49:26 +02:00
|
|
|
using Microsoft.AspNetCore.Http;
|
2021-01-14 19:41:32 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-09-21 09:52:58 +02:00
|
|
|
using Microsoft.Extensions.Logging;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
using Umbraco.Cms.Core.Actions;
|
2021-03-05 15:36:27 +01:00
|
|
|
using Umbraco.Cms.Core.Cache;
|
2021-02-23 16:09:36 +01:00
|
|
|
using Umbraco.Cms.Core.Events;
|
2021-02-25 15:08:56 +01:00
|
|
|
using Umbraco.Cms.Core.Mail;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Models.ContentEditing;
|
|
|
|
|
using Umbraco.Cms.Core.Models.Entities;
|
2022-06-20 08:37:17 +02:00
|
|
|
using Umbraco.Cms.Core.Models.Membership;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Models.Trees;
|
|
|
|
|
using Umbraco.Cms.Core.Security;
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Cms.Core.Trees;
|
2021-02-15 11:45:27 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Search;
|
2021-02-10 11:42:04 +01:00
|
|
|
using Umbraco.Cms.Web.Common.Attributes;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Authorization;
|
2021-02-09 11:26:22 +01:00
|
|
|
using Umbraco.Extensions;
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
namespace Umbraco.Cms.Web.BackOffice.Trees;
|
|
|
|
|
|
|
|
|
|
[Authorize(Policy = AuthorizationPolicies.SectionAccessForContentTree)]
|
|
|
|
|
[Tree(Constants.Applications.Content, Constants.Trees.Content)]
|
|
|
|
|
[PluginController(Constants.Web.Mvc.BackOfficeTreeArea)]
|
|
|
|
|
[CoreTree]
|
|
|
|
|
[SearchableTree("searchResultFormatter", "configureContentResult", 10)]
|
2022-07-11 14:07:08 +02:00
|
|
|
public class ContentTreeController : ContentTreeControllerBase, ISearchableTreeWithCulture
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
private readonly ActionCollection _actions;
|
|
|
|
|
private readonly AppCaches _appCaches;
|
|
|
|
|
private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor;
|
|
|
|
|
private readonly IContentService _contentService;
|
|
|
|
|
private readonly IEmailSender _emailSender;
|
|
|
|
|
private readonly IEntityService _entityService;
|
|
|
|
|
private readonly ILocalizationService _localizationService;
|
|
|
|
|
private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;
|
|
|
|
|
private readonly IPublicAccessService _publicAccessService;
|
|
|
|
|
private readonly UmbracoTreeSearcher _treeSearcher;
|
|
|
|
|
private readonly IUserService _userService;
|
|
|
|
|
|
|
|
|
|
private int[]? _userStartNodes;
|
|
|
|
|
|
|
|
|
|
public ContentTreeController(
|
|
|
|
|
ILocalizedTextService localizedTextService,
|
|
|
|
|
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
|
|
|
|
|
IMenuItemCollectionFactory menuItemCollectionFactory,
|
|
|
|
|
IEntityService entityService,
|
|
|
|
|
IBackOfficeSecurityAccessor backofficeSecurityAccessor,
|
|
|
|
|
ILogger<ContentTreeController> logger,
|
|
|
|
|
ActionCollection actionCollection,
|
|
|
|
|
IUserService userService,
|
|
|
|
|
IDataTypeService dataTypeService,
|
|
|
|
|
UmbracoTreeSearcher treeSearcher,
|
|
|
|
|
ActionCollection actions,
|
|
|
|
|
IContentService contentService,
|
|
|
|
|
IPublicAccessService publicAccessService,
|
|
|
|
|
ILocalizationService localizationService,
|
|
|
|
|
IEventAggregator eventAggregator,
|
|
|
|
|
IEmailSender emailSender,
|
|
|
|
|
AppCaches appCaches)
|
|
|
|
|
: base(
|
|
|
|
|
localizedTextService,
|
|
|
|
|
umbracoApiControllerTypeCollection,
|
|
|
|
|
menuItemCollectionFactory,
|
|
|
|
|
entityService,
|
|
|
|
|
backofficeSecurityAccessor,
|
|
|
|
|
logger,
|
|
|
|
|
actionCollection,
|
|
|
|
|
userService,
|
|
|
|
|
dataTypeService,
|
|
|
|
|
eventAggregator,
|
|
|
|
|
appCaches)
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
_treeSearcher = treeSearcher;
|
|
|
|
|
_actions = actions;
|
|
|
|
|
_menuItemCollectionFactory = menuItemCollectionFactory;
|
|
|
|
|
_backofficeSecurityAccessor = backofficeSecurityAccessor;
|
|
|
|
|
_contentService = contentService;
|
|
|
|
|
_entityService = entityService;
|
|
|
|
|
_publicAccessService = publicAccessService;
|
|
|
|
|
_userService = userService;
|
|
|
|
|
_localizationService = localizationService;
|
|
|
|
|
_emailSender = emailSender;
|
|
|
|
|
_appCaches = appCaches;
|
|
|
|
|
}
|
2019-10-15 00:07:44 +11:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
protected override int RecycleBinId => Constants.System.RecycleBinContent;
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
protected override bool RecycleBinSmells => _contentService.RecycleBinSmells();
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
protected override int[] UserStartNodes
|
|
|
|
|
=> _userStartNodes ??=
|
|
|
|
|
_backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.CalculateContentStartNodeIds(_entityService, _appCaches) ?? Array.Empty<int>();
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
protected override UmbracoObjectTypes UmbracoObjectType => UmbracoObjectTypes.Document;
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
public async Task<EntitySearchResults> SearchAsync(string query, int pageSize, long pageIndex, string? searchFrom = null)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<SearchResultEntity> results = _treeSearcher.ExamineSearch(query, UmbracoEntityTypes.Document, pageSize, pageIndex, out var totalFound, searchFrom);
|
|
|
|
|
return new EntitySearchResults(results, totalFound);
|
|
|
|
|
}
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override TreeNode? GetSingleTreeNode(IEntitySlim entity, string parentId, FormCollection? queryStrings)
|
|
|
|
|
{
|
|
|
|
|
var culture = queryStrings?["culture"].ToString();
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-10-21 17:35:51 +08:00
|
|
|
if(culture.IsNullOrWhiteSpace())
|
|
|
|
|
{
|
|
|
|
|
culture = _localizationService.GetDefaultLanguageIsoCode();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
IEnumerable<MenuItem> allowedUserOptions = GetAllowedUserMenuItemsForNode(entity);
|
|
|
|
|
if (CanUserAccessNode(entity, allowedUserOptions, culture))
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
//Special check to see if it is a container, if so then we'll hide children.
|
|
|
|
|
var isContainer = entity.IsContainer; // && (queryStrings.Get("isDialog") != "true");
|
|
|
|
|
|
|
|
|
|
TreeNode node = CreateTreeNode(
|
|
|
|
|
entity,
|
|
|
|
|
Constants.ObjectTypes.Document,
|
|
|
|
|
parentId,
|
|
|
|
|
queryStrings,
|
|
|
|
|
entity.HasChildren);
|
|
|
|
|
|
|
|
|
|
// set container style if it is one
|
|
|
|
|
if (isContainer)
|
|
|
|
|
{
|
|
|
|
|
node.AdditionalData.Add("isContainer", true);
|
|
|
|
|
node.SetContainerStyle();
|
|
|
|
|
}
|
2018-07-09 18:26:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
var documentEntity = (IDocumentEntitySlim)entity;
|
2018-07-09 18:26:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
if (!documentEntity.Variations.VariesByCulture())
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
if (!documentEntity.Published)
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
node.SetNotPublishedStyle();
|
2018-06-29 19:55:15 +02:00
|
|
|
}
|
2022-06-20 08:37:17 +02:00
|
|
|
else if (documentEntity.Edited)
|
2018-11-15 15:24:09 +11:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
node.SetHasPendingVersionStyle();
|
2018-11-15 15:24:09 +11:00
|
|
|
}
|
2022-06-20 08:37:17 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!culture.IsNullOrWhiteSpace())
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
if (!documentEntity.Published || !documentEntity.PublishedCultures.Contains(culture))
|
|
|
|
|
{
|
|
|
|
|
node.SetNotPublishedStyle();
|
|
|
|
|
}
|
|
|
|
|
else if (documentEntity.EditedCultures.Contains(culture))
|
2018-09-21 15:49:37 +10:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
node.SetHasPendingVersionStyle();
|
2018-09-21 15:49:37 +10:00
|
|
|
}
|
2018-06-29 19:55:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
node.AdditionalData.Add("variesByCulture", documentEntity.Variations.VariesByCulture());
|
|
|
|
|
node.AdditionalData.Add("contentType", documentEntity.ContentTypeAlias);
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
if (_publicAccessService.IsProtected(entity.Path).Success)
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
node.SetProtectedStyle();
|
|
|
|
|
}
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
return node;
|
|
|
|
|
}
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
protected override ActionResult<MenuItemCollection> PerformGetMenuForNode(string id, FormCollection queryStrings)
|
|
|
|
|
{
|
|
|
|
|
if (id == Constants.System.RootString)
|
|
|
|
|
{
|
|
|
|
|
MenuItemCollection menu = _menuItemCollectionFactory.Create();
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +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)
|
|
|
|
|
{
|
2020-06-09 07:49:26 +02:00
|
|
|
menu.Items.Add(new RefreshNode(LocalizedTextService, true));
|
2018-06-29 19:55:15 +02:00
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
//set the default to create
|
|
|
|
|
menu.DefaultMenuAlias = ActionNew.ActionAlias;
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
// we need to get the default permissions as you can't set permissions on the very root node
|
|
|
|
|
EntityPermission permission = _userService
|
|
|
|
|
.GetPermissions(_backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser, Constants.System.Root)
|
|
|
|
|
.First();
|
|
|
|
|
IEnumerable<MenuItem> nodeActions = _actions.FromEntityPermission(permission)
|
|
|
|
|
.Select(x => new MenuItem(x));
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
//these two are the standard items
|
2022-07-11 14:07:08 +02:00
|
|
|
menu.Items.Add<ActionNew>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);
|
|
|
|
|
menu.Items.Add<ActionSort>(LocalizedTextService, hasSeparator: true, opensDialog: true, useLegacyIcon: false);
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
//filter the standard items
|
|
|
|
|
FilterUserAllowedMenuItems(menu, nodeActions);
|
2019-11-05 12:54:22 +01:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
if (menu.Items.Any())
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
menu.Items.Last().SeparatorBefore = true;
|
2018-06-29 19:55:15 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
// add default actions for *all* users
|
|
|
|
|
menu.Items.Add(new RefreshNode(LocalizedTextService, true));
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
return menu;
|
2018-06-29 19:55:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
//return a normal node menu:
|
|
|
|
|
if (int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out int iid) == false)
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
return NotFound();
|
2018-05-10 18:20:33 +10:00
|
|
|
}
|
|
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
IEntitySlim? item = _entityService.Get(iid, UmbracoObjectTypes.Document);
|
|
|
|
|
if (item == null)
|
2018-05-10 18:20:33 +10:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
return NotFound();
|
|
|
|
|
}
|
2018-05-10 18:20:33 +10:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
//if the user has no path access for this node, all they can do is refresh
|
|
|
|
|
if (!_backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.HasContentPathAccess(item, _entityService, _appCaches) ?? false)
|
|
|
|
|
{
|
|
|
|
|
MenuItemCollection menu = _menuItemCollectionFactory.Create();
|
|
|
|
|
menu.Items.Add(new RefreshNode(LocalizedTextService, true));
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
MenuItemCollection nodeMenu = GetAllNodeMenuItems(item);
|
2018-05-10 18:20:33 +10:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
//if the content node is in the recycle bin, don't have a default menu, just show the regular menu
|
|
|
|
|
if (item.Path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)
|
|
|
|
|
.Contains(RecycleBinId.ToInvariantString()))
|
|
|
|
|
{
|
|
|
|
|
nodeMenu.DefaultMenuAlias = null;
|
|
|
|
|
nodeMenu = GetNodeMenuItemsForDeletedContent(item);
|
2018-06-29 19:55:15 +02:00
|
|
|
}
|
2022-06-20 08:37:17 +02:00
|
|
|
else
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
//set the default to create
|
|
|
|
|
nodeMenu.DefaultMenuAlias = ActionNew.ActionAlias;
|
|
|
|
|
}
|
2019-05-26 19:06:24 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
IEnumerable<MenuItem> allowedMenuItems = GetAllowedUserMenuItemsForNode(item);
|
|
|
|
|
FilterUserAllowedMenuItems(nodeMenu, allowedMenuItems);
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
return nodeMenu;
|
|
|
|
|
}
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02: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, FormCollection queryStrings)
|
|
|
|
|
{
|
|
|
|
|
IEntitySlim? entity = GetEntityFromId(id);
|
|
|
|
|
return HasPathAccess(entity, queryStrings);
|
|
|
|
|
}
|
2018-06-29 19:55:15 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
protected override ActionResult<IEnumerable<IEntitySlim>> GetChildEntities(string id, FormCollection queryStrings)
|
|
|
|
|
{
|
|
|
|
|
ActionResult<IEnumerable<IEntitySlim>> result = base.GetChildEntities(id, queryStrings);
|
|
|
|
|
|
|
|
|
|
if (!(result.Result is null))
|
2018-07-11 15:58:48 +10:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
return result.Result;
|
|
|
|
|
}
|
2018-07-11 15:58:48 +10:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
Attempt<string> culture = queryStrings["culture"].TryConvertTo<string>();
|
2018-07-11 15:58:48 +10:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
//if this is null we'll set it to the default.
|
|
|
|
|
var cultureVal =
|
|
|
|
|
(culture.Success ? culture.Result : null).IfNullOrWhiteSpace(
|
|
|
|
|
_localizationService.GetDefaultLanguageIsoCode());
|
|
|
|
|
|
|
|
|
|
// set names according to variations
|
|
|
|
|
foreach (IEntitySlim entity in result.Value!)
|
|
|
|
|
{
|
|
|
|
|
EnsureName(entity, cultureVal);
|
2018-07-11 15:58:48 +10:00
|
|
|
}
|
2019-11-05 12:54:22 +01:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
MenuItemCollection menu = _menuItemCollectionFactory.Create();
|
2022-07-11 14:07:08 +02:00
|
|
|
AddActionNode<ActionNew>(item, menu, opensDialog: true, useLegacyIcon: false);
|
|
|
|
|
AddActionNode<ActionDelete>(item, menu, opensDialog: true, useLegacyIcon: false);
|
|
|
|
|
AddActionNode<ActionCreateBlueprintFromContent>(item, menu, opensDialog: true, useLegacyIcon: false);
|
|
|
|
|
AddActionNode<ActionMove>(item, menu, hasSeparator: true, opensDialog: true, useLegacyIcon: false);
|
|
|
|
|
AddActionNode<ActionCopy>(item, menu, opensDialog: true, useLegacyIcon: false);
|
|
|
|
|
AddActionNode<ActionSort>(item, menu, hasSeparator: true, opensDialog: true, useLegacyIcon: false);
|
|
|
|
|
AddActionNode<ActionAssignDomain>(item, menu, opensDialog: true, useLegacyIcon: false);
|
|
|
|
|
AddActionNode<ActionRights>(item, menu, opensDialog: true, useLegacyIcon: false);
|
|
|
|
|
AddActionNode<ActionProtect>(item, menu, hasSeparator: true, opensDialog: true, useLegacyIcon: false);
|
2022-06-20 08:37:17 +02:00
|
|
|
|
|
|
|
|
if (_emailSender.CanSendRequiredEmail())
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
menu.Items.Add(new MenuItem("notify", LocalizedTextService)
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-07-11 14:07:08 +02:00
|
|
|
Icon = "icon-megaphone",
|
2022-06-20 08:37:17 +02:00
|
|
|
SeparatorBefore = true,
|
2022-07-11 14:07:08 +02:00
|
|
|
OpensDialog = true,
|
|
|
|
|
UseLegacyIcon = false
|
2022-06-20 08:37:17 +02:00
|
|
|
});
|
|
|
|
|
}
|
2019-01-30 22:01:57 +11:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
if ((item is DocumentEntitySlim documentEntity && documentEntity.IsContainer) == false)
|
|
|
|
|
{
|
|
|
|
|
menu.Items.Add(new RefreshNode(LocalizedTextService, true));
|
|
|
|
|
}
|
2018-05-10 18:20:33 +10:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
return menu;
|
|
|
|
|
}
|
2018-05-10 18:20:33 +10:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a collection of all menu items that can be on a deleted (in recycle bin) content node
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected MenuItemCollection GetNodeMenuItemsForDeletedContent(IUmbracoEntity item)
|
|
|
|
|
{
|
|
|
|
|
MenuItemCollection menu = _menuItemCollectionFactory.Create();
|
2022-07-11 14:07:08 +02:00
|
|
|
menu.Items.Add<ActionRestore>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);
|
|
|
|
|
menu.Items.Add<ActionMove>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);
|
|
|
|
|
menu.Items.Add<ActionDelete>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);
|
2018-05-10 18:20:33 +10:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
menu.Items.Add(new RefreshNode(LocalizedTextService, true));
|
2018-05-10 19:16:46 +10:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
return menu;
|
|
|
|
|
}
|
2018-05-10 19:16:46 +10:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// set name according to variations
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="entity"></param>
|
|
|
|
|
/// <param name="culture"></param>
|
|
|
|
|
private void EnsureName(IEntitySlim entity, string? culture)
|
|
|
|
|
{
|
|
|
|
|
if (culture == null)
|
|
|
|
|
{
|
2018-05-10 19:16:46 +10:00
|
|
|
if (string.IsNullOrWhiteSpace(entity.Name))
|
2019-01-30 22:01:57 +11:00
|
|
|
{
|
2018-06-29 19:55:15 +02:00
|
|
|
entity.Name = "[[" + entity.Id + "]]";
|
2019-01-30 22:01:57 +11:00
|
|
|
}
|
2022-06-20 08:37:17 +02:00
|
|
|
|
|
|
|
|
return;
|
2018-06-29 19:55:15 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
if (!(entity is IDocumentEntitySlim docEntity))
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
throw new InvalidOperationException(
|
|
|
|
|
$"Cannot render a tree node for a culture when the entity isn't {typeof(IDocumentEntitySlim)}, instead it is {entity.GetType()}");
|
2018-06-29 19:55:15 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
// we are getting the tree for a given culture,
|
|
|
|
|
// for those items that DO support cultures, we need to get the proper name, IF it exists
|
|
|
|
|
// otherwise, invariant is fine (with brackets)
|
2022-07-04 13:45:33 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
if (docEntity.Variations.VariesByCulture())
|
2018-06-29 19:55:15 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
if (docEntity.CultureNames.TryGetValue(culture, out var name) &&
|
|
|
|
|
!string.IsNullOrWhiteSpace(name))
|
|
|
|
|
{
|
|
|
|
|
entity.Name = name;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
entity.Name = "(" + entity.Name + ")";
|
|
|
|
|
}
|
2018-05-10 18:20:33 +10:00
|
|
|
}
|
2022-06-20 08:37:17 +02:00
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(entity.Name))
|
|
|
|
|
{
|
|
|
|
|
entity.Name = "[[" + entity.Id + "]]";
|
2018-05-10 18:20:33 +10:00
|
|
|
}
|
2018-06-29 19:55:15 +02:00
|
|
|
}
|
2022-06-20 08:37:17 +02:00
|
|
|
|
2022-07-11 14:07:08 +02:00
|
|
|
private void AddActionNode<TAction>(IUmbracoEntity item, MenuItemCollection menu, bool hasSeparator = false, bool opensDialog = false, bool useLegacyIcon = true)
|
2022-06-20 08:37:17 +02:00
|
|
|
where TAction : IAction
|
|
|
|
|
{
|
2022-07-11 14:07:08 +02:00
|
|
|
MenuItem? menuItem = menu.Items.Add<TAction>(LocalizedTextService, hasSeparator, opensDialog, useLegacyIcon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<EntitySearchResults> SearchAsync(string query, int pageSize, long pageIndex, string? searchFrom = null, string? culture = null)
|
|
|
|
|
{
|
|
|
|
|
var results = _treeSearcher.ExamineSearch(query, UmbracoEntityTypes.Document, pageSize, pageIndex, out long totalFound, culture: culture, searchFrom: searchFrom);
|
|
|
|
|
return new EntitySearchResults(results, totalFound);
|
2018-06-29 19:55:15 +02:00
|
|
|
}
|
|
|
|
|
}
|