33using Sitecore . Data ;
44using Sitecore . Data . Items ;
55using Sitecore . Security . Accounts ;
6+ using Sitecore . SecurityModel ;
67using Spe . Core . Diagnostics ;
78using System ;
89using System . Collections . Concurrent ;
@@ -20,28 +21,35 @@ public static class DelegatedAccessManager
2021
2122 public const string DelegatedItemPath = "/sitecore/system/Modules/PowerShell/Delegated Access" ;
2223
24+ private static bool _isInitialized = false ;
25+
2326 public static void Invalidate ( )
2427 {
2528 PowerShellLog . Audit ( $ "Clearing { nameof ( DelegatedAccessEntry ) } entries.") ;
2629 _accessEntries . Clear ( ) ;
2730 _delegatedItems . Clear ( ) ;
31+ _isInitialized = false ;
2832 }
2933
3034 private static IEnumerable < Item > GetDelegatedItems ( )
3135 {
32- if ( _delegatedItems . Any ( ) )
36+ if ( _isInitialized )
3337 {
3438 return _delegatedItems ;
3539 }
3640
37- var db = Factory . GetDatabase ( ApplicationSettings . ScriptLibraryDb ) ;
38- var delegatedItems = db . GetItem ( DelegatedItemPath )
39- . Axes . GetDescendants ( )
40- . Where ( d => d . TemplateID == Templates . DelegatedAccess . Id ) ;
41+ using ( new SecurityDisabler ( ) )
42+ {
43+ var db = Factory . GetDatabase ( ApplicationSettings . ScriptLibraryDb ) ;
44+ var delegatedItems = db . GetItem ( DelegatedItemPath )
45+ . Axes . GetDescendants ( )
46+ . Where ( d => d . TemplateID == Templates . DelegatedAccess . Id ) ;
4147
42- _delegatedItems . AddRange ( delegatedItems ) ;
48+ _delegatedItems . AddRange ( delegatedItems ) ;
49+ }
4350
44- return delegatedItems ;
51+ _isInitialized = true ;
52+ return _delegatedItems ;
4553 }
4654
4755 private static DelegatedAccessEntry GetDelegatedAccessEntry ( User currentUser , Item scriptItem )
0 commit comments