diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs index e635c1b1..48b3aafe 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs @@ -48,10 +48,14 @@ public static async Task TestEmailQuotaManagementBehaviorAsync( else if (warningLevel >= 80) { await context.GoToDashboardAsync(); - context.CheckExistence( - By.XPath($"//p[contains(@class,'alert-warning')]" + - $"[contains(.,'It seems that your site sent out {warningLevel.ToTechnicalString()}% of e-mail')]"), - exists: true); + CheckMessageExistence(context, warningLevel.ToTechnicalString()); + + await context.GoToContentItemsPageAsync(); + CheckMessageExistence(context, warningLevel.ToTechnicalString()); + + await context.GoToFeaturesPageAsync(); + CheckMessageExistence(context, warningLevel.ToTechnicalString()); + if (!warningEmails.Contains(warningLevel)) { warningEmails.Add(warningLevel); @@ -78,10 +82,16 @@ public static async Task TestEmailQuotaManagementBehaviorAsync( context.CheckExistence(ByHelper.SmtpInboxRow(UnSuccessfulSubject), exists: !moduleShouldInterfere); } + private static void CheckMessageExistence(UITestContext context, string warningLevel) => + context.CheckExistence( + By.XPath($"//p[contains(@class,'alert-warning')]" + + $"[contains(.,'It seems that your site sent out {warningLevel}% of e-mail')]"), + exists: true); + private static void CheckEmailsSentWarningMessage(UITestContext context, bool exists, int maximumEmailQuota, int currentEmailCount) => context.CheckExistence( By.XPath($"//p[contains(@class,'alert-warning')][contains(.,'{currentEmailCount.ToTechnicalString()} emails" + - $" from the total of {maximumEmailQuota.ToTechnicalString()}.')]"), + $" from the total of {maximumEmailQuota.ToTechnicalString()} this month.')]"), exists); private static async Task SendTestEmailAsync(UITestContext context, string subject) diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs index 81af25c3..9804084f 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs @@ -1,11 +1,8 @@ using Lombiq.Hosting.Tenants.EmailQuotaManagement.Services; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -using OrchardCore.Admin.Controllers; -using OrchardCore.AdminDashboard.Controllers; using OrchardCore.DisplayManagement; using OrchardCore.DisplayManagement.Layout; -using OrchardCore.Mvc.Core.Utilities; using System.Threading.Tasks; namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Filters; @@ -34,21 +31,9 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE return; } - var actionRouteController = context.ActionDescriptor.RouteValues["Controller"]; - var actionRouteArea = context.ActionDescriptor.RouteValues["Area"]; - var actionRouteValue = context.ActionDescriptor.RouteValues["Action"]; - - if ((actionRouteController == typeof(AdminController).ControllerName() || - actionRouteController == typeof(DashboardController).ControllerName()) && - actionRouteArea is $"{nameof(OrchardCore)}.{nameof(OrchardCore.Admin)}" or - $"{nameof(OrchardCore)}.{nameof(OrchardCore.AdminDashboard)}" && - actionRouteValue is nameof(AdminController.Index) or - nameof(DashboardController.Index) && - context.Result is ViewResult && + if (context.Result is ViewResult && _emailQuotaService.ShouldLimitEmails()) { - var layout = await _layoutAccessor.GetLayoutAsync(); - var contentZone = layout.Zones["Content"]; var currentEmailQuota = await _emailQuotaService.IsQuotaOverTheLimitAsync(); var currentUsagePercentage = currentEmailQuota.EmailQuota @@ -56,6 +41,8 @@ context.Result is ViewResult && if (currentUsagePercentage >= 80) { + var layout = await _layoutAccessor.GetLayoutAsync(); + var contentZone = layout.Zones["Messages"]; await contentZone.AddAsync( await _shapeFactory.CreateAsync("DashboardQuotaMessage", new { diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Views/EmailSettingsQuotaMessage.cshtml b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Views/EmailSettingsQuotaMessage.cshtml index 5e7d8cae..e180df88 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Views/EmailSettingsQuotaMessage.cshtml +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Views/EmailSettingsQuotaMessage.cshtml @@ -1,6 +1,6 @@

@T["Unless you use your own SMTP server you have limited e-mails to send. " + - "You've sent {0} emails from the total of {1}.", + "You've sent {0} emails from the total of {1} this month.", Model.CurrentEmailUsageCount, Model.EmailQuotaPerMonth]