Skip to content

Commit

Permalink
Merge pull request #129 from Lombiq/issue/OSOE-893
Browse files Browse the repository at this point in the history
OSOE-893: Fixing SMTP config management
  • Loading branch information
sarahelsaig authored Aug 9, 2024
2 parents d458c76 + 3e06fdc commit e712041
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
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

0 comments on commit e712041

Please sign in to comment.