Skip to content

Commit

Permalink
Merge pull request #78 from Lombiq/issue/LMBQ-180
Browse files Browse the repository at this point in the history
LMBQ-180: Extending options with custom name-url config
  • Loading branch information
DemeSzabolcs authored Jul 18, 2023
2 parents 56a6eed + e7cde37 commit 1afa25a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
21 changes: 17 additions & 4 deletions Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using OrchardCore.Environment.Shell;
using System.Collections.Generic;
using System.Linq;

namespace Lombiq.Hosting.Tenants.Maintenance.Helpers;

Expand All @@ -13,11 +15,22 @@ public static string ReplaceTenantName(string url, string tenantName) =>
public static string GetEvaluatedValueForTenant(
string valueForDefaultTenant,
string valueForAnyTenant,
ShellSettings shellSettings)
ShellSettings shellSettings,
IDictionary<string, string> valueForTenantByName = null)
{
var evaluatedValue = !string.IsNullOrEmpty(valueForAnyTenant)
? ReplaceTenantName(valueForAnyTenant, shellSettings.Name)
: string.Empty;
var evaluatedValue = string.Empty;

if (!string.IsNullOrEmpty(valueForAnyTenant))
{
evaluatedValue = ReplaceTenantName(valueForAnyTenant, shellSettings.Name);
}
else if (valueForTenantByName?.Any() == true)
{
foreach (var pair in valueForTenantByName)
{
if (pair.Key == shellSettings.Name) evaluatedValue = pair.Value;
}
}

return shellSettings.IsDefaultShell() ? valueForDefaultTenant : evaluatedValue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System.Collections.Generic;

namespace Lombiq.Hosting.Tenants.Maintenance.Maintenance.UpdateSiteUrl;

public class UpdateSiteUrlMaintenanceOptions
{
public bool IsEnabled { get; set; }
public string DefaultTenantSiteUrl { get; set; }
public string SiteUrl { get; set; }
public IDictionary<string, string> SiteUrlFromTenantName { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context)
siteSettings.BaseUrl = TenantUrlHelpers.GetEvaluatedValueForTenant(
_options.Value.DefaultTenantSiteUrl,
_options.Value.SiteUrl,
_shellSettings);
_shellSettings,
_options.Value.SiteUrlFromTenantName);

await _siteService.UpdateSiteSettingsAsync(siteSettings);
}
Expand Down
19 changes: 19 additions & 0 deletions Lombiq.Hosting.Tenants.Maintenance/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ The following configuration options are available to set the site URL:

**NOTE**: The `{TenantName}` placeholder will be replaced with the actual tenant name automatically.

Defining each tenant's URL separately is also an option, in this case, you have to use the `SiteUrlFromTenantName` property instead of `SiteUrl` and add your tenants' name and URL:

```json
{
"OrchardCore": {
"Lombiq_Hosting_Tenants_Maintenance": {
"UpdateSiteUrl": {
"IsEnabled": true,
"DefaultTenantSiteUrl": "https://domain.com",
"SiteUrlFromTenantName": {
"Tenant1": "https://domain.com/custom-url",
"Tenant2": "https://custom-domain.com"
}
}
}
}
}
```

### `Lombiq.Hosting.Tenants.Maintenance.UpdateShellRequestUrls`

It's a maintenance task that updates the shell's request URLs in each tenant's shell settings based on the app configuration. It is available only for the default tenant.
Expand Down

0 comments on commit 1afa25a

Please sign in to comment.