From 4cea22d813513aa8e3222118d26ac368d648d7a1 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Tue, 19 Dec 2023 08:41:36 -0500 Subject: [PATCH] add defensive logic to Alias.Path, improve new GetAlias method --- Oqtane.Server/Infrastructure/TenantManager.cs | 12 ++++++------ Oqtane.Shared/Models/Alias.cs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Oqtane.Server/Infrastructure/TenantManager.cs b/Oqtane.Server/Infrastructure/TenantManager.cs index 96af4e05..92191f4e 100644 --- a/Oqtane.Server/Infrastructure/TenantManager.cs +++ b/Oqtane.Server/Infrastructure/TenantManager.cs @@ -26,13 +26,14 @@ namespace Oqtane.Infrastructure { 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) { @@ -78,20 +79,19 @@ namespace Oqtane.Infrastructure 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 }; } } diff --git a/Oqtane.Shared/Models/Alias.cs b/Oqtane.Shared/Models/Alias.cs index 17ec6e80..1cc800c0 100644 --- a/Oqtane.Shared/Models/Alias.cs +++ b/Oqtane.Shared/Models/Alias.cs @@ -46,7 +46,7 @@ namespace Oqtane.Models { get { - if (Name.Contains("/")) + if (Name != null && Name.Contains("/")) { return Name.Substring(Name.IndexOf("/") + 1); } @@ -58,7 +58,7 @@ namespace Oqtane.Models } /// - /// 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...) /// [NotMapped] public string SiteKey