Skip to content

Commit

Permalink
Merge pull request #102 from Lombiq/issue/OSOE-708
Browse files Browse the repository at this point in the history
OSOE-708: Email Quota Management UX improvements in Lombiq.Hosting.Tenants
  • Loading branch information
Psichorex authored Nov 27, 2023
2 parents dc88ba0 + 4c85006 commit adb4e3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,28 +31,18 @@ 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
.CurrentUsagePercentage(_emailQuotaService.GetEmailQuotaPerMonth());

if (currentUsagePercentage >= 80)
{
var layout = await _layoutAccessor.GetLayoutAsync();
var contentZone = layout.Zones["Messages"];
await contentZone.AddAsync(
await _shapeFactory.CreateAsync("DashboardQuotaMessage", new
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p class="alert alert-warning">
@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]
</p>

0 comments on commit adb4e3f

Please sign in to comment.