11
11
using Umbraco . Cms . Core . Persistence . Repositories ;
12
12
using Umbraco . Cms . Core . Scoping ;
13
13
using Umbraco . Cms . Core . Services . Changes ;
14
+ using Umbraco . Cms . Core . Services . Filters ;
14
15
using Umbraco . Cms . Core . Services . OperationStatus ;
15
16
using Umbraco . Extensions ;
16
17
@@ -25,6 +26,7 @@ public abstract class ContentTypeServiceBase<TRepository, TItem> : ContentTypeSe
25
26
private readonly IEntityRepository _entityRepository ;
26
27
private readonly IEventAggregator _eventAggregator ;
27
28
private readonly IUserIdKeyResolver _userIdKeyResolver ;
29
+ private readonly ContentTypeFilterCollection _contentTypeFilters ;
28
30
29
31
protected ContentTypeServiceBase (
30
32
ICoreScopeProvider provider ,
@@ -35,7 +37,8 @@ protected ContentTypeServiceBase(
35
37
IEntityContainerRepository containerRepository ,
36
38
IEntityRepository entityRepository ,
37
39
IEventAggregator eventAggregator ,
38
- IUserIdKeyResolver userIdKeyResolver )
40
+ IUserIdKeyResolver userIdKeyResolver ,
41
+ ContentTypeFilterCollection contentTypeFilters )
39
42
: base ( provider , loggerFactory , eventMessagesFactory )
40
43
{
41
44
Repository = repository ;
@@ -44,6 +47,7 @@ protected ContentTypeServiceBase(
44
47
_entityRepository = entityRepository ;
45
48
_eventAggregator = eventAggregator ;
46
49
_userIdKeyResolver = userIdKeyResolver ;
50
+ _contentTypeFilters = contentTypeFilters ;
47
51
}
48
52
49
53
[ Obsolete ( "Use the ctor specifying all dependencies instead" ) ]
@@ -69,6 +73,31 @@ protected ContentTypeServiceBase(
69
73
{
70
74
}
71
75
76
+ [ Obsolete ( "Use the ctor specifying all dependencies instead" ) ]
77
+ protected ContentTypeServiceBase (
78
+ ICoreScopeProvider provider ,
79
+ ILoggerFactory loggerFactory ,
80
+ IEventMessagesFactory eventMessagesFactory ,
81
+ TRepository repository ,
82
+ IAuditRepository auditRepository ,
83
+ IEntityContainerRepository containerRepository ,
84
+ IEntityRepository entityRepository ,
85
+ IEventAggregator eventAggregator ,
86
+ IUserIdKeyResolver userIdKeyResolver )
87
+ : this (
88
+ provider ,
89
+ loggerFactory ,
90
+ eventMessagesFactory ,
91
+ repository ,
92
+ auditRepository ,
93
+ containerRepository ,
94
+ entityRepository ,
95
+ eventAggregator ,
96
+ userIdKeyResolver ,
97
+ StaticServiceProvider . Instance . GetRequiredService < ContentTypeFilterCollection > ( ) )
98
+ {
99
+ }
100
+
72
101
protected TRepository Repository { get ; }
73
102
protected abstract int [ ] WriteLockIds { get ; }
74
103
protected abstract int [ ] ReadLockIds { get ; }
@@ -1129,7 +1158,7 @@ public TItem Copy(TItem original, string alias, string name, TItem? parent)
1129
1158
#region Allowed types
1130
1159
1131
1160
/// <inheritdoc />
1132
- public Task < PagedModel < TItem > > GetAllAllowedAsRootAsync ( int skip , int take )
1161
+ public async Task < PagedModel < TItem > > GetAllAllowedAsRootAsync ( int skip , int take )
1133
1162
{
1134
1163
using ICoreScope scope = ScopeProvider . CreateCoreScope ( autoComplete : true ) ;
1135
1164
@@ -1139,28 +1168,39 @@ public Task<PagedModel<TItem>> GetAllAllowedAsRootAsync(int skip, int take)
1139
1168
IQuery < TItem > query = ScopeProvider . CreateQuery < TItem > ( ) . Where ( x => x . AllowedAsRoot ) ;
1140
1169
IEnumerable < TItem > contentTypes = Repository . Get ( query ) . ToArray ( ) ;
1141
1170
1171
+ foreach ( IContentTypeFilter filter in _contentTypeFilters )
1172
+ {
1173
+ contentTypes = await filter . FilterAllowedAtRootAsync ( contentTypes ) ;
1174
+ }
1175
+
1142
1176
var pagedModel = new PagedModel < TItem >
1143
1177
{
1144
1178
Total = contentTypes . Count ( ) ,
1145
1179
Items = contentTypes . Skip ( skip ) . Take ( take )
1146
1180
} ;
1147
1181
1148
- return Task . FromResult ( pagedModel ) ;
1182
+ return pagedModel ;
1149
1183
}
1150
1184
1151
1185
/// <inheritdoc />
1152
- public Task < Attempt < PagedModel < TItem > ? , ContentTypeOperationStatus > > GetAllowedChildrenAsync ( Guid key , int skip , int take )
1186
+ public async Task < Attempt < PagedModel < TItem > ? , ContentTypeOperationStatus > > GetAllowedChildrenAsync ( Guid key , int skip , int take )
1153
1187
{
1154
1188
using ICoreScope scope = ScopeProvider . CreateCoreScope ( autoComplete : true ) ;
1155
1189
TItem ? parent = Get ( key ) ;
1156
1190
1157
1191
if ( parent ? . AllowedContentTypes is null )
1158
1192
{
1159
- return Task . FromResult ( Attempt . FailWithStatus < PagedModel < TItem > ? , ContentTypeOperationStatus > ( ContentTypeOperationStatus . NotFound , null ) ) ;
1193
+ return Attempt . FailWithStatus < PagedModel < TItem > ? , ContentTypeOperationStatus > ( ContentTypeOperationStatus . NotFound , null ) ;
1194
+ }
1195
+
1196
+ IEnumerable < ContentTypeSort > allowedContentTypes = parent . AllowedContentTypes ;
1197
+ foreach ( IContentTypeFilter filter in _contentTypeFilters )
1198
+ {
1199
+ allowedContentTypes = await filter . FilterAllowedChildrenAsync ( allowedContentTypes , key ) ;
1160
1200
}
1161
1201
1162
1202
PagedModel < TItem > result ;
1163
- if ( parent . AllowedContentTypes . Any ( ) is false )
1203
+ if ( allowedContentTypes . Any ( ) is false )
1164
1204
{
1165
1205
// no content types allowed under parent
1166
1206
result = new PagedModel < TItem >
@@ -1173,7 +1213,7 @@ public Task<PagedModel<TItem>> GetAllAllowedAsRootAsync(int skip, int take)
1173
1213
{
1174
1214
// Get the sorted keys. Whilst we can't guarantee the order that comes back from GetMany, we can use
1175
1215
// this to sort the resulting list of allowed children.
1176
- Guid [ ] sortedKeys = parent . AllowedContentTypes . OrderBy ( x => x . SortOrder ) . Select ( x => x . Key ) . ToArray ( ) ;
1216
+ Guid [ ] sortedKeys = allowedContentTypes . OrderBy ( x => x . SortOrder ) . Select ( x => x . Key ) . ToArray ( ) ;
1177
1217
1178
1218
TItem [ ] allowedChildren = GetMany ( sortedKeys ) . ToArray ( ) ;
1179
1219
result = new PagedModel < TItem >
@@ -1183,7 +1223,7 @@ public Task<PagedModel<TItem>> GetAllAllowedAsRootAsync(int skip, int take)
1183
1223
} ;
1184
1224
}
1185
1225
1186
- return Task . FromResult ( Attempt . SucceedWithStatus < PagedModel < TItem > ? , ContentTypeOperationStatus > ( ContentTypeOperationStatus . Success , result ) ) ;
1226
+ return Attempt . SucceedWithStatus < PagedModel < TItem > ? , ContentTypeOperationStatus > ( ContentTypeOperationStatus . Success , result ) ;
1187
1227
}
1188
1228
1189
1229
#endregion
0 commit comments