Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-893: Fixing SMTP config management #129

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ public static class EmailQuotaManagementExtensions
{
public static void SetEmailQuotaManagementOptionsForUITest(
this OrchardCoreUITestExecutorConfiguration configuration,
long maximumEmails,
string emailHost = "localhost")
long maximumEmails)
{
configuration.OrchardCoreConfiguration.BeforeAppStart +=
(_, argumentsBuilder) =>
Expand All @@ -18,11 +17,6 @@ public static void SetEmailQuotaManagementOptionsForUITest(
"OrchardCore:Lombiq_Hosting_Tenants_EmailQuotaManagement:EmailQuotaPerMonth",
maximumEmails);

argumentsBuilder
.AddWithValue(
"OrchardCore:SmtpSettings:Host",
emailHost);

return Task.CompletedTask;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static async Task TestEmailQuotaManagementBehaviorAsync(
await context.SignInDirectlyAndGoToDashboardAsync();
context.Missing(By.XPath(DashboardExceededMessage));

await context.ConfigureSmtpPortAsync(publish: false);
await context.GoToEmailSettingsAsync();
CheckEmailsSentWarningMessage(context, exists: moduleShouldInterfere, maximumEmailQuota, 0);
await context.ClickReliablyOnAsync(By.ClassName("save"));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using OrchardCore.Email;
using OrchardCore.Environment.Shell.Configuration;
using OrchardCore.Modules;
using OrchardCore.Security;
using OrchardCore.Security.Services;
Expand All @@ -25,24 +23,24 @@ public class EmailQuotaService : IEmailQuotaService
{
private readonly ISession _session;
private readonly EmailQuotaOptions _emailQuotaOptions;
private readonly IShellConfiguration _shellConfiguration;
private readonly SmtpSettings _smtpOptions;
private readonly DefaultSmtpOptions _defaultSmtpOptions;
private readonly SmtpOptions _smtpOptions;
private readonly IClock _clock;
private readonly IRoleService _roleService;
private readonly UserManager<IUser> _userManager;

public EmailQuotaService(
ISession session,
IOptions<EmailQuotaOptions> emailQuotaOptions,
IShellConfiguration shellConfiguration,
IOptions<SmtpSettings> smtpOptions,
IOptions<DefaultSmtpOptions> defaultSmtpOptions,
IOptions<SmtpOptions> smtpOptions,
IClock clock,
IRoleService roleService,
UserManager<IUser> userManager)
{
_session = session;
_emailQuotaOptions = emailQuotaOptions.Value;
_shellConfiguration = shellConfiguration;
_defaultSmtpOptions = defaultSmtpOptions.Value;
_smtpOptions = smtpOptions.Value;
_clock = clock;
_roleService = roleService;
Expand All @@ -66,11 +64,8 @@ public async Task<IEnumerable<string>> GetUserEmailsForEmailReminderAsync()
return siteOwners.Select(user => (user as User)?.Email);
}

public bool ShouldLimitEmails()
{
var originalHost = _shellConfiguration.GetValue<string>("SmtpSettings:Host");
return originalHost == _smtpOptions.Host;
}
public bool ShouldLimitEmails() =>
_defaultSmtpOptions.Host == _smtpOptions.Host || (_defaultSmtpOptions.Host != null && _smtpOptions.Host == null);

public async Task<QuotaResult> IsQuotaOverTheLimitAsync()
{
Expand Down