Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LMBQ-180: Extending options with custom name-url config #78

Merged
merged 6 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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