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

add defensive logic to Alias.Path, improve new GetAlias method #3575

Merged
merged 1 commit into from
Dec 19, 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
12 changes: 6 additions & 6 deletions Oqtane.Server/Infrastructure/TenantManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ public Alias GetAlias()
{
Alias alias = null;

if (_siteState?.Alias != null && _siteState.Alias.AliasId != -1)
// does not support mock Alias objects (GetTenant should be used to retrieve a TenantId)
if (_siteState?.Alias != null && _siteState.Alias.AliasId != -1)
{
alias = _siteState.Alias;
}
else
{
// if there is http context
// if there is HttpContext
var httpcontext = _httpContextAccessor.HttpContext;
if (httpcontext != null)
{
Expand Down Expand Up @@ -78,20 +79,19 @@ public Tenant GetTenant()
return null;
}

// background processes can set the alias using the SiteState service
public void SetAlias(Alias alias)
{
// background processes can set the alias using the SiteState service
_siteState.Alias = alias;
}

public void SetAlias(int tenantId, int siteId)
{
// background processes can set the alias using the SiteState service
_siteState.Alias = new Alias { TenantId = tenantId, AliasId = -1, SiteId = siteId };
_siteState.Alias = _aliasRepository.GetAliases().ToList().FirstOrDefault(item => item.TenantId == tenantId && item.SiteId == siteId);
}

public void SetTenant(int tenantId)
{
// background processes can set the alias using the SiteState service
_siteState.Alias = new Alias { TenantId = tenantId, AliasId = -1, SiteId = -1 };
}
}
Expand Down
4 changes: 2 additions & 2 deletions Oqtane.Shared/Models/Alias.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public string Path
{
get
{
if (Name.Contains("/"))
if (Name != null && Name.Contains("/"))
{
return Name.Substring(Name.IndexOf("/") + 1);
}
Expand All @@ -58,7 +58,7 @@ public string Path
}

/// <summary>
/// Unique key used for identifying a site within a runtime process (ie. cache, etc...)
/// Unique key used for identifying a site within a runtime process (ie. cache, file system, etc...)
/// </summary>
[NotMapped]
public string SiteKey
Expand Down