11using System . Globalization ;
2+ using Microsoft . Extensions . DependencyInjection ;
23using Microsoft . Extensions . Logging ;
4+ using Umbraco . Cms . Core . DependencyInjection ;
35using Umbraco . Cms . Core . Events ;
46using Umbraco . Cms . Core . Models ;
57using Umbraco . Cms . Core . Models . Entities ;
@@ -16,19 +18,41 @@ internal class PublicAccessService : RepositoryService, IPublicAccessService
1618 private readonly IPublicAccessRepository _publicAccessRepository ;
1719 private readonly IEntityService _entityService ;
1820 private readonly IContentService _contentService ;
21+ private readonly IIdKeyMap _idKeyMap ;
1922
23+ [ Obsolete ( "Please use the constructor that accepts all parameter. Will be removed in V16." ) ]
2024 public PublicAccessService (
2125 ICoreScopeProvider provider ,
2226 ILoggerFactory loggerFactory ,
2327 IEventMessagesFactory eventMessagesFactory ,
2428 IPublicAccessRepository publicAccessRepository ,
2529 IEntityService entityService ,
2630 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 )
2750 : base ( provider , loggerFactory , eventMessagesFactory )
2851 {
2952 _publicAccessRepository = publicAccessRepository ;
3053 _entityService = entityService ;
3154 _contentService = contentService ;
55+ _idKeyMap = idKeyMap ;
3256 }
3357
3458 /// <summary>
@@ -381,6 +405,23 @@ private Attempt<PublicAccessNodesValidationResult, PublicAccessOperationStatus>
381405 return Task . FromResult ( Attempt . SucceedWithStatus < PublicAccessEntry ? , PublicAccessOperationStatus > ( PublicAccessOperationStatus . Success , entry ) ) ;
382406 }
383407
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+
384425 public async Task < Attempt < PublicAccessOperationStatus > > DeleteAsync ( Guid key )
385426 {
386427 using ( ICoreScope scope = ScopeProvider . CreateCoreScope ( ) )
0 commit comments