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

This commit is contained in:
sbwalker 2023-12-19 08:41:36 -05:00
parent edad4e7d35
commit 4cea22d813
2 changed files with 8 additions and 8 deletions

View File

@ -26,13 +26,14 @@ namespace Oqtane.Infrastructure
{ {
Alias alias = null; Alias alias = null;
// does not support mock Alias objects (GetTenant should be used to retrieve a TenantId)
if (_siteState?.Alias != null && _siteState.Alias.AliasId != -1) if (_siteState?.Alias != null && _siteState.Alias.AliasId != -1)
{ {
alias = _siteState.Alias; alias = _siteState.Alias;
} }
else else
{ {
// if there is http context // if there is HttpContext
var httpcontext = _httpContextAccessor.HttpContext; var httpcontext = _httpContextAccessor.HttpContext;
if (httpcontext != null) if (httpcontext != null)
{ {
@ -78,20 +79,19 @@ namespace Oqtane.Infrastructure
return null; return null;
} }
// background processes can set the alias using the SiteState service
public void SetAlias(Alias alias) public void SetAlias(Alias alias)
{ {
// background processes can set the alias using the SiteState service
_siteState.Alias = alias; _siteState.Alias = alias;
} }
public void SetAlias(int tenantId, int siteId) public void SetAlias(int tenantId, int siteId)
{ {
// background processes can set the alias using the SiteState service _siteState.Alias = _aliasRepository.GetAliases().ToList().FirstOrDefault(item => item.TenantId == tenantId && item.SiteId == siteId);
_siteState.Alias = new Alias { TenantId = tenantId, AliasId = -1, SiteId = siteId };
} }
public void SetTenant(int tenantId) 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 }; _siteState.Alias = new Alias { TenantId = tenantId, AliasId = -1, SiteId = -1 };
} }
} }

View File

@ -46,7 +46,7 @@ namespace Oqtane.Models
{ {
get get
{ {
if (Name.Contains("/")) if (Name != null && Name.Contains("/"))
{ {
return Name.Substring(Name.IndexOf("/") + 1); return Name.Substring(Name.IndexOf("/") + 1);
} }
@ -58,7 +58,7 @@ namespace Oqtane.Models
} }
/// <summary> /// <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> /// </summary>
[NotMapped] [NotMapped]
public string SiteKey public string SiteKey