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/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..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 @@ -1,7 +1,7 @@ - net6.0 + net8.0 true $(DefaultItemExcludes);.git*;node_modules\**;Tests\** @@ -34,10 +34,10 @@ - - - - + + + + @@ -45,7 +45,7 @@ - + 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.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..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 @@ -1,7 +1,7 @@ - net6.0 + net8.0 $(DefaultItemExcludes);.git*;node_modules\** @@ -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 3f0ae065..c814c783 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 @@ - - - - - - - - + + + + + + + + - + @@ -52,7 +52,7 @@ - - + + 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.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..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 @@ -1,7 +1,7 @@ - net6.0 + net8.0 @@ -21,7 +21,7 @@ - + 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..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 @@ -1,7 +1,7 @@ - net6.0 + net8.0 $(DefaultItemExcludes);.git*;node_modules\** @@ -33,7 +33,7 @@ - + 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/Lombiq.Hosting.Tenants.FeaturesGuard.csproj b/Lombiq.Hosting.Tenants.FeaturesGuard/Lombiq.Hosting.Tenants.FeaturesGuard.csproj index bec3934e..514f3ea4 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 @@ - - - - - + + + + + @@ -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 3d8aae8a..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 @@ -1,7 +1,7 @@ - net6.0 + net8.0 @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.IdleTenantManagement/Lombiq.Hosting.Tenants.IdleTenantManagement.csproj b/Lombiq.Hosting.Tenants.IdleTenantManagement/Lombiq.Hosting.Tenants.IdleTenantManagement.csproj index d223572c..6bad9d1e 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\** @@ -23,10 +23,10 @@ - - - - + + + + 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..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 @@ -1,7 +1,7 @@ - net6.0 + net8.0 @@ -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 a87b0eb6..d276f37c 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 @@ - - - - - - - + + + + + + + @@ -50,8 +50,8 @@ - - + + 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.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..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 @@ -1,7 +1,7 @@ - net6.0 + net8.0 @@ -21,7 +21,7 @@ - + diff --git a/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs b/Lombiq.Hosting.Tenants.Management/Controllers/ShellSettingsEditorController.cs index 8b4df56e..4e0d9a0a 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; @@ -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,27 +93,10 @@ 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) = - 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( 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 c028278a..907b44b9 100644 --- a/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs +++ b/Lombiq.Hosting.Tenants.Management/Filters/ForbiddenTenantsFilter.cs @@ -50,11 +50,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(); + var unacceptableHostnames = hosts.Where(hostname => forbiddenRequestUrlHosts.Contains(hostname)).ToList(); - unacceptableHostnames.AddRange(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/Lombiq.Hosting.Tenants.Management.csproj b/Lombiq.Hosting.Tenants.Management/Lombiq.Hosting.Tenants.Management.csproj index 43140fdf..c807d3c8 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 @@ - - - + + + @@ -45,7 +45,7 @@ - + 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.Management/Views/ShellSettingsEditor.cshtml b/Lombiq.Hosting.Tenants.Management/Views/ShellSettingsEditor.cshtml index 03d9dbf7..0a20b765 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."] @@ -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(); 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..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 @@ -1,7 +1,7 @@ - net6.0 + net8.0 $(DefaultItemExcludes);.git*;node_modules\** @@ -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 30e9a6a7..94ff1792 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 @@ - - - - + + + + @@ -46,7 +46,7 @@ - + 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", - } + ] )]