1212
1313namespace Umbraco . Cms . Api . Management . Install ;
1414
15- public class CreateUnattendedUserNotificationHandler : INotificationAsyncHandler < UnattendedInstallNotification >
15+ public class PostUnattendedInstallNotificationHandler : INotificationAsyncHandler < UnattendedInstallNotification >
1616{
1717 private readonly IServiceScopeFactory _serviceScopeFactory ;
1818 private readonly IOptions < UnattendedSettings > _unattendedSettings ;
1919 private readonly IUserService _userService ;
20+ private readonly IMetricsConsentService _metricsConsentService ;
2021
21- public CreateUnattendedUserNotificationHandler ( IOptions < UnattendedSettings > unattendedSettings , IUserService userService , IServiceScopeFactory serviceScopeFactory )
22+ public PostUnattendedInstallNotificationHandler ( IOptions < UnattendedSettings > unattendedSettings , IUserService userService , IServiceScopeFactory serviceScopeFactory , IMetricsConsentService metricsConsentService )
2223 {
2324 _unattendedSettings = unattendedSettings ;
2425 _userService = userService ;
2526 _serviceScopeFactory = serviceScopeFactory ;
27+ _metricsConsentService = metricsConsentService ;
2628 }
2729
2830 /// <summary>
29- /// Listening for when the UnattendedInstallNotification fired after a sucessfulk
31+ /// Listening for when the UnattendedInstallNotification fired after a successful unattended install
32+ /// This creates the user and sets the telemetry level based on the 'Unattended' settings.
3033 /// </summary>
3134 /// <param name="notification"></param>
3235 /// <param name="cancellationToken"></param>
3336 public async Task HandleAsync ( UnattendedInstallNotification notification , CancellationToken cancellationToken )
3437 {
3538 UnattendedSettings ? unattendedSettings = _unattendedSettings . Value ;
39+
3640 // Ensure we have the setting enabled (Sanity check)
3741 // In theory this should always be true as the event only fired when a sucessfull
3842 if ( _unattendedSettings . Value . InstallUnattended == false )
@@ -83,7 +87,7 @@ public async Task HandleAsync(UnattendedInstallNotification notification, Cancel
8387 $ "No user found in membership provider with id of { Constants . Security . SuperUserIdAsString } .") ;
8488 }
8589
86- //To change the password here we actually need to reset it since we don't have an old one to use to change
90+ // To change the password here we actually need to reset it since we don't have an old one to use to change
8791 var resetToken = await backOfficeUserManager . GeneratePasswordResetTokenAsync ( membershipUser ) ;
8892 if ( string . IsNullOrWhiteSpace ( resetToken ) )
8993 {
@@ -98,5 +102,7 @@ await backOfficeUserManager.ChangePasswordWithResetAsync(membershipUser.Id, rese
98102 throw new InvalidOperationException ( "Could not reset password: " +
99103 string . Join ( ", " , resetResult . Errors . ToErrorMessage ( ) ) ) ;
100104 }
105+
106+ await _metricsConsentService . SetConsentLevelAsync ( unattendedSettings . UnattendedTelemetryLevel ) ;
101107 }
102108}
0 commit comments