-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathElementTreeControllerBase.cs
More file actions
82 lines (71 loc) · 3.46 KB
/
ElementTreeControllerBase.cs
File metadata and controls
82 lines (71 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.Controllers.Tree;
using Umbraco.Cms.Api.Management.Factories;
using Umbraco.Cms.Api.Management.Routing;
using Umbraco.Cms.Api.Management.Services.Entities;
using Umbraco.Cms.Api.Management.Services.Flags;
using Umbraco.Cms.Api.Management.ViewModels.Tree;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.Common.Authorization;
namespace Umbraco.Cms.Api.Management.Controllers.Element.Tree;
[VersionedApiBackOfficeRoute($"{Constants.Web.RoutePath.Tree}/{Constants.UdiEntityType.Element}")]
[ApiExplorerSettings(GroupName = nameof(Constants.UdiEntityType.Element))]
[Authorize(Policy = AuthorizationPolicies.SectionAccessForElementTree)]
public class ElementTreeControllerBase : UserStartNodeFolderTreeControllerBase<ElementTreeItemResponseModel>
{
private readonly AppCaches _appCaches;
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
private readonly IElementPresentationFactory _elementPresentationFactory;
public ElementTreeControllerBase(
IEntityService entityService,
FlagProviderCollection flagProviders,
IUserStartNodeEntitiesService userStartNodeEntitiesService,
IDataTypeService dataTypeService,
AppCaches appCaches,
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IElementPresentationFactory elementPresentationFactory)
: base(entityService, flagProviders, userStartNodeEntitiesService, dataTypeService)
{
_appCaches = appCaches;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
_elementPresentationFactory = elementPresentationFactory;
}
protected override UmbracoObjectTypes ItemObjectType => UmbracoObjectTypes.Element;
protected override UmbracoObjectTypes FolderObjectType => UmbracoObjectTypes.ElementContainer;
protected override int[] GetUserStartNodeIds()
=> _backOfficeSecurityAccessor
.BackOfficeSecurity?
.CurrentUser?
.CalculateElementStartNodeIds(EntityService, _appCaches)
?? [];
protected override string[] GetUserStartNodePaths()
=> _backOfficeSecurityAccessor
.BackOfficeSecurity?
.CurrentUser?
.GetElementStartNodePaths(EntityService, _appCaches)
?? [];
protected override ElementTreeItemResponseModel MapTreeItemViewModel(Guid? parentKey, IEntitySlim entity)
{
ElementTreeItemResponseModel responseModel = base.MapTreeItemViewModel(parentKey, entity);
if (entity is IElementEntitySlim elementEntitySlim)
{
responseModel.HasChildren = false;
responseModel.CreateDate = elementEntitySlim.CreateDate;
responseModel.DocumentType = _elementPresentationFactory.CreateDocumentTypeReferenceResponseModel(elementEntitySlim);
responseModel.Variants = _elementPresentationFactory.CreateVariantsItemResponseModels(elementEntitySlim);
}
return responseModel;
}
protected override ElementTreeItemResponseModel MapTreeItemViewModelAsNoAccess(Guid? parentKey, IEntitySlim entity)
{
ElementTreeItemResponseModel viewModel = MapTreeItemViewModel(parentKey, entity);
viewModel.NoAccess = true;
return viewModel;
}
}