factor out auth constants, remove TAlias is Alias is not an extensible type, improve SiteOptions cache clearing, improve principal validation, localization improvements
This commit is contained in:
		| @ -20,7 +20,9 @@ namespace Oqtane.Infrastructure | ||||
|         { | ||||
|             // check if framework is installed | ||||
|             var config = context.RequestServices.GetService(typeof(IConfigManager)) as IConfigManager; | ||||
|             if (config.IsInstalled()) | ||||
|             string path = context.Request.Path.ToString(); | ||||
|  | ||||
|             if (config.IsInstalled() && !path.StartsWith("/_blazor")) | ||||
|             { | ||||
|                 // get alias (note that this also sets SiteState.Alias) | ||||
|                 var tenantManager = context.RequestServices.GetService(typeof(ITenantManager)) as ITenantManager; | ||||
| @ -28,7 +30,7 @@ namespace Oqtane.Infrastructure | ||||
|  | ||||
|                 if (alias != null) | ||||
|                 { | ||||
|                     // get site settings | ||||
|                     // add site settings to alias | ||||
|                     var cache = context.RequestServices.GetService(typeof(IMemoryCache)) as IMemoryCache; | ||||
|                     alias.SiteSettings = cache.GetOrCreate("sitesettings:" + alias.SiteKey, entry => | ||||
|                     { | ||||
| @ -36,13 +38,14 @@ namespace Oqtane.Infrastructure | ||||
|                         return settingRepository.GetSettings(EntityNames.Site, alias.SiteId) | ||||
|                             .ToDictionary(setting => setting.SettingName, setting => setting.SettingValue); | ||||
|                     }); | ||||
|                     // save alias in HttpContext | ||||
|                     // save alias in HttpContext for server-side usage | ||||
|                     context.Items.Add(Constants.HttpContextAliasKey, alias); | ||||
|                     // remove site settings so they are not available client-side | ||||
|                     alias.SiteSettings = null; | ||||
|  | ||||
|                     // rewrite path by removing alias path prefix from api and pages requests (for consistent routing) | ||||
|                     if (!string.IsNullOrEmpty(alias.Path)) | ||||
|                     { | ||||
|                         string path = context.Request.Path.ToString(); | ||||
|                         if (path.StartsWith("/" + alias.Path) && (path.Contains("/api/") || path.Contains("/pages/"))) | ||||
|                         { | ||||
|                             context.Request.Path = path.Replace("/" + alias.Path, ""); | ||||
|  | ||||
| @ -1,12 +1,10 @@ | ||||
|  | ||||
| using Oqtane.Models; | ||||
|  | ||||
| namespace Oqtane.Infrastructure | ||||
| { | ||||
|     public interface ISiteOptions<TOptions, TAlias> | ||||
|     public interface ISiteOptions<TOptions> | ||||
|         where TOptions : class, new() | ||||
|         where TAlias : class, IAlias, new() | ||||
|     { | ||||
|         void Configure(TOptions options, TAlias siteOptions); | ||||
|         void Configure(TOptions options, Alias alias); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -3,20 +3,19 @@ using Oqtane.Models; | ||||
|  | ||||
| namespace Oqtane.Infrastructure | ||||
| { | ||||
|     public class SiteOptions<TOptions, TAlias> : ISiteOptions<TOptions, TAlias> | ||||
|     public class SiteOptions<TOptions> : ISiteOptions<TOptions> | ||||
|         where TOptions : class, new() | ||||
|         where TAlias : class, IAlias, new() | ||||
|     { | ||||
|         private readonly Action<TOptions, TAlias> configureOptions; | ||||
|         private readonly Action<TOptions, Alias> configureOptions; | ||||
|  | ||||
|         public SiteOptions(Action<TOptions, TAlias> configureOptions) | ||||
|         public SiteOptions(Action<TOptions, Alias> configureOptions) | ||||
|         { | ||||
|             this.configureOptions = configureOptions; | ||||
|         } | ||||
|  | ||||
|         public void Configure(TOptions options, TAlias siteOptions) | ||||
|         public void Configure(TOptions options, Alias alias) | ||||
|         { | ||||
|             configureOptions(options, siteOptions); | ||||
|             configureOptions(options, alias); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -5,9 +5,8 @@ using Oqtane.Models; | ||||
|  | ||||
| namespace Oqtane.Infrastructure | ||||
| { | ||||
|     public class SiteOptionsCache<TOptions, TAlias> : IOptionsMonitorCache<TOptions> | ||||
|         where TOptions : class | ||||
|         where TAlias : class, IAlias, new() | ||||
|     public class SiteOptionsCache<TOptions> : IOptionsMonitorCache<TOptions> | ||||
|         where TOptions : class, new() | ||||
|     { | ||||
|         private readonly IAliasAccessor _aliasAccessor; | ||||
|         private readonly ConcurrentDictionary<string, IOptionsMonitorCache<TOptions>> map = new ConcurrentDictionary<string, IOptionsMonitorCache<TOptions>>(); | ||||
|  | ||||
| @ -1,25 +1,21 @@ | ||||
| using System.Collections.Generic; | ||||
| using Microsoft.Extensions.Options; | ||||
| using Oqtane.Models; | ||||
|  | ||||
| namespace Oqtane.Infrastructure | ||||
| { | ||||
|     public class SiteOptionsFactory<TOptions, TAlias> : IOptionsFactory<TOptions> | ||||
|     public class SiteOptionsFactory<TOptions> : IOptionsFactory<TOptions> | ||||
|         where TOptions : class, new() | ||||
|         where TAlias : class, IAlias, new() | ||||
|     { | ||||
|         private readonly IConfigureOptions<TOptions>[] _configureOptions; | ||||
|         private readonly IPostConfigureOptions<TOptions>[] _postConfigureOptions; | ||||
|         private readonly IValidateOptions<TOptions>[] _validations; | ||||
|         private readonly ISiteOptions<TOptions, TAlias>[] _siteOptions; | ||||
|         private readonly ISiteOptions<TOptions>[] _siteOptions; | ||||
|         private readonly IAliasAccessor _aliasAccessor; | ||||
|  | ||||
|         public SiteOptionsFactory(IEnumerable<IConfigureOptions<TOptions>> configureOptions, IEnumerable<IPostConfigureOptions<TOptions>> postConfigureOptions, IEnumerable<IValidateOptions<TOptions>> validations, IEnumerable<ISiteOptions<TOptions, TAlias>> siteOptions, IAliasAccessor aliasAccessor) | ||||
|         public SiteOptionsFactory(IEnumerable<IConfigureOptions<TOptions>> configureOptions, IEnumerable<IPostConfigureOptions<TOptions>> postConfigureOptions, IEnumerable<ISiteOptions<TOptions>> siteOptions, IAliasAccessor aliasAccessor) | ||||
|         { | ||||
|             _configureOptions = configureOptions as IConfigureOptions<TOptions>[] ?? new List<IConfigureOptions<TOptions>>(configureOptions).ToArray(); | ||||
|             _postConfigureOptions = postConfigureOptions as IPostConfigureOptions<TOptions>[] ?? new List<IPostConfigureOptions<TOptions>>(postConfigureOptions).ToArray(); | ||||
|             _validations = validations as IValidateOptions<TOptions>[] ?? new List<IValidateOptions<TOptions>>(validations).ToArray(); | ||||
|             _siteOptions = siteOptions as ISiteOptions<TOptions, TAlias>[] ?? new List<ISiteOptions<TOptions, TAlias>>(siteOptions).ToArray(); | ||||
|             _siteOptions = siteOptions as ISiteOptions<TOptions>[] ?? new List<ISiteOptions<TOptions>>(siteOptions).ToArray(); | ||||
|             _aliasAccessor = aliasAccessor; | ||||
|          } | ||||
|  | ||||
| @ -44,7 +40,7 @@ namespace Oqtane.Infrastructure | ||||
|             { | ||||
|                 foreach (var siteOption in _siteOptions) | ||||
|                 { | ||||
|                     siteOption.Configure(options, _aliasAccessor.Alias as TAlias); | ||||
|                     siteOption.Configure(options, _aliasAccessor.Alias); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker