From c7f6d511688f0ae459640dc5765c3f8e4f93080c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20Bartha?= Date: Thu, 18 May 2023 14:15:29 +0200 Subject: [PATCH 1/2] Adding DefaultShellRequestUrlPrefix --- .../Helpers/TenantUrlHelpers.cs | 16 ++++++++-------- .../UpdateShellRequestUrlMaintenanceOptions.cs | 1 + .../UpdateShellRequestUrlsMaintenanceProvider.cs | 7 ++++--- .../UpdateSiteUrlMaintenanceProvider.cs | 2 +- Lombiq.Hosting.Tenants.Maintenance/Readme.md | 1 + 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs b/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs index 7f7a214a..45ccbaca 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs @@ -10,16 +10,16 @@ public static string ReplaceTenantName(string url, string tenantName) => url?.Replace("{TenantName}", tenantName.ToLowerInvariant()); #pragma warning restore CA1308 // Normalize strings to uppercase - public static string GetTenantUrl(string urlForDefaultTenant, string urlForAnyTenant, ShellSettings shellSettings) + public static string GetEvaluatedValueForTenant( + string valueForDefaultTenant, + string valueForAnyTenant, + ShellSettings shellSettings) { - var evaluatedRequestUrl = !string.IsNullOrEmpty(urlForAnyTenant) - ? ReplaceTenantName(urlForAnyTenant, shellSettings.Name) + var evaluatedValue = !string.IsNullOrEmpty(valueForAnyTenant) + ? ReplaceTenantName(valueForAnyTenant, shellSettings.Name) : string.Empty; - var defaultShellRequestUrl = - string.IsNullOrEmpty(urlForDefaultTenant) - ? evaluatedRequestUrl - : urlForDefaultTenant; + var evaluatedValueForDefaultTenant = valueForDefaultTenant ?? evaluatedValue; - return shellSettings.IsDefaultShell() ? defaultShellRequestUrl : evaluatedRequestUrl; + return shellSettings.IsDefaultShell() ? evaluatedValueForDefaultTenant : evaluatedValue; } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlMaintenanceOptions.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlMaintenanceOptions.cs index 4f23e550..f73f4318 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlMaintenanceOptions.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlMaintenanceOptions.cs @@ -6,4 +6,5 @@ public class UpdateShellRequestUrlMaintenanceOptions public string DefaultShellRequestUrl { get; set; } public string RequestUrl { get; set; } public string RequestUrlPrefix { get; set; } + public string DefaultShellRequestUrlPrefix { get; set; } } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs index 2f5c7e53..503db90a 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateShellRequestUrl/UpdateShellRequestUrlsMaintenanceProvider.cs @@ -34,13 +34,14 @@ public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) var allShellSettings = await _shellSettingsManager.LoadSettingsAsync(); foreach (var shellSettings in allShellSettings) { - shellSettings.RequestUrlHost = TenantUrlHelpers.GetTenantUrl( + shellSettings.RequestUrlHost = TenantUrlHelpers.GetEvaluatedValueForTenant( _options.Value.DefaultShellRequestUrl, _options.Value.RequestUrl, shellSettings); - shellSettings.RequestUrlPrefix = TenantUrlHelpers.ReplaceTenantName( + shellSettings.RequestUrlPrefix = TenantUrlHelpers.GetEvaluatedValueForTenant( + _options.Value.DefaultShellRequestUrlPrefix, _options.Value.RequestUrlPrefix, - shellSettings.Name); + shellSettings); await _shellSettingsManager.SaveSettingsAsync(shellSettings); } diff --git a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs index a732507c..68931684 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Maintenance/UpdateSiteUrl/UpdateSiteUrlMaintenanceProvider.cs @@ -31,7 +31,7 @@ public override Task ShouldExecuteAsync(MaintenanceTaskExecutionContext co public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context) { var siteSettings = await _siteService.LoadSiteSettingsAsync(); - siteSettings.BaseUrl = TenantUrlHelpers.GetTenantUrl( + siteSettings.BaseUrl = TenantUrlHelpers.GetEvaluatedValueForTenant( _options.Value.DefaultTenantSiteUrl, _options.Value.SiteUrl, _shellSettings); diff --git a/Lombiq.Hosting.Tenants.Maintenance/Readme.md b/Lombiq.Hosting.Tenants.Maintenance/Readme.md index 1c4decf0..4ace2cee 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Readme.md +++ b/Lombiq.Hosting.Tenants.Maintenance/Readme.md @@ -66,6 +66,7 @@ The following configuration options are available to set the shell request URLs: "IsEnabled": true, "DefaultShellRequestUrl": "domain.com", "RequestUrl": "{TenantName}.domain.com", + "DefaultShellRequestUrlPrefix": "", "RequestUrlPrefix": "{TenantName}" } } From 3ac6cc4d61dbb932c09e2d192866c008101c9430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20Bartha?= Date: Thu, 18 May 2023 15:03:14 +0200 Subject: [PATCH 2/2] Fixing logic --- Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs b/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs index 45ccbaca..9da8aaf5 100644 --- a/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs +++ b/Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs @@ -18,8 +18,7 @@ public static string GetEvaluatedValueForTenant( var evaluatedValue = !string.IsNullOrEmpty(valueForAnyTenant) ? ReplaceTenantName(valueForAnyTenant, shellSettings.Name) : string.Empty; - var evaluatedValueForDefaultTenant = valueForDefaultTenant ?? evaluatedValue; - return shellSettings.IsDefaultShell() ? evaluatedValueForDefaultTenant : evaluatedValue; + return shellSettings.IsDefaultShell() ? valueForDefaultTenant : evaluatedValue; } }