1
1
using System . Globalization ;
2
+ using Microsoft . Extensions . DependencyInjection ;
2
3
using Microsoft . Extensions . Logging ;
4
+ using Umbraco . Cms . Core . DependencyInjection ;
3
5
using Umbraco . Cms . Core . Events ;
4
6
using Umbraco . Cms . Core . Models ;
5
7
using Umbraco . Cms . Core . Models . Entities ;
@@ -16,19 +18,41 @@ internal class PublicAccessService : RepositoryService, IPublicAccessService
16
18
private readonly IPublicAccessRepository _publicAccessRepository ;
17
19
private readonly IEntityService _entityService ;
18
20
private readonly IContentService _contentService ;
21
+ private readonly IIdKeyMap _idKeyMap ;
19
22
23
+ [ Obsolete ( "Please use the constructor that accepts all parameter. Will be removed in V16." ) ]
20
24
public PublicAccessService (
21
25
ICoreScopeProvider provider ,
22
26
ILoggerFactory loggerFactory ,
23
27
IEventMessagesFactory eventMessagesFactory ,
24
28
IPublicAccessRepository publicAccessRepository ,
25
29
IEntityService entityService ,
26
30
IContentService contentService )
31
+ : this (
32
+ provider ,
33
+ loggerFactory ,
34
+ eventMessagesFactory ,
35
+ publicAccessRepository ,
36
+ entityService ,
37
+ contentService ,
38
+ StaticServiceProvider . Instance . GetRequiredService < IIdKeyMap > ( ) )
39
+ {
40
+ }
41
+
42
+ public PublicAccessService (
43
+ ICoreScopeProvider provider ,
44
+ ILoggerFactory loggerFactory ,
45
+ IEventMessagesFactory eventMessagesFactory ,
46
+ IPublicAccessRepository publicAccessRepository ,
47
+ IEntityService entityService ,
48
+ IContentService contentService ,
49
+ IIdKeyMap idKeyMap )
27
50
: base ( provider , loggerFactory , eventMessagesFactory )
28
51
{
29
52
_publicAccessRepository = publicAccessRepository ;
30
53
_entityService = entityService ;
31
54
_contentService = contentService ;
55
+ _idKeyMap = idKeyMap ;
32
56
}
33
57
34
58
/// <summary>
@@ -381,6 +405,23 @@ private Attempt<PublicAccessNodesValidationResult, PublicAccessOperationStatus>
381
405
return Task . FromResult ( Attempt . SucceedWithStatus < PublicAccessEntry ? , PublicAccessOperationStatus > ( PublicAccessOperationStatus . Success , entry ) ) ;
382
406
}
383
407
408
+ public async Task < Attempt < PublicAccessEntry ? , PublicAccessOperationStatus > > GetEntryByContentKeyWithoutAncestorsAsync ( Guid key )
409
+ {
410
+ Attempt < PublicAccessEntry ? , PublicAccessOperationStatus > result = await GetEntryByContentKeyAsync ( key ) ;
411
+ if ( result . Success is false || result . Result is null )
412
+ {
413
+ return result ;
414
+ }
415
+
416
+ Attempt < Guid > idToKeyAttempt = _idKeyMap . GetKeyForId ( result . Result . ProtectedNodeId , UmbracoObjectTypes . Document ) ;
417
+ if ( idToKeyAttempt . Success is false || idToKeyAttempt . Result != key )
418
+ {
419
+ return Attempt . SucceedWithStatus < PublicAccessEntry ? , PublicAccessOperationStatus > ( PublicAccessOperationStatus . EntryNotFound , null ) ;
420
+ }
421
+
422
+ return result ;
423
+ }
424
+
384
425
public async Task < Attempt < PublicAccessOperationStatus > > DeleteAsync ( Guid key )
385
426
{
386
427
using ( ICoreScope scope = ScopeProvider . CreateCoreScope ( ) )
0 commit comments