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-708: Email Quota Management UX improvements in Lombiq.Hosting.Tenants #102

Merged
merged 5 commits into from
Nov 27, 2023
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 @@ -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>