-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
NEST-403: Maintenance to clear all links of users
- Loading branch information
Showing
16 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/RemoveUsersMaintenanceOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.RemoveUsers; | ||
|
||
public class RemoveUsersMaintenanceOptions | ||
{ | ||
public bool IsEnabled { get; set; } | ||
public string EmailDomain { get; set; } | ||
} |
45 changes: 45 additions & 0 deletions
45
Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/RemoveUsersMaintenanceProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Lombiq.Hosting.Tenants.Maintenance.Extensions; | ||
using Lombiq.Hosting.Tenants.Maintenance.Models; | ||
using Lombiq.Hosting.Tenants.Maintenance.Services; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.Extensions.Options; | ||
using OrchardCore.Users; | ||
using OrchardCore.Users.Models; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using YesSql; | ||
|
||
namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.RemoveUsers; | ||
|
||
public class RemoveUsersMaintenanceProvider : MaintenanceProviderBase | ||
{ | ||
private readonly IOptions<RemoveUsersMaintenanceOptions> _options; | ||
private readonly ISession _session; | ||
private readonly UserManager<IUser> _userManager; | ||
|
||
public RemoveUsersMaintenanceProvider( | ||
IOptions<RemoveUsersMaintenanceOptions> options, | ||
ISession session, | ||
UserManager<IUser> userManager) | ||
{ | ||
_options = options; | ||
_session = session; | ||
_userManager = userManager; | ||
} | ||
|
||
public override Task<bool> ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => | ||
Task.FromResult( | ||
_options.Value.IsEnabled && | ||
!context.WasLatestExecutionSuccessful()); | ||
|
||
public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) | ||
{ | ||
var users = await _session.Query<User>().ListAsync(); | ||
foreach (var user in users.Where(user => | ||
user.Email.EndsWith($"@{_options.Value.EmailDomain}", StringComparison.InvariantCulture))) | ||
{ | ||
await _userManager.DeleteAsync(user); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Lombiq.Hosting.Tenants.Maintenance.Constants; | ||
using Lombiq.Hosting.Tenants.Maintenance.Services; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using OrchardCore.Environment.Shell.Configuration; | ||
using OrchardCore.Modules; | ||
|
||
namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.RemoveUsers; | ||
|
||
[Feature(FeatureNames.RemoveUsers)] | ||
public class Startup : StartupBase | ||
{ | ||
private readonly IShellConfiguration _shellConfiguration; | ||
|
||
public Startup(IShellConfiguration shellConfiguration) => | ||
_shellConfiguration = shellConfiguration; | ||
|
||
public override void ConfigureServices(IServiceCollection services) | ||
{ | ||
var options = new RemoveUsersMaintenanceOptions(); | ||
var configSection = _shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:RemoveUsers"); | ||
configSection.Bind(options); | ||
services.Configure<RemoveUsersMaintenanceOptions>(configSection); | ||
|
||
services.AddScoped<IMaintenanceProvider, RemoveUsersMaintenanceProvider>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters