From 5c282ed7beee4bae372d23649e701e76b8d498b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Thu, 18 Jan 2024 12:05:24 +0100 Subject: [PATCH 01/23] Upgrading to .NET 8 and OC 1.8.2 --- .../Filters/TenantsIndexFilter.cs | 2 +- .../Lombiq.Hosting.Tenants.Admin.Login.csproj | 10 +++++----- ...nants.EmailQuotaManagement.Tests.UI.csproj | 2 +- ...osting.Tenants.EmailQuotaManagement.csproj | 20 +++++++++---------- .../Migrations/EmailQuotaMigrations.cs | 9 +++++---- .../Services/EmailQuotaResetTask.cs | 4 ++-- .../Services/EmailQuotaService.cs | 16 +++++++-------- .../Services/IEmailQuotaService.cs | 8 ++++---- .../QuotaManagingSmtpServiceDecorator.cs | 12 +++++------ ....Tenants.EnvironmentRobots.Tests.UI.csproj | 2 +- ...q.Hosting.Tenants.EnvironmentRobots.csproj | 8 ++++---- ...ting.Tenants.FeaturesGuard.Tests.UI.csproj | 2 +- ...ombiq.Hosting.Tenants.FeaturesGuard.csproj | 12 +++++------ ...nants.IdleTenantManagement.Tests.UI.csproj | 2 +- ...osting.Tenants.IdleTenantManagement.csproj | 8 ++++---- ...osting.Tenants.Maintenance.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.Maintenance.csproj | 16 +++++++-------- .../Migrations.cs | 7 ++++--- .../Services/MaintenanceManager.cs | 2 +- ...Hosting.Tenants.Management.Tests.UI.csproj | 2 +- .../Filters/ForbiddenTenantsFilter.cs | 1 + .../Lombiq.Hosting.Tenants.Management.csproj | 8 ++++---- .../Service/SetupWithRecipesFilterService.cs | 1 + .../Views/ShellSettingsEditor.cshtml | 8 ++++---- ...nts.MediaStorageManagement.Tests.UI.csproj | 2 +- ...ting.Tenants.MediaStorageManagement.csproj | 10 +++++----- 26 files changed, 90 insertions(+), 86 deletions(-) diff --git a/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs b/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs index a97b780e..99302312 100644 --- a/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs +++ b/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs @@ -7,9 +7,9 @@ using OrchardCore.DisplayManagement.Layout; using OrchardCore.Environment.Shell; using OrchardCore.Environment.Shell.Models; +using OrchardCore.Modules; using OrchardCore.Mvc.Core.Utilities; using OrchardCore.Tenants.Controllers; -using System; using System.Threading.Tasks; namespace Lombiq.Hosting.Tenants.Admin.Login.Filters; diff --git a/Lombiq.Hosting.Tenants.Admin.Login/Lombiq.Hosting.Tenants.Admin.Login.csproj b/Lombiq.Hosting.Tenants.Admin.Login/Lombiq.Hosting.Tenants.Admin.Login.csproj index dd2547f5..1ff9b7c0 100644 --- a/Lombiq.Hosting.Tenants.Admin.Login/Lombiq.Hosting.Tenants.Admin.Login.csproj +++ b/Lombiq.Hosting.Tenants.Admin.Login/Lombiq.Hosting.Tenants.Admin.Login.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 true $(DefaultItemExcludes);.git*;node_modules\**;Tests\** @@ -34,10 +34,10 @@ - - - - + + + + diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj index 8ae8ec00..0081e63c 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 $(DefaultItemExcludes);.git*;node_modules\** diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj index 3f0ae065..b3773132 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 true $(DefaultItemExcludes);.git*;node_modules\** @@ -34,16 +34,16 @@ - - - - - - - - + + + + + + + + - + diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Migrations/EmailQuotaMigrations.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Migrations/EmailQuotaMigrations.cs index 0230fc22..a187e62c 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Migrations/EmailQuotaMigrations.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Migrations/EmailQuotaMigrations.cs @@ -1,4 +1,5 @@ using OrchardCore.Data.Migration; +using System.Threading.Tasks; namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Migrations; @@ -14,19 +15,19 @@ public class EmailQuotaMigrations : DataMigration #pragma warning restore CA1822 // Mark members as static #pragma warning restore IDE0079 // Remove unnecessary suppression - public int UpdateFrom1() + public async Task UpdateFrom1Async() { - SchemaBuilder.AlterTable("EmailQuotaIndex", table => table + await SchemaBuilder.AlterTableAsync("EmailQuotaIndex", table => table .AddColumn("LastReminderPercentage") ); return 2; } - public int UpdateFrom2() + public async Task UpdateFrom2Async() { // Deleting index because it is not needed. - SchemaBuilder.DropTable("EmailQuotaIndex"); + await SchemaBuilder.DropTableAsync("EmailQuotaIndex"); return 3; } diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaResetTask.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaResetTask.cs index 2a8c7d93..3dde05ae 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaResetTask.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaResetTask.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using OrchardCore.BackgroundTasks; using System; using System.Threading; @@ -15,6 +15,6 @@ public async Task DoWorkAsync(IServiceProvider serviceProvider, CancellationToke { var emailQuotaService = serviceProvider.GetRequiredService(); var currentQuota = await emailQuotaService.GetOrCreateCurrentQuotaAsync(); - emailQuotaService.ResetQuota(currentQuota); + await emailQuotaService.ResetQuotaAsync(currentQuota); } } diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs index b194770b..92af9ffb 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models; +using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; @@ -91,22 +91,22 @@ public async Task GetOrCreateCurrentQuotaAsync() // Need to set default value otherwise the database might complain about being 01/01/0001 out of range. LastReminderUtc = _clock.UtcNow.AddMonths(-1), }; - _session.Save(currentQuota); + await _session.SaveAsync(currentQuota); return currentQuota; } - public void IncreaseEmailUsage(EmailQuota emailQuota) + public Task IncreaseEmailUsageAsync(EmailQuota emailQuota) { emailQuota.CurrentEmailUsageCount++; - _session.Save(emailQuota); + return _session.SaveAsync(emailQuota); } - public void SetQuotaOnEmailReminder(EmailQuota emailQuota) + public Task SetQuotaOnEmailReminderAsync(EmailQuota emailQuota) { emailQuota.LastReminderUtc = _clock.UtcNow; emailQuota.LastReminderPercentage = emailQuota.CurrentUsagePercentage(GetEmailQuotaPerMonth()); - _session.Save(emailQuota); + return _session.SaveAsync(emailQuota); } public bool ShouldSendReminderEmail(EmailQuota emailQuota, int currentUsagePercentage) @@ -128,10 +128,10 @@ public bool ShouldSendReminderEmail(EmailQuota emailQuota, int currentUsagePerce emailQuota.LastReminderPercentage >= 100); } - public void ResetQuota(EmailQuota emailQuota) + public Task ResetQuotaAsync(EmailQuota emailQuota) { emailQuota.CurrentEmailUsageCount = 0; - _session.Save(emailQuota); + return _session.SaveAsync(emailQuota); } public int GetEmailQuotaPerMonth() => diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/IEmailQuotaService.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/IEmailQuotaService.cs index 4c40ee34..006c2e46 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/IEmailQuotaService.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/IEmailQuotaService.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models; +using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models; using System.Collections.Generic; using System.Threading.Tasks; @@ -34,20 +34,20 @@ public interface IEmailQuotaService /// /// Increases the usage count of the given and saves it to the database. /// - void IncreaseEmailUsage(EmailQuota emailQuota); + Task IncreaseEmailUsageAsync(EmailQuota emailQuota); /// /// Resets the given to 0 and saves it /// to the database. /// - void ResetQuota(EmailQuota emailQuota); + Task ResetQuotaAsync(EmailQuota emailQuota); /// /// Sets the to the current date and /// to the current email quota usage percentage then saves it to the /// database. /// - void SetQuotaOnEmailReminder(EmailQuota emailQuota); + Task SetQuotaOnEmailReminderAsync(EmailQuota emailQuota); /// /// Returns , if the reminder email should be sent. diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs index 7008084e..703472e8 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs @@ -1,4 +1,4 @@ -using Lombiq.HelpfulExtensions.Extensions.Emails.Services; +using Lombiq.HelpfulExtensions.Extensions.Emails.Services; using Lombiq.Hosting.Tenants.EmailQuotaManagement.Models; using Microsoft.Extensions.Localization; using OrchardCore.Email; @@ -54,7 +54,7 @@ public async Task SendAsync(MailMessage message) var emailResult = await _smtpService.SendAsync(message); if (emailResult == SmtpResult.Success) { - _emailQuotaService.IncreaseEmailUsage(isQuotaOverResult.EmailQuota); + await _emailQuotaService.IncreaseEmailUsageAsync(isQuotaOverResult.EmailQuota); } return emailResult; @@ -68,7 +68,7 @@ private async Task SendAlertEmailIfNecessaryAsync(EmailQuota emailQuota) var siteOwnerEmails = (await _emailQuotaService.GetUserEmailsForEmailReminderAsync()).ToList(); if (currentUsagePercentage >= 100) { - SendQuotaEmail( + await SendQuotaEmailAsync( emailQuota, siteOwnerEmails, "EmailQuotaExceededError", @@ -77,7 +77,7 @@ private async Task SendAlertEmailIfNecessaryAsync(EmailQuota emailQuota) return; } - SendQuotaEmail( + await SendQuotaEmailAsync( emailQuota, siteOwnerEmails, $"EmailQuotaWarning", @@ -85,7 +85,7 @@ private async Task SendAlertEmailIfNecessaryAsync(EmailQuota emailQuota) currentUsagePercentage); } - private void SendQuotaEmail( + private Task SendQuotaEmailAsync( EmailQuota emailQuota, IEnumerable siteOwnerEmails, string emailTemplateName, @@ -113,6 +113,6 @@ private void SendQuotaEmail( }); } - _emailQuotaService.SetQuotaOnEmailReminder(emailQuota); + return _emailQuotaService.SetQuotaOnEmailReminderAsync(emailQuota); } } diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj b/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj index 599dcff6..648ece77 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots/Lombiq.Hosting.Tenants.EnvironmentRobots.csproj b/Lombiq.Hosting.Tenants.EnvironmentRobots/Lombiq.Hosting.Tenants.EnvironmentRobots.csproj index f4db79af..d0c29dee 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots/Lombiq.Hosting.Tenants.EnvironmentRobots.csproj +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots/Lombiq.Hosting.Tenants.EnvironmentRobots.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 true $(DefaultItemExcludes);.git*;node_modules\** @@ -34,8 +34,8 @@ - - - + + + diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj b/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj index 8da04880..9fb74457 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 $(DefaultItemExcludes);.git*;node_modules\** diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard/Lombiq.Hosting.Tenants.FeaturesGuard.csproj b/Lombiq.Hosting.Tenants.FeaturesGuard/Lombiq.Hosting.Tenants.FeaturesGuard.csproj index bec3934e..2522734d 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard/Lombiq.Hosting.Tenants.FeaturesGuard.csproj +++ b/Lombiq.Hosting.Tenants.FeaturesGuard/Lombiq.Hosting.Tenants.FeaturesGuard.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 true $(DefaultItemExcludes);.git*;node_modules\** @@ -34,11 +34,11 @@ - - - - - + + + + + diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj index 3d8aae8a..16556b4e 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement/Lombiq.Hosting.Tenants.IdleTenantManagement.csproj b/Lombiq.Hosting.Tenants.IdleTenantManagement/Lombiq.Hosting.Tenants.IdleTenantManagement.csproj index d223572c..beee6725 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement/Lombiq.Hosting.Tenants.IdleTenantManagement.csproj +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement/Lombiq.Hosting.Tenants.IdleTenantManagement.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 true $(DefaultItemExcludes);.git*;node_modules\**;Tests\** @@ -24,9 +24,9 @@ - - - + + + diff --git a/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj b/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj index 3449b903..f75d1ad9 100644 --- a/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 diff --git a/Lombiq.Hosting.Tenants.Maintenance/Lombiq.Hosting.Tenants.Maintenance.csproj b/Lombiq.Hosting.Tenants.Maintenance/Lombiq.Hosting.Tenants.Maintenance.csproj index a87b0eb6..58930014 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Lombiq.Hosting.Tenants.Maintenance.csproj +++ b/Lombiq.Hosting.Tenants.Maintenance/Lombiq.Hosting.Tenants.Maintenance.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 true $(DefaultItemExcludes);.git*;node_modules\**;Tests\** @@ -23,13 +23,13 @@ - - - - - - - + + + + + + + diff --git a/Lombiq.Hosting.Tenants.Maintenance/Migrations.cs b/Lombiq.Hosting.Tenants.Maintenance/Migrations.cs index 29e563b8..200dc4bd 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Migrations.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Migrations.cs @@ -2,22 +2,23 @@ using Lombiq.Hosting.Tenants.Maintenance.Indexes; using OrchardCore.Data.Migration; using System; +using System.Threading.Tasks; using YesSql.Sql; namespace Lombiq.Hosting.Tenants.Maintenance; public class Migrations : DataMigration { - public int Create() + public async Task CreateAsync() { - SchemaBuilder.CreateMapIndexTable( + await SchemaBuilder.CreateMapIndexTableAsync( table => table .Column(nameof(MaintenanceTaskExecutionIndex.MaintenanceId)) .Column(nameof(MaintenanceTaskExecutionIndex.ExecutionTimeUtc)) .Column(nameof(MaintenanceTaskExecutionIndex.IsSuccess)), collection: DocumentCollections.Maintenance); - SchemaBuilder.AlterIndexTable( + await SchemaBuilder.AlterIndexTableAsync( table => table .CreateIndex( $"IDX_{nameof(MaintenanceTaskExecutionIndex)}_{nameof(MaintenanceTaskExecutionIndex.MaintenanceId)}", diff --git a/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs b/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs index 4a05ad12..dcc9ce1f 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs @@ -99,7 +99,7 @@ private async Task ExecuteMaintenanceTaskIfNeededAsync( provider.Id); } - _session.Save(execution, collection: DocumentCollections.Maintenance); + await _session.SaveAsync(execution, collection: DocumentCollections.Maintenance); await _session.SaveChangesAsync(); if (context.ReloadShellAfterMaintenanceCompletion) await _shellHost.ReloadShellContextAsync(_shellSettings); diff --git a/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj b/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj index d9ae33f2..b6f0a3d1 100644 --- a/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 diff --git a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs index c028278a..e33c13ad 100644 --- a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs +++ b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; +using OrchardCore.Modules; using OrchardCore.Mvc.Core.Utilities; using OrchardCore.Tenants.Controllers; using OrchardCore.Tenants.ViewModels; diff --git a/Lombiq.Hosting.Tenants.Management/Lombiq.Hosting.Tenants.Management.csproj b/Lombiq.Hosting.Tenants.Management/Lombiq.Hosting.Tenants.Management.csproj index 43140fdf..3adc713b 100644 --- a/Lombiq.Hosting.Tenants.Management/Lombiq.Hosting.Tenants.Management.csproj +++ b/Lombiq.Hosting.Tenants.Management/Lombiq.Hosting.Tenants.Management.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 true $(DefaultItemExcludes);.git*;node_modules\**;Tests\** @@ -34,9 +34,9 @@ - - - + + + diff --git a/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs b/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs index 5e41a207..0c712bf5 100644 --- a/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs +++ b/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs @@ -1,6 +1,7 @@ using Lombiq.Hosting.Tenants.Management.Settings; using Microsoft.Extensions.Options; using OrchardCore.Environment.Shell; +using OrchardCore.Modules; using OrchardCore.Recipes.Models; using OrchardCore.Setup.Services; using System; diff --git a/Lombiq.Hosting.Tenants.Management/Views/ShellSettingsEditor.cshtml b/Lombiq.Hosting.Tenants.Management/Views/ShellSettingsEditor.cshtml index 03d9dbf7..b723a87c 100644 --- a/Lombiq.Hosting.Tenants.Management/Views/ShellSettingsEditor.cshtml +++ b/Lombiq.Hosting.Tenants.Management/Views/ShellSettingsEditor.cshtml @@ -1,4 +1,4 @@ -@using Lombiq.Hosting.Tenants.Management.Controllers +@using Lombiq.Hosting.Tenants.Management.Controllers @using Newtonsoft.Json @using OrchardCore @using OrchardCore.Mvc.Core.Utilities @@ -11,9 +11,9 @@ asp-area="@Module" method="post" class="no-multisubmit"> -
- -
+
+ +
@T["JSON key-value pairs should be set here, in the same way you'd configure the tenant-specific section in an appsettings.json file."] diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj index 2b5f8217..601004d5 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 $(DefaultItemExcludes);.git*;node_modules\** diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Lombiq.Hosting.Tenants.MediaStorageManagement.csproj b/Lombiq.Hosting.Tenants.MediaStorageManagement/Lombiq.Hosting.Tenants.MediaStorageManagement.csproj index 30e9a6a7..30006ef3 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Lombiq.Hosting.Tenants.MediaStorageManagement.csproj +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Lombiq.Hosting.Tenants.MediaStorageManagement.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 true $(DefaultItemExcludes);.git*;node_modules\**;Tests\** @@ -34,10 +34,10 @@ - - - - + + + + From d12a9f24f3a247a255c961363043cce3ae06d6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Fri, 19 Jan 2024 14:06:39 +0100 Subject: [PATCH 02/23] Addressing warnings. --- .../Controllers/TenantLoginController.cs | 1 - Lombiq.Hosting.Tenants.Admin.Login/Manifest.cs | 2 +- .../Manifest.cs | 6 +++--- Lombiq.Hosting.Tenants.Maintenance/Manifest.cs | 12 ++++++------ Lombiq.Hosting.Tenants.Management/Manifest.cs | 6 +++--- .../Manifest.cs | 6 +++--- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs b/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs index 5c1afe4f..ed086af8 100644 --- a/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs +++ b/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs @@ -9,7 +9,6 @@ using OrchardCore.Modules; using OrchardCore.Settings; using OrchardCore.Users; -using System; using System.Linq; using System.Threading.Tasks; using static Lombiq.Hosting.Tenants.Admin.Login.Constants.FeatureNames; diff --git a/Lombiq.Hosting.Tenants.Admin.Login/Manifest.cs b/Lombiq.Hosting.Tenants.Admin.Login/Manifest.cs index cc201f7b..80fe02a1 100644 --- a/Lombiq.Hosting.Tenants.Admin.Login/Manifest.cs +++ b/Lombiq.Hosting.Tenants.Admin.Login/Manifest.cs @@ -14,7 +14,7 @@ Description = "Ability to log in as a tenant’s admin user.", Category = "Hosting", DefaultTenantOnly = true, - Dependencies = new[] { "OrchardCore.Tenants" } + Dependencies = ["OrchardCore.Tenants"] )] [assembly: Feature( diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Manifest.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Manifest.cs index 0e75921a..6ce59803 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Manifest.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Manifest.cs @@ -15,9 +15,9 @@ Name = "Lombiq Hosting - Tenants Email Quota Management", Category = "Hosting", IsAlwaysEnabled = true, - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.Emails", "Lombiq.HelpfulExtensions.Emails", - } + ] )] diff --git a/Lombiq.Hosting.Tenants.Maintenance/Manifest.cs b/Lombiq.Hosting.Tenants.Maintenance/Manifest.cs index 1ac3a09d..6883a7bb 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Manifest.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Manifest.cs @@ -13,7 +13,7 @@ Name = "Lombiq Hosting - Tenants Maintenance", Description = "Provides maintenance operations for tenants.", Category = "Hosting", - Dependencies = new[] { "OrchardCore.Tenants" } + Dependencies = ["OrchardCore.Tenants"] )] [assembly: Feature( @@ -21,7 +21,7 @@ Name = "Lombiq Hosting - Tenants Maintenance Update Site URL", Description = "Updates the URL of the site in the site settings (e.g., when the production database is copied to staging).", Category = "Maintenance", - Dependencies = new[] { Maintenance } + Dependencies = [Maintenance] )] [assembly: Feature( @@ -31,7 +31,7 @@ " It's executed only on the default tenant.", Category = "Maintenance", DefaultTenantOnly = true, - Dependencies = new[] { Maintenance } + Dependencies = [Maintenance] )] [assembly: Feature( @@ -40,7 +40,7 @@ Description = "Adds the Site Owner permission to a role (e.g., when the production database is copied to staging).", Category = "Maintenance", DefaultTenantOnly = true, - Dependencies = new[] { Maintenance } + Dependencies = [Maintenance] )] [assembly: Feature( @@ -49,7 +49,7 @@ Description = "Removes users with the configured email domain.", Category = "Maintenance", DefaultTenantOnly = true, - Dependencies = new[] { Maintenance } + Dependencies = [Maintenance] )] [assembly: Feature( @@ -58,5 +58,5 @@ Description = "Replaces the users' username, email and password with realistic but random values.", Category = "Maintenance", DefaultTenantOnly = true, - Dependencies = new[] { Maintenance } + Dependencies = [Maintenance] )] diff --git a/Lombiq.Hosting.Tenants.Management/Manifest.cs b/Lombiq.Hosting.Tenants.Management/Manifest.cs index 422e71b9..ad385898 100644 --- a/Lombiq.Hosting.Tenants.Management/Manifest.cs +++ b/Lombiq.Hosting.Tenants.Management/Manifest.cs @@ -15,7 +15,7 @@ Description = "Ability to configure hostnames that aren't allowed during tenant creation.", Category = "Hosting", DefaultTenantOnly = true, - Dependencies = new[] { "OrchardCore.Tenants" } + Dependencies = ["OrchardCore.Tenants"] )] [assembly: Feature( @@ -24,7 +24,7 @@ Description = "Adds the ability to hide recipes from the setup screen based on configurable tags.", Category = "Hosting", DefaultTenantOnly = true, - Dependencies = new[] { "OrchardCore.Setup" } + Dependencies = ["OrchardCore.Setup"] )] [assembly: Feature( @@ -33,5 +33,5 @@ Description = "Adds a shell settings editor to the tenant editor page.", Category = "Hosting", DefaultTenantOnly = true, - Dependencies = new[] { "OrchardCore.Tenants" } + Dependencies = ["OrchardCore.Tenants"] )] diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Manifest.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Manifest.cs index 73428eb6..f470929f 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Manifest.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Manifest.cs @@ -15,10 +15,10 @@ Description = "Ability to configure storage quota for tenants.", Category = "Hosting", IsAlwaysEnabled = true, - Dependencies = new[] - { + Dependencies = + [ "OrchardCore.Media", "OrchardCore.DisplayManagement", "OrchardCore.ResourceManagement", - } + ] )] From 5addb2ec1742776eaba9bbafeb959ac6da6b26e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 20 Jan 2024 12:14:47 +0100 Subject: [PATCH 03/23] Addressing warnings. --- .../Controllers/TenantLoginController.cs | 50 ++++++--------- .../Filters/TenantsIndexFilter.cs | 37 ++++------- .../Filters/DashboardQuotaFilter.cs | 29 +++------ .../Filters/EmailSettingsQuotaFilter.cs | 29 +++------ .../Services/EmailQuotaService.cs | 58 +++++++----------- .../Services/EmailQuotaSubjectService.cs | 13 ++-- .../QuotaManagingSmtpServiceDecorator.cs | 61 +++++++------------ .../Startup.cs | 9 +-- .../Filters/EnvironmentRobotsMetaTagFilter.cs | 21 +++---- .../EnvironmentRobotsMiddleware.cs | 23 ++----- .../Startup.cs | 9 +-- .../Handlers/FeaturesEventHandler.cs | 6 +- .../Startup.cs | 7 +-- .../Middlewares/IdleTimeProviderMiddleware.cs | 10 +-- .../Services/IdleShutdown.cs | 45 +++++--------- .../Startup.cs | 9 +-- ...wnerPermissionToRoleMaintenanceProvider.cs | 21 ++----- .../AddSiteOwnerPermissionToRole/Startup.cs | 9 +-- ...UserSensitiveContentMaintenanceProvider.cs | 37 ++++------- .../ChangeUserSensitiveContent/Startup.cs | 9 +-- .../RemoveUsersMaintenanceProvider.cs | 27 +++----- .../Maintenance/RemoveUsers/Startup.cs | 9 +-- .../UpdateShellRequestUrl/Startup.cs | 9 +-- ...dateShellRequestUrlsMaintenanceProvider.cs | 49 ++++++--------- .../Maintenance/UpdateSiteUrl/Startup.cs | 9 +-- .../UpdateSiteUrlMaintenanceProvider.cs | 33 ++++------ .../Services/MaintenanceManager.cs | 53 ++++++---------- .../Services/MaintenanceRunnerService.cs | 27 +++----- .../ShellSettingsEditorController.cs | 45 +++++--------- ...ombiqHostingTenantsManagementExtensions.cs | 3 +- .../Filters/ForbiddenTenantsFilter.cs | 23 +++---- .../Filters/ShellSettingsEditorFilter.cs | 25 +++----- .../Service/SetupWithRecipesFilterService.cs | 27 +++----- Lombiq.Hosting.Tenants.Management/Startup.cs | 8 +-- .../Filters/UploadFileSizeShapeFilter.cs | 25 +++----- .../Service/MediaStorageQuotaService.cs | 17 ++---- .../Startup.cs | 10 +-- 37 files changed, 278 insertions(+), 613 deletions(-) diff --git a/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs b/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs index ed086af8..0dc73d74 100644 --- a/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs +++ b/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs @@ -17,45 +17,29 @@ namespace Lombiq.Hosting.Tenants.Admin.Login.Controllers; [Feature(SubTenant)] -public class TenantLoginController : Controller +public class TenantLoginController( + ISiteService siteService, + SignInManager userSignInManager, + IShellHost shellHost, + ShellSettings shellSettings, + ILogger logger, + INotifier notifier, + IHtmlLocalizer htmlLocalizer) : Controller { - private readonly ISiteService _siteService; - private readonly SignInManager _userSignInManager; - private readonly IShellHost _shellHost; - private readonly ShellSettings _shellSettings; - private readonly ILogger _logger; - private readonly INotifier _notifier; - private readonly IHtmlLocalizer H; - - public TenantLoginController( - ISiteService siteService, - SignInManager userSignInManager, - IShellHost shellHost, - ShellSettings shellSettings, - ILogger logger, - INotifier notifier, - IHtmlLocalizer htmlLocalizer) - { - _siteService = siteService; - _userSignInManager = userSignInManager; - _shellHost = shellHost; - _shellSettings = shellSettings; - _logger = logger; - _notifier = notifier; - H = htmlLocalizer; - } + private readonly ILogger _logger = logger; + private readonly IHtmlLocalizer H = htmlLocalizer; [HttpPost] // This is necessary because requests for this action will come from the Default tenant. [IgnoreAntiforgeryToken] public async Task Index(string password) { - if (_shellSettings.Name.EqualsOrdinalIgnoreCase(ShellSettings.DefaultShellName)) + if (shellSettings.Name.EqualsOrdinalIgnoreCase(ShellSettings.DefaultShellName)) { return NotFound(); } - var defaultShell = await _shellHost.GetScopeAsync(ShellSettings.DefaultShellName); + var defaultShell = await shellHost.GetScopeAsync(ShellSettings.DefaultShellName); var tenantLoginPasswordValidator = defaultShell?.ServiceProvider.GetService(); if (defaultShell == null || @@ -65,17 +49,17 @@ public async Task Index(string password) return NotFound(); } - var sitesettings = await _siteService.LoadSiteSettingsAsync(); - var adminUser = await _userSignInManager.UserManager.FindByIdAsync(sitesettings.SuperUser); - adminUser ??= (await _userSignInManager.UserManager.GetUsersInRoleAsync(Administrator)).FirstOrDefault(); + var sitesettings = await siteService.LoadSiteSettingsAsync(); + var adminUser = await userSignInManager.UserManager.FindByIdAsync(sitesettings.SuperUser); + adminUser ??= (await userSignInManager.UserManager.GetUsersInRoleAsync(Administrator)).FirstOrDefault(); if (adminUser == null) { - await _notifier.ErrorAsync(H["No user with administrator role in this tenant."]); + await notifier.ErrorAsync(H["No user with administrator role in this tenant."]); return Redirect("~/"); } - await _userSignInManager.SignInAsync(adminUser, isPersistent: false); + await userSignInManager.SignInAsync(adminUser, isPersistent: false); _logger.LogInformation(1, "An admin user logged in from the Default tenant."); return RedirectToAction("Index", "Admin", new { area = "OrchardCore.Admin" }); diff --git a/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs b/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs index 99302312..ba1d95e0 100644 --- a/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs +++ b/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs @@ -14,28 +14,13 @@ namespace Lombiq.Hosting.Tenants.Admin.Login.Filters; -public class TenantsIndexFilter : IAsyncResultFilter +public class TenantsIndexFilter( + ILayoutAccessor layoutAccessor, + IShapeFactory shapeFactory, + IShellHost shellHost, + IHttpContextAccessor hca, + IAuthorizationService authorizationService) : IAsyncResultFilter { - private readonly ILayoutAccessor _layoutAccessor; - private readonly IShapeFactory _shapeFactory; - private readonly IShellHost _shellHost; - private readonly IHttpContextAccessor _hca; - private readonly IAuthorizationService _authorizationService; - - public TenantsIndexFilter( - ILayoutAccessor layoutAccessor, - IShapeFactory shapeFactory, - IShellHost shellHost, - IHttpContextAccessor hca, - IAuthorizationService authorizationService) - { - _layoutAccessor = layoutAccessor; - _shapeFactory = shapeFactory; - _shellHost = shellHost; - _hca = hca; - _authorizationService = authorizationService; - } - public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var actionRouteController = context.ActionDescriptor.RouteValues["Controller"]; @@ -46,20 +31,20 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE actionRouteArea == $"{nameof(OrchardCore)}.{nameof(OrchardCore.Tenants)}" && actionRouteValue is nameof(AdminController.Edit) && context.Result is ViewResult && - await _authorizationService.AuthorizeAsync( - _hca.HttpContext.User, + await authorizationService.AuthorizeAsync( + hca.HttpContext.User, TenantAdminPermissions.LoginAsAdmin) ) { - var shellSettings = _shellHost.GetSettings(context.RouteData.Values["Id"].ToString()); + var shellSettings = shellHost.GetSettings(context.RouteData.Values["Id"].ToString()); if (shellSettings != null && shellSettings.State == TenantState.Running && !shellSettings.Name.EqualsOrdinalIgnoreCase(ShellSettings.DefaultShellName)) { - var layout = await _layoutAccessor.GetLayoutAsync(); + var layout = await layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Content"]; await contentZone.AddAsync( - await _shapeFactory.CreateAsync("TenantAdminShape", new + await shapeFactory.CreateAsync("TenantAdminShape", new { shellSettings.RequestUrlHost, shellSettings.RequestUrlPrefix, diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs index 9804084f..e2fdd7fc 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs @@ -7,22 +7,11 @@ namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Filters; -public class DashboardQuotaFilter : IAsyncResultFilter +public class DashboardQuotaFilter( + IShapeFactory shapeFactory, + ILayoutAccessor layoutAccessor, + IEmailQuotaService emailQuotaService) : IAsyncResultFilter { - private readonly IShapeFactory _shapeFactory; - private readonly ILayoutAccessor _layoutAccessor; - private readonly IEmailQuotaService _emailQuotaService; - - public DashboardQuotaFilter( - IShapeFactory shapeFactory, - ILayoutAccessor layoutAccessor, - IEmailQuotaService emailQuotaService) - { - _shapeFactory = shapeFactory; - _layoutAccessor = layoutAccessor; - _emailQuotaService = emailQuotaService; - } - public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (!context.IsAdmin()) @@ -32,19 +21,19 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE } if (context.Result is ViewResult && - _emailQuotaService.ShouldLimitEmails()) + emailQuotaService.ShouldLimitEmails()) { - var currentEmailQuota = await _emailQuotaService.IsQuotaOverTheLimitAsync(); + var currentEmailQuota = await emailQuotaService.IsQuotaOverTheLimitAsync(); var currentUsagePercentage = currentEmailQuota.EmailQuota - .CurrentUsagePercentage(_emailQuotaService.GetEmailQuotaPerMonth()); + .CurrentUsagePercentage(emailQuotaService.GetEmailQuotaPerMonth()); if (currentUsagePercentage >= 80) { - var layout = await _layoutAccessor.GetLayoutAsync(); + var layout = await layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Messages"]; await contentZone.AddAsync( - await _shapeFactory.CreateAsync("DashboardQuotaMessage", new + await shapeFactory.CreateAsync("DashboardQuotaMessage", new { currentEmailQuota.IsOverQuota, UsagePercentage = currentUsagePercentage, diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/EmailSettingsQuotaFilter.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/EmailSettingsQuotaFilter.cs index b4543ede..35922c44 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/EmailSettingsQuotaFilter.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/EmailSettingsQuotaFilter.cs @@ -9,22 +9,11 @@ namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Filters; -public class EmailSettingsQuotaFilter : IAsyncResultFilter +public class EmailSettingsQuotaFilter( + IShapeFactory shapeFactory, + ILayoutAccessor layoutAccessor, + IEmailQuotaService emailQuotaService) : IAsyncResultFilter { - private readonly IShapeFactory _shapeFactory; - private readonly ILayoutAccessor _layoutAccessor; - private readonly IEmailQuotaService _emailQuotaService; - - public EmailSettingsQuotaFilter( - IShapeFactory shapeFactory, - ILayoutAccessor layoutAccessor, - IEmailQuotaService emailQuotaService) - { - _shapeFactory = shapeFactory; - _layoutAccessor = layoutAccessor; - _emailQuotaService = emailQuotaService; - } - public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (!context.IsAdmin()) @@ -43,17 +32,17 @@ actionRouteValue is nameof(AdminController.Index) && context.Result is ViewResult && context.RouteData.Values.TryGetValue("GroupId", out var groupId) && (string)groupId == "email" && - _emailQuotaService.ShouldLimitEmails()) + emailQuotaService.ShouldLimitEmails()) { - var layout = await _layoutAccessor.GetLayoutAsync(); + var layout = await layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Content"]; - var quota = await _emailQuotaService.GetOrCreateCurrentQuotaAsync(); + var quota = await emailQuotaService.GetOrCreateCurrentQuotaAsync(); await contentZone.AddAsync( - await _shapeFactory.CreateAsync("EmailSettingsQuotaMessage", new + await shapeFactory.CreateAsync("EmailSettingsQuotaMessage", new { quota.CurrentEmailUsageCount, - EmailQuotaPerMonth = _emailQuotaService.GetEmailQuotaPerMonth(), + EmailQuotaPerMonth = emailQuotaService.GetEmailQuotaPerMonth(), }), "0"); } diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs index 92af9ffb..90e2b343 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs @@ -19,38 +19,22 @@ namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Services; -public class EmailQuotaService : IEmailQuotaService +public class EmailQuotaService( + ISession session, + IOptions emailQuotaOptions, + IShellConfiguration shellConfiguration, + IOptions smtpOptions, + IClock clock, + IRoleService roleService, + UserManager userManager) : IEmailQuotaService { - private readonly ISession _session; - private readonly EmailQuotaOptions _emailQuotaOptions; - private readonly IShellConfiguration _shellConfiguration; - private readonly SmtpSettings _smtpOptions; - private readonly IClock _clock; - private readonly IRoleService _roleService; - private readonly UserManager _userManager; - - public EmailQuotaService( - ISession session, - IOptions emailQuotaOptions, - IShellConfiguration shellConfiguration, - IOptions smtpOptions, - IClock clock, - IRoleService roleService, - UserManager userManager) - { - _session = session; - _emailQuotaOptions = emailQuotaOptions.Value; - _shellConfiguration = shellConfiguration; - _smtpOptions = smtpOptions.Value; - _clock = clock; - _roleService = roleService; - _userManager = userManager; - } + private readonly EmailQuotaOptions _emailQuotaOptions = emailQuotaOptions.Value; + private readonly SmtpSettings _smtpOptions = smtpOptions.Value; public async Task> GetUserEmailsForEmailReminderAsync() { // Get users with site owner permission. - var roles = await _roleService.GetRolesAsync(); + var roles = await roleService.GetRolesAsync(); var siteOwnerRoles = roles.Where(role => (role as Role)?.RoleClaims.Exists(claim => claim.ClaimType == ClaimType && claim.ClaimValue == SiteOwner.Name) == true); @@ -58,7 +42,7 @@ public async Task> GetUserEmailsForEmailReminderAsync() var siteOwners = new List(); foreach (var role in siteOwnerRoles) { - siteOwners.AddRange(await _userManager.GetUsersInRoleAsync(role.RoleName)); + siteOwners.AddRange(await userManager.GetUsersInRoleAsync(role.RoleName)); } return siteOwners.Select(user => (user as User)?.Email); @@ -66,7 +50,7 @@ public async Task> GetUserEmailsForEmailReminderAsync() public bool ShouldLimitEmails() { - var originalHost = _shellConfiguration.GetValue("SmtpSettings:Host"); + var originalHost = shellConfiguration.GetValue("SmtpSettings:Host"); return originalHost == _smtpOptions.Host; } @@ -82,16 +66,16 @@ public async Task IsQuotaOverTheLimitAsync() public async Task GetOrCreateCurrentQuotaAsync() { - var currentQuota = await _session.Query().FirstOrDefaultAsync(); + var currentQuota = await session.Query().FirstOrDefaultAsync(); if (currentQuota != null) return currentQuota; currentQuota = new EmailQuota { // Need to set default value otherwise the database might complain about being 01/01/0001 out of range. - LastReminderUtc = _clock.UtcNow.AddMonths(-1), + LastReminderUtc = clock.UtcNow.AddMonths(-1), }; - await _session.SaveAsync(currentQuota); + await session.SaveAsync(currentQuota); return currentQuota; } @@ -99,14 +83,14 @@ public async Task GetOrCreateCurrentQuotaAsync() public Task IncreaseEmailUsageAsync(EmailQuota emailQuota) { emailQuota.CurrentEmailUsageCount++; - return _session.SaveAsync(emailQuota); + return session.SaveAsync(emailQuota); } public Task SetQuotaOnEmailReminderAsync(EmailQuota emailQuota) { - emailQuota.LastReminderUtc = _clock.UtcNow; + emailQuota.LastReminderUtc = clock.UtcNow; emailQuota.LastReminderPercentage = emailQuota.CurrentUsagePercentage(GetEmailQuotaPerMonth()); - return _session.SaveAsync(emailQuota); + return session.SaveAsync(emailQuota); } public bool ShouldSendReminderEmail(EmailQuota emailQuota, int currentUsagePercentage) @@ -116,7 +100,7 @@ public bool ShouldSendReminderEmail(EmailQuota emailQuota, int currentUsagePerce return false; } - var isSameMonth = IsSameMonth(_clock.UtcNow, emailQuota.LastReminderUtc); + var isSameMonth = IsSameMonth(clock.UtcNow, emailQuota.LastReminderUtc); if (!isSameMonth) { @@ -131,7 +115,7 @@ public bool ShouldSendReminderEmail(EmailQuota emailQuota, int currentUsagePerce public Task ResetQuotaAsync(EmailQuota emailQuota) { emailQuota.CurrentEmailUsageCount = 0; - return _session.SaveAsync(emailQuota); + return session.SaveAsync(emailQuota); } public int GetEmailQuotaPerMonth() => diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs index 433c8ab7..b1a37d1c 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs @@ -1,17 +1,12 @@ -using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Localization; namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Services; -public class EmailQuotaSubjectService : IEmailQuotaSubjectService +public class EmailQuotaSubjectService(IStringLocalizer stringLocalizer) : IEmailQuotaSubjectService { - private readonly IStringLocalizer T; - - public EmailQuotaSubjectService(IStringLocalizer stringLocalizer) => - T = stringLocalizer; - public LocalizedString GetWarningEmailSubject(int percentage) => - T["[Warning] Your site has used {0}% of its e-mail quota", percentage]; + stringLocalizer["[Warning] Your site has used {0}% of its e-mail quota", percentage]; public LocalizedString GetExceededEmailSubject() => - T["[Action Required] Your site has run over its e-mail quota"]; + stringLocalizer["[Action Required] Your site has run over its e-mail quota"]; } diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs index 703472e8..6bcbcd43 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs @@ -10,51 +10,34 @@ namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Services; -public class QuotaManagingSmtpServiceDecorator : ISmtpService +public class QuotaManagingSmtpServiceDecorator( + ISmtpService smtpService, + IStringLocalizer stringLocalizer, + IEmailQuotaService emailQuotaService, + ShellSettings shellSettings, + IEmailTemplateService emailTemplateService, + IEmailQuotaSubjectService emailQuotaSubjectService) : ISmtpService { - private readonly IStringLocalizer T; - private readonly ISmtpService _smtpService; - private readonly IEmailQuotaService _emailQuotaService; - private readonly ShellSettings _shellSettings; - private readonly IEmailTemplateService _emailTemplateService; - private readonly IEmailQuotaSubjectService _emailQuotaSubjectService; - - public QuotaManagingSmtpServiceDecorator( - ISmtpService smtpService, - IStringLocalizer stringLocalizer, - IEmailQuotaService emailQuotaService, - ShellSettings shellSettings, - IEmailTemplateService emailTemplateService, - IEmailQuotaSubjectService emailQuotaSubjectService) - { - _smtpService = smtpService; - T = stringLocalizer; - _emailQuotaService = emailQuotaService; - _shellSettings = shellSettings; - _emailTemplateService = emailTemplateService; - _emailQuotaSubjectService = emailQuotaSubjectService; - } - public async Task SendAsync(MailMessage message) { - if (!_emailQuotaService.ShouldLimitEmails()) + if (!emailQuotaService.ShouldLimitEmails()) { - return await _smtpService.SendAsync(message); + return await smtpService.SendAsync(message); } - var isQuotaOverResult = await _emailQuotaService.IsQuotaOverTheLimitAsync(); + var isQuotaOverResult = await emailQuotaService.IsQuotaOverTheLimitAsync(); await SendAlertEmailIfNecessaryAsync(isQuotaOverResult.EmailQuota); // Should send the email if the quota is not over the limit. if (isQuotaOverResult.IsOverQuota) { - return SmtpResult.Failed(T["The email quota for the site has been exceeded."]); + return SmtpResult.Failed(stringLocalizer["The email quota for the site has been exceeded."]); } - var emailResult = await _smtpService.SendAsync(message); + var emailResult = await smtpService.SendAsync(message); if (emailResult == SmtpResult.Success) { - await _emailQuotaService.IncreaseEmailUsageAsync(isQuotaOverResult.EmailQuota); + await emailQuotaService.IncreaseEmailUsageAsync(isQuotaOverResult.EmailQuota); } return emailResult; @@ -62,17 +45,17 @@ public async Task SendAsync(MailMessage message) private async Task SendAlertEmailIfNecessaryAsync(EmailQuota emailQuota) { - var currentUsagePercentage = emailQuota.CurrentUsagePercentage(_emailQuotaService.GetEmailQuotaPerMonth()); - if (!_emailQuotaService.ShouldSendReminderEmail(emailQuota, currentUsagePercentage)) return; + var currentUsagePercentage = emailQuota.CurrentUsagePercentage(emailQuotaService.GetEmailQuotaPerMonth()); + if (!emailQuotaService.ShouldSendReminderEmail(emailQuota, currentUsagePercentage)) return; - var siteOwnerEmails = (await _emailQuotaService.GetUserEmailsForEmailReminderAsync()).ToList(); + var siteOwnerEmails = (await emailQuotaService.GetUserEmailsForEmailReminderAsync()).ToList(); if (currentUsagePercentage >= 100) { await SendQuotaEmailAsync( emailQuota, siteOwnerEmails, "EmailQuotaExceededError", - _emailQuotaSubjectService.GetExceededEmailSubject(), + emailQuotaSubjectService.GetExceededEmailSubject(), currentUsagePercentage); return; } @@ -81,7 +64,7 @@ await SendQuotaEmailAsync( emailQuota, siteOwnerEmails, $"EmailQuotaWarning", - _emailQuotaSubjectService.GetWarningEmailSubject(currentUsagePercentage), + emailQuotaSubjectService.GetWarningEmailSubject(currentUsagePercentage), currentUsagePercentage); } @@ -102,17 +85,17 @@ private Task SendQuotaEmailAsync( ShellScope.AddDeferredTask(async _ => { emailMessage.To = siteOwnerEmail; - emailMessage.Body = await _emailTemplateService.RenderEmailTemplateAsync(emailTemplateName, new + emailMessage.Body = await emailTemplateService.RenderEmailTemplateAsync(emailTemplateName, new { - HostName = _shellSettings.Name, + HostName = shellSettings.Name, Percentage = percentage, }); // ISmtpService must be used within this class otherwise it won't call the original ISmtpService // implementation, but loop back to here. - await _smtpService.SendAsync(emailMessage); + await smtpService.SendAsync(emailMessage); }); } - return _emailQuotaService.SetQuotaOnEmailReminderAsync(emailQuota); + return emailQuotaService.SetQuotaOnEmailReminderAsync(emailQuota); } } diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Startup.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Startup.cs index abeebcbf..3fadfb6a 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Startup.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Startup.cs @@ -16,20 +16,15 @@ namespace Lombiq.Hosting.Tenants.EmailQuotaManagement; [Feature(FeatureNames.EmailQuotaManagement)] -public class Startup : StartupBase +public class Startup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration; - - public Startup(IShellConfiguration shellConfiguration) => - _shellConfiguration = shellConfiguration; - public override void ConfigureServices(IServiceCollection services) { services.AddDataMigration(); services.AddSingleton(); services.Configure(options => - options.EmailQuotaPerMonth = _shellConfiguration.GetValue("Lombiq_Hosting_Tenants_EmailQuotaManagement:EmailQuotaPerMonth") + options.EmailQuotaPerMonth = shellConfiguration.GetValue("Lombiq_Hosting_Tenants_EmailQuotaManagement:EmailQuotaPerMonth") ?? DefaultEmailQuota); services.Configure(options => diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs b/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs index ee924d8a..63de9a36 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs @@ -7,21 +7,14 @@ namespace Lombiq.Hosting.Tenants.EnvironmentRobots.Filters; -public class EnvironmentRobotsMetaTagFilter : IResultFilter +public class EnvironmentRobotsMetaTagFilter( + IHostEnvironment hostEnvironment, + IOptions options, + IResourceManager resourceManager) : IResultFilter { - private readonly IHostEnvironment _hostEnvironment; - private readonly IOptions _options; - private readonly IResourceManager _resourceManager; - - public EnvironmentRobotsMetaTagFilter( - IHostEnvironment hostEnvironment, - IOptions options, - IResourceManager resourceManager) - { - _hostEnvironment = hostEnvironment; - _options = options; - _resourceManager = resourceManager; - } + private readonly IHostEnvironment _hostEnvironment = hostEnvironment; + private readonly IOptions _options = options; + private readonly IResourceManager _resourceManager = resourceManager; public void OnResultExecuting(ResultExecutingContext context) { diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots/Middlewares/EnvironmentRobotsMiddleware.cs b/Lombiq.Hosting.Tenants.EnvironmentRobots/Middlewares/EnvironmentRobotsMiddleware.cs index 5d9a96f0..ecf6ad92 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots/Middlewares/EnvironmentRobotsMiddleware.cs +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots/Middlewares/EnvironmentRobotsMiddleware.cs @@ -9,25 +9,14 @@ namespace Lombiq.Hosting.Tenants.EnvironmentRobots.Middlewares; -public class EnvironmentRobotsMiddleware +public class EnvironmentRobotsMiddleware( + RequestDelegate next, + IHostEnvironment hostEnvironment, + IOptions options) { - private readonly RequestDelegate _next; - private readonly IHostEnvironment _hostEnvironment; - private readonly IOptions _options; - - public EnvironmentRobotsMiddleware( - RequestDelegate next, - IHostEnvironment hostEnvironment, - IOptions options) - { - _next = next; - _hostEnvironment = hostEnvironment; - _options = options; - } - public Task InvokeAsync(HttpContext context) { - if (!_hostEnvironment.IsProductionWithConfiguration(_options)) + if (!hostEnvironment.IsProductionWithConfiguration(options)) { var headerValue = context.Response.Headers["X-Robots-Tag"].FirstOrDefault() ?? string.Empty; @@ -57,6 +46,6 @@ public Task InvokeAsync(HttpContext context) } } - return _next(context); + return next(context); } } diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots/Startup.cs b/Lombiq.Hosting.Tenants.EnvironmentRobots/Startup.cs index d978e6e7..bdea74d4 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots/Startup.cs +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots/Startup.cs @@ -13,17 +13,12 @@ namespace Lombiq.Hosting.Tenants.EnvironmentRobots; [Feature(FeatureNames.EnvironmentRobots)] -public class Startup : StartupBase +public class Startup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration; - - public Startup(IShellConfiguration shellConfiguration) => - _shellConfiguration = shellConfiguration; - public override void ConfigureServices(IServiceCollection services) { var options = new EnvironmentRobotsOptions(); - var configSection = _shellConfiguration + var configSection = shellConfiguration .GetSection("Lombiq_Hosting_Tenants_EnvironmentRobots:EnvironmentRobotsOptions"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs b/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs index e9b6682e..87afdff0 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs +++ b/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs @@ -97,7 +97,7 @@ private Task HandleConditionallyEnabledFeaturesAsync() throw new InvalidOperationException("'IsAlwaysEnabled' feature can't be disabled by FeaturesGuard."); } - if (!featuresToEnable.Any() && !featuresToDisable.Any()) + if (featuresToEnable.Count == 0 && featuresToDisable.Count == 0) { return; } @@ -119,7 +119,7 @@ private Task HandleConditionallyEnabledFeaturesAsync() /// private static bool TryGetFeaturesToBeEnabledAndDisabled( IDictionary> conditionallyEnabledFeatures, - IReadOnlySet enabledFeatureIds, + HashSet enabledFeatureIds, out HashSet featuresToEnable, out HashSet featuresToDisable) { @@ -152,6 +152,6 @@ private static bool TryGetFeaturesToBeEnabledAndDisabled( featuresToEnable = featuresToEnableIds; featuresToDisable = featuresToDisableIds; - return featuresToEnableIds.Any() || featuresToDisableIds.Any(); + return featuresToEnableIds.Count != 0 || featuresToDisableIds.Count != 0; } } diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs b/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs index fdd8251e..31a53b33 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs +++ b/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs @@ -10,12 +10,9 @@ namespace Lombiq.Hosting.Tenants.FeaturesGuard; [Feature(FeatureNames.FeaturesGuard)] -public class Startup : StartupBase +public class Startup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration; - - public Startup(IConfiguration configuration, IShellConfiguration shellConfiguration) => - _shellConfiguration = shellConfiguration; + private readonly IShellConfiguration _shellConfiguration = shellConfiguration; public override void ConfigureServices(IServiceCollection services) { diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement/Middlewares/IdleTimeProviderMiddleware.cs b/Lombiq.Hosting.Tenants.IdleTenantManagement/Middlewares/IdleTimeProviderMiddleware.cs index 76d1ac7e..d2243cb0 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement/Middlewares/IdleTimeProviderMiddleware.cs +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement/Middlewares/IdleTimeProviderMiddleware.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.IdleTenantManagement.Services; +using Lombiq.Hosting.Tenants.IdleTenantManagement.Services; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using OrchardCore.Modules; @@ -6,16 +6,12 @@ namespace Lombiq.Hosting.Tenants.IdleTenantManagement.Middlewares; -public class IdleTimeProviderMiddleware +public class IdleTimeProviderMiddleware(RequestDelegate next) { - private readonly RequestDelegate _next; - - public IdleTimeProviderMiddleware(RequestDelegate next) => _next = next; - public Task InvokeAsync(HttpContext context, ILastActiveTimeAccessor lastActiveTimeAccessor) { lastActiveTimeAccessor.Update(context.RequestServices.GetService()); - return _next(context); + return next(context); } } diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement/Services/IdleShutdown.cs b/Lombiq.Hosting.Tenants.IdleTenantManagement/Services/IdleShutdown.cs index 9639bc4b..22861214 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement/Services/IdleShutdown.cs +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement/Services/IdleShutdown.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.IdleTenantManagement.Models; +using Lombiq.Hosting.Tenants.IdleTenantManagement.Models; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using OrchardCore.Environment.Shell; @@ -7,44 +7,27 @@ namespace Lombiq.Hosting.Tenants.IdleTenantManagement.Services; -public class IdleShutdown : IIdleShutdown +public class IdleShutdown( + IOptions options, + ShellSettings shellSettings, + IClock clock, + ILastActiveTimeAccessor lastActiveTimeAccessor, + ILogger logger, + IShellHost shellHost) : IIdleShutdown { - private readonly IOptions _options; - private readonly ShellSettings _shellSettings; - private readonly IClock _clock; - private readonly ILastActiveTimeAccessor _lastActiveTimeAccessor; - private readonly ILogger _logger; - private readonly IShellHost _shellHost; - - public IdleShutdown( - IOptions options, - ShellSettings shellSettings, - IClock clock, - ILastActiveTimeAccessor lastActiveTimeAccessor, - ILogger logger, - IShellHost shellHost) - { - _options = options; - _shellSettings = shellSettings; - _clock = clock; - _lastActiveTimeAccessor = lastActiveTimeAccessor; - _logger = logger; - _shellHost = shellHost; - } - public async Task ShutDownIdleTenantsAsync() { - var maxIdleMinutes = _options.Value.MaxIdleMinutes; + var maxIdleMinutes = options.Value.MaxIdleMinutes; - if (maxIdleMinutes <= 0 || _shellSettings.IsDefaultShell()) return; + if (maxIdleMinutes <= 0 || shellSettings.IsDefaultShell()) return; - var lastActiveDateTimeUtc = _lastActiveTimeAccessor.LastActiveDateTimeUtc; + var lastActiveDateTimeUtc = lastActiveTimeAccessor.LastActiveDateTimeUtc; - if (lastActiveDateTimeUtc.AddMinutes(maxIdleMinutes) <= _clock?.UtcNow) + if (lastActiveDateTimeUtc.AddMinutes(maxIdleMinutes) <= clock?.UtcNow) { - _logger?.LogInformation("Shutting down tenant \"{ShellName}\" because of idle timeout.", _shellSettings.Name); + logger?.LogInformation("Shutting down tenant \"{ShellName}\" because of idle timeout.", shellSettings.Name); - await _shellHost.ReleaseShellContextAsync(_shellSettings, eventSource: false); + await shellHost.ReleaseShellContextAsync(shellSettings, eventSource: false); } } } diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement/Startup.cs b/Lombiq.Hosting.Tenants.IdleTenantManagement/Startup.cs index 43f4fe8f..b4ac8e90 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement/Startup.cs +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement/Startup.cs @@ -14,13 +14,8 @@ namespace Lombiq.Hosting.Tenants.IdleTenantManagement; [Feature(FeatureNames.ShutDownIdleTenants)] -public class ShutDownIdleTenantsStartup : StartupBase +public class ShutDownIdleTenantsStartup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration; - - public ShutDownIdleTenantsStartup(IShellConfiguration shellConfiguration) => - _shellConfiguration = shellConfiguration; - public override void Configure( IApplicationBuilder app, IEndpointRouteBuilder routes, @@ -35,7 +30,7 @@ public override void ConfigureServices(IServiceCollection services) // Idle Minutes Settings services.Configure(options => - _shellConfiguration + shellConfiguration .GetSection("Lombiq_Hosting_Tenants_IdleTenantManagement:IdleShutdownOptions") .Bind(options)); } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/AddSiteOwnerPermissionToRoleMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/AddSiteOwnerPermissionToRoleMaintenanceProvider.cs index d346d9ea..68eab3cf 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/AddSiteOwnerPermissionToRoleMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/AddSiteOwnerPermissionToRoleMaintenanceProvider.cs @@ -10,32 +10,23 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.AddSiteOwnerPermissionToRole; -public class AddSiteOwnerPermissionToRoleMaintenanceProvider : MaintenanceProviderBase +public class AddSiteOwnerPermissionToRoleMaintenanceProvider( + IOptions options, + RoleManager roleManager) : MaintenanceProviderBase { - private readonly IOptions _options; - private readonly RoleManager _roleManager; - - public AddSiteOwnerPermissionToRoleMaintenanceProvider( - IOptions options, - RoleManager roleManager) - { - _options = options; - _roleManager = roleManager; - } - public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => Task.FromResult( - _options.Value.IsEnabled && + options.Value.IsEnabled && !context.WasLatestExecutionSuccessful()); public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { - if (await _roleManager.FindByNameAsync(_options.Value.Role) is not Role role) return; + if (await roleManager.FindByNameAsync(options.Value.Role) is not Role role) return; if (role.RoleClaims.Exists(claim => claim.ClaimType == ClaimType && claim.ClaimValue == SiteOwner.Name)) return; role.RoleClaims.Add(new RoleClaim { ClaimType = ClaimType, ClaimValue = SiteOwner.Name }); - await _roleManager.UpdateAsync(role); + await roleManager.UpdateAsync(role); } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/Startup.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/Startup.cs index 4722717d..24487a73 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/Startup.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/Startup.cs @@ -8,17 +8,12 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.AddSiteOwnerPermissionToRole; [Feature(FeatureNames.AddSiteOwnerPermissionToRole)] -public class Startup : StartupBase +public class Startup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration; - - public Startup(IShellConfiguration shellConfiguration) => - _shellConfiguration = shellConfiguration; - public override void ConfigureServices(IServiceCollection services) { var options = new AddSiteOwnerPermissionToRoleMaintenanceOptions(); - var configSection = _shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:AddSiteOwnerPermissionToRole"); + var configSection = shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:AddSiteOwnerPermissionToRole"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/ChangeUserSensitiveContentMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/ChangeUserSensitiveContentMaintenanceProvider.cs index 0327d3f4..c574b882 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/ChangeUserSensitiveContentMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/ChangeUserSensitiveContentMaintenanceProvider.cs @@ -15,39 +15,24 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.ChangeUserSensitiveContent; -public class ChangeUserSensitiveContentMaintenanceProvider : MaintenanceProviderBase +public class ChangeUserSensitiveContentMaintenanceProvider( + IOptions options, + ISession session, + UserManager userManager, + IPasswordHasher passwordHasher, + ShellSettings shellSettings) : MaintenanceProviderBase { - private readonly IOptions _options; - private readonly ISession _session; - private readonly UserManager _userManager; - private readonly IPasswordHasher _passwordHasher; - private readonly ShellSettings _shellSettings; - - public ChangeUserSensitiveContentMaintenanceProvider( - IOptions options, - ISession session, - UserManager userManager, - IPasswordHasher passwordHasher, - ShellSettings shellSettings) - { - _options = options; - _session = session; - _userManager = userManager; - _passwordHasher = passwordHasher; - _shellSettings = shellSettings; - } - public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => Task.FromResult( - _options.Value.IsEnabled && + options.Value.IsEnabled && !context.WasLatestExecutionSuccessful() && - _options.Value.TenantNames.Replace(" ", string.Empty).SplitByCommas().Contains(_shellSettings.Name)); + options.Value.TenantNames.Replace(" ", string.Empty).SplitByCommas().Contains(shellSettings.Name)); public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { var randomNameGenerator = new PersonNameGenerator(); - var users = await _session.Query().ListAsync(); + var users = await session.Query().ListAsync(); foreach (var user in users.Where(user => !user.Email.Trim().EndsWith($"@lombiq.com", StringComparison.InvariantCulture))) { @@ -60,9 +45,9 @@ public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) user.NormalizedUserName = formattedFullName.ToUpperInvariant(); user.Email = formattedEmail; user.NormalizedEmail = formattedEmail.ToUpperInvariant(); - user.PasswordHash = _passwordHasher.HashPassword(user, GenerateRandomPassword(32)); + user.PasswordHash = passwordHasher.HashPassword(user, GenerateRandomPassword(32)); - await _userManager.UpdateAsync(user); + await userManager.UpdateAsync(user); } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/Startup.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/Startup.cs index 23e7e97e..905e1ea3 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/Startup.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/Startup.cs @@ -8,17 +8,12 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.ChangeUserSensitiveContent; [Feature(FeatureNames.ChangeUserSensitiveContent)] -public class Startup : StartupBase +public class Startup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration; - - public Startup(IShellConfiguration shellConfiguration) => - _shellConfiguration = shellConfiguration; - public override void ConfigureServices(IServiceCollection services) { var options = new ChangeUserSensitiveContentMaintenanceOptions(); - var configSection = _shellConfiguration + var configSection = shellConfiguration .GetSection("Lombiq_Hosting_Tenants_Maintenance:ChangeUserSensitiveContent"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/RemoveUsersMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/RemoveUsersMaintenanceProvider.cs index 61820da9..c38e7717 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/RemoveUsersMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/RemoveUsersMaintenanceProvider.cs @@ -12,34 +12,23 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.RemoveUsers; -public class RemoveUsersMaintenanceProvider : MaintenanceProviderBase +public class RemoveUsersMaintenanceProvider( + IOptions options, + ISession session, + UserManager userManager) : MaintenanceProviderBase { - private readonly IOptions _options; - private readonly ISession _session; - private readonly UserManager _userManager; - - public RemoveUsersMaintenanceProvider( - IOptions options, - ISession session, - UserManager userManager) - { - _options = options; - _session = session; - _userManager = userManager; - } - public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => Task.FromResult( - _options.Value.IsEnabled && + options.Value.IsEnabled && !context.WasLatestExecutionSuccessful()); public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { - var users = await _session.Query().ListAsync(); + var users = await session.Query().ListAsync(); foreach (var user in users.Where(user => - user.Email.EndsWith($"@{_options.Value.EmailDomain}", StringComparison.InvariantCulture))) + user.Email.EndsWith($"@{options.Value.EmailDomain}", StringComparison.InvariantCulture))) { - await _userManager.DeleteAsync(user); + await userManager.DeleteAsync(user); } } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/Startup.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/Startup.cs index 58fa4760..ed3d1c62 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/Startup.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/Startup.cs @@ -8,17 +8,12 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.RemoveUsers; [Feature(FeatureNames.RemoveUsers)] -public class Startup : StartupBase +public class Startup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration; - - public Startup(IShellConfiguration shellConfiguration) => - _shellConfiguration = shellConfiguration; - public override void ConfigureServices(IServiceCollection services) { var options = new RemoveUsersMaintenanceOptions(); - var configSection = _shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:RemoveUsers"); + var configSection = shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:RemoveUsers"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/Startup.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/Startup.cs index 2b21fa1e..26fcf43e 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/Startup.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/Startup.cs @@ -8,17 +8,12 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.UpdateShellRequestUrl; [Feature(FeatureNames.UpdateShellRequestUrls)] -public class Startup : StartupBase +public class Startup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration; - - public Startup(IShellConfiguration shellConfiguration) => - _shellConfiguration = shellConfiguration; - public override void ConfigureServices(IServiceCollection services) { var options = new UpdateShellRequestUrlMaintenanceOptions(); - var configSection = _shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:UpdateShellRequestUrl"); + var configSection = shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:UpdateShellRequestUrl"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs index 6d7759c5..13e56bc4 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs @@ -8,45 +8,32 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.UpdateShellRequestUrl; -public class UpdateShellRequestUrlsMaintenanceProvider : MaintenanceProviderBase +public class UpdateShellRequestUrlsMaintenanceProvider( + ShellSettings shellSettings, + IOptions options, + IShellSettingsManager shellSettingsManager, + IShellHost shellHost) : MaintenanceProviderBase { - private readonly ShellSettings _shellSettings; - private readonly IOptions _options; - private readonly IShellSettingsManager _shellSettingsManager; - private readonly IShellHost _shellHost; - - public UpdateShellRequestUrlsMaintenanceProvider( - ShellSettings shellSettings, - IOptions options, - IShellSettingsManager shellSettingsManager, - IShellHost shellHost) - { - _shellSettings = shellSettings; - _options = options; - _shellSettingsManager = shellSettingsManager; - _shellHost = shellHost; - } - public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => - Task.FromResult(_options.Value.IsEnabled && - _shellSettings.IsDefaultShell() && + Task.FromResult(options.Value.IsEnabled && + shellSettings.IsDefaultShell() && !context.WasLatestExecutionSuccessful()); public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { - var allShellSettings = await _shellSettingsManager.LoadSettingsAsync(); - foreach (var shellSettings in allShellSettings) + var allShellSettings = await shellSettingsManager.LoadSettingsAsync(); + foreach (var settings in allShellSettings) { - shellSettings.RequestUrlHost = TenantUrlHelpers.GetEvaluatedValueForTenant( - _options.Value.DefaultShellRequestUrl, - _options.Value.RequestUrl, - shellSettings); - shellSettings.RequestUrlPrefix = TenantUrlHelpers.GetEvaluatedValueForTenant( - _options.Value.DefaultShellRequestUrlPrefix, - _options.Value.RequestUrlPrefix, - shellSettings); + settings.RequestUrlHost = TenantUrlHelpers.GetEvaluatedValueForTenant( + options.Value.DefaultShellRequestUrl, + options.Value.RequestUrl, + settings); + settings.RequestUrlPrefix = TenantUrlHelpers.GetEvaluatedValueForTenant( + options.Value.DefaultShellRequestUrlPrefix, + options.Value.RequestUrlPrefix, + settings); - await _shellHost.UpdateShellSettingsAsync(shellSettings); + await shellHost.UpdateShellSettingsAsync(settings); } context.ReloadShellAfterMaintenanceCompletion = true; diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/Startup.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/Startup.cs index ff86c21c..717ed5c4 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/Startup.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/Startup.cs @@ -8,17 +8,12 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.UpdateSiteUrl; [Feature(FeatureNames.UpdateSiteUrl)] -public class Startup : StartupBase +public class Startup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration; - - public Startup(IShellConfiguration shellConfiguration) => - _shellConfiguration = shellConfiguration; - public override void ConfigureServices(IServiceCollection services) { var options = new UpdateSiteUrlMaintenanceOptions(); - var configSection = _shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:UpdateSiteUrl"); + var configSection = shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:UpdateSiteUrl"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs index f27eca5c..97e111e4 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs @@ -9,34 +9,23 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.UpdateSiteUrl; -public class UpdateSiteUrlMaintenanceProvider : MaintenanceProviderBase +public class UpdateSiteUrlMaintenanceProvider( + ISiteService siteService, + ShellSettings shellSettings, + IOptions options) : MaintenanceProviderBase { - private readonly ISiteService _siteService; - private readonly ShellSettings _shellSettings; - private readonly IOptions _options; - - public UpdateSiteUrlMaintenanceProvider( - ISiteService siteService, - ShellSettings shellSettings, - IOptions options) - { - _siteService = siteService; - _shellSettings = shellSettings; - _options = options; - } - public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => - Task.FromResult(_options.Value.IsEnabled && !context.WasLatestExecutionSuccessful()); + Task.FromResult(options.Value.IsEnabled && !context.WasLatestExecutionSuccessful()); public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { - var siteSettings = await _siteService.LoadSiteSettingsAsync(); + var siteSettings = await siteService.LoadSiteSettingsAsync(); siteSettings.BaseUrl = TenantUrlHelpers.GetEvaluatedValueForTenant( - _options.Value.DefaultTenantSiteUrl, - _options.Value.SiteUrl, - _shellSettings, - _options.Value.SiteUrlFromTenantName); + options.Value.DefaultTenantSiteUrl, + options.Value.SiteUrl, + shellSettings, + options.Value.SiteUrlFromTenantName); - await _siteService.UpdateSiteSettingsAsync(siteSettings); + await siteService.UpdateSiteSettingsAsync(siteSettings); } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs b/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs index dcc9ce1f..be1bea6d 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs @@ -12,46 +12,29 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Services; -public class MaintenanceManager : IMaintenanceManager +public class MaintenanceManager( + IOrchardClock clock, + ILogger logger, + IEnumerable maintenanceProviders, + ISession session, + IShellHost shellHost, + ShellSettings shellSettings) : IMaintenanceManager { - private readonly IOrchardClock _clock; - private readonly ILogger _logger; - private readonly IEnumerable _maintenanceProviders; - private readonly ISession _session; - private readonly IShellHost _shellHost; - private readonly ShellSettings _shellSettings; - - public MaintenanceManager( - IOrchardClock clock, - ILogger logger, - IEnumerable maintenanceProviders, - ISession session, - IShellHost shellHost, - ShellSettings shellSettings) - { - _clock = clock; - _logger = logger; - _maintenanceProviders = maintenanceProviders; - _session = session; - _shellHost = shellHost; - _shellSettings = shellSettings; - } - public Task GetLatestExecutionByMaintenanceIdAsync(string maintenanceId) => - _session.Query(collection: DocumentCollections.Maintenance) + session.Query(collection: DocumentCollections.Maintenance) .Where(execution => execution.MaintenanceId == maintenanceId) .OrderByDescending(execution => execution.ExecutionTimeUtc) .FirstOrDefaultAsync(); public async Task ExecuteMaintenanceTasksAsync() { - var orderedProviders = _maintenanceProviders.OrderBy(provider => provider.Order); + var orderedProviders = maintenanceProviders.OrderBy(provider => provider.Order); foreach (var provider in orderedProviders) { var currentExecution = new MaintenanceTaskExecutionData { MaintenanceId = provider.Id, - ExecutionTimeUtc = _clock.UtcNow, + ExecutionTimeUtc = clock.UtcNow, }; var context = new MaintenanceTaskExecutionContext { @@ -68,7 +51,7 @@ private async Task ExecuteMaintenanceTaskIfNeededAsync( MaintenanceTaskExecutionContext context, MaintenanceTaskExecutionData execution) { - _logger.LogDebug("Executing maintenance task {MaintenanceId}, if needed.", provider.Id); + logger.LogDebug("Executing maintenance task {MaintenanceId}, if needed.", provider.Id); if (await provider.ShouldExecuteAsync(context)) { @@ -78,11 +61,11 @@ private async Task ExecuteMaintenanceTaskIfNeededAsync( execution.IsSuccess = string.IsNullOrEmpty(execution.Error); if (execution.IsSuccess) { - _logger.LogDebug("Maintenance task {MaintenanceId} executed successfully.", provider.Id); + logger.LogDebug("Maintenance task {MaintenanceId} executed successfully.", provider.Id); } else { - _logger.LogError( + logger.LogError( "Maintenance task {MaintenanceId} executed with error: {Error}", provider.Id, execution.Error); @@ -93,20 +76,20 @@ private async Task ExecuteMaintenanceTaskIfNeededAsync( execution.IsSuccess = false; execution.Error = exception.ToString(); - _logger.LogError( + logger.LogError( exception, "Maintenance task {MaintenanceId} failed to execute due to an exception.", provider.Id); } - await _session.SaveAsync(execution, collection: DocumentCollections.Maintenance); - await _session.SaveChangesAsync(); + await session.SaveAsync(execution, collection: DocumentCollections.Maintenance); + await session.SaveChangesAsync(); - if (context.ReloadShellAfterMaintenanceCompletion) await _shellHost.ReloadShellContextAsync(_shellSettings); + if (context.ReloadShellAfterMaintenanceCompletion) await shellHost.ReloadShellContextAsync(shellSettings); } else { - _logger.LogDebug("Maintenance task {MaintenanceId} is not needed.", provider.Id); + logger.LogDebug("Maintenance task {MaintenanceId} is not needed.", provider.Id); } } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceRunnerService.cs b/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceRunnerService.cs index 2ef3fc85..a78953d4 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceRunnerService.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceRunnerService.cs @@ -7,29 +7,18 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Services; -public class MaintenanceRunnerService : ModularTenantEvents +public class MaintenanceRunnerService( + ShellSettings shellSettings, + ILogger logger, + Lazy maintenanceManagerLazy) : ModularTenantEvents { - private readonly ShellSettings _shellSettings; - private readonly ILogger _logger; - private readonly Lazy _maintenanceManagerLazy; - - public MaintenanceRunnerService( - ShellSettings shellSettings, - ILogger logger, - Lazy maintenanceManagerLazy) - { - _shellSettings = shellSettings; - _logger = logger; - _maintenanceManagerLazy = maintenanceManagerLazy; - } - public override async Task ActivatedAsync() { - if (_shellSettings.State != TenantState.Running) return; + if (shellSettings.State != TenantState.Running) return; - _logger.LogDebug( + logger.LogDebug( "Executing maintenance tasks on shell '{ShellName}'.", - _shellSettings.Name); - await _maintenanceManagerLazy.Value.ExecuteMaintenanceTasksAsync(); + shellSettings.Name); + await maintenanceManagerLazy.Value.ExecuteMaintenanceTasksAsync(); } } diff --git a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs index 8b4df56e..f6d10f63 100644 --- a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs +++ b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.Management.Constants; +using Lombiq.Hosting.Tenants.Management.Constants; using Lombiq.Hosting.Tenants.Management.Models; using Lombiq.Hosting.Tenants.Management.Service; using Microsoft.AspNetCore.Authorization; @@ -22,37 +22,20 @@ namespace Lombiq.Hosting.Tenants.Management.Controllers; [Feature(FeatureNames.ShellSettingsEditor)] -public class ShellSettingsEditorController : Controller +public class ShellSettingsEditorController( + IAuthorizationService authorizationService, + IShellHost shellHost, + IShellConfigurationSources shellConfigurationSources, + IDistributedLock distributedLock, + INotifier notifier, + IHtmlLocalizer htmlLocalizer) : Controller { - private readonly IAuthorizationService _authorizationService; - private readonly IShellHost _shellHost; - private readonly IShellConfigurationSources _shellConfigurationSources; - private readonly IDistributedLock _distributedLock; - private readonly INotifier _notifier; - private readonly IHtmlLocalizer H; - - public ShellSettingsEditorController( - IAuthorizationService authorizationService, - IShellHost shellHost, - IShellConfigurationSources shellConfigurationSources, - IDistributedLock distributedLock, - INotifier notifier, - IHtmlLocalizer htmlLocalizer) - { - _authorizationService = authorizationService; - _shellHost = shellHost; - _shellConfigurationSources = shellConfigurationSources; - _distributedLock = distributedLock; - _notifier = notifier; - H = htmlLocalizer; - } - [HttpPost] [ValidateAntiForgeryToken] public async Task Edit(ShellSettingsEditorViewModel model) { - if (!await _authorizationService.AuthorizeAsync(User, ManageTenants) || - !_shellHost.TryGetSettings(model.TenantId, out var shellSettings)) + if (!await authorizationService.AuthorizeAsync(User, ManageTenants) || + !shellHost.TryGetSettings(model.TenantId, out var shellSettings)) { return NotFound(); } @@ -60,7 +43,7 @@ public async Task Edit(ShellSettingsEditorViewModel model) model.Json ??= "{}"; if (!IsValidJson(model.Json)) { - await _notifier.ErrorAsync(H["Please provide valid JSON input for shell settings."]); + await notifier.ErrorAsync(htmlLocalizer["Please provide valid JSON input for shell settings."]); TempData["ValidationErrorJson"] = model.Json; return RedirectToAction( @@ -104,7 +87,7 @@ public async Task Edit(ShellSettingsEditorViewModel model) } var (locker, locked) = - await _distributedLock.TryAcquireLockAsync( + await distributedLock.TryAcquireLockAsync( "LOMBIQ_HOSTING_TENANTS_MANAGEMENT_SHELL_SETTINGS_EDITOR_LOCK", TimeSpan.FromSeconds(10)); @@ -119,8 +102,8 @@ await _distributedLock.TryAcquireLockAsync( // not save settings that has a key with multiple sections, see // https://github.com/OrchardCMS/OrchardCore/issues/14481. Once this is fixed, we can get rid of the locking and // retrieve and save the shell settings settings with IShellHost. - await _shellConfigurationSources.SaveAsync(shellSettings.Name, newTenantConfiguration); - await _shellHost.UpdateShellSettingsAsync(shellSettings); + await shellConfigurationSources.SaveAsync(shellSettings.Name, newTenantConfiguration); + await shellHost.UpdateShellSettingsAsync(shellSettings); return RedirectToAction( nameof(AdminController.Edit), diff --git a/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs b/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs index 52bdbf47..0982f8f2 100644 --- a/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs +++ b/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs @@ -1,6 +1,5 @@ using Lombiq.Hosting.Tenants.Management.Settings; using Microsoft.Extensions.DependencyInjection; -using System.Linq; using static Lombiq.Hosting.Tenants.Management.Constants.FeatureNames; namespace Lombiq.Hosting.Tenants.Management.Extensions; @@ -21,7 +20,7 @@ public static OrchardCoreBuilder HideRecipesByTagsFromSetup(this OrchardCoreBuil .ConfigureServices(services => services.Configure(options => { - if (tags.Any()) + if (tags.Length != 0) { options.HiddenTags = tags; } diff --git a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs index e33c13ad..eaa24710 100644 --- a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs +++ b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs @@ -14,18 +14,11 @@ namespace Lombiq.Hosting.Tenants.Management.Filters; -public class ForbiddenTenantsFilter : IAsyncActionFilter +public class ForbiddenTenantsFilter( + IStringLocalizer stringLocalizer, + IOptions forbiddenTenantsOptions) : IAsyncActionFilter { - private readonly IStringLocalizer T; - private readonly IOptions _forbiddenTenantsOptions; - - public ForbiddenTenantsFilter( - IStringLocalizer stringLocalizer, - IOptions forbiddenTenantsOptions) - { - _forbiddenTenantsOptions = forbiddenTenantsOptions; - T = stringLocalizer; - } + private readonly IStringLocalizer T = stringLocalizer; public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { @@ -44,18 +37,16 @@ public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecuti return next(); } - var forbiddenRequestUrlHosts = _forbiddenTenantsOptions.Value.RequestUrlHosts; + var forbiddenRequestUrlHosts = forbiddenTenantsOptions.Value.RequestUrlHosts; if (forbiddenRequestUrlHosts != null && forbiddenRequestUrlHosts.Any()) { var requestUrlHost = context.HttpContext.Request.Form[nameof(CreateApiViewModel.RequestUrlHost)].ToString(); var hosts = requestUrlHost.Split(',').Select(host => host.Trim()); - List unacceptableHostnames = new(); - - unacceptableHostnames.AddRange(hosts.Where(hostname => forbiddenRequestUrlHosts.Contains(hostname))); + List unacceptableHostnames = [.. hosts.Where(hostname => forbiddenRequestUrlHosts.Contains(hostname))]; - if (unacceptableHostnames.Any()) + if (unacceptableHostnames.Count != 0) { var unacceptableHostnamesString = string.Join(", ", unacceptableHostnames); context.ModelState.AddModelError( diff --git a/Lombiq.Hosting.Tenants.Management/Filters/ShellSettingsEditorFilter.cs b/Lombiq.Hosting.Tenants.Management/Filters/ShellSettingsEditorFilter.cs index 1866e363..61122bd1 100644 --- a/Lombiq.Hosting.Tenants.Management/Filters/ShellSettingsEditorFilter.cs +++ b/Lombiq.Hosting.Tenants.Management/Filters/ShellSettingsEditorFilter.cs @@ -11,22 +11,11 @@ namespace Lombiq.Hosting.Tenants.Management.Filters; -public class ShellSettingsEditorFilter : IAsyncResultFilter +public class ShellSettingsEditorFilter( + ILayoutAccessor layoutAccessor, + IShapeFactory shapeFactory, + IShellHost shellHost) : IAsyncResultFilter { - private readonly ILayoutAccessor _layoutAccessor; - private readonly IShapeFactory _shapeFactory; - private readonly IShellHost _shellHost; - - public ShellSettingsEditorFilter( - ILayoutAccessor layoutAccessor, - IShapeFactory shapeFactory, - IShellHost shellHost) - { - _layoutAccessor = layoutAccessor; - _shapeFactory = shapeFactory; - _shellHost = shellHost; - } - public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var actionRouteController = context.ActionDescriptor.RouteValues["Controller"]; @@ -39,13 +28,13 @@ actionRouteValue is nameof(AdminController.Edit) && context.Result is ViewResult) { var tenantName = context.RouteData.Values["Id"].ToString(); - if (!_shellHost.TryGetSettings(tenantName, out var shellSettings)) + if (!shellHost.TryGetSettings(tenantName, out var shellSettings)) { await next(); return; } - var layout = await _layoutAccessor.GetLayoutAsync(); + var layout = await layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Content"]; (context.Controller as Controller) @@ -60,7 +49,7 @@ actionRouteValue is nameof(AdminController.Edit) && : validationErrorJson.ToString(); await contentZone.AddAsync( - await _shapeFactory.CreateAsync( + await shapeFactory.CreateAsync( "ShellSettingsEditor", viewModel => { diff --git a/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs b/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs index 0c712bf5..a42a27e9 100644 --- a/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs +++ b/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs @@ -11,37 +11,26 @@ namespace Lombiq.Hosting.Tenants.Management.Service; -public class SetupWithRecipesFilterService : ISetupService +public class SetupWithRecipesFilterService( + IOptions hideRecipesFromSetupOptions, + ShellSettings shellSettings, + ISetupService setupService) : ISetupService { - private readonly IOptions _hideRecipesFromSetupOptions; - private readonly ShellSettings _shellSettings; - private readonly ISetupService _setupService; - - public SetupWithRecipesFilterService( - IOptions hideRecipesFromSetupOptions, - ShellSettings shellSettings, - ISetupService setupService) - { - _hideRecipesFromSetupOptions = hideRecipesFromSetupOptions; - _shellSettings = shellSettings; - _setupService = setupService; - } - public async Task> GetSetupRecipesAsync() { - var recipesDescriptors = await _setupService.GetSetupRecipesAsync(); + var recipesDescriptors = await setupService.GetSetupRecipesAsync(); // The first case is when we specify the tenant recipe name via the Default tenant admin UI or AutoSetup // feature, the second case is necessary because the Default tenant doesn't fill in RecipeName even if we use // auto setup. - if (_shellSettings["RecipeName"] != null || _shellSettings.Name.EqualsOrdinalIgnoreCase("Default")) + if (shellSettings["RecipeName"] != null || shellSettings.Name.EqualsOrdinalIgnoreCase("Default")) { return recipesDescriptors; } - var hiddenTags = _hideRecipesFromSetupOptions.Value.HiddenTags; + var hiddenTags = hideRecipesFromSetupOptions.Value.HiddenTags; return recipesDescriptors.Where(recipe => !recipe.Tags.Exists(tag => hiddenTags.Contains(tag))); } - public Task SetupAsync(SetupContext context) => _setupService.SetupAsync(context); + public Task SetupAsync(SetupContext context) => setupService.SetupAsync(context); } diff --git a/Lombiq.Hosting.Tenants.Management/Startup.cs b/Lombiq.Hosting.Tenants.Management/Startup.cs index 4547afbe..409832c0 100644 --- a/Lombiq.Hosting.Tenants.Management/Startup.cs +++ b/Lombiq.Hosting.Tenants.Management/Startup.cs @@ -12,16 +12,12 @@ namespace Lombiq.Hosting.Tenants.Management; [Feature(FeatureNames.ForbiddenTenantNames)] -public class ForbiddenTenantNamesStartup : StartupBase +public class ForbiddenTenantNamesStartup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration; - - public ForbiddenTenantNamesStartup(IShellConfiguration shellConfiguration) => _shellConfiguration = shellConfiguration; - public override void ConfigureServices(IServiceCollection services) { services.Configure(options => - _shellConfiguration + shellConfiguration .GetSection("Lombiq_Hosting_Tenants_Management:Forbidden_Tenants_Options") .Bind(options)); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs index dd200e84..250da4e4 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs @@ -10,22 +10,11 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Filters; -public class UploadFileSizeShapeFilter : IAsyncResultFilter +public class UploadFileSizeShapeFilter( + IShapeFactory shapeFactory, + ILayoutAccessor layoutAccessor, + IMediaStorageQuotaService mediaStorageQuotaService) : IAsyncResultFilter { - private readonly IShapeFactory _shapeFactory; - private readonly ILayoutAccessor _layoutAccessor; - private readonly IMediaStorageQuotaService _mediaStorageQuotaService; - - public UploadFileSizeShapeFilter( - IShapeFactory shapeFactory, - ILayoutAccessor layoutAccessor, - IMediaStorageQuotaService mediaStorageQuotaService) - { - _shapeFactory = shapeFactory; - _layoutAccessor = layoutAccessor; - _mediaStorageQuotaService = mediaStorageQuotaService; - } - public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (!context.IsAdmin()) @@ -43,10 +32,10 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE actionRouteValue is nameof(AdminController.Index) && context.Result is ViewResult) { - var layout = await _layoutAccessor.GetLayoutAsync(); + var layout = await layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Footer"]; - var maximumStorageQuotaMegabytes = _mediaStorageQuotaService.GetMaxStorageQuotaMegabytes(); - await contentZone.AddAsync(await _shapeFactory.CreateAsync( + var maximumStorageQuotaMegabytes = mediaStorageQuotaService.GetMaxStorageQuotaMegabytes(); + await contentZone.AddAsync(await shapeFactory.CreateAsync( "UploadFileSize", viewModel => viewModel.MaximumStorageQuotaMegabytes = maximumStorageQuotaMegabytes)); } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs index 06cbd9c7..29aa88ad 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs @@ -6,22 +6,15 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Service; -public class MediaStorageQuotaService : IMediaStorageQuotaService +public class MediaStorageQuotaService( + IOptions mediaStorageManagementOptions, + IMediaFileStore mediaFileStore) : IMediaStorageQuotaService { - private readonly MediaStorageManagementOptions _mediaStorageManagementOptions; - private readonly IMediaFileStore _mediaFileStore; - - public MediaStorageQuotaService( - IOptions mediaStorageManagementOptions, - IMediaFileStore mediaFileStore) - { - _mediaStorageManagementOptions = mediaStorageManagementOptions.Value; - _mediaFileStore = mediaFileStore; - } + private readonly MediaStorageManagementOptions _mediaStorageManagementOptions = mediaStorageManagementOptions.Value; public async Task GetRemainingMediaStorageQuotaBytesAsync() { - var directoryContent = _mediaFileStore.GetDirectoryContentAsync(includeSubDirectories: true); + var directoryContent = mediaFileStore.GetDirectoryContentAsync(includeSubDirectories: true); var listed = await directoryContent.ToListAsync(); var sumBytes = listed.Where(item => item.Length > 0).Sum(item => item.Length); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs index 300b24d8..5ae428fb 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs @@ -10,18 +10,14 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement; -public class Startup : StartupBase +public class Startup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration; - - public Startup(IShellConfiguration shellConfiguration) => _shellConfiguration = shellConfiguration; - public override void ConfigureServices(IServiceCollection services) { var maximumStorageQuotaBytes = - _shellConfiguration.GetValue( + shellConfiguration.GetValue( "Lombiq_Hosting_Tenants_MediaStorageManagement:MaximumStorageQuotaBytes") ?? - _shellConfiguration.GetValue( + shellConfiguration.GetValue( "Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpace"); services.Configure(options => options.MaximumStorageQuotaBytes = maximumStorageQuotaBytes ?? MaximumStorageQuotaBytes); From d514b8331abd967c7ed00b00e26c89a6c63dc436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sun, 28 Jan 2024 19:36:05 +0100 Subject: [PATCH 04/23] Fixing. --- .../Controllers/ShellSettingsEditorController.cs | 4 ++-- .../Views/ShellSettingsEditor.cshtml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs index f6d10f63..c18c8091 100644 --- a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs +++ b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs @@ -82,8 +82,8 @@ public async Task Edit(ShellSettingsEditorViewModel model) foreach (var key in deletableKeys) { var tenantSettingsPrefixWithKey = $"{tenantSettingsPrefix}{key}"; - newTenantConfiguration[key] = null; - newTenantConfiguration[tenantSettingsPrefixWithKey] = null; + shellSettings[key] = null; + shellSettings[tenantSettingsPrefixWithKey] = null; } var (locker, locked) = diff --git a/Lombiq.Hosting.Tenants.Management/Views/ShellSettingsEditor.cshtml b/Lombiq.Hosting.Tenants.Management/Views/ShellSettingsEditor.cshtml index b723a87c..0a20b765 100644 --- a/Lombiq.Hosting.Tenants.Management/Views/ShellSettingsEditor.cshtml +++ b/Lombiq.Hosting.Tenants.Management/Views/ShellSettingsEditor.cshtml @@ -56,7 +56,7 @@ const editor = monaco.editor.create(document.getElementById('@Html.IdFor(model => model.Json)_editor'), settings); const textArea = document.getElementById('@Html.IdFor(model => model.Json)'); - editor.getModel().setValue(textArea.value); + editor.setValue(textArea.value); window.addEventListener('submit', () => { textArea.value = editor.getValue(); From 5a47e816b570c9422ca410733bd6608872d416a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 14:53:48 +0100 Subject: [PATCH 05/23] Keeping T. --- .../Services/EmailQuotaSubjectService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs index b1a37d1c..5be07de5 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs @@ -4,9 +4,11 @@ namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Services; public class EmailQuotaSubjectService(IStringLocalizer stringLocalizer) : IEmailQuotaSubjectService { + private readonly IStringLocalizer T = stringLocalizer; + public LocalizedString GetWarningEmailSubject(int percentage) => - stringLocalizer["[Warning] Your site has used {0}% of its e-mail quota", percentage]; + T["[Warning] Your site has used {0}% of its e-mail quota", percentage]; public LocalizedString GetExceededEmailSubject() => - stringLocalizer["[Action Required] Your site has run over its e-mail quota"]; + T["[Action Required] Your site has run over its e-mail quota"]; } From 856c0fbc9958b655fe198aadb843088befc7e156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 14:55:34 +0100 Subject: [PATCH 06/23] Keeping T. --- .../Services/QuotaManagingSmtpServiceDecorator.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs index 6bcbcd43..e409121b 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs @@ -18,6 +18,8 @@ public class QuotaManagingSmtpServiceDecorator( IEmailTemplateService emailTemplateService, IEmailQuotaSubjectService emailQuotaSubjectService) : ISmtpService { + private readonly IStringLocalizer T = stringLocalizer; + public async Task SendAsync(MailMessage message) { if (!emailQuotaService.ShouldLimitEmails()) @@ -31,7 +33,7 @@ public async Task SendAsync(MailMessage message) // Should send the email if the quota is not over the limit. if (isQuotaOverResult.IsOverQuota) { - return SmtpResult.Failed(stringLocalizer["The email quota for the site has been exceeded."]); + return SmtpResult.Failed(T["The email quota for the site has been exceeded."]); } var emailResult = await smtpService.SendAsync(message); From 16918b8b825fd3e8c2b54cd0f09936da7c73039d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 14:58:14 +0100 Subject: [PATCH 07/23] Removing fields. --- .../Filters/EnvironmentRobotsMetaTagFilter.cs | 8 ++------ Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs b/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs index 63de9a36..f4c13e5d 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs @@ -12,15 +12,11 @@ public class EnvironmentRobotsMetaTagFilter( IOptions options, IResourceManager resourceManager) : IResultFilter { - private readonly IHostEnvironment _hostEnvironment = hostEnvironment; - private readonly IOptions _options = options; - private readonly IResourceManager _resourceManager = resourceManager; - public void OnResultExecuting(ResultExecutingContext context) { - if (!_hostEnvironment.IsProductionWithConfiguration(_options)) + if (!hostEnvironment.IsProductionWithConfiguration(options)) { - _resourceManager.RegisterMeta(new MetaEntry + resourceManager.RegisterMeta(new MetaEntry { Name = "robots", Content = "noindex, nofollow", diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs b/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs index 31a53b33..0cb67e9c 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs +++ b/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs @@ -12,14 +12,12 @@ namespace Lombiq.Hosting.Tenants.FeaturesGuard; [Feature(FeatureNames.FeaturesGuard)] public class Startup(IShellConfiguration shellConfiguration) : StartupBase { - private readonly IShellConfiguration _shellConfiguration = shellConfiguration; - public override void ConfigureServices(IServiceCollection services) { services.AddScoped(); services.Configure(options => - _shellConfiguration + shellConfiguration .GetSection("Lombiq_Hosting_Tenants_FeaturesGuard:ConditionallyEnabledFeaturesOptions:ConditionallyEnabledFeatures") .Bind(options)); } From 1597f4c8e39ec4d171c444249036d06369f27eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 15:01:33 +0100 Subject: [PATCH 08/23] Keeping H. --- .../Controllers/ShellSettingsEditorController.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs index c18c8091..ee4e2162 100644 --- a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs +++ b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs @@ -30,6 +30,8 @@ public class ShellSettingsEditorController( INotifier notifier, IHtmlLocalizer htmlLocalizer) : Controller { + private readonly IHtmlLocalizer H = htmlLocalizer; + [HttpPost] [ValidateAntiForgeryToken] public async Task Edit(ShellSettingsEditorViewModel model) @@ -43,7 +45,7 @@ public async Task Edit(ShellSettingsEditorViewModel model) model.Json ??= "{}"; if (!IsValidJson(model.Json)) { - await notifier.ErrorAsync(htmlLocalizer["Please provide valid JSON input for shell settings."]); + await notifier.ErrorAsync(H["Please provide valid JSON input for shell settings."]); TempData["ValidationErrorJson"] = model.Json; return RedirectToAction( From 8dea1366889fbd33f63f8afbc1f47a5d8bca05de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 17:03:26 +0100 Subject: [PATCH 09/23] Adding comment. --- .../Controllers/ShellSettingsEditorController.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs index ee4e2162..25c8939b 100644 --- a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs +++ b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs @@ -84,6 +84,8 @@ public async Task Edit(ShellSettingsEditorViewModel model) foreach (var key in deletableKeys) { var tenantSettingsPrefixWithKey = $"{tenantSettingsPrefix}{key}"; + // We are using the shellSettings[key] directly because using SaveAsnyc(tenant, newConfig) + // is not saving the new value. https://github.com/OrchardCMS/OrchardCore/issues/15184 shellSettings[key] = null; shellSettings[tenantSettingsPrefixWithKey] = null; } From 3e9780db7e3238530592839c457e35cb0e4e1ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Mon, 29 Jan 2024 17:07:57 +0100 Subject: [PATCH 10/23] Adding comment. --- .../Controllers/ShellSettingsEditorController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs index 25c8939b..03fdda86 100644 --- a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs +++ b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs @@ -84,8 +84,8 @@ public async Task Edit(ShellSettingsEditorViewModel model) foreach (var key in deletableKeys) { var tenantSettingsPrefixWithKey = $"{tenantSettingsPrefix}{key}"; - // We are using the shellSettings[key] directly because using SaveAsnyc(tenant, newConfig) - // is not saving the new value. https://github.com/OrchardCMS/OrchardCore/issues/15184 + // We are using the shellSettings[key] directly because when we try to save it at line 109 + // it is not saving the new value. https://github.com/OrchardCMS/OrchardCore/issues/15184 shellSettings[key] = null; shellSettings[tenantSettingsPrefixWithKey] = null; } From 71ca884ccbcb33ca0cf9ab59d6bc86b75872b93b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Tue, 30 Jan 2024 11:34:39 +0100 Subject: [PATCH 11/23] Revert "Addressing warnings." This reverts commit 5addb2ec1742776eaba9bbafeb959ac6da6b26e8. # Conflicts: # Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs # Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs # Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs # Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs # Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs --- .../Controllers/TenantLoginController.cs | 50 ++++++++++------ .../Filters/TenantsIndexFilter.cs | 37 ++++++++---- .../Filters/DashboardQuotaFilter.cs | 29 ++++++--- .../Filters/EmailSettingsQuotaFilter.cs | 29 ++++++--- .../Services/EmailQuotaService.cs | 58 +++++++++++------- .../Services/EmailQuotaSubjectService.cs | 9 ++- .../QuotaManagingSmtpServiceDecorator.cs | 59 ++++++++++++------- .../Startup.cs | 9 ++- .../Filters/EnvironmentRobotsMetaTagFilter.cs | 23 ++++++-- .../EnvironmentRobotsMiddleware.cs | 23 ++++++-- .../Startup.cs | 9 ++- .../Handlers/FeaturesEventHandler.cs | 6 +- .../Startup.cs | 9 ++- .../Middlewares/IdleTimeProviderMiddleware.cs | 10 +++- .../Services/IdleShutdown.cs | 45 +++++++++----- .../Startup.cs | 9 ++- ...wnerPermissionToRoleMaintenanceProvider.cs | 21 +++++-- .../AddSiteOwnerPermissionToRole/Startup.cs | 9 ++- ...UserSensitiveContentMaintenanceProvider.cs | 37 ++++++++---- .../ChangeUserSensitiveContent/Startup.cs | 9 ++- .../RemoveUsersMaintenanceProvider.cs | 27 ++++++--- .../Maintenance/RemoveUsers/Startup.cs | 9 ++- .../UpdateShellRequestUrl/Startup.cs | 9 ++- ...dateShellRequestUrlsMaintenanceProvider.cs | 49 +++++++++------ .../Maintenance/UpdateSiteUrl/Startup.cs | 9 ++- .../UpdateSiteUrlMaintenanceProvider.cs | 33 +++++++---- .../Services/MaintenanceManager.cs | 53 +++++++++++------ .../Services/MaintenanceRunnerService.cs | 27 ++++++--- .../ShellSettingsEditorController.cs | 51 ++++++++++------ ...ombiqHostingTenantsManagementExtensions.cs | 3 +- .../Filters/ForbiddenTenantsFilter.cs | 23 +++++--- .../Filters/ShellSettingsEditorFilter.cs | 25 +++++--- .../Service/SetupWithRecipesFilterService.cs | 27 ++++++--- Lombiq.Hosting.Tenants.Management/Startup.cs | 8 ++- .../Filters/UploadFileSizeShapeFilter.cs | 25 +++++--- .../Service/MediaStorageQuotaService.cs | 17 ++++-- .../Startup.cs | 10 +++- 37 files changed, 614 insertions(+), 281 deletions(-) diff --git a/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs b/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs index 0dc73d74..ed086af8 100644 --- a/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs +++ b/Lombiq.Hosting.Tenants.Admin.Login/Controllers/TenantLoginController.cs @@ -17,29 +17,45 @@ namespace Lombiq.Hosting.Tenants.Admin.Login.Controllers; [Feature(SubTenant)] -public class TenantLoginController( - ISiteService siteService, - SignInManager userSignInManager, - IShellHost shellHost, - ShellSettings shellSettings, - ILogger logger, - INotifier notifier, - IHtmlLocalizer htmlLocalizer) : Controller +public class TenantLoginController : Controller { - private readonly ILogger _logger = logger; - private readonly IHtmlLocalizer H = htmlLocalizer; + private readonly ISiteService _siteService; + private readonly SignInManager _userSignInManager; + private readonly IShellHost _shellHost; + private readonly ShellSettings _shellSettings; + private readonly ILogger _logger; + private readonly INotifier _notifier; + private readonly IHtmlLocalizer H; + + public TenantLoginController( + ISiteService siteService, + SignInManager userSignInManager, + IShellHost shellHost, + ShellSettings shellSettings, + ILogger logger, + INotifier notifier, + IHtmlLocalizer htmlLocalizer) + { + _siteService = siteService; + _userSignInManager = userSignInManager; + _shellHost = shellHost; + _shellSettings = shellSettings; + _logger = logger; + _notifier = notifier; + H = htmlLocalizer; + } [HttpPost] // This is necessary because requests for this action will come from the Default tenant. [IgnoreAntiforgeryToken] public async Task Index(string password) { - if (shellSettings.Name.EqualsOrdinalIgnoreCase(ShellSettings.DefaultShellName)) + if (_shellSettings.Name.EqualsOrdinalIgnoreCase(ShellSettings.DefaultShellName)) { return NotFound(); } - var defaultShell = await shellHost.GetScopeAsync(ShellSettings.DefaultShellName); + var defaultShell = await _shellHost.GetScopeAsync(ShellSettings.DefaultShellName); var tenantLoginPasswordValidator = defaultShell?.ServiceProvider.GetService(); if (defaultShell == null || @@ -49,17 +65,17 @@ public async Task Index(string password) return NotFound(); } - var sitesettings = await siteService.LoadSiteSettingsAsync(); - var adminUser = await userSignInManager.UserManager.FindByIdAsync(sitesettings.SuperUser); - adminUser ??= (await userSignInManager.UserManager.GetUsersInRoleAsync(Administrator)).FirstOrDefault(); + var sitesettings = await _siteService.LoadSiteSettingsAsync(); + var adminUser = await _userSignInManager.UserManager.FindByIdAsync(sitesettings.SuperUser); + adminUser ??= (await _userSignInManager.UserManager.GetUsersInRoleAsync(Administrator)).FirstOrDefault(); if (adminUser == null) { - await notifier.ErrorAsync(H["No user with administrator role in this tenant."]); + await _notifier.ErrorAsync(H["No user with administrator role in this tenant."]); return Redirect("~/"); } - await userSignInManager.SignInAsync(adminUser, isPersistent: false); + await _userSignInManager.SignInAsync(adminUser, isPersistent: false); _logger.LogInformation(1, "An admin user logged in from the Default tenant."); return RedirectToAction("Index", "Admin", new { area = "OrchardCore.Admin" }); diff --git a/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs b/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs index ba1d95e0..99302312 100644 --- a/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs +++ b/Lombiq.Hosting.Tenants.Admin.Login/Filters/TenantsIndexFilter.cs @@ -14,13 +14,28 @@ namespace Lombiq.Hosting.Tenants.Admin.Login.Filters; -public class TenantsIndexFilter( - ILayoutAccessor layoutAccessor, - IShapeFactory shapeFactory, - IShellHost shellHost, - IHttpContextAccessor hca, - IAuthorizationService authorizationService) : IAsyncResultFilter +public class TenantsIndexFilter : IAsyncResultFilter { + private readonly ILayoutAccessor _layoutAccessor; + private readonly IShapeFactory _shapeFactory; + private readonly IShellHost _shellHost; + private readonly IHttpContextAccessor _hca; + private readonly IAuthorizationService _authorizationService; + + public TenantsIndexFilter( + ILayoutAccessor layoutAccessor, + IShapeFactory shapeFactory, + IShellHost shellHost, + IHttpContextAccessor hca, + IAuthorizationService authorizationService) + { + _layoutAccessor = layoutAccessor; + _shapeFactory = shapeFactory; + _shellHost = shellHost; + _hca = hca; + _authorizationService = authorizationService; + } + public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var actionRouteController = context.ActionDescriptor.RouteValues["Controller"]; @@ -31,20 +46,20 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE actionRouteArea == $"{nameof(OrchardCore)}.{nameof(OrchardCore.Tenants)}" && actionRouteValue is nameof(AdminController.Edit) && context.Result is ViewResult && - await authorizationService.AuthorizeAsync( - hca.HttpContext.User, + await _authorizationService.AuthorizeAsync( + _hca.HttpContext.User, TenantAdminPermissions.LoginAsAdmin) ) { - var shellSettings = shellHost.GetSettings(context.RouteData.Values["Id"].ToString()); + var shellSettings = _shellHost.GetSettings(context.RouteData.Values["Id"].ToString()); if (shellSettings != null && shellSettings.State == TenantState.Running && !shellSettings.Name.EqualsOrdinalIgnoreCase(ShellSettings.DefaultShellName)) { - var layout = await layoutAccessor.GetLayoutAsync(); + var layout = await _layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Content"]; await contentZone.AddAsync( - await shapeFactory.CreateAsync("TenantAdminShape", new + await _shapeFactory.CreateAsync("TenantAdminShape", new { shellSettings.RequestUrlHost, shellSettings.RequestUrlPrefix, diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs index e2fdd7fc..9804084f 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/DashboardQuotaFilter.cs @@ -7,11 +7,22 @@ namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Filters; -public class DashboardQuotaFilter( - IShapeFactory shapeFactory, - ILayoutAccessor layoutAccessor, - IEmailQuotaService emailQuotaService) : IAsyncResultFilter +public class DashboardQuotaFilter : IAsyncResultFilter { + private readonly IShapeFactory _shapeFactory; + private readonly ILayoutAccessor _layoutAccessor; + private readonly IEmailQuotaService _emailQuotaService; + + public DashboardQuotaFilter( + IShapeFactory shapeFactory, + ILayoutAccessor layoutAccessor, + IEmailQuotaService emailQuotaService) + { + _shapeFactory = shapeFactory; + _layoutAccessor = layoutAccessor; + _emailQuotaService = emailQuotaService; + } + public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (!context.IsAdmin()) @@ -21,19 +32,19 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE } if (context.Result is ViewResult && - emailQuotaService.ShouldLimitEmails()) + _emailQuotaService.ShouldLimitEmails()) { - var currentEmailQuota = await emailQuotaService.IsQuotaOverTheLimitAsync(); + var currentEmailQuota = await _emailQuotaService.IsQuotaOverTheLimitAsync(); var currentUsagePercentage = currentEmailQuota.EmailQuota - .CurrentUsagePercentage(emailQuotaService.GetEmailQuotaPerMonth()); + .CurrentUsagePercentage(_emailQuotaService.GetEmailQuotaPerMonth()); if (currentUsagePercentage >= 80) { - var layout = await layoutAccessor.GetLayoutAsync(); + var layout = await _layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Messages"]; await contentZone.AddAsync( - await shapeFactory.CreateAsync("DashboardQuotaMessage", new + await _shapeFactory.CreateAsync("DashboardQuotaMessage", new { currentEmailQuota.IsOverQuota, UsagePercentage = currentUsagePercentage, diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/EmailSettingsQuotaFilter.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/EmailSettingsQuotaFilter.cs index 35922c44..b4543ede 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/EmailSettingsQuotaFilter.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Filters/EmailSettingsQuotaFilter.cs @@ -9,11 +9,22 @@ namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Filters; -public class EmailSettingsQuotaFilter( - IShapeFactory shapeFactory, - ILayoutAccessor layoutAccessor, - IEmailQuotaService emailQuotaService) : IAsyncResultFilter +public class EmailSettingsQuotaFilter : IAsyncResultFilter { + private readonly IShapeFactory _shapeFactory; + private readonly ILayoutAccessor _layoutAccessor; + private readonly IEmailQuotaService _emailQuotaService; + + public EmailSettingsQuotaFilter( + IShapeFactory shapeFactory, + ILayoutAccessor layoutAccessor, + IEmailQuotaService emailQuotaService) + { + _shapeFactory = shapeFactory; + _layoutAccessor = layoutAccessor; + _emailQuotaService = emailQuotaService; + } + public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (!context.IsAdmin()) @@ -32,17 +43,17 @@ actionRouteValue is nameof(AdminController.Index) && context.Result is ViewResult && context.RouteData.Values.TryGetValue("GroupId", out var groupId) && (string)groupId == "email" && - emailQuotaService.ShouldLimitEmails()) + _emailQuotaService.ShouldLimitEmails()) { - var layout = await layoutAccessor.GetLayoutAsync(); + var layout = await _layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Content"]; - var quota = await emailQuotaService.GetOrCreateCurrentQuotaAsync(); + var quota = await _emailQuotaService.GetOrCreateCurrentQuotaAsync(); await contentZone.AddAsync( - await shapeFactory.CreateAsync("EmailSettingsQuotaMessage", new + await _shapeFactory.CreateAsync("EmailSettingsQuotaMessage", new { quota.CurrentEmailUsageCount, - EmailQuotaPerMonth = emailQuotaService.GetEmailQuotaPerMonth(), + EmailQuotaPerMonth = _emailQuotaService.GetEmailQuotaPerMonth(), }), "0"); } diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs index 90e2b343..92af9ffb 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaService.cs @@ -19,22 +19,38 @@ namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Services; -public class EmailQuotaService( - ISession session, - IOptions emailQuotaOptions, - IShellConfiguration shellConfiguration, - IOptions smtpOptions, - IClock clock, - IRoleService roleService, - UserManager userManager) : IEmailQuotaService +public class EmailQuotaService : IEmailQuotaService { - private readonly EmailQuotaOptions _emailQuotaOptions = emailQuotaOptions.Value; - private readonly SmtpSettings _smtpOptions = smtpOptions.Value; + private readonly ISession _session; + private readonly EmailQuotaOptions _emailQuotaOptions; + private readonly IShellConfiguration _shellConfiguration; + private readonly SmtpSettings _smtpOptions; + private readonly IClock _clock; + private readonly IRoleService _roleService; + private readonly UserManager _userManager; + + public EmailQuotaService( + ISession session, + IOptions emailQuotaOptions, + IShellConfiguration shellConfiguration, + IOptions smtpOptions, + IClock clock, + IRoleService roleService, + UserManager userManager) + { + _session = session; + _emailQuotaOptions = emailQuotaOptions.Value; + _shellConfiguration = shellConfiguration; + _smtpOptions = smtpOptions.Value; + _clock = clock; + _roleService = roleService; + _userManager = userManager; + } public async Task> GetUserEmailsForEmailReminderAsync() { // Get users with site owner permission. - var roles = await roleService.GetRolesAsync(); + var roles = await _roleService.GetRolesAsync(); var siteOwnerRoles = roles.Where(role => (role as Role)?.RoleClaims.Exists(claim => claim.ClaimType == ClaimType && claim.ClaimValue == SiteOwner.Name) == true); @@ -42,7 +58,7 @@ public async Task> GetUserEmailsForEmailReminderAsync() var siteOwners = new List(); foreach (var role in siteOwnerRoles) { - siteOwners.AddRange(await userManager.GetUsersInRoleAsync(role.RoleName)); + siteOwners.AddRange(await _userManager.GetUsersInRoleAsync(role.RoleName)); } return siteOwners.Select(user => (user as User)?.Email); @@ -50,7 +66,7 @@ public async Task> GetUserEmailsForEmailReminderAsync() public bool ShouldLimitEmails() { - var originalHost = shellConfiguration.GetValue("SmtpSettings:Host"); + var originalHost = _shellConfiguration.GetValue("SmtpSettings:Host"); return originalHost == _smtpOptions.Host; } @@ -66,16 +82,16 @@ public async Task IsQuotaOverTheLimitAsync() public async Task GetOrCreateCurrentQuotaAsync() { - var currentQuota = await session.Query().FirstOrDefaultAsync(); + var currentQuota = await _session.Query().FirstOrDefaultAsync(); if (currentQuota != null) return currentQuota; currentQuota = new EmailQuota { // Need to set default value otherwise the database might complain about being 01/01/0001 out of range. - LastReminderUtc = clock.UtcNow.AddMonths(-1), + LastReminderUtc = _clock.UtcNow.AddMonths(-1), }; - await session.SaveAsync(currentQuota); + await _session.SaveAsync(currentQuota); return currentQuota; } @@ -83,14 +99,14 @@ public async Task GetOrCreateCurrentQuotaAsync() public Task IncreaseEmailUsageAsync(EmailQuota emailQuota) { emailQuota.CurrentEmailUsageCount++; - return session.SaveAsync(emailQuota); + return _session.SaveAsync(emailQuota); } public Task SetQuotaOnEmailReminderAsync(EmailQuota emailQuota) { - emailQuota.LastReminderUtc = clock.UtcNow; + emailQuota.LastReminderUtc = _clock.UtcNow; emailQuota.LastReminderPercentage = emailQuota.CurrentUsagePercentage(GetEmailQuotaPerMonth()); - return session.SaveAsync(emailQuota); + return _session.SaveAsync(emailQuota); } public bool ShouldSendReminderEmail(EmailQuota emailQuota, int currentUsagePercentage) @@ -100,7 +116,7 @@ public bool ShouldSendReminderEmail(EmailQuota emailQuota, int currentUsagePerce return false; } - var isSameMonth = IsSameMonth(clock.UtcNow, emailQuota.LastReminderUtc); + var isSameMonth = IsSameMonth(_clock.UtcNow, emailQuota.LastReminderUtc); if (!isSameMonth) { @@ -115,7 +131,7 @@ public bool ShouldSendReminderEmail(EmailQuota emailQuota, int currentUsagePerce public Task ResetQuotaAsync(EmailQuota emailQuota) { emailQuota.CurrentEmailUsageCount = 0; - return session.SaveAsync(emailQuota); + return _session.SaveAsync(emailQuota); } public int GetEmailQuotaPerMonth() => diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs index 5be07de5..433c8ab7 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/EmailQuotaSubjectService.cs @@ -1,10 +1,13 @@ -using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Localization; namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Services; -public class EmailQuotaSubjectService(IStringLocalizer stringLocalizer) : IEmailQuotaSubjectService +public class EmailQuotaSubjectService : IEmailQuotaSubjectService { - private readonly IStringLocalizer T = stringLocalizer; + private readonly IStringLocalizer T; + + public EmailQuotaSubjectService(IStringLocalizer stringLocalizer) => + T = stringLocalizer; public LocalizedString GetWarningEmailSubject(int percentage) => T["[Warning] Your site has used {0}% of its e-mail quota", percentage]; diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs index e409121b..703472e8 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Services/QuotaManagingSmtpServiceDecorator.cs @@ -10,24 +10,39 @@ namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Services; -public class QuotaManagingSmtpServiceDecorator( - ISmtpService smtpService, - IStringLocalizer stringLocalizer, - IEmailQuotaService emailQuotaService, - ShellSettings shellSettings, - IEmailTemplateService emailTemplateService, - IEmailQuotaSubjectService emailQuotaSubjectService) : ISmtpService +public class QuotaManagingSmtpServiceDecorator : ISmtpService { - private readonly IStringLocalizer T = stringLocalizer; + private readonly IStringLocalizer T; + private readonly ISmtpService _smtpService; + private readonly IEmailQuotaService _emailQuotaService; + private readonly ShellSettings _shellSettings; + private readonly IEmailTemplateService _emailTemplateService; + private readonly IEmailQuotaSubjectService _emailQuotaSubjectService; + + public QuotaManagingSmtpServiceDecorator( + ISmtpService smtpService, + IStringLocalizer stringLocalizer, + IEmailQuotaService emailQuotaService, + ShellSettings shellSettings, + IEmailTemplateService emailTemplateService, + IEmailQuotaSubjectService emailQuotaSubjectService) + { + _smtpService = smtpService; + T = stringLocalizer; + _emailQuotaService = emailQuotaService; + _shellSettings = shellSettings; + _emailTemplateService = emailTemplateService; + _emailQuotaSubjectService = emailQuotaSubjectService; + } public async Task SendAsync(MailMessage message) { - if (!emailQuotaService.ShouldLimitEmails()) + if (!_emailQuotaService.ShouldLimitEmails()) { - return await smtpService.SendAsync(message); + return await _smtpService.SendAsync(message); } - var isQuotaOverResult = await emailQuotaService.IsQuotaOverTheLimitAsync(); + var isQuotaOverResult = await _emailQuotaService.IsQuotaOverTheLimitAsync(); await SendAlertEmailIfNecessaryAsync(isQuotaOverResult.EmailQuota); // Should send the email if the quota is not over the limit. @@ -36,10 +51,10 @@ public async Task SendAsync(MailMessage message) return SmtpResult.Failed(T["The email quota for the site has been exceeded."]); } - var emailResult = await smtpService.SendAsync(message); + var emailResult = await _smtpService.SendAsync(message); if (emailResult == SmtpResult.Success) { - await emailQuotaService.IncreaseEmailUsageAsync(isQuotaOverResult.EmailQuota); + await _emailQuotaService.IncreaseEmailUsageAsync(isQuotaOverResult.EmailQuota); } return emailResult; @@ -47,17 +62,17 @@ public async Task SendAsync(MailMessage message) private async Task SendAlertEmailIfNecessaryAsync(EmailQuota emailQuota) { - var currentUsagePercentage = emailQuota.CurrentUsagePercentage(emailQuotaService.GetEmailQuotaPerMonth()); - if (!emailQuotaService.ShouldSendReminderEmail(emailQuota, currentUsagePercentage)) return; + var currentUsagePercentage = emailQuota.CurrentUsagePercentage(_emailQuotaService.GetEmailQuotaPerMonth()); + if (!_emailQuotaService.ShouldSendReminderEmail(emailQuota, currentUsagePercentage)) return; - var siteOwnerEmails = (await emailQuotaService.GetUserEmailsForEmailReminderAsync()).ToList(); + var siteOwnerEmails = (await _emailQuotaService.GetUserEmailsForEmailReminderAsync()).ToList(); if (currentUsagePercentage >= 100) { await SendQuotaEmailAsync( emailQuota, siteOwnerEmails, "EmailQuotaExceededError", - emailQuotaSubjectService.GetExceededEmailSubject(), + _emailQuotaSubjectService.GetExceededEmailSubject(), currentUsagePercentage); return; } @@ -66,7 +81,7 @@ await SendQuotaEmailAsync( emailQuota, siteOwnerEmails, $"EmailQuotaWarning", - emailQuotaSubjectService.GetWarningEmailSubject(currentUsagePercentage), + _emailQuotaSubjectService.GetWarningEmailSubject(currentUsagePercentage), currentUsagePercentage); } @@ -87,17 +102,17 @@ private Task SendQuotaEmailAsync( ShellScope.AddDeferredTask(async _ => { emailMessage.To = siteOwnerEmail; - emailMessage.Body = await emailTemplateService.RenderEmailTemplateAsync(emailTemplateName, new + emailMessage.Body = await _emailTemplateService.RenderEmailTemplateAsync(emailTemplateName, new { - HostName = shellSettings.Name, + HostName = _shellSettings.Name, Percentage = percentage, }); // ISmtpService must be used within this class otherwise it won't call the original ISmtpService // implementation, but loop back to here. - await smtpService.SendAsync(emailMessage); + await _smtpService.SendAsync(emailMessage); }); } - return emailQuotaService.SetQuotaOnEmailReminderAsync(emailQuota); + return _emailQuotaService.SetQuotaOnEmailReminderAsync(emailQuota); } } diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Startup.cs b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Startup.cs index 3fadfb6a..abeebcbf 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Startup.cs +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Startup.cs @@ -16,15 +16,20 @@ namespace Lombiq.Hosting.Tenants.EmailQuotaManagement; [Feature(FeatureNames.EmailQuotaManagement)] -public class Startup(IShellConfiguration shellConfiguration) : StartupBase +public class Startup : StartupBase { + private readonly IShellConfiguration _shellConfiguration; + + public Startup(IShellConfiguration shellConfiguration) => + _shellConfiguration = shellConfiguration; + public override void ConfigureServices(IServiceCollection services) { services.AddDataMigration(); services.AddSingleton(); services.Configure(options => - options.EmailQuotaPerMonth = shellConfiguration.GetValue("Lombiq_Hosting_Tenants_EmailQuotaManagement:EmailQuotaPerMonth") + options.EmailQuotaPerMonth = _shellConfiguration.GetValue("Lombiq_Hosting_Tenants_EmailQuotaManagement:EmailQuotaPerMonth") ?? DefaultEmailQuota); services.Configure(options => diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs b/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs index f4c13e5d..ee924d8a 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots/Filters/EnvironmentRobotsMetaTagFilter.cs @@ -7,16 +7,27 @@ namespace Lombiq.Hosting.Tenants.EnvironmentRobots.Filters; -public class EnvironmentRobotsMetaTagFilter( - IHostEnvironment hostEnvironment, - IOptions options, - IResourceManager resourceManager) : IResultFilter +public class EnvironmentRobotsMetaTagFilter : IResultFilter { + private readonly IHostEnvironment _hostEnvironment; + private readonly IOptions _options; + private readonly IResourceManager _resourceManager; + + public EnvironmentRobotsMetaTagFilter( + IHostEnvironment hostEnvironment, + IOptions options, + IResourceManager resourceManager) + { + _hostEnvironment = hostEnvironment; + _options = options; + _resourceManager = resourceManager; + } + public void OnResultExecuting(ResultExecutingContext context) { - if (!hostEnvironment.IsProductionWithConfiguration(options)) + if (!_hostEnvironment.IsProductionWithConfiguration(_options)) { - resourceManager.RegisterMeta(new MetaEntry + _resourceManager.RegisterMeta(new MetaEntry { Name = "robots", Content = "noindex, nofollow", diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots/Middlewares/EnvironmentRobotsMiddleware.cs b/Lombiq.Hosting.Tenants.EnvironmentRobots/Middlewares/EnvironmentRobotsMiddleware.cs index ecf6ad92..5d9a96f0 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots/Middlewares/EnvironmentRobotsMiddleware.cs +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots/Middlewares/EnvironmentRobotsMiddleware.cs @@ -9,14 +9,25 @@ namespace Lombiq.Hosting.Tenants.EnvironmentRobots.Middlewares; -public class EnvironmentRobotsMiddleware( - RequestDelegate next, - IHostEnvironment hostEnvironment, - IOptions options) +public class EnvironmentRobotsMiddleware { + private readonly RequestDelegate _next; + private readonly IHostEnvironment _hostEnvironment; + private readonly IOptions _options; + + public EnvironmentRobotsMiddleware( + RequestDelegate next, + IHostEnvironment hostEnvironment, + IOptions options) + { + _next = next; + _hostEnvironment = hostEnvironment; + _options = options; + } + public Task InvokeAsync(HttpContext context) { - if (!hostEnvironment.IsProductionWithConfiguration(options)) + if (!_hostEnvironment.IsProductionWithConfiguration(_options)) { var headerValue = context.Response.Headers["X-Robots-Tag"].FirstOrDefault() ?? string.Empty; @@ -46,6 +57,6 @@ public Task InvokeAsync(HttpContext context) } } - return next(context); + return _next(context); } } diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots/Startup.cs b/Lombiq.Hosting.Tenants.EnvironmentRobots/Startup.cs index bdea74d4..d978e6e7 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots/Startup.cs +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots/Startup.cs @@ -13,12 +13,17 @@ namespace Lombiq.Hosting.Tenants.EnvironmentRobots; [Feature(FeatureNames.EnvironmentRobots)] -public class Startup(IShellConfiguration shellConfiguration) : StartupBase +public class Startup : StartupBase { + private readonly IShellConfiguration _shellConfiguration; + + public Startup(IShellConfiguration shellConfiguration) => + _shellConfiguration = shellConfiguration; + public override void ConfigureServices(IServiceCollection services) { var options = new EnvironmentRobotsOptions(); - var configSection = shellConfiguration + var configSection = _shellConfiguration .GetSection("Lombiq_Hosting_Tenants_EnvironmentRobots:EnvironmentRobotsOptions"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs b/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs index 87afdff0..e9b6682e 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs +++ b/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs @@ -97,7 +97,7 @@ private Task HandleConditionallyEnabledFeaturesAsync() throw new InvalidOperationException("'IsAlwaysEnabled' feature can't be disabled by FeaturesGuard."); } - if (featuresToEnable.Count == 0 && featuresToDisable.Count == 0) + if (!featuresToEnable.Any() && !featuresToDisable.Any()) { return; } @@ -119,7 +119,7 @@ private Task HandleConditionallyEnabledFeaturesAsync() /// private static bool TryGetFeaturesToBeEnabledAndDisabled( IDictionary> conditionallyEnabledFeatures, - HashSet enabledFeatureIds, + IReadOnlySet enabledFeatureIds, out HashSet featuresToEnable, out HashSet featuresToDisable) { @@ -152,6 +152,6 @@ private static bool TryGetFeaturesToBeEnabledAndDisabled( featuresToEnable = featuresToEnableIds; featuresToDisable = featuresToDisableIds; - return featuresToEnableIds.Count != 0 || featuresToDisableIds.Count != 0; + return featuresToEnableIds.Any() || featuresToDisableIds.Any(); } } diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs b/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs index 0cb67e9c..fdd8251e 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs +++ b/Lombiq.Hosting.Tenants.FeaturesGuard/Startup.cs @@ -10,14 +10,19 @@ namespace Lombiq.Hosting.Tenants.FeaturesGuard; [Feature(FeatureNames.FeaturesGuard)] -public class Startup(IShellConfiguration shellConfiguration) : StartupBase +public class Startup : StartupBase { + private readonly IShellConfiguration _shellConfiguration; + + public Startup(IConfiguration configuration, IShellConfiguration shellConfiguration) => + _shellConfiguration = shellConfiguration; + public override void ConfigureServices(IServiceCollection services) { services.AddScoped(); services.Configure(options => - shellConfiguration + _shellConfiguration .GetSection("Lombiq_Hosting_Tenants_FeaturesGuard:ConditionallyEnabledFeaturesOptions:ConditionallyEnabledFeatures") .Bind(options)); } diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement/Middlewares/IdleTimeProviderMiddleware.cs b/Lombiq.Hosting.Tenants.IdleTenantManagement/Middlewares/IdleTimeProviderMiddleware.cs index d2243cb0..76d1ac7e 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement/Middlewares/IdleTimeProviderMiddleware.cs +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement/Middlewares/IdleTimeProviderMiddleware.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.IdleTenantManagement.Services; +using Lombiq.Hosting.Tenants.IdleTenantManagement.Services; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using OrchardCore.Modules; @@ -6,12 +6,16 @@ namespace Lombiq.Hosting.Tenants.IdleTenantManagement.Middlewares; -public class IdleTimeProviderMiddleware(RequestDelegate next) +public class IdleTimeProviderMiddleware { + private readonly RequestDelegate _next; + + public IdleTimeProviderMiddleware(RequestDelegate next) => _next = next; + public Task InvokeAsync(HttpContext context, ILastActiveTimeAccessor lastActiveTimeAccessor) { lastActiveTimeAccessor.Update(context.RequestServices.GetService()); - return next(context); + return _next(context); } } diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement/Services/IdleShutdown.cs b/Lombiq.Hosting.Tenants.IdleTenantManagement/Services/IdleShutdown.cs index 22861214..9639bc4b 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement/Services/IdleShutdown.cs +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement/Services/IdleShutdown.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.IdleTenantManagement.Models; +using Lombiq.Hosting.Tenants.IdleTenantManagement.Models; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using OrchardCore.Environment.Shell; @@ -7,27 +7,44 @@ namespace Lombiq.Hosting.Tenants.IdleTenantManagement.Services; -public class IdleShutdown( - IOptions options, - ShellSettings shellSettings, - IClock clock, - ILastActiveTimeAccessor lastActiveTimeAccessor, - ILogger logger, - IShellHost shellHost) : IIdleShutdown +public class IdleShutdown : IIdleShutdown { + private readonly IOptions _options; + private readonly ShellSettings _shellSettings; + private readonly IClock _clock; + private readonly ILastActiveTimeAccessor _lastActiveTimeAccessor; + private readonly ILogger _logger; + private readonly IShellHost _shellHost; + + public IdleShutdown( + IOptions options, + ShellSettings shellSettings, + IClock clock, + ILastActiveTimeAccessor lastActiveTimeAccessor, + ILogger logger, + IShellHost shellHost) + { + _options = options; + _shellSettings = shellSettings; + _clock = clock; + _lastActiveTimeAccessor = lastActiveTimeAccessor; + _logger = logger; + _shellHost = shellHost; + } + public async Task ShutDownIdleTenantsAsync() { - var maxIdleMinutes = options.Value.MaxIdleMinutes; + var maxIdleMinutes = _options.Value.MaxIdleMinutes; - if (maxIdleMinutes <= 0 || shellSettings.IsDefaultShell()) return; + if (maxIdleMinutes <= 0 || _shellSettings.IsDefaultShell()) return; - var lastActiveDateTimeUtc = lastActiveTimeAccessor.LastActiveDateTimeUtc; + var lastActiveDateTimeUtc = _lastActiveTimeAccessor.LastActiveDateTimeUtc; - if (lastActiveDateTimeUtc.AddMinutes(maxIdleMinutes) <= clock?.UtcNow) + if (lastActiveDateTimeUtc.AddMinutes(maxIdleMinutes) <= _clock?.UtcNow) { - logger?.LogInformation("Shutting down tenant \"{ShellName}\" because of idle timeout.", shellSettings.Name); + _logger?.LogInformation("Shutting down tenant \"{ShellName}\" because of idle timeout.", _shellSettings.Name); - await shellHost.ReleaseShellContextAsync(shellSettings, eventSource: false); + await _shellHost.ReleaseShellContextAsync(_shellSettings, eventSource: false); } } } diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement/Startup.cs b/Lombiq.Hosting.Tenants.IdleTenantManagement/Startup.cs index b4ac8e90..43f4fe8f 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement/Startup.cs +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement/Startup.cs @@ -14,8 +14,13 @@ namespace Lombiq.Hosting.Tenants.IdleTenantManagement; [Feature(FeatureNames.ShutDownIdleTenants)] -public class ShutDownIdleTenantsStartup(IShellConfiguration shellConfiguration) : StartupBase +public class ShutDownIdleTenantsStartup : StartupBase { + private readonly IShellConfiguration _shellConfiguration; + + public ShutDownIdleTenantsStartup(IShellConfiguration shellConfiguration) => + _shellConfiguration = shellConfiguration; + public override void Configure( IApplicationBuilder app, IEndpointRouteBuilder routes, @@ -30,7 +35,7 @@ public override void ConfigureServices(IServiceCollection services) // Idle Minutes Settings services.Configure(options => - shellConfiguration + _shellConfiguration .GetSection("Lombiq_Hosting_Tenants_IdleTenantManagement:IdleShutdownOptions") .Bind(options)); } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/AddSiteOwnerPermissionToRoleMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/AddSiteOwnerPermissionToRoleMaintenanceProvider.cs index 68eab3cf..d346d9ea 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/AddSiteOwnerPermissionToRoleMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/AddSiteOwnerPermissionToRoleMaintenanceProvider.cs @@ -10,23 +10,32 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.AddSiteOwnerPermissionToRole; -public class AddSiteOwnerPermissionToRoleMaintenanceProvider( - IOptions options, - RoleManager roleManager) : MaintenanceProviderBase +public class AddSiteOwnerPermissionToRoleMaintenanceProvider : MaintenanceProviderBase { + private readonly IOptions _options; + private readonly RoleManager _roleManager; + + public AddSiteOwnerPermissionToRoleMaintenanceProvider( + IOptions options, + RoleManager roleManager) + { + _options = options; + _roleManager = roleManager; + } + public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => Task.FromResult( - options.Value.IsEnabled && + _options.Value.IsEnabled && !context.WasLatestExecutionSuccessful()); public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { - if (await roleManager.FindByNameAsync(options.Value.Role) is not Role role) return; + if (await _roleManager.FindByNameAsync(_options.Value.Role) is not Role role) return; if (role.RoleClaims.Exists(claim => claim.ClaimType == ClaimType && claim.ClaimValue == SiteOwner.Name)) return; role.RoleClaims.Add(new RoleClaim { ClaimType = ClaimType, ClaimValue = SiteOwner.Name }); - await roleManager.UpdateAsync(role); + await _roleManager.UpdateAsync(role); } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/Startup.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/Startup.cs index 24487a73..4722717d 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/Startup.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/AddSiteOwnerPermissionToRole/Startup.cs @@ -8,12 +8,17 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.AddSiteOwnerPermissionToRole; [Feature(FeatureNames.AddSiteOwnerPermissionToRole)] -public class Startup(IShellConfiguration shellConfiguration) : StartupBase +public class Startup : StartupBase { + private readonly IShellConfiguration _shellConfiguration; + + public Startup(IShellConfiguration shellConfiguration) => + _shellConfiguration = shellConfiguration; + public override void ConfigureServices(IServiceCollection services) { var options = new AddSiteOwnerPermissionToRoleMaintenanceOptions(); - var configSection = shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:AddSiteOwnerPermissionToRole"); + var configSection = _shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:AddSiteOwnerPermissionToRole"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/ChangeUserSensitiveContentMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/ChangeUserSensitiveContentMaintenanceProvider.cs index c574b882..0327d3f4 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/ChangeUserSensitiveContentMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/ChangeUserSensitiveContentMaintenanceProvider.cs @@ -15,24 +15,39 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.ChangeUserSensitiveContent; -public class ChangeUserSensitiveContentMaintenanceProvider( - IOptions options, - ISession session, - UserManager userManager, - IPasswordHasher passwordHasher, - ShellSettings shellSettings) : MaintenanceProviderBase +public class ChangeUserSensitiveContentMaintenanceProvider : MaintenanceProviderBase { + private readonly IOptions _options; + private readonly ISession _session; + private readonly UserManager _userManager; + private readonly IPasswordHasher _passwordHasher; + private readonly ShellSettings _shellSettings; + + public ChangeUserSensitiveContentMaintenanceProvider( + IOptions options, + ISession session, + UserManager userManager, + IPasswordHasher passwordHasher, + ShellSettings shellSettings) + { + _options = options; + _session = session; + _userManager = userManager; + _passwordHasher = passwordHasher; + _shellSettings = shellSettings; + } + public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => Task.FromResult( - options.Value.IsEnabled && + _options.Value.IsEnabled && !context.WasLatestExecutionSuccessful() && - options.Value.TenantNames.Replace(" ", string.Empty).SplitByCommas().Contains(shellSettings.Name)); + _options.Value.TenantNames.Replace(" ", string.Empty).SplitByCommas().Contains(_shellSettings.Name)); public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { var randomNameGenerator = new PersonNameGenerator(); - var users = await session.Query().ListAsync(); + var users = await _session.Query().ListAsync(); foreach (var user in users.Where(user => !user.Email.Trim().EndsWith($"@lombiq.com", StringComparison.InvariantCulture))) { @@ -45,9 +60,9 @@ public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) user.NormalizedUserName = formattedFullName.ToUpperInvariant(); user.Email = formattedEmail; user.NormalizedEmail = formattedEmail.ToUpperInvariant(); - user.PasswordHash = passwordHasher.HashPassword(user, GenerateRandomPassword(32)); + user.PasswordHash = _passwordHasher.HashPassword(user, GenerateRandomPassword(32)); - await userManager.UpdateAsync(user); + await _userManager.UpdateAsync(user); } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/Startup.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/Startup.cs index 905e1ea3..23e7e97e 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/Startup.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/ChangeUserSensitiveContent/Startup.cs @@ -8,12 +8,17 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.ChangeUserSensitiveContent; [Feature(FeatureNames.ChangeUserSensitiveContent)] -public class Startup(IShellConfiguration shellConfiguration) : StartupBase +public class Startup : StartupBase { + private readonly IShellConfiguration _shellConfiguration; + + public Startup(IShellConfiguration shellConfiguration) => + _shellConfiguration = shellConfiguration; + public override void ConfigureServices(IServiceCollection services) { var options = new ChangeUserSensitiveContentMaintenanceOptions(); - var configSection = shellConfiguration + var configSection = _shellConfiguration .GetSection("Lombiq_Hosting_Tenants_Maintenance:ChangeUserSensitiveContent"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/RemoveUsersMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/RemoveUsersMaintenanceProvider.cs index c38e7717..61820da9 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/RemoveUsersMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/RemoveUsersMaintenanceProvider.cs @@ -12,23 +12,34 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.RemoveUsers; -public class RemoveUsersMaintenanceProvider( - IOptions options, - ISession session, - UserManager userManager) : MaintenanceProviderBase +public class RemoveUsersMaintenanceProvider : MaintenanceProviderBase { + private readonly IOptions _options; + private readonly ISession _session; + private readonly UserManager _userManager; + + public RemoveUsersMaintenanceProvider( + IOptions options, + ISession session, + UserManager userManager) + { + _options = options; + _session = session; + _userManager = userManager; + } + public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => Task.FromResult( - options.Value.IsEnabled && + _options.Value.IsEnabled && !context.WasLatestExecutionSuccessful()); public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { - var users = await session.Query().ListAsync(); + var users = await _session.Query().ListAsync(); foreach (var user in users.Where(user => - user.Email.EndsWith($"@{options.Value.EmailDomain}", StringComparison.InvariantCulture))) + user.Email.EndsWith($"@{_options.Value.EmailDomain}", StringComparison.InvariantCulture))) { - await userManager.DeleteAsync(user); + await _userManager.DeleteAsync(user); } } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/Startup.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/Startup.cs index ed3d1c62..58fa4760 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/Startup.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/RemoveUsers/Startup.cs @@ -8,12 +8,17 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.RemoveUsers; [Feature(FeatureNames.RemoveUsers)] -public class Startup(IShellConfiguration shellConfiguration) : StartupBase +public class Startup : StartupBase { + private readonly IShellConfiguration _shellConfiguration; + + public Startup(IShellConfiguration shellConfiguration) => + _shellConfiguration = shellConfiguration; + public override void ConfigureServices(IServiceCollection services) { var options = new RemoveUsersMaintenanceOptions(); - var configSection = shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:RemoveUsers"); + var configSection = _shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:RemoveUsers"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/Startup.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/Startup.cs index 26fcf43e..2b21fa1e 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/Startup.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/Startup.cs @@ -8,12 +8,17 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.UpdateShellRequestUrl; [Feature(FeatureNames.UpdateShellRequestUrls)] -public class Startup(IShellConfiguration shellConfiguration) : StartupBase +public class Startup : StartupBase { + private readonly IShellConfiguration _shellConfiguration; + + public Startup(IShellConfiguration shellConfiguration) => + _shellConfiguration = shellConfiguration; + public override void ConfigureServices(IServiceCollection services) { var options = new UpdateShellRequestUrlMaintenanceOptions(); - var configSection = shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:UpdateShellRequestUrl"); + var configSection = _shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:UpdateShellRequestUrl"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs index 13e56bc4..6d7759c5 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs @@ -8,32 +8,45 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.UpdateShellRequestUrl; -public class UpdateShellRequestUrlsMaintenanceProvider( - ShellSettings shellSettings, - IOptions options, - IShellSettingsManager shellSettingsManager, - IShellHost shellHost) : MaintenanceProviderBase +public class UpdateShellRequestUrlsMaintenanceProvider : MaintenanceProviderBase { + private readonly ShellSettings _shellSettings; + private readonly IOptions _options; + private readonly IShellSettingsManager _shellSettingsManager; + private readonly IShellHost _shellHost; + + public UpdateShellRequestUrlsMaintenanceProvider( + ShellSettings shellSettings, + IOptions options, + IShellSettingsManager shellSettingsManager, + IShellHost shellHost) + { + _shellSettings = shellSettings; + _options = options; + _shellSettingsManager = shellSettingsManager; + _shellHost = shellHost; + } + public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => - Task.FromResult(options.Value.IsEnabled && - shellSettings.IsDefaultShell() && + Task.FromResult(_options.Value.IsEnabled && + _shellSettings.IsDefaultShell() && !context.WasLatestExecutionSuccessful()); public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { - var allShellSettings = await shellSettingsManager.LoadSettingsAsync(); - foreach (var settings in allShellSettings) + var allShellSettings = await _shellSettingsManager.LoadSettingsAsync(); + foreach (var shellSettings in allShellSettings) { - settings.RequestUrlHost = TenantUrlHelpers.GetEvaluatedValueForTenant( - options.Value.DefaultShellRequestUrl, - options.Value.RequestUrl, - settings); - settings.RequestUrlPrefix = TenantUrlHelpers.GetEvaluatedValueForTenant( - options.Value.DefaultShellRequestUrlPrefix, - options.Value.RequestUrlPrefix, - settings); + shellSettings.RequestUrlHost = TenantUrlHelpers.GetEvaluatedValueForTenant( + _options.Value.DefaultShellRequestUrl, + _options.Value.RequestUrl, + shellSettings); + shellSettings.RequestUrlPrefix = TenantUrlHelpers.GetEvaluatedValueForTenant( + _options.Value.DefaultShellRequestUrlPrefix, + _options.Value.RequestUrlPrefix, + shellSettings); - await shellHost.UpdateShellSettingsAsync(settings); + await _shellHost.UpdateShellSettingsAsync(shellSettings); } context.ReloadShellAfterMaintenanceCompletion = true; diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/Startup.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/Startup.cs index 717ed5c4..ff86c21c 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/Startup.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/Startup.cs @@ -8,12 +8,17 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.UpdateSiteUrl; [Feature(FeatureNames.UpdateSiteUrl)] -public class Startup(IShellConfiguration shellConfiguration) : StartupBase +public class Startup : StartupBase { + private readonly IShellConfiguration _shellConfiguration; + + public Startup(IShellConfiguration shellConfiguration) => + _shellConfiguration = shellConfiguration; + public override void ConfigureServices(IServiceCollection services) { var options = new UpdateSiteUrlMaintenanceOptions(); - var configSection = shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:UpdateSiteUrl"); + var configSection = _shellConfiguration.GetSection("Lombiq_Hosting_Tenants_Maintenance:UpdateSiteUrl"); configSection.Bind(options); services.Configure(configSection); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs index 97e111e4..f27eca5c 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs @@ -9,23 +9,34 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.UpdateSiteUrl; -public class UpdateSiteUrlMaintenanceProvider( - ISiteService siteService, - ShellSettings shellSettings, - IOptions options) : MaintenanceProviderBase +public class UpdateSiteUrlMaintenanceProvider : MaintenanceProviderBase { + private readonly ISiteService _siteService; + private readonly ShellSettings _shellSettings; + private readonly IOptions _options; + + public UpdateSiteUrlMaintenanceProvider( + ISiteService siteService, + ShellSettings shellSettings, + IOptions options) + { + _siteService = siteService; + _shellSettings = shellSettings; + _options = options; + } + public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext context) => - Task.FromResult(options.Value.IsEnabled && !context.WasLatestExecutionSuccessful()); + Task.FromResult(_options.Value.IsEnabled && !context.WasLatestExecutionSuccessful()); public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { - var siteSettings = await siteService.LoadSiteSettingsAsync(); + var siteSettings = await _siteService.LoadSiteSettingsAsync(); siteSettings.BaseUrl = TenantUrlHelpers.GetEvaluatedValueForTenant( - options.Value.DefaultTenantSiteUrl, - options.Value.SiteUrl, - shellSettings, - options.Value.SiteUrlFromTenantName); + _options.Value.DefaultTenantSiteUrl, + _options.Value.SiteUrl, + _shellSettings, + _options.Value.SiteUrlFromTenantName); - await siteService.UpdateSiteSettingsAsync(siteSettings); + await _siteService.UpdateSiteSettingsAsync(siteSettings); } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs b/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs index be1bea6d..dcc9ce1f 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceManager.cs @@ -12,29 +12,46 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Services; -public class MaintenanceManager( - IOrchardClock clock, - ILogger logger, - IEnumerable maintenanceProviders, - ISession session, - IShellHost shellHost, - ShellSettings shellSettings) : IMaintenanceManager +public class MaintenanceManager : IMaintenanceManager { + private readonly IOrchardClock _clock; + private readonly ILogger _logger; + private readonly IEnumerable _maintenanceProviders; + private readonly ISession _session; + private readonly IShellHost _shellHost; + private readonly ShellSettings _shellSettings; + + public MaintenanceManager( + IOrchardClock clock, + ILogger logger, + IEnumerable maintenanceProviders, + ISession session, + IShellHost shellHost, + ShellSettings shellSettings) + { + _clock = clock; + _logger = logger; + _maintenanceProviders = maintenanceProviders; + _session = session; + _shellHost = shellHost; + _shellSettings = shellSettings; + } + public Task GetLatestExecutionByMaintenanceIdAsync(string maintenanceId) => - session.Query(collection: DocumentCollections.Maintenance) + _session.Query(collection: DocumentCollections.Maintenance) .Where(execution => execution.MaintenanceId == maintenanceId) .OrderByDescending(execution => execution.ExecutionTimeUtc) .FirstOrDefaultAsync(); public async Task ExecuteMaintenanceTasksAsync() { - var orderedProviders = maintenanceProviders.OrderBy(provider => provider.Order); + var orderedProviders = _maintenanceProviders.OrderBy(provider => provider.Order); foreach (var provider in orderedProviders) { var currentExecution = new MaintenanceTaskExecutionData { MaintenanceId = provider.Id, - ExecutionTimeUtc = clock.UtcNow, + ExecutionTimeUtc = _clock.UtcNow, }; var context = new MaintenanceTaskExecutionContext { @@ -51,7 +68,7 @@ private async Task ExecuteMaintenanceTaskIfNeededAsync( MaintenanceTaskExecutionContext context, MaintenanceTaskExecutionData execution) { - logger.LogDebug("Executing maintenance task {MaintenanceId}, if needed.", provider.Id); + _logger.LogDebug("Executing maintenance task {MaintenanceId}, if needed.", provider.Id); if (await provider.ShouldExecuteAsync(context)) { @@ -61,11 +78,11 @@ private async Task ExecuteMaintenanceTaskIfNeededAsync( execution.IsSuccess = string.IsNullOrEmpty(execution.Error); if (execution.IsSuccess) { - logger.LogDebug("Maintenance task {MaintenanceId} executed successfully.", provider.Id); + _logger.LogDebug("Maintenance task {MaintenanceId} executed successfully.", provider.Id); } else { - logger.LogError( + _logger.LogError( "Maintenance task {MaintenanceId} executed with error: {Error}", provider.Id, execution.Error); @@ -76,20 +93,20 @@ private async Task ExecuteMaintenanceTaskIfNeededAsync( execution.IsSuccess = false; execution.Error = exception.ToString(); - logger.LogError( + _logger.LogError( exception, "Maintenance task {MaintenanceId} failed to execute due to an exception.", provider.Id); } - await session.SaveAsync(execution, collection: DocumentCollections.Maintenance); - await session.SaveChangesAsync(); + await _session.SaveAsync(execution, collection: DocumentCollections.Maintenance); + await _session.SaveChangesAsync(); - if (context.ReloadShellAfterMaintenanceCompletion) await shellHost.ReloadShellContextAsync(shellSettings); + if (context.ReloadShellAfterMaintenanceCompletion) await _shellHost.ReloadShellContextAsync(_shellSettings); } else { - logger.LogDebug("Maintenance task {MaintenanceId} is not needed.", provider.Id); + _logger.LogDebug("Maintenance task {MaintenanceId} is not needed.", provider.Id); } } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceRunnerService.cs b/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceRunnerService.cs index a78953d4..2ef3fc85 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceRunnerService.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Services/MaintenanceRunnerService.cs @@ -7,18 +7,29 @@ namespace Lombiq.Hosting.Tenants.Maintenance.Services; -public class MaintenanceRunnerService( - ShellSettings shellSettings, - ILogger logger, - Lazy maintenanceManagerLazy) : ModularTenantEvents +public class MaintenanceRunnerService : ModularTenantEvents { + private readonly ShellSettings _shellSettings; + private readonly ILogger _logger; + private readonly Lazy _maintenanceManagerLazy; + + public MaintenanceRunnerService( + ShellSettings shellSettings, + ILogger logger, + Lazy maintenanceManagerLazy) + { + _shellSettings = shellSettings; + _logger = logger; + _maintenanceManagerLazy = maintenanceManagerLazy; + } + public override async Task ActivatedAsync() { - if (shellSettings.State != TenantState.Running) return; + if (_shellSettings.State != TenantState.Running) return; - logger.LogDebug( + _logger.LogDebug( "Executing maintenance tasks on shell '{ShellName}'.", - shellSettings.Name); - await maintenanceManagerLazy.Value.ExecuteMaintenanceTasksAsync(); + _shellSettings.Name); + await _maintenanceManagerLazy.Value.ExecuteMaintenanceTasksAsync(); } } diff --git a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs index 03fdda86..8b4df56e 100644 --- a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs +++ b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.Management.Constants; +using Lombiq.Hosting.Tenants.Management.Constants; using Lombiq.Hosting.Tenants.Management.Models; using Lombiq.Hosting.Tenants.Management.Service; using Microsoft.AspNetCore.Authorization; @@ -22,22 +22,37 @@ namespace Lombiq.Hosting.Tenants.Management.Controllers; [Feature(FeatureNames.ShellSettingsEditor)] -public class ShellSettingsEditorController( - IAuthorizationService authorizationService, - IShellHost shellHost, - IShellConfigurationSources shellConfigurationSources, - IDistributedLock distributedLock, - INotifier notifier, - IHtmlLocalizer htmlLocalizer) : Controller +public class ShellSettingsEditorController : Controller { - private readonly IHtmlLocalizer H = htmlLocalizer; + private readonly IAuthorizationService _authorizationService; + private readonly IShellHost _shellHost; + private readonly IShellConfigurationSources _shellConfigurationSources; + private readonly IDistributedLock _distributedLock; + private readonly INotifier _notifier; + private readonly IHtmlLocalizer H; + + public ShellSettingsEditorController( + IAuthorizationService authorizationService, + IShellHost shellHost, + IShellConfigurationSources shellConfigurationSources, + IDistributedLock distributedLock, + INotifier notifier, + IHtmlLocalizer htmlLocalizer) + { + _authorizationService = authorizationService; + _shellHost = shellHost; + _shellConfigurationSources = shellConfigurationSources; + _distributedLock = distributedLock; + _notifier = notifier; + H = htmlLocalizer; + } [HttpPost] [ValidateAntiForgeryToken] public async Task Edit(ShellSettingsEditorViewModel model) { - if (!await authorizationService.AuthorizeAsync(User, ManageTenants) || - !shellHost.TryGetSettings(model.TenantId, out var shellSettings)) + if (!await _authorizationService.AuthorizeAsync(User, ManageTenants) || + !_shellHost.TryGetSettings(model.TenantId, out var shellSettings)) { return NotFound(); } @@ -45,7 +60,7 @@ public async Task Edit(ShellSettingsEditorViewModel model) model.Json ??= "{}"; if (!IsValidJson(model.Json)) { - await notifier.ErrorAsync(H["Please provide valid JSON input for shell settings."]); + await _notifier.ErrorAsync(H["Please provide valid JSON input for shell settings."]); TempData["ValidationErrorJson"] = model.Json; return RedirectToAction( @@ -84,14 +99,12 @@ public async Task Edit(ShellSettingsEditorViewModel model) foreach (var key in deletableKeys) { var tenantSettingsPrefixWithKey = $"{tenantSettingsPrefix}{key}"; - // We are using the shellSettings[key] directly because when we try to save it at line 109 - // it is not saving the new value. https://github.com/OrchardCMS/OrchardCore/issues/15184 - shellSettings[key] = null; - shellSettings[tenantSettingsPrefixWithKey] = null; + newTenantConfiguration[key] = null; + newTenantConfiguration[tenantSettingsPrefixWithKey] = null; } var (locker, locked) = - await distributedLock.TryAcquireLockAsync( + await _distributedLock.TryAcquireLockAsync( "LOMBIQ_HOSTING_TENANTS_MANAGEMENT_SHELL_SETTINGS_EDITOR_LOCK", TimeSpan.FromSeconds(10)); @@ -106,8 +119,8 @@ await distributedLock.TryAcquireLockAsync( // not save settings that has a key with multiple sections, see // https://github.com/OrchardCMS/OrchardCore/issues/14481. Once this is fixed, we can get rid of the locking and // retrieve and save the shell settings settings with IShellHost. - await shellConfigurationSources.SaveAsync(shellSettings.Name, newTenantConfiguration); - await shellHost.UpdateShellSettingsAsync(shellSettings); + await _shellConfigurationSources.SaveAsync(shellSettings.Name, newTenantConfiguration); + await _shellHost.UpdateShellSettingsAsync(shellSettings); return RedirectToAction( nameof(AdminController.Edit), diff --git a/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs b/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs index 0982f8f2..52bdbf47 100644 --- a/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs +++ b/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs @@ -1,5 +1,6 @@ using Lombiq.Hosting.Tenants.Management.Settings; using Microsoft.Extensions.DependencyInjection; +using System.Linq; using static Lombiq.Hosting.Tenants.Management.Constants.FeatureNames; namespace Lombiq.Hosting.Tenants.Management.Extensions; @@ -20,7 +21,7 @@ public static OrchardCoreBuilder HideRecipesByTagsFromSetup(this OrchardCoreBuil .ConfigureServices(services => services.Configure(options => { - if (tags.Length != 0) + if (tags.Any()) { options.HiddenTags = tags; } diff --git a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs index eaa24710..e33c13ad 100644 --- a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs +++ b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs @@ -14,11 +14,18 @@ namespace Lombiq.Hosting.Tenants.Management.Filters; -public class ForbiddenTenantsFilter( - IStringLocalizer stringLocalizer, - IOptions forbiddenTenantsOptions) : IAsyncActionFilter +public class ForbiddenTenantsFilter : IAsyncActionFilter { - private readonly IStringLocalizer T = stringLocalizer; + private readonly IStringLocalizer T; + private readonly IOptions _forbiddenTenantsOptions; + + public ForbiddenTenantsFilter( + IStringLocalizer stringLocalizer, + IOptions forbiddenTenantsOptions) + { + _forbiddenTenantsOptions = forbiddenTenantsOptions; + T = stringLocalizer; + } public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { @@ -37,16 +44,18 @@ public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecuti return next(); } - var forbiddenRequestUrlHosts = forbiddenTenantsOptions.Value.RequestUrlHosts; + var forbiddenRequestUrlHosts = _forbiddenTenantsOptions.Value.RequestUrlHosts; if (forbiddenRequestUrlHosts != null && forbiddenRequestUrlHosts.Any()) { var requestUrlHost = context.HttpContext.Request.Form[nameof(CreateApiViewModel.RequestUrlHost)].ToString(); var hosts = requestUrlHost.Split(',').Select(host => host.Trim()); - List unacceptableHostnames = [.. hosts.Where(hostname => forbiddenRequestUrlHosts.Contains(hostname))]; + List unacceptableHostnames = new(); + + unacceptableHostnames.AddRange(hosts.Where(hostname => forbiddenRequestUrlHosts.Contains(hostname))); - if (unacceptableHostnames.Count != 0) + if (unacceptableHostnames.Any()) { var unacceptableHostnamesString = string.Join(", ", unacceptableHostnames); context.ModelState.AddModelError( diff --git a/Lombiq.Hosting.Tenants.Management/Filters/ShellSettingsEditorFilter.cs b/Lombiq.Hosting.Tenants.Management/Filters/ShellSettingsEditorFilter.cs index 61122bd1..1866e363 100644 --- a/Lombiq.Hosting.Tenants.Management/Filters/ShellSettingsEditorFilter.cs +++ b/Lombiq.Hosting.Tenants.Management/Filters/ShellSettingsEditorFilter.cs @@ -11,11 +11,22 @@ namespace Lombiq.Hosting.Tenants.Management.Filters; -public class ShellSettingsEditorFilter( - ILayoutAccessor layoutAccessor, - IShapeFactory shapeFactory, - IShellHost shellHost) : IAsyncResultFilter +public class ShellSettingsEditorFilter : IAsyncResultFilter { + private readonly ILayoutAccessor _layoutAccessor; + private readonly IShapeFactory _shapeFactory; + private readonly IShellHost _shellHost; + + public ShellSettingsEditorFilter( + ILayoutAccessor layoutAccessor, + IShapeFactory shapeFactory, + IShellHost shellHost) + { + _layoutAccessor = layoutAccessor; + _shapeFactory = shapeFactory; + _shellHost = shellHost; + } + public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { var actionRouteController = context.ActionDescriptor.RouteValues["Controller"]; @@ -28,13 +39,13 @@ actionRouteValue is nameof(AdminController.Edit) && context.Result is ViewResult) { var tenantName = context.RouteData.Values["Id"].ToString(); - if (!shellHost.TryGetSettings(tenantName, out var shellSettings)) + if (!_shellHost.TryGetSettings(tenantName, out var shellSettings)) { await next(); return; } - var layout = await layoutAccessor.GetLayoutAsync(); + var layout = await _layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Content"]; (context.Controller as Controller) @@ -49,7 +60,7 @@ actionRouteValue is nameof(AdminController.Edit) && : validationErrorJson.ToString(); await contentZone.AddAsync( - await shapeFactory.CreateAsync( + await _shapeFactory.CreateAsync( "ShellSettingsEditor", viewModel => { diff --git a/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs b/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs index a42a27e9..0c712bf5 100644 --- a/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs +++ b/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs @@ -11,26 +11,37 @@ namespace Lombiq.Hosting.Tenants.Management.Service; -public class SetupWithRecipesFilterService( - IOptions hideRecipesFromSetupOptions, - ShellSettings shellSettings, - ISetupService setupService) : ISetupService +public class SetupWithRecipesFilterService : ISetupService { + private readonly IOptions _hideRecipesFromSetupOptions; + private readonly ShellSettings _shellSettings; + private readonly ISetupService _setupService; + + public SetupWithRecipesFilterService( + IOptions hideRecipesFromSetupOptions, + ShellSettings shellSettings, + ISetupService setupService) + { + _hideRecipesFromSetupOptions = hideRecipesFromSetupOptions; + _shellSettings = shellSettings; + _setupService = setupService; + } + public async Task> GetSetupRecipesAsync() { - var recipesDescriptors = await setupService.GetSetupRecipesAsync(); + var recipesDescriptors = await _setupService.GetSetupRecipesAsync(); // The first case is when we specify the tenant recipe name via the Default tenant admin UI or AutoSetup // feature, the second case is necessary because the Default tenant doesn't fill in RecipeName even if we use // auto setup. - if (shellSettings["RecipeName"] != null || shellSettings.Name.EqualsOrdinalIgnoreCase("Default")) + if (_shellSettings["RecipeName"] != null || _shellSettings.Name.EqualsOrdinalIgnoreCase("Default")) { return recipesDescriptors; } - var hiddenTags = hideRecipesFromSetupOptions.Value.HiddenTags; + var hiddenTags = _hideRecipesFromSetupOptions.Value.HiddenTags; return recipesDescriptors.Where(recipe => !recipe.Tags.Exists(tag => hiddenTags.Contains(tag))); } - public Task SetupAsync(SetupContext context) => setupService.SetupAsync(context); + public Task SetupAsync(SetupContext context) => _setupService.SetupAsync(context); } diff --git a/Lombiq.Hosting.Tenants.Management/Startup.cs b/Lombiq.Hosting.Tenants.Management/Startup.cs index 409832c0..4547afbe 100644 --- a/Lombiq.Hosting.Tenants.Management/Startup.cs +++ b/Lombiq.Hosting.Tenants.Management/Startup.cs @@ -12,12 +12,16 @@ namespace Lombiq.Hosting.Tenants.Management; [Feature(FeatureNames.ForbiddenTenantNames)] -public class ForbiddenTenantNamesStartup(IShellConfiguration shellConfiguration) : StartupBase +public class ForbiddenTenantNamesStartup : StartupBase { + private readonly IShellConfiguration _shellConfiguration; + + public ForbiddenTenantNamesStartup(IShellConfiguration shellConfiguration) => _shellConfiguration = shellConfiguration; + public override void ConfigureServices(IServiceCollection services) { services.Configure(options => - shellConfiguration + _shellConfiguration .GetSection("Lombiq_Hosting_Tenants_Management:Forbidden_Tenants_Options") .Bind(options)); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs index 250da4e4..dd200e84 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Filters/UploadFileSizeShapeFilter.cs @@ -10,11 +10,22 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Filters; -public class UploadFileSizeShapeFilter( - IShapeFactory shapeFactory, - ILayoutAccessor layoutAccessor, - IMediaStorageQuotaService mediaStorageQuotaService) : IAsyncResultFilter +public class UploadFileSizeShapeFilter : IAsyncResultFilter { + private readonly IShapeFactory _shapeFactory; + private readonly ILayoutAccessor _layoutAccessor; + private readonly IMediaStorageQuotaService _mediaStorageQuotaService; + + public UploadFileSizeShapeFilter( + IShapeFactory shapeFactory, + ILayoutAccessor layoutAccessor, + IMediaStorageQuotaService mediaStorageQuotaService) + { + _shapeFactory = shapeFactory; + _layoutAccessor = layoutAccessor; + _mediaStorageQuotaService = mediaStorageQuotaService; + } + public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { if (!context.IsAdmin()) @@ -32,10 +43,10 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE actionRouteValue is nameof(AdminController.Index) && context.Result is ViewResult) { - var layout = await layoutAccessor.GetLayoutAsync(); + var layout = await _layoutAccessor.GetLayoutAsync(); var contentZone = layout.Zones["Footer"]; - var maximumStorageQuotaMegabytes = mediaStorageQuotaService.GetMaxStorageQuotaMegabytes(); - await contentZone.AddAsync(await shapeFactory.CreateAsync( + var maximumStorageQuotaMegabytes = _mediaStorageQuotaService.GetMaxStorageQuotaMegabytes(); + await contentZone.AddAsync(await _shapeFactory.CreateAsync( "UploadFileSize", viewModel => viewModel.MaximumStorageQuotaMegabytes = maximumStorageQuotaMegabytes)); } diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs index 29aa88ad..06cbd9c7 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs @@ -6,15 +6,22 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Service; -public class MediaStorageQuotaService( - IOptions mediaStorageManagementOptions, - IMediaFileStore mediaFileStore) : IMediaStorageQuotaService +public class MediaStorageQuotaService : IMediaStorageQuotaService { - private readonly MediaStorageManagementOptions _mediaStorageManagementOptions = mediaStorageManagementOptions.Value; + private readonly MediaStorageManagementOptions _mediaStorageManagementOptions; + private readonly IMediaFileStore _mediaFileStore; + + public MediaStorageQuotaService( + IOptions mediaStorageManagementOptions, + IMediaFileStore mediaFileStore) + { + _mediaStorageManagementOptions = mediaStorageManagementOptions.Value; + _mediaFileStore = mediaFileStore; + } public async Task GetRemainingMediaStorageQuotaBytesAsync() { - var directoryContent = mediaFileStore.GetDirectoryContentAsync(includeSubDirectories: true); + var directoryContent = _mediaFileStore.GetDirectoryContentAsync(includeSubDirectories: true); var listed = await directoryContent.ToListAsync(); var sumBytes = listed.Where(item => item.Length > 0).Sum(item => item.Length); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs index 5ae428fb..300b24d8 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Startup.cs @@ -10,14 +10,18 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement; -public class Startup(IShellConfiguration shellConfiguration) : StartupBase +public class Startup : StartupBase { + private readonly IShellConfiguration _shellConfiguration; + + public Startup(IShellConfiguration shellConfiguration) => _shellConfiguration = shellConfiguration; + public override void ConfigureServices(IServiceCollection services) { var maximumStorageQuotaBytes = - shellConfiguration.GetValue( + _shellConfiguration.GetValue( "Lombiq_Hosting_Tenants_MediaStorageManagement:MaximumStorageQuotaBytes") ?? - shellConfiguration.GetValue( + _shellConfiguration.GetValue( "Lombiq_Hosting_Tenants_MediaStorageManagement:Media_Storage_Management_Options:MaximumSpace"); services.Configure(options => options.MaximumStorageQuotaBytes = maximumStorageQuotaBytes ?? MaximumStorageQuotaBytes); From 6253c59f2511ae2e518f44970c0c71fc32d9238d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Tue, 30 Jan 2024 11:42:22 +0100 Subject: [PATCH 12/23] Fixes. --- .../Handlers/FeaturesEventHandler.cs | 6 +++--- .../Extensions/LombiqHostingTenantsManagementExtensions.cs | 3 +-- .../Filters/ForbiddenTenantsFilter.cs | 6 ++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs b/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs index e9b6682e..87afdff0 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs +++ b/Lombiq.Hosting.Tenants.FeaturesGuard/Handlers/FeaturesEventHandler.cs @@ -97,7 +97,7 @@ private Task HandleConditionallyEnabledFeaturesAsync() throw new InvalidOperationException("'IsAlwaysEnabled' feature can't be disabled by FeaturesGuard."); } - if (!featuresToEnable.Any() && !featuresToDisable.Any()) + if (featuresToEnable.Count == 0 && featuresToDisable.Count == 0) { return; } @@ -119,7 +119,7 @@ private Task HandleConditionallyEnabledFeaturesAsync() /// private static bool TryGetFeaturesToBeEnabledAndDisabled( IDictionary> conditionallyEnabledFeatures, - IReadOnlySet enabledFeatureIds, + HashSet enabledFeatureIds, out HashSet featuresToEnable, out HashSet featuresToDisable) { @@ -152,6 +152,6 @@ private static bool TryGetFeaturesToBeEnabledAndDisabled( featuresToEnable = featuresToEnableIds; featuresToDisable = featuresToDisableIds; - return featuresToEnableIds.Any() || featuresToDisableIds.Any(); + return featuresToEnableIds.Count != 0 || featuresToDisableIds.Count != 0; } } diff --git a/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs b/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs index 52bdbf47..0982f8f2 100644 --- a/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs +++ b/Lombiq.Hosting.Tenants.Management/Extensions/LombiqHostingTenantsManagementExtensions.cs @@ -1,6 +1,5 @@ using Lombiq.Hosting.Tenants.Management.Settings; using Microsoft.Extensions.DependencyInjection; -using System.Linq; using static Lombiq.Hosting.Tenants.Management.Constants.FeatureNames; namespace Lombiq.Hosting.Tenants.Management.Extensions; @@ -21,7 +20,7 @@ public static OrchardCoreBuilder HideRecipesByTagsFromSetup(this OrchardCoreBuil .ConfigureServices(services => services.Configure(options => { - if (tags.Any()) + if (tags.Length != 0) { options.HiddenTags = tags; } diff --git a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs index e33c13ad..0a438d62 100644 --- a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs +++ b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs @@ -51,11 +51,9 @@ public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecuti var requestUrlHost = context.HttpContext.Request.Form[nameof(CreateApiViewModel.RequestUrlHost)].ToString(); var hosts = requestUrlHost.Split(',').Select(host => host.Trim()); - List unacceptableHostnames = new(); + List unacceptableHostnames = [.. hosts.Where(hostname => forbiddenRequestUrlHosts.Contains(hostname))]; - unacceptableHostnames.AddRange(hosts.Where(hostname => forbiddenRequestUrlHosts.Contains(hostname))); - - if (unacceptableHostnames.Any()) + if (unacceptableHostnames.Count != 0) { var unacceptableHostnamesString = string.Join(", ", unacceptableHostnames); context.ModelState.AddModelError( From 98f029c168c0bf5992a90d0ea6a859c3a121ff8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Tue, 30 Jan 2024 12:48:00 +0100 Subject: [PATCH 13/23] Fixes. --- .../Controllers/ShellSettingsEditorController.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs index 8b4df56e..eab37618 100644 --- a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs +++ b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs @@ -1,4 +1,4 @@ -using Lombiq.Hosting.Tenants.Management.Constants; +using Lombiq.Hosting.Tenants.Management.Constants; using Lombiq.Hosting.Tenants.Management.Models; using Lombiq.Hosting.Tenants.Management.Service; using Microsoft.AspNetCore.Authorization; @@ -99,8 +99,10 @@ public async Task Edit(ShellSettingsEditorViewModel model) foreach (var key in deletableKeys) { var tenantSettingsPrefixWithKey = $"{tenantSettingsPrefix}{key}"; - newTenantConfiguration[key] = null; - newTenantConfiguration[tenantSettingsPrefixWithKey] = null; + // We are using the shellSettings[key] directly because when we try to save it at line 109 + // it is not saving the new value. https://github.com/OrchardCMS/OrchardCore/issues/15184 + shellSettings[key] = null; + shellSettings[tenantSettingsPrefixWithKey] = null; } var (locker, locked) = From e4c85a7747df93faf2c613c4b0d6a66c0e2b7ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Tue, 30 Jan 2024 13:13:36 +0100 Subject: [PATCH 14/23] Removing workaround. --- .../ShellSettingsEditorController.cs | 29 ++----------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs index eab37618..4e0d9a0a 100644 --- a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs +++ b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs @@ -12,7 +12,6 @@ using OrchardCore.Modules; using OrchardCore.Mvc.Core.Utilities; using OrchardCore.Tenants.Controllers; -using System; using System.Collections.Generic; using System.Linq; using System.Text.Json; @@ -26,8 +25,6 @@ public class ShellSettingsEditorController : Controller { private readonly IAuthorizationService _authorizationService; private readonly IShellHost _shellHost; - private readonly IShellConfigurationSources _shellConfigurationSources; - private readonly IDistributedLock _distributedLock; private readonly INotifier _notifier; private readonly IHtmlLocalizer H; @@ -41,8 +38,6 @@ public ShellSettingsEditorController( { _authorizationService = authorizationService; _shellHost = shellHost; - _shellConfigurationSources = shellConfigurationSources; - _distributedLock = distributedLock; _notifier = notifier; H = htmlLocalizer; } @@ -74,7 +69,6 @@ public async Task Edit(ShellSettingsEditorViewModel model) } var tenantConfiguration = new JsonConfigurationParser().ParseConfiguration(model.Json); - var newTenantConfiguration = new Dictionary(); var tenantSettingsPrefix = $"{model.TenantId}Prefix:"; var currentSettings = shellSettings.ShellConfiguration.AsEnumerable() @@ -87,8 +81,8 @@ public async Task Edit(ShellSettingsEditorViewModel model) var tenantSettingsPrefixWithKey = $"{tenantSettingsPrefix}{key}"; if (shellSettings[key] != tenantConfiguration[key]) { - newTenantConfiguration[tenantSettingsPrefixWithKey] = tenantConfiguration[key]; - newTenantConfiguration[key] = tenantConfiguration[key]; + shellSettings[tenantSettingsPrefixWithKey] = tenantConfiguration[key]; + shellSettings[key] = tenantConfiguration[key]; } } @@ -99,29 +93,10 @@ public async Task Edit(ShellSettingsEditorViewModel model) foreach (var key in deletableKeys) { var tenantSettingsPrefixWithKey = $"{tenantSettingsPrefix}{key}"; - // We are using the shellSettings[key] directly because when we try to save it at line 109 - // it is not saving the new value. https://github.com/OrchardCMS/OrchardCore/issues/15184 shellSettings[key] = null; shellSettings[tenantSettingsPrefixWithKey] = null; } - var (locker, locked) = - await _distributedLock.TryAcquireLockAsync( - "LOMBIQ_HOSTING_TENANTS_MANAGEMENT_SHELL_SETTINGS_EDITOR_LOCK", - TimeSpan.FromSeconds(10)); - - if (!locked) - { - throw new TimeoutException($"Failed to acquire a lock before saving settings to the tenant: {model.TenantId}."); - } - - await using var acquiredLock = locker; - - // We are using the shell configuration sources directly because using IShellHost.UpdateShellSettingsAsync would - // not save settings that has a key with multiple sections, see - // https://github.com/OrchardCMS/OrchardCore/issues/14481. Once this is fixed, we can get rid of the locking and - // retrieve and save the shell settings settings with IShellHost. - await _shellConfigurationSources.SaveAsync(shellSettings.Name, newTenantConfiguration); await _shellHost.UpdateShellSettingsAsync(shellSettings); return RedirectToAction( From 53112a5143a005619ce15554e100ab7e0b374443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= <92299130+Psichorex@users.noreply.github.com> Date: Thu, 1 Feb 2024 11:21:25 +0100 Subject: [PATCH 15/23] Update Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- .../Filters/ForbiddenTenantsFilter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs index 0a438d62..86082097 100644 --- a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs +++ b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs @@ -51,7 +51,7 @@ public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecuti var requestUrlHost = context.HttpContext.Request.Form[nameof(CreateApiViewModel.RequestUrlHost)].ToString(); var hosts = requestUrlHost.Split(',').Select(host => host.Trim()); - List unacceptableHostnames = [.. hosts.Where(hostname => forbiddenRequestUrlHosts.Contains(hostname))]; + var unacceptableHostnames = hosts.Where(hostname => forbiddenRequestUrlHosts.Contains(hostname)).ToList(); if (unacceptableHostnames.Count != 0) { From 6c17a3490c37091cf0a651c4e50e86e736dee291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Thu, 1 Feb 2024 12:47:09 +0100 Subject: [PATCH 16/23] Minor fixing. --- .../Filters/ForbiddenTenantsFilter.cs | 1 - .../Service/SetupWithRecipesFilterService.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs index 86082097..907b44b9 100644 --- a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs +++ b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; -using OrchardCore.Modules; using OrchardCore.Mvc.Core.Utilities; using OrchardCore.Tenants.Controllers; using OrchardCore.Tenants.ViewModels; diff --git a/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs b/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs index 0c712bf5..5e41a207 100644 --- a/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs +++ b/Lombiq.Hosting.Tenants.Management/Service/SetupWithRecipesFilterService.cs @@ -1,7 +1,6 @@ using Lombiq.Hosting.Tenants.Management.Settings; using Microsoft.Extensions.Options; using OrchardCore.Environment.Shell; -using OrchardCore.Modules; using OrchardCore.Recipes.Models; using OrchardCore.Setup.Services; using System; From 1269e6e72f077084140c7b84d4112f54467a1865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Tue, 6 Feb 2024 08:09:40 +0100 Subject: [PATCH 17/23] Upgrading MS package. --- .../Lombiq.Hosting.Tenants.IdleTenantManagement.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement/Lombiq.Hosting.Tenants.IdleTenantManagement.csproj b/Lombiq.Hosting.Tenants.IdleTenantManagement/Lombiq.Hosting.Tenants.IdleTenantManagement.csproj index beee6725..6bad9d1e 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement/Lombiq.Hosting.Tenants.IdleTenantManagement.csproj +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement/Lombiq.Hosting.Tenants.IdleTenantManagement.csproj @@ -23,7 +23,7 @@ - + From 72f87fa5011d463f7d21151939878a121c55bcf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Fri, 16 Feb 2024 17:25:35 +0100 Subject: [PATCH 18/23] Using issue branch reference. --- .github/workflows/publish-nuget.yml | 2 +- .../Lombiq.Hosting.Tenants.Admin.Login.csproj | 2 +- ...ombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj | 4 ++-- .../Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.FeaturesGuard.csproj | 4 ++-- ...ombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.Maintenance.csproj | 4 ++-- .../Lombiq.Hosting.Tenants.Management.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.Management.csproj | 2 +- ...biq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.MediaStorageManagement.csproj | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml index 4b26cfcf..8360fd9e 100644 --- a/.github/workflows/publish-nuget.yml +++ b/.github/workflows/publish-nuget.yml @@ -7,6 +7,6 @@ on: jobs: publish-nuget: - uses: Lombiq/GitHub-Actions/.github/workflows/publish-nuget.yml@dev + uses: Lombiq/GitHub-Actions/.github/workflows/publish-nuget.yml@issue/OSOE-751 secrets: API_KEY: ${{ secrets.DEFAULT_NUGET_PUBLISH_API_KEY }} diff --git a/Lombiq.Hosting.Tenants.Admin.Login/Lombiq.Hosting.Tenants.Admin.Login.csproj b/Lombiq.Hosting.Tenants.Admin.Login/Lombiq.Hosting.Tenants.Admin.Login.csproj index 1ff9b7c0..1383759b 100644 --- a/Lombiq.Hosting.Tenants.Admin.Login/Lombiq.Hosting.Tenants.Admin.Login.csproj +++ b/Lombiq.Hosting.Tenants.Admin.Login/Lombiq.Hosting.Tenants.Admin.Login.csproj @@ -45,7 +45,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj index 0081e63c..9b9e8346 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj @@ -33,7 +33,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj index b3773132..aabbb436 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj @@ -52,7 +52,7 @@ - - + + diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj b/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj index 648ece77..87f66110 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj b/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj index 9fb74457..095db940 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj @@ -33,7 +33,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard/Lombiq.Hosting.Tenants.FeaturesGuard.csproj b/Lombiq.Hosting.Tenants.FeaturesGuard/Lombiq.Hosting.Tenants.FeaturesGuard.csproj index 2522734d..514f3ea4 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard/Lombiq.Hosting.Tenants.FeaturesGuard.csproj +++ b/Lombiq.Hosting.Tenants.FeaturesGuard/Lombiq.Hosting.Tenants.FeaturesGuard.csproj @@ -47,8 +47,8 @@ - - + + diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj index 16556b4e..aace13ec 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj b/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj index f75d1ad9..2b10d2c3 100644 --- a/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.Maintenance/Lombiq.Hosting.Tenants.Maintenance.csproj b/Lombiq.Hosting.Tenants.Maintenance/Lombiq.Hosting.Tenants.Maintenance.csproj index 58930014..d276f37c 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Lombiq.Hosting.Tenants.Maintenance.csproj +++ b/Lombiq.Hosting.Tenants.Maintenance/Lombiq.Hosting.Tenants.Maintenance.csproj @@ -50,8 +50,8 @@ - - + + diff --git a/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj b/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj index b6f0a3d1..28da6b8b 100644 --- a/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.Management/Lombiq.Hosting.Tenants.Management.csproj b/Lombiq.Hosting.Tenants.Management/Lombiq.Hosting.Tenants.Management.csproj index 3adc713b..c807d3c8 100644 --- a/Lombiq.Hosting.Tenants.Management/Lombiq.Hosting.Tenants.Management.csproj +++ b/Lombiq.Hosting.Tenants.Management/Lombiq.Hosting.Tenants.Management.csproj @@ -45,7 +45,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj index 601004d5..65c04e0a 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj @@ -33,7 +33,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Lombiq.Hosting.Tenants.MediaStorageManagement.csproj b/Lombiq.Hosting.Tenants.MediaStorageManagement/Lombiq.Hosting.Tenants.MediaStorageManagement.csproj index 30006ef3..94ff1792 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Lombiq.Hosting.Tenants.MediaStorageManagement.csproj +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Lombiq.Hosting.Tenants.MediaStorageManagement.csproj @@ -46,7 +46,7 @@ - + From aab34c38400e84d7746c2c1e1918386742f64af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sat, 17 Feb 2024 10:53:33 +0100 Subject: [PATCH 19/23] Using alpha. --- .../Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj index aabbb436..79fd9c93 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj @@ -53,6 +53,6 @@ - + From 697fae6e8e5edfa80c346bca40f776cbb93da6fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Sun, 18 Feb 2024 14:11:10 +0100 Subject: [PATCH 20/23] Using alphas. --- .../Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj | 2 +- .../Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.Management.Tests.UI.csproj | 2 +- ...ombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj index 9b9e8346..4c3112dd 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj @@ -33,7 +33,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj index 79fd9c93..b1932f2d 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj @@ -53,6 +53,6 @@ - + diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj b/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj index 87f66110..baeb7c9c 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj b/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj index 095db940..f1a34d12 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj @@ -33,7 +33,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj index aace13ec..bf742256 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj b/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj index 2b10d2c3..44e52896 100644 --- a/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj b/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj index 28da6b8b..3a252d66 100644 --- a/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj index 65c04e0a..c836f011 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj @@ -33,7 +33,7 @@ - + From 97cc9463dca5e6a318ce1db5e5bfe371c60f1e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Tue, 20 Feb 2024 10:07:55 +0100 Subject: [PATCH 21/23] Updating UITT alpha. --- .../Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj | 2 +- .../Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.Management.Tests.UI.csproj | 2 +- ...ombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj index 4c3112dd..12ceb31d 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj @@ -33,7 +33,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj index b1932f2d..36f9cc44 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj @@ -53,6 +53,6 @@ - + diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj b/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj index baeb7c9c..57f978cb 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj b/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj index f1a34d12..b9817612 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj @@ -33,7 +33,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj index bf742256..0338d60d 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj b/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj index 44e52896..28a1dc59 100644 --- a/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj b/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj index 3a252d66..535179b7 100644 --- a/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj index c836f011..0778e69b 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj @@ -33,7 +33,7 @@ - + From ef7c66d2e72714f68847e1264433b7cb1c62dfee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Wed, 21 Feb 2024 12:06:00 +0100 Subject: [PATCH 22/23] Using new UITT alpha. --- .../Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj | 2 +- .../Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj | 2 +- .../Lombiq.Hosting.Tenants.Management.Tests.UI.csproj | 2 +- ...ombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj index 12ceb31d..6951047d 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI/Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.csproj @@ -33,7 +33,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj index 36f9cc44..c814c783 100644 --- a/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj +++ b/Lombiq.Hosting.Tenants.EmailQuotaManagement/Lombiq.Hosting.Tenants.EmailQuotaManagement.csproj @@ -53,6 +53,6 @@ - + diff --git a/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj b/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj index 57f978cb..c3e8ec06 100644 --- a/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI/Lombiq.Hosting.Tenants.EnvironmentRobots.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj b/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj index b9817612..d20e51bf 100644 --- a/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI/Lombiq.Hosting.Tenants.FeaturesGuard.Tests.UI.csproj @@ -33,7 +33,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj index 0338d60d..bcc86e5e 100644 --- a/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI/Lombiq.Hosting.Tenants.IdleTenantManagement.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj b/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj index 28a1dc59..4d2fc703 100644 --- a/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.Maintenance.Tests.UI/Lombiq.Hosting.Tenants.Maintenance.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj b/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj index 535179b7..f699d6bd 100644 --- a/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.Management.Tests.UI/Lombiq.Hosting.Tenants.Management.Tests.UI.csproj @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj index 0778e69b..1115e878 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI/Lombiq.Hosting.Tenants.MediaStorageManagement.Tests.UI.csproj @@ -33,7 +33,7 @@ - + From 37cd30cba2dfbbb1eb89a00ae14269abdb5433dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20M=C3=A1rkus?= Date: Wed, 21 Feb 2024 16:24:26 +0100 Subject: [PATCH 23/23] Reverting to dev reference. --- .github/workflows/publish-nuget.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-nuget.yml b/.github/workflows/publish-nuget.yml index 8360fd9e..4b26cfcf 100644 --- a/.github/workflows/publish-nuget.yml +++ b/.github/workflows/publish-nuget.yml @@ -7,6 +7,6 @@ on: jobs: publish-nuget: - uses: Lombiq/GitHub-Actions/.github/workflows/publish-nuget.yml@issue/OSOE-751 + uses: Lombiq/GitHub-Actions/.github/workflows/publish-nuget.yml@dev secrets: API_KEY: ${{ secrets.DEFAULT_NUGET_PUBLISH_API_KEY }}