2020-11-19 19:23:41 +11: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;
|
2022-04-19 08:55:13 +02:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core;
|
2021-02-23 16:09:36 +01:00
|
|
|
using Umbraco.Cms.Core.Events;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Cms.Core.Trees;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Attributes;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Authorization;
|
2022-04-19 08:55:13 +02:00
|
|
|
using Umbraco.Cms.Web.Common.DependencyInjection;
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
namespace Umbraco.Cms.Web.BackOffice.Trees;
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
[Authorize(Policy = AuthorizationPolicies.TreeAccessMemberGroups)]
|
|
|
|
|
[Tree(Constants.Applications.Members, Constants.Trees.MemberGroups, SortOrder = 1)]
|
|
|
|
|
[PluginController(Constants.Web.Mvc.BackOfficeTreeArea)]
|
|
|
|
|
[CoreTree]
|
|
|
|
|
public class MemberGroupTreeController : MemberTypeAndGroupTreeControllerBase
|
2020-06-09 07:49:26 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
private readonly IMemberGroupService _memberGroupService;
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
[
|
|
|
|
|
ActivatorUtilitiesConstructor]
|
|
|
|
|
public MemberGroupTreeController(
|
|
|
|
|
ILocalizedTextService localizedTextService,
|
|
|
|
|
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
|
|
|
|
|
IMenuItemCollectionFactory menuItemCollectionFactory,
|
|
|
|
|
IMemberGroupService memberGroupService,
|
|
|
|
|
IEventAggregator eventAggregator,
|
|
|
|
|
IMemberTypeService memberTypeService)
|
|
|
|
|
: base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, eventAggregator,
|
|
|
|
|
memberTypeService)
|
|
|
|
|
=> _memberGroupService = memberGroupService;
|
2022-04-19 08:55:13 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
[Obsolete("Use ctor with all params")]
|
|
|
|
|
public MemberGroupTreeController(
|
|
|
|
|
ILocalizedTextService localizedTextService,
|
|
|
|
|
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
|
|
|
|
|
IMenuItemCollectionFactory menuItemCollectionFactory,
|
|
|
|
|
IMemberGroupService memberGroupService,
|
|
|
|
|
IEventAggregator eventAggregator)
|
|
|
|
|
: this(localizedTextService,
|
|
|
|
|
umbracoApiControllerTypeCollection,
|
|
|
|
|
menuItemCollectionFactory,
|
|
|
|
|
memberGroupService,
|
|
|
|
|
eventAggregator,
|
|
|
|
|
StaticServiceProvider.Instance.GetRequiredService<IMemberTypeService>())
|
2020-06-09 07:49:26 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
}
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
protected override IEnumerable<TreeNode> GetTreeNodesFromService(string id, FormCollection queryStrings)
|
|
|
|
|
=> _memberGroupService.GetAll()
|
|
|
|
|
.OrderBy(x => x.Name)
|
|
|
|
|
.Select(dt =>
|
|
|
|
|
CreateTreeNode(dt.Id.ToString(), id, queryStrings, dt.Name, Constants.Icons.MemberGroup, false));
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
protected override ActionResult<TreeNode?> CreateRootNode(FormCollection queryStrings)
|
|
|
|
|
{
|
|
|
|
|
ActionResult<TreeNode?> rootResult = base.CreateRootNode(queryStrings);
|
|
|
|
|
if (!(rootResult.Result is null))
|
2022-04-19 08:55:13 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
return rootResult.Result;
|
2022-04-19 08:55:13 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
TreeNode? root = rootResult.Value;
|
2020-06-09 07:49:26 +02:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
if (root is not null)
|
2020-06-09 07:49:26 +02:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
// Check if there are any groups
|
|
|
|
|
root.HasChildren = _memberGroupService.GetAll().Any();
|
2020-06-09 07:49:26 +02:00
|
|
|
}
|
2022-06-20 08:37:17 +02:00
|
|
|
|
|
|
|
|
return root;
|
2020-06-09 07:49:26 +02:00
|
|
|
}
|
|
|
|
|
}
|