2018-06-29 19:52:40 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2020-06-09 07:49:26 +02:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
2020-09-22 10:01:00 +02:00
|
|
|
|
using Umbraco.Core.Security;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
using Umbraco.Core.Services;
|
2020-06-09 07:49:26 +02:00
|
|
|
|
using Umbraco.Extensions;
|
2018-10-29 17:27:33 +11:00
|
|
|
|
using Umbraco.Web.Actions;
|
2020-06-09 07:49:26 +02:00
|
|
|
|
using Umbraco.Web.BackOffice.Filters;
|
|
|
|
|
|
using Umbraco.Web.BackOffice.Trees;
|
|
|
|
|
|
using Umbraco.Web.Common.Attributes;
|
|
|
|
|
|
using Umbraco.Web.Common.ModelBinders;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
using Umbraco.Web.Models.Trees;
|
|
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
|
|
|
|
|
using Umbraco.Web.Search;
|
|
|
|
|
|
using Constants = Umbraco.Core.Constants;
|
2019-11-25 21:20:00 +11:00
|
|
|
|
using Umbraco.Web.Security;
|
2020-06-09 07:49:26 +02:00
|
|
|
|
using Umbraco.Web.WebApi;
|
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.Members)]
|
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-09-22 10:01:00 +02: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,
|
2020-09-22 10:01:00 +02:00
|
|
|
|
IBackofficeSecurityAccessor backofficeSecurityAccessor)
|
2020-06-09 07:49:26 +02:00
|
|
|
|
: base(localizedTextService, umbracoApiControllerTypeCollection)
|
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>
|
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
/// <param name="queryStrings"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2020-06-09 07:49:26 +02:00
|
|
|
|
public ActionResult<TreeNode> GetTreeNode(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings)
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
var node = GetSingleTreeNode(id, queryStrings);
|
|
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-09 07:49:26 +02:00
|
|
|
|
protected override 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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-09 07:49:26 +02:00
|
|
|
|
protected override 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-09-22 10:01:00 +02: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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|