Skip to content

Commit c3112dd

Browse files
KaasKop97nul800sebastiaan
authored andcommitted
Added the ability to set the telemetry level for an unattended install
Added 'UnattendedTelemetryLevel' to 'UnattendedSettings' Renamed 'CreateUnattendedUserNotificationHandler' to 'PostUnattendedInstallNotificationHandler' Set the telemetry level in the unattended install notification handler
1 parent 81f29be commit c3112dd

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/Umbraco.Cms.Api.Management/DependencyInjection/InstallerBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal static IUmbracoBuilder AddInstaller(this IUmbracoBuilder builder)
2525

2626
builder.AddInstallSteps();
2727
services.AddTransient<IInstallService, InstallService>();
28-
builder.AddNotificationAsyncHandler<UnattendedInstallNotification, CreateUnattendedUserNotificationHandler>();
28+
builder.AddNotificationAsyncHandler<UnattendedInstallNotification, PostUnattendedInstallNotificationHandler>();
2929
builder.WithCollectionBuilder<MapDefinitionCollectionBuilder>().Add<InstallerViewModelsMapDefinition>();
3030

3131
return builder;

src/Umbraco.Cms.Api.Management/Install/CreateUnattendedUserNotificationHandler.cs renamed to src/Umbraco.Cms.Api.Management/Install/PostUnattendedInstallNotificationHandler.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,31 @@
1212

1313
namespace 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
}

src/Umbraco.Core/Configuration/Models/UnattendedSettings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.ComponentModel;
55
using System.ComponentModel.DataAnnotations;
6+
using Umbraco.Cms.Core.Models;
67

78
namespace Umbraco.Cms.Core.Configuration.Models;
89

@@ -14,6 +15,7 @@ public class UnattendedSettings
1415
{
1516
private const bool StaticInstallUnattended = false;
1617
private const bool StaticUpgradeUnattended = false;
18+
private const TelemetryLevel StaticTelemetryLevel = TelemetryLevel.Detailed;
1719

1820
/// <summary>
1921
/// Gets or sets a value indicating whether unattended installs are enabled.
@@ -58,4 +60,9 @@ public class UnattendedSettings
5860
/// Gets or sets a value to use for creating a user with a password for Unattended Installs
5961
/// </summary>
6062
public string? UnattendedUserPassword { get; set; } = null;
63+
64+
/// <summary>
65+
/// Gets or sets a telemetry level to use for Unattended Installs
66+
/// </summary>
67+
public TelemetryLevel UnattendedTelemetryLevel { get; set; } = StaticTelemetryLevel;
6168
}

0 commit comments

Comments
 (0)