2021-01-13 11:02:29 +01:00
|
|
|
using System;
|
2018-06-29 19:52:40 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-01-14 19:41:32 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-06-09 07:49:26 +02:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
using Umbraco.Cms.Core.Actions;
|
2021-02-23 16:09:36 +01:00
|
|
|
using Umbraco.Cms.Core.Events;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Models.ContentEditing;
|
|
|
|
|
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;
|
|
|
|
|
using Umbraco.Cms.Web.Common.ModelBinders;
|
2020-06-09 07:49:26 +02:00
|
|
|
using Umbraco.Extensions;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Constants = Umbraco.Cms.Core.Constants;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2021-02-10 11:11:18 +01:00
|
|
|
namespace Umbraco.Cms.Web.BackOffice.Trees
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-11-19 22:17:42 +11:00
|
|
|
[Authorize(Policy = AuthorizationPolicies.SectionAccessForMemberTree)]
|
2019-01-22 09:31:47 +01:00
|
|
|
[Tree(Constants.Applications.Members, Constants.Trees.Members, SortOrder = 0)]
|
2020-09-23 08:55:25 +02:00
|
|
|
[PluginController(Constants.Web.Mvc.BackOfficeTreeArea)]
|
2018-06-29 19:52:40 +02:00
|
|
|
[CoreTree]
|
|
|
|
|
[SearchableTree("searchResultFormatter", "configureMemberResult")]
|
2020-02-26 10:33:05 +01:00
|
|
|
public class MemberTreeController : TreeController, ISearchableTree, ITreeNodeController
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-02-17 14:58:34 +01:00
|
|
|
private readonly UmbracoTreeSearcher _treeSearcher;
|
|
|
|
|
private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;
|
2020-06-09 07:49:26 +02:00
|
|
|
private readonly IMemberService _memberService;
|
|
|
|
|
private readonly IMemberTypeService _memberTypeService;
|
2020-10-21 16:51:00 +11:00
|
|
|
private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor;
|
2020-02-17 14:58:34 +01:00
|
|
|
|
|
|
|
|
public MemberTreeController(
|
2020-06-09 07:49:26 +02:00
|
|
|
ILocalizedTextService localizedTextService,
|
|
|
|
|
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
|
2020-02-17 14:58:34 +01:00
|
|
|
UmbracoTreeSearcher treeSearcher,
|
2020-06-09 07:49:26 +02:00
|
|
|
IMenuItemCollectionFactory menuItemCollectionFactory,
|
|
|
|
|
IMemberService memberService,
|
|
|
|
|
IMemberTypeService memberTypeService,
|
2021-02-23 16:09:36 +01:00
|
|
|
IBackOfficeSecurityAccessor backofficeSecurityAccessor,
|
|
|
|
|
IEventAggregator eventAggregator)
|
|
|
|
|
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2018-12-03 22:10:56 +11:00
|
|
|
_treeSearcher = treeSearcher;
|
2020-02-17 14:58:34 +01:00
|
|
|
_menuItemCollectionFactory = menuItemCollectionFactory;
|
2020-06-09 07:49:26 +02:00
|
|
|
_memberService = memberService;
|
|
|
|
|
_memberTypeService = memberTypeService;
|
2020-09-22 10:01:00 +02:00
|
|
|
_backofficeSecurityAccessor = backofficeSecurityAccessor;
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets an individual tree node
|
|
|
|
|
/// </summary>
|
2021-01-22 09:20:46 +01:00
|
|
|
public ActionResult<TreeNode> GetTreeNode([FromRoute]string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2021-01-22 09:20:46 +01:00
|
|
|
ActionResult<TreeNode> node = GetSingleTreeNode(id, queryStrings);
|
|
|
|
|
|
|
|
|
|
if (!(node.Result is null))
|
|
|
|
|
{
|
|
|
|
|
return node.Result;
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
//add the tree alias to the node since it is standalone (has no root for which this normally belongs)
|
2020-06-09 07:49:26 +02:00
|
|
|
node.Value.AdditionalData["treeAlias"] = TreeAlias;
|
2018-06-29 19:52:40 +02:00
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 07:49:26 +02:00
|
|
|
protected ActionResult<TreeNode> GetSingleTreeNode(string id, FormCollection queryStrings)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2019-11-25 21:20:00 +11:00
|
|
|
Guid asGuid;
|
|
|
|
|
if (Guid.TryParse(id, out asGuid) == false)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-06-09 07:49:26 +02:00
|
|
|
return NotFound();
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
2019-11-25 21:20:00 +11:00
|
|
|
|
2020-06-09 07:49:26 +02:00
|
|
|
var member = _memberService.GetByKey(asGuid);
|
2019-11-25 21:20:00 +11:00
|
|
|
if (member == null)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-06-09 07:49:26 +02:00
|
|
|
return NotFound();
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
2019-11-25 21:20:00 +11:00
|
|
|
|
|
|
|
|
var node = CreateTreeNode(
|
|
|
|
|
member.Key.ToString("N"),
|
|
|
|
|
"-1",
|
|
|
|
|
queryStrings,
|
|
|
|
|
member.Name,
|
|
|
|
|
Constants.Icons.Member,
|
|
|
|
|
false,
|
|
|
|
|
"",
|
|
|
|
|
Udi.Create(ObjectTypes.GetUdiType(Constants.ObjectTypes.Member), member.Key));
|
|
|
|
|
|
|
|
|
|
node.AdditionalData.Add("contentType", member.ContentTypeAlias);
|
|
|
|
|
node.AdditionalData.Add("isContainer", true);
|
|
|
|
|
|
|
|
|
|
return node;
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
2021-01-14 19:41:32 +01:00
|
|
|
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
|
|
|
|
var nodes = new TreeNodeCollection();
|
|
|
|
|
|
2019-03-29 12:06:23 +00:00
|
|
|
if (id == Constants.System.RootString)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
|
|
|
|
nodes.Add(
|
2020-06-09 07:49:26 +02:00
|
|
|
CreateTreeNode(Constants.Conventions.MemberTypes.AllMembersListId, id, queryStrings, LocalizedTextService.Localize("member/allMembers"), Constants.Icons.MemberType, true,
|
2019-01-30 19:48:42 +11:00
|
|
|
queryStrings.GetRequiredValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/" + Constants.Conventions.MemberTypes.AllMembersListId));
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2020-06-09 07:49:26 +02:00
|
|
|
nodes.AddRange(_memberTypeService.GetAll()
|
2018-06-29 19:52:40 +02:00
|
|
|
.Select(memberType =>
|
2019-10-15 12:38:16 +02:00
|
|
|
CreateTreeNode(memberType.Alias, id, queryStrings, memberType.Name, memberType.Icon.IfNullOrWhiteSpace(Constants.Icons.Member), true,
|
2019-01-30 19:48:42 +11:00
|
|
|
queryStrings.GetRequiredValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/" + memberType.Alias)));
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//There is no menu for any of these nodes
|
|
|
|
|
nodes.ForEach(x => x.MenuUrl = null);
|
|
|
|
|
//All nodes are containers
|
|
|
|
|
nodes.ForEach(x => x.AdditionalData.Add("isContainer", true));
|
|
|
|
|
|
|
|
|
|
return nodes;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 11:02:29 +01:00
|
|
|
protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-02-17 14:58:34 +01:00
|
|
|
var menu = _menuItemCollectionFactory.Create();
|
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
|
|
|
{
|
|
|
|
|
// root actions
|
2019-11-25 21:20:00 +11:00
|
|
|
//set default
|
|
|
|
|
menu.DefaultMenuAlias = ActionNew.ActionAlias;
|
|
|
|
|
|
|
|
|
|
//Create the normal create action
|
2020-06-09 07:49:26 +02:00
|
|
|
menu.Items.Add<ActionNew>(LocalizedTextService, opensDialog: true);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2020-06-09 07:49:26 +02:00
|
|
|
menu.Items.Add(new RefreshNode(LocalizedTextService, true));
|
2018-06-29 19:52:40 +02:00
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add delete option for all members
|
2020-06-09 07:49:26 +02:00
|
|
|
menu.Items.Add<ActionDelete>(LocalizedTextService, opensDialog: true);
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2020-10-21 16:51:00 +11:00
|
|
|
if (_backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser.HasAccessToSensitiveData())
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-06-09 07:49:26 +02:00
|
|
|
menu.Items.Add(new ExportMember(LocalizedTextService));
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2018-12-03 22:10:56 +11:00
|
|
|
return _treeSearcher.ExamineSearch(query, UmbracoEntityTypes.Member, pageSize, pageIndex, out totalFound, searchFrom);
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|