Skip to content

Commit 63a8ee8

Browse files
author
Rick Butterfield
committed
Automatically add section to admin user group on startup
1 parent 1bce3ec commit 63a8ee8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Umbraco.Community.Sustainability/Notifications/PageMetricsNotificationHandler.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ public class PageMetricsNotificationHandler : INotificationHandler<UmbracoApplic
1717
private readonly ICoreScopeProvider _coreScopeProvider;
1818
private readonly IKeyValueService _keyValueService;
1919
private readonly IRuntimeState _runtimeState;
20+
private readonly IUserService _userService;
2021

2122
public PageMetricsNotificationHandler(
2223
ICoreScopeProvider coreScopeProvider,
2324
IMigrationPlanExecutor migrationPlanExecutor,
2425
IKeyValueService keyValueService,
25-
IRuntimeState runtimeState)
26+
IRuntimeState runtimeState,
27+
IUserService userService)
2628
{
2729
_migrationPlanExecutor = migrationPlanExecutor;
2830
_coreScopeProvider = coreScopeProvider;
2931
_keyValueService = keyValueService;
3032
_runtimeState = runtimeState;
33+
_userService = userService;
3134
}
3235

3336
public void Handle(UmbracoApplicationStartingNotification notification)
@@ -54,6 +57,16 @@ public void Handle(UmbracoApplicationStartingNotification notification)
5457
_migrationPlanExecutor,
5558
_coreScopeProvider,
5659
_keyValueService);
60+
61+
var adminGroup = _userService.GetUserGroupByAlias(Cms.Core.Constants.Security.AdminGroupAlias);
62+
if (adminGroup != null)
63+
{
64+
if (!adminGroup.AllowedSections.Contains(Constants.SectionAlias))
65+
{
66+
adminGroup.AddAllowedSection(Constants.SectionAlias);
67+
_userService.Save(adminGroup);
68+
}
69+
}
5770
}
5871
}
5972
}

0 commit comments

Comments
 (0)