Skip to content

Commit

Permalink
Adding EmailExcludePattern config
Browse files Browse the repository at this point in the history
  • Loading branch information
Piedone committed Jun 20, 2024
1 parent 3493a19 commit 23579f3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public class ChangeUserSensitiveContentMaintenanceOptions
{
public bool IsEnabled { get; set; }
public string TenantNames { get; set; }
public string EmailExcludePattern { get; set; } = "[email protected]$";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using RandomNameGeneratorLibrary;
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using YesSql;
using static Lombiq.HelpfulLibraries.OrchardCore.Users.PasswordHelper;
Expand Down Expand Up @@ -49,7 +50,7 @@ public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context)

var users = await _session.Query<User>().ListAsync();
foreach (var user in users.Where(user =>
!user.Email.Trim().EndsWith($"@lombiq.com", StringComparison.InvariantCulture)))
!Regex.IsMatch(user.Email.Trim(), _options.Value.EmailExcludePattern, RegexOptions.None, TimeSpan.FromMilliseconds(400))))
{
var firstName = randomNameGenerator.GenerateRandomFirstName();
var lastName = randomNameGenerator.GenerateRandomLastName();
Expand Down
5 changes: 4 additions & 1 deletion Lombiq.Hosting.Tenants.Maintenance/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@ The following configuration should be used to allow the maintenance to run:
"Lombiq_Hosting_Tenants_Maintenance": {
"ChangeUserSensitiveContent": {
"IsEnabled": true,
"TenantNames": "Default, Tenant1, Tenant2"
"TenantNames": "Default, Tenant1, Tenant2",
"EmailExcludePattern": ".+@(lombiq.com|example.com)$"
}
}
}
}
```

Any user accounts with an e-mail matching the `EmailExcludePattern` regex will not be depersonalized.

0 comments on commit 23579f3

Please sign in to comment.