optimizing tenant resolution and routing
This commit is contained in:
@ -14,7 +14,7 @@ using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class AliasController : Controller
|
||||
{
|
||||
private readonly IAliasRepository _aliases;
|
||||
@ -46,17 +46,16 @@ namespace Oqtane.Controllers
|
||||
return _aliases.GetAlias(id);
|
||||
}
|
||||
|
||||
// GET api/<controller>/name/xxx?sync=yyyyMMddHHmmssfff
|
||||
[HttpGet("name/{**name}")]
|
||||
public Alias Get(string name, string sync)
|
||||
// GET api/<controller>/name/?path=xxx&sync=yyyyMMddHHmmssfff
|
||||
[HttpGet("name")]
|
||||
public Alias Get(string path, string sync)
|
||||
{
|
||||
Alias alias = null;
|
||||
|
||||
if (_accessor.HttpContext != null)
|
||||
{
|
||||
name = (name == "~") ? "" : name;
|
||||
name = _accessor.HttpContext.Request.Host.Value + "/" + WebUtility.UrlDecode(name);
|
||||
alias = _aliases.GetAlias(name);
|
||||
path = _accessor.HttpContext.Request.Host.Value + "/" + WebUtility.UrlDecode(path);
|
||||
alias = _aliases.GetAlias(path);
|
||||
}
|
||||
|
||||
// get sync events
|
||||
|
@ -16,30 +16,27 @@ using System.Net;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository;
|
||||
using Microsoft.AspNetCore.Routing.Constraints;
|
||||
using Oqtane.Extensions;
|
||||
|
||||
// ReSharper disable StringIndexOfIsCultureSpecific.1
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class FileController : Controller
|
||||
{
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
private readonly IFileRepository _files;
|
||||
private readonly IFolderRepository _folders;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly ITenantResolver _tenants;
|
||||
private readonly ILogManager _logger;
|
||||
|
||||
public FileController(IWebHostEnvironment environment, IFileRepository files, IFolderRepository folders, IUserPermissions userPermissions, ITenantResolver tenants, ILogManager logger)
|
||||
public FileController(IWebHostEnvironment environment, IFileRepository files, IFolderRepository folders, IUserPermissions userPermissions, ILogManager logger)
|
||||
{
|
||||
_environment = environment;
|
||||
_files = files;
|
||||
_folders = folders;
|
||||
_userPermissions = userPermissions;
|
||||
_tenants = tenants;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
@ -15,21 +15,21 @@ using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class FolderController : Controller
|
||||
{
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
private readonly IFolderRepository _folders;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly ITenantResolver _tenants;
|
||||
private readonly ITenantManager _tenantManager;
|
||||
private readonly ILogManager _logger;
|
||||
|
||||
public FolderController(IWebHostEnvironment environment, IFolderRepository folders, IUserPermissions userPermissions, ITenantResolver tenants, ILogManager logger)
|
||||
public FolderController(IWebHostEnvironment environment, IFolderRepository folders, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger)
|
||||
{
|
||||
_environment = environment;
|
||||
_folders = folders;
|
||||
_userPermissions = userPermissions;
|
||||
_tenants = tenants;
|
||||
_tenantManager = tenantManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ namespace Oqtane.Controllers
|
||||
|
||||
private string GetFolderPath(Folder folder)
|
||||
{
|
||||
return Utilities.PathCombine(_environment.ContentRootPath, "Content", "Tenants", _tenants.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path);
|
||||
return Utilities.PathCombine(_environment.ContentRootPath, "Content", "Tenants", _tenantManager.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,11 +12,10 @@ using Oqtane.Modules;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.Themes;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class InstallationController : Controller
|
||||
{
|
||||
private readonly IConfigurationRoot _config;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Oqtane.Models;
|
||||
@ -12,7 +12,7 @@ using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class JobController : Controller
|
||||
{
|
||||
private readonly IJobRepository _jobs;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Oqtane.Enums;
|
||||
@ -9,7 +9,7 @@ using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class JobLogController : Controller
|
||||
{
|
||||
private readonly IJobLogRepository _jobLogs;
|
||||
|
@ -9,7 +9,7 @@ using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class LanguageController : Controller
|
||||
{
|
||||
private readonly ILanguageRepository _languages;
|
||||
|
@ -9,7 +9,7 @@ using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class LocalizationController : Controller
|
||||
{
|
||||
private readonly ILocalizationManager _localizationManager;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@ -9,7 +9,7 @@ using Oqtane.Shared;
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class LogController : Controller
|
||||
{
|
||||
private readonly ILogManager _logger;
|
||||
|
@ -11,7 +11,7 @@ using Oqtane.Security;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class ModuleController : Controller
|
||||
{
|
||||
private readonly IModuleRepository _modules;
|
||||
@ -20,11 +20,11 @@ namespace Oqtane.Controllers
|
||||
private readonly IModuleDefinitionRepository _moduleDefinitions;
|
||||
private readonly ISettingRepository _settings;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly ITenantResolver _tenants;
|
||||
private readonly ISyncManager _syncManager;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public ModuleController(IModuleRepository modules, IPageModuleRepository pageModules, IPageRepository pages, IModuleDefinitionRepository moduleDefinitions, ISettingRepository settings, IUserPermissions userPermissions, ITenantResolver tenants, ISyncManager syncManager, ILogManager logger)
|
||||
public ModuleController(IModuleRepository modules, IPageModuleRepository pageModules, IPageRepository pages, IModuleDefinitionRepository moduleDefinitions, ISettingRepository settings, IUserPermissions userPermissions, ITenantManager tenantManager, ISyncManager syncManager, ILogManager logger)
|
||||
{
|
||||
_modules = modules;
|
||||
_pageModules = pageModules;
|
||||
@ -32,9 +32,9 @@ namespace Oqtane.Controllers
|
||||
_moduleDefinitions = moduleDefinitions;
|
||||
_settings = settings;
|
||||
_userPermissions = userPermissions;
|
||||
_tenants = tenants;
|
||||
_syncManager = syncManager;
|
||||
_logger = logger;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
// GET: api/<controller>?siteid=x
|
||||
@ -108,7 +108,7 @@ namespace Oqtane.Controllers
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, module.PageId, PermissionNames.Edit))
|
||||
{
|
||||
module = _modules.AddModule(module);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, _tenants.GetAlias().SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Module Added {Module}", module);
|
||||
}
|
||||
else
|
||||
@ -142,7 +142,7 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, _tenants.GetAlias().SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -161,7 +161,7 @@ namespace Oqtane.Controllers
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Module, id, PermissionNames.Edit))
|
||||
{
|
||||
_modules.DeleteModule(id);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, _tenants.GetAlias().SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Deleted {ModuleId}", id);
|
||||
}
|
||||
else
|
||||
|
@ -17,7 +17,7 @@ using System.Text.Json;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class ModuleDefinitionController : Controller
|
||||
{
|
||||
private readonly IModuleDefinitionRepository _moduleDefinitions;
|
||||
|
@ -10,7 +10,7 @@ using Oqtane.Security;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class NotificationController : Controller
|
||||
{
|
||||
private readonly INotificationRepository _notifications;
|
||||
|
@ -16,7 +16,7 @@ using Oqtane.Enums;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class PackageController : Controller
|
||||
{
|
||||
private readonly IInstallationManager _installationManager;
|
||||
|
@ -13,7 +13,7 @@ using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class PageController : Controller
|
||||
{
|
||||
private readonly IPageRepository _pages;
|
||||
@ -21,20 +21,20 @@ namespace Oqtane.Controllers
|
||||
private readonly IPageModuleRepository _pageModules;
|
||||
private readonly ISettingRepository _settings;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly ITenantResolver _tenants;
|
||||
private readonly ISyncManager _syncManager;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public PageController(IPageRepository pages, IModuleRepository modules, IPageModuleRepository pageModules, ISettingRepository settings, IUserPermissions userPermissions, ITenantResolver tenants, ISyncManager syncManager, ILogManager logger)
|
||||
public PageController(IPageRepository pages, IModuleRepository modules, IPageModuleRepository pageModules, ISettingRepository settings, IUserPermissions userPermissions, ITenantManager tenantManager, ISyncManager syncManager, ILogManager logger)
|
||||
{
|
||||
_pages = pages;
|
||||
_modules = modules;
|
||||
_pageModules = pageModules;
|
||||
_settings = settings;
|
||||
_userPermissions = userPermissions;
|
||||
_tenants = tenants;
|
||||
_syncManager = syncManager;
|
||||
_logger = logger;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
// GET: api/<controller>?siteid=x
|
||||
@ -132,7 +132,7 @@ namespace Oqtane.Controllers
|
||||
if (_userPermissions.IsAuthorized(User,PermissionNames.Edit, permissions))
|
||||
{
|
||||
page = _pages.AddPage(page);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, page.SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, page.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Added {Page}", page);
|
||||
|
||||
if (!page.Path.StartsWith("admin/"))
|
||||
@ -183,7 +183,7 @@ namespace Oqtane.Controllers
|
||||
page.IsPersonalizable = false;
|
||||
page.UserId = int.Parse(userid);
|
||||
page = _pages.AddPage(page);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, page.SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, page.SiteId);
|
||||
|
||||
// copy modules
|
||||
List<PageModule> pagemodules = _pageModules.GetPageModules(page.SiteId).ToList();
|
||||
@ -228,7 +228,7 @@ namespace Oqtane.Controllers
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, page.PageId, PermissionNames.Edit))
|
||||
{
|
||||
page = _pages.UpdatePage(page);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, page.SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, page.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Updated {Page}", page);
|
||||
}
|
||||
else
|
||||
@ -258,7 +258,7 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
order += 2;
|
||||
}
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, siteid);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, siteid);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Order Updated {SiteId} {PageId} {ParentId}", siteid, pageid, parentid);
|
||||
}
|
||||
else
|
||||
@ -277,7 +277,7 @@ namespace Oqtane.Controllers
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Page, page.PageId, PermissionNames.Edit))
|
||||
{
|
||||
_pages.DeletePage(page.PageId);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, page.SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, page.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Page Deleted {PageId}", page.PageId);
|
||||
}
|
||||
else
|
||||
|
@ -11,22 +11,22 @@ using Oqtane.Security;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class PageModuleController : Controller
|
||||
{
|
||||
private readonly IPageModuleRepository _pageModules;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly ITenantResolver _tenants;
|
||||
private readonly ISyncManager _syncManager;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public PageModuleController(IPageModuleRepository pageModules, IUserPermissions userPermissions, ITenantResolver tenants, ISyncManager syncManager, ILogManager logger)
|
||||
public PageModuleController(IPageModuleRepository pageModules, IUserPermissions userPermissions, ITenantManager tenantManager, ISyncManager syncManager, ILogManager logger)
|
||||
{
|
||||
_pageModules = pageModules;
|
||||
_userPermissions = userPermissions;
|
||||
_tenants = tenants;
|
||||
_syncManager = syncManager;
|
||||
_logger = logger;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
// GET api/<controller>/5
|
||||
@ -71,7 +71,7 @@ namespace Oqtane.Controllers
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, pageModule.PageId, PermissionNames.Edit))
|
||||
{
|
||||
pageModule = _pageModules.AddPageModule(pageModule);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, _tenants.GetAlias().SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Module Added {PageModule}", pageModule);
|
||||
}
|
||||
else
|
||||
@ -91,7 +91,7 @@ namespace Oqtane.Controllers
|
||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Module, pageModule.ModuleId, PermissionNames.Edit))
|
||||
{
|
||||
pageModule = _pageModules.UpdatePageModule(pageModule);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, _tenants.GetAlias().SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Module Updated {PageModule}", pageModule);
|
||||
}
|
||||
else
|
||||
@ -121,7 +121,7 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
order += 2;
|
||||
}
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, _tenants.GetAlias().SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Module Order Updated {PageId} {Pane}", pageid, pane);
|
||||
}
|
||||
else
|
||||
@ -140,7 +140,7 @@ namespace Oqtane.Controllers
|
||||
if (_userPermissions.IsAuthorized(User, EntityNames.Page, pagemodule.PageId, PermissionNames.Edit))
|
||||
{
|
||||
_pageModules.DeletePageModule(id);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, _tenants.GetAlias().SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Page Module Deleted {PageModuleId}", id);
|
||||
}
|
||||
else
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Oqtane.Enums;
|
||||
@ -9,7 +9,7 @@ using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class ProfileController : Controller
|
||||
{
|
||||
private readonly IProfileRepository _profiles;
|
||||
|
@ -9,7 +9,7 @@ using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class RoleController : Controller
|
||||
{
|
||||
private readonly IRoleRepository _roles;
|
||||
|
@ -10,24 +10,24 @@ using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class SettingController : Controller
|
||||
{
|
||||
private readonly ISettingRepository _settings;
|
||||
private readonly IPageModuleRepository _pageModules;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly ITenantResolver _tenants;
|
||||
private readonly ISyncManager _syncManager;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public SettingController(ISettingRepository settings, IPageModuleRepository pageModules, IUserPermissions userPermissions, ITenantResolver tenants, ISyncManager syncManager, ILogManager logger)
|
||||
public SettingController(ISettingRepository settings, IPageModuleRepository pageModules, IUserPermissions userPermissions, ITenantManager tenantManager, ISyncManager syncManager, ILogManager logger)
|
||||
{
|
||||
_settings = settings;
|
||||
_pageModules = pageModules;
|
||||
_userPermissions = userPermissions;
|
||||
_tenants = tenants;
|
||||
_syncManager = syncManager;
|
||||
_logger = logger;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
// GET: api/<controller>
|
||||
@ -73,7 +73,7 @@ namespace Oqtane.Controllers
|
||||
setting = _settings.AddSetting(setting);
|
||||
if (setting.EntityName == EntityNames.Module)
|
||||
{
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, _tenants.GetAlias().SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
|
||||
}
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Setting Added {Setting}", setting);
|
||||
}
|
||||
@ -95,7 +95,7 @@ namespace Oqtane.Controllers
|
||||
setting = _settings.UpdateSetting(setting);
|
||||
if (setting.EntityName == EntityNames.Module)
|
||||
{
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, _tenants.GetAlias().SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
|
||||
}
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Setting Updated {Setting}", setting);
|
||||
}
|
||||
@ -118,7 +118,7 @@ namespace Oqtane.Controllers
|
||||
_settings.DeleteSetting(id);
|
||||
if (setting.EntityName == EntityNames.Module)
|
||||
{
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, _tenants.GetAlias().SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
|
||||
}
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Setting Deleted {Setting}", setting);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Oqtane.Models;
|
||||
@ -10,20 +10,20 @@ using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class SiteController : Controller
|
||||
{
|
||||
private readonly ISiteRepository _sites;
|
||||
private readonly ITenantResolver _tenants;
|
||||
private readonly ISyncManager _syncManager;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public SiteController(ISiteRepository sites, ITenantResolver tenants, ISyncManager syncManager, ILogManager logger)
|
||||
public SiteController(ISiteRepository sites, ITenantManager tenantManager, ISyncManager syncManager, ILogManager logger)
|
||||
{
|
||||
_sites = sites;
|
||||
_tenants = tenants;
|
||||
_syncManager = syncManager;
|
||||
_logger = logger;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
// GET: api/<controller>
|
||||
@ -52,8 +52,7 @@ namespace Oqtane.Controllers
|
||||
{
|
||||
// provision initial site during installation
|
||||
authorized = true;
|
||||
Tenant tenant = _tenants.GetTenant();
|
||||
site.TenantId = tenant.TenantId;
|
||||
site.TenantId = _alias.TenantId;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -76,7 +75,7 @@ namespace Oqtane.Controllers
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
site = _sites.UpdateSite(site);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.Site, site.SiteId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, site.SiteId);
|
||||
_logger.Log(site.SiteId, LogLevel.Information, this, LogFunction.Update, "Site Updated {Site}", site);
|
||||
}
|
||||
return site;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oqtane.Models;
|
||||
@ -7,7 +7,7 @@ using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class SiteTemplateController : Controller
|
||||
{
|
||||
private readonly ISiteTemplateRepository _siteTemplates;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
@ -11,7 +11,7 @@ using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class SqlController : Controller
|
||||
{
|
||||
private readonly ITenantRepository _tenants;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Shared;
|
||||
@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class SystemController : Controller
|
||||
{
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Oqtane.Models;
|
||||
using System.Collections.Generic;
|
||||
@ -9,7 +9,7 @@ using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class TenantController : Controller
|
||||
{
|
||||
private readonly ITenantRepository _tenants;
|
||||
|
@ -16,7 +16,7 @@ using System.Text.Json;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class ThemeController : Controller
|
||||
{
|
||||
private readonly IThemeRepository _themes;
|
||||
|
@ -18,7 +18,7 @@ using Oqtane.Extensions;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class UserController : Controller
|
||||
{
|
||||
private readonly IUserRepository _users;
|
||||
@ -26,26 +26,26 @@ namespace Oqtane.Controllers
|
||||
private readonly IUserRoleRepository _userRoles;
|
||||
private readonly UserManager<IdentityUser> _identityUserManager;
|
||||
private readonly SignInManager<IdentityUser> _identitySignInManager;
|
||||
private readonly ITenantResolver _tenants;
|
||||
private readonly INotificationRepository _notifications;
|
||||
private readonly IFolderRepository _folders;
|
||||
private readonly ISyncManager _syncManager;
|
||||
private readonly ISiteRepository _sites;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public UserController(IUserRepository users, IRoleRepository roles, IUserRoleRepository userRoles, UserManager<IdentityUser> identityUserManager, SignInManager<IdentityUser> identitySignInManager, ITenantResolver tenants, INotificationRepository notifications, IFolderRepository folders, ISyncManager syncManager, ISiteRepository sites, ILogManager logger)
|
||||
public UserController(IUserRepository users, IRoleRepository roles, IUserRoleRepository userRoles, UserManager<IdentityUser> identityUserManager, SignInManager<IdentityUser> identitySignInManager, ITenantManager tenantManager, INotificationRepository notifications, IFolderRepository folders, ISyncManager syncManager, ISiteRepository sites, ILogManager logger)
|
||||
{
|
||||
_users = users;
|
||||
_roles = roles;
|
||||
_userRoles = userRoles;
|
||||
_identityUserManager = identityUserManager;
|
||||
_identitySignInManager = identitySignInManager;
|
||||
_tenants = tenants;
|
||||
_folders = folders;
|
||||
_notifications = notifications;
|
||||
_syncManager = syncManager;
|
||||
_sites = sites;
|
||||
_logger = logger;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
// GET api/<controller>/5?siteid=x
|
||||
@ -146,7 +146,7 @@ namespace Oqtane.Controllers
|
||||
if (!verified)
|
||||
{
|
||||
string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser);
|
||||
string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
|
||||
string url = HttpContext.Request.Scheme + "://" + _alias.Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
|
||||
string body = "Dear " + user.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!";
|
||||
var notification = new Notification(user.SiteId, null, newUser, "User Account Verification", body, null);
|
||||
_notifications.AddNotification(notification);
|
||||
@ -243,7 +243,7 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
}
|
||||
user = _users.UpdateUser(user);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.User, user.UserId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.User, user.UserId);
|
||||
user.Password = ""; // remove sensitive information
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "User Updated {User}", user);
|
||||
}
|
||||
@ -401,7 +401,7 @@ namespace Oqtane.Controllers
|
||||
if (identityuser != null)
|
||||
{
|
||||
string token = await _identityUserManager.GeneratePasswordResetTokenAsync(identityuser);
|
||||
string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/reset?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
|
||||
string url = HttpContext.Request.Scheme + "://" + _alias.Name + "/reset?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
|
||||
string body = "Dear " + user.DisplayName + ",\n\nPlease Click The Link Displayed Below To Reset Your Password:\n\n" + url + "\n\nThank You!";
|
||||
var notification = new Notification(user.SiteId, null, user, "User Password Reset", body, null);
|
||||
_notifications.AddNotification(notification);
|
||||
|
@ -10,22 +10,22 @@ using System.Linq;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class UserRoleController : Controller
|
||||
{
|
||||
private readonly IUserRoleRepository _userRoles;
|
||||
private readonly IRoleRepository _roles;
|
||||
private readonly ITenantResolver _tenants;
|
||||
private readonly ISyncManager _syncManager;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public UserRoleController(IUserRoleRepository userRoles, IRoleRepository roles, ITenantResolver tenants, ISyncManager syncManager, ILogManager logger)
|
||||
public UserRoleController(IUserRoleRepository userRoles, IRoleRepository roles, ITenantManager tenantManager, ISyncManager syncManager, ILogManager logger)
|
||||
{
|
||||
_userRoles = userRoles;
|
||||
_roles = roles;
|
||||
_syncManager = syncManager;
|
||||
_tenants = tenants;
|
||||
_logger = logger;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
// GET: api/<controller>?siteid=x
|
||||
@ -62,7 +62,7 @@ namespace Oqtane.Controllers
|
||||
userRole = _userRoles.AddUserRole(userRole);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole);
|
||||
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.User, userRole.UserId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.User, userRole.UserId);
|
||||
}
|
||||
return userRole;
|
||||
}
|
||||
@ -76,7 +76,7 @@ namespace Oqtane.Controllers
|
||||
if (ModelState.IsValid && (User.IsInRole(RoleNames.Host) || role.Name != RoleNames.Host))
|
||||
{
|
||||
userRole = _userRoles.UpdateUserRole(userRole);
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.User, userRole.UserId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.User, userRole.UserId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "User Role Updated {UserRole}", userRole);
|
||||
}
|
||||
return userRole;
|
||||
@ -96,15 +96,15 @@ namespace Oqtane.Controllers
|
||||
if (userRole.Role.Name == RoleNames.Host)
|
||||
{
|
||||
// add site specific user roles to preserve user access
|
||||
var role = _roles.GetRoles(_tenants.GetAlias().SiteId).FirstOrDefault(item => item.Name == RoleNames.Registered);
|
||||
var role = _roles.GetRoles(_alias.SiteId).FirstOrDefault(item => item.Name == RoleNames.Registered);
|
||||
userRole = _userRoles.AddUserRole(new UserRole { UserId = userRole.UserId, RoleId = role.RoleId, EffectiveDate = null, ExpiryDate = null });
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole);
|
||||
role = _roles.GetRoles(_tenants.GetAlias().SiteId).FirstOrDefault(item => item.Name == RoleNames.Admin);
|
||||
role = _roles.GetRoles(_alias.SiteId).FirstOrDefault(item => item.Name == RoleNames.Admin);
|
||||
userRole = _userRoles.AddUserRole(new UserRole { UserId = userRole.UserId, RoleId = role.RoleId, EffectiveDate = null, ExpiryDate = null });
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole);
|
||||
}
|
||||
|
||||
_syncManager.AddSyncEvent(_tenants.GetTenant().TenantId, EntityNames.User, userRole.UserId);
|
||||
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.User, userRole.UserId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,5 +38,8 @@ namespace Oqtane.Extensions
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
public static IApplicationBuilder UseTenantResolution(this IApplicationBuilder builder)
|
||||
=> builder.UseMiddleware<TenantMiddleware>();
|
||||
}
|
||||
}
|
||||
|
@ -464,12 +464,12 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
using (var scope = _serviceScopeFactory.CreateScope())
|
||||
{
|
||||
// use the SiteState to set the Alias explicitly so the tenant can be resolved
|
||||
// set the alias explicitly so the tenant can be resolved
|
||||
var aliases = scope.ServiceProvider.GetRequiredService<IAliasRepository>();
|
||||
var firstAlias = install.Aliases.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0];
|
||||
var alias = aliases.GetAliases().FirstOrDefault(item => item.Name == firstAlias);
|
||||
var siteState = scope.ServiceProvider.GetRequiredService<SiteState>();
|
||||
siteState.Alias = alias;
|
||||
var tenantManager = scope.ServiceProvider.GetRequiredService<ITenantManager>();
|
||||
tenantManager.SetAlias(alias);
|
||||
|
||||
var sites = scope.ServiceProvider.GetRequiredService<ISiteRepository>();
|
||||
var site = sites.GetSites().FirstOrDefault(item => item.Name == install.SiteName);
|
||||
|
12
Oqtane.Server/Infrastructure/Interfaces/ITenantManager.cs
Normal file
12
Oqtane.Server/Infrastructure/Interfaces/ITenantManager.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
public interface ITenantManager
|
||||
{
|
||||
Alias GetAlias();
|
||||
Tenant GetTenant();
|
||||
void SetAlias(Alias alias);
|
||||
void SetTenant(int tenantId);
|
||||
}
|
||||
}
|
@ -92,11 +92,12 @@ namespace Oqtane.Infrastructure
|
||||
try
|
||||
{
|
||||
var notes = "";
|
||||
var tenants = scope.ServiceProvider.GetRequiredService<ITenantRepository>();
|
||||
var siteState = scope.ServiceProvider.GetRequiredService<SiteState>();
|
||||
foreach (var tenant in tenants.GetTenants())
|
||||
var tenantRepository = scope.ServiceProvider.GetRequiredService<ITenantRepository>();
|
||||
var tenantManager = scope.ServiceProvider.GetRequiredService<ITenantManager>();
|
||||
foreach (var tenant in tenantRepository.GetTenants())
|
||||
{
|
||||
siteState.Alias = new Alias { TenantId = tenant.TenantId };
|
||||
// set tenant and execute job
|
||||
tenantManager.SetTenant(tenant.TenantId);
|
||||
notes += ExecuteJob(scope.ServiceProvider);
|
||||
}
|
||||
log.Notes = notes;
|
||||
|
@ -14,18 +14,18 @@ namespace Oqtane.Infrastructure
|
||||
public class LogManager : ILogManager
|
||||
{
|
||||
private readonly ILogRepository _logs;
|
||||
private readonly ITenantResolver _tenantResolver;
|
||||
private readonly IConfigurationRoot _config;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public LogManager(ILogRepository logs, ITenantResolver tenantResolver, IConfigurationRoot config, IUserPermissions userPermissions, IHttpContextAccessor accessor)
|
||||
public LogManager(ILogRepository logs, ITenantManager tenantManager, IConfigurationRoot config, IUserPermissions userPermissions, IHttpContextAccessor accessor)
|
||||
{
|
||||
_logs = logs;
|
||||
_tenantResolver = tenantResolver;
|
||||
_config = config;
|
||||
_userPermissions = userPermissions;
|
||||
_accessor = accessor;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
public void Log(LogLevel level, object @class, LogFunction function, string message, params object[] args)
|
||||
@ -49,10 +49,9 @@ namespace Oqtane.Infrastructure
|
||||
if (siteId == -1)
|
||||
{
|
||||
log.SiteId = null;
|
||||
Alias alias = _tenantResolver.GetAlias();
|
||||
if (alias != null)
|
||||
if (_alias != null)
|
||||
{
|
||||
log.SiteId = alias.SiteId;
|
||||
log.SiteId = _alias.SiteId;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
41
Oqtane.Server/Infrastructure/Middleware/TenantMiddleware.cs
Normal file
41
Oqtane.Server/Infrastructure/Middleware/TenantMiddleware.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
internal class TenantMiddleware
|
||||
{
|
||||
private readonly RequestDelegate next;
|
||||
|
||||
public TenantMiddleware(RequestDelegate next)
|
||||
{
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
// check if framework is installed
|
||||
var config = context.RequestServices.GetService(typeof(IConfiguration)) as IConfiguration;
|
||||
if (!string.IsNullOrEmpty(config.GetConnectionString("DefaultConnection")))
|
||||
{
|
||||
// get alias
|
||||
var tenantManager = context.RequestServices.GetService(typeof(ITenantManager)) as ITenantManager;
|
||||
var alias = tenantManager.GetAlias();
|
||||
|
||||
// rewrite path by removing alias path prefix from api and pages requests
|
||||
if (alias != null && !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, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// continue processing
|
||||
if (next != null) await next(context);
|
||||
}
|
||||
}
|
||||
}
|
87
Oqtane.Server/Infrastructure/TenantManager.cs
Normal file
87
Oqtane.Server/Infrastructure/TenantManager.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
public class TenantManager : ITenantManager
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IAliasRepository _aliasRepository;
|
||||
private readonly ITenantRepository _tenantRepository;
|
||||
private readonly SiteState _siteState;
|
||||
|
||||
public TenantManager(IHttpContextAccessor httpContextAccessor, IAliasRepository aliasRepository, ITenantRepository tenantRepository, SiteState siteState)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_aliasRepository = aliasRepository;
|
||||
_tenantRepository = tenantRepository;
|
||||
_siteState = siteState;
|
||||
}
|
||||
|
||||
public Alias GetAlias()
|
||||
{
|
||||
Alias alias = null;
|
||||
|
||||
if (_siteState != null && _siteState.Alias != null)
|
||||
{
|
||||
alias = _siteState.Alias;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if there is http context
|
||||
if (_httpContextAccessor.HttpContext != null)
|
||||
{
|
||||
// legacy support for client api requests which would include the alias as a path prefix ( ie. {alias}/api/[controller] )
|
||||
int aliasId;
|
||||
string[] segments = _httpContextAccessor.HttpContext.Request.Path.Value.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (segments.Length > 1 && (segments[1] == "api" || segments[1] == "pages") && int.TryParse(segments[0], out aliasId))
|
||||
{
|
||||
alias = _aliasRepository.GetAliases().ToList().FirstOrDefault(item => item.AliasId == aliasId);
|
||||
}
|
||||
|
||||
// resolve alias based on host name and path
|
||||
if (alias == null)
|
||||
{
|
||||
string name = _httpContextAccessor.HttpContext.Request.Host.Value + _httpContextAccessor.HttpContext.Request.Path;
|
||||
alias = _aliasRepository.GetAlias(name);
|
||||
}
|
||||
|
||||
// if there is a match save it
|
||||
if (alias != null)
|
||||
{
|
||||
_siteState.Alias = alias;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return alias;
|
||||
}
|
||||
|
||||
public Tenant GetTenant()
|
||||
{
|
||||
var alias = GetAlias();
|
||||
if (alias != null)
|
||||
{
|
||||
// return tenant details
|
||||
return _tenantRepository.GetTenants().ToList().FirstOrDefault(item => item.TenantId == alias.TenantId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetAlias(Alias alias)
|
||||
{
|
||||
// background processes can set the alias using the SiteState service
|
||||
_siteState.Alias = alias;
|
||||
}
|
||||
|
||||
public void SetTenant(int tenantId)
|
||||
{
|
||||
// background processes can set the alias using the SiteState service
|
||||
_siteState.Alias = new Alias { TenantId = tenantId };
|
||||
}
|
||||
}
|
||||
}
|
@ -27,9 +27,9 @@ namespace Oqtane.Infrastructure
|
||||
// core framework upgrade logic - executed for every tenant
|
||||
using (var scope = _serviceScopeFactory.CreateScope())
|
||||
{
|
||||
// set SiteState based on tenant
|
||||
var siteState = scope.ServiceProvider.GetRequiredService<SiteState>();
|
||||
siteState.Alias = new Alias { TenantId = tenant.TenantId };
|
||||
// set tenant
|
||||
var tenantManager = scope.ServiceProvider.GetRequiredService<ITenantManager>();
|
||||
tenantManager.SetTenant(tenant.TenantId);
|
||||
|
||||
switch (version)
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Oqtane.Modules.HtmlText.Models;
|
||||
using Oqtane.Modules.HtmlText.Repository;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Shared;
|
||||
@ -12,7 +11,7 @@ using Oqtane.Controllers;
|
||||
|
||||
namespace Oqtane.Modules.HtmlText.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.Default)]
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class HtmlTextController : ModuleControllerBase
|
||||
{
|
||||
private readonly IHtmlTextRepository _htmlText;
|
||||
|
@ -1,8 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Modules.HtmlText.Models;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Interfaces;
|
||||
using Oqtane.Repository.Databases.Interfaces;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
@ -12,7 +10,7 @@ namespace Oqtane.Modules.HtmlText.Repository
|
||||
{
|
||||
public class HtmlTextContext : DBContextBase, IService, IMultiDatabase
|
||||
{
|
||||
public HtmlTextContext(IDbConfig dbConfig, ITenantResolver tenantResolver) : base(dbConfig, tenantResolver)
|
||||
public HtmlTextContext(IDbConfig dbConfig, ITenantManager tenantManager) : base(dbConfig, tenantManager)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
@page "/{alias}/pages/login"
|
||||
@page "/pages/login"
|
||||
@namespace Oqtane.Pages
|
||||
@model Oqtane.Pages.LoginModel
|
||||
|
@ -1,3 +1,3 @@
|
||||
@page "/{alias}/pages/logout"
|
||||
@page "/pages/logout"
|
||||
@namespace Oqtane.Pages
|
||||
@model Oqtane.Pages.LogoutModel
|
||||
|
@ -8,7 +8,6 @@ using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using Oqtane.Repository;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -18,21 +17,18 @@ namespace Oqtane.Pages
|
||||
public class HostModel : PageModel
|
||||
{
|
||||
private IConfiguration _configuration;
|
||||
private readonly SiteState _state;
|
||||
private readonly IAliasRepository _aliases;
|
||||
private readonly ITenantManager _tenantManager;
|
||||
private readonly ILocalizationManager _localizationManager;
|
||||
private readonly ILanguageRepository _languages;
|
||||
|
||||
public HostModel(
|
||||
IConfiguration configuration,
|
||||
SiteState state,
|
||||
IAliasRepository aliases,
|
||||
ITenantManager tenantManager,
|
||||
ILocalizationManager localizationManager,
|
||||
ILanguageRepository languages)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_state = state;
|
||||
_aliases = aliases;
|
||||
_tenantManager = tenantManager;
|
||||
_localizationManager = localizationManager;
|
||||
_languages = languages;
|
||||
}
|
||||
@ -54,19 +50,14 @@ namespace Oqtane.Pages
|
||||
// if culture not specified and framework is installed
|
||||
if (HttpContext.Request.Cookies[CookieRequestCultureProvider.DefaultCookieName] == null && !string.IsNullOrEmpty(_configuration.GetConnectionString("DefaultConnection")))
|
||||
{
|
||||
var uri = new Uri(Request.GetDisplayUrl());
|
||||
var hostname = uri.Authority + "/" + uri.LocalPath.Substring(1);
|
||||
var alias = _aliases.GetAlias(hostname);
|
||||
var alias = _tenantManager.GetAlias();
|
||||
if (alias != null)
|
||||
{
|
||||
_state.Alias = alias;
|
||||
|
||||
// set default language for site if the culture is not supported
|
||||
var languages = _languages.GetLanguages(alias.SiteId);
|
||||
if (languages.Any() && languages.All(l => l.Code != CultureInfo.CurrentUICulture.Name))
|
||||
{
|
||||
var defaultLanguage = languages.Where(l => l.IsDefault).SingleOrDefault() ?? languages.First();
|
||||
|
||||
SetLocalizationCookie(defaultLanguage.Code);
|
||||
}
|
||||
else
|
||||
@ -74,10 +65,6 @@ namespace Oqtane.Pages
|
||||
SetLocalizationCookie(_localizationManager.GetDefaultCulture());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Message = $"No Matching Alias For Host Name {hostname}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,17 +55,28 @@ namespace Oqtane.Repository
|
||||
List<Alias> aliases = GetAliases().ToList();
|
||||
var segments = name.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
// iterate segments in reverse order
|
||||
for (int i = segments.Length; i > 0; i--)
|
||||
// iterate segments to find keywords
|
||||
int start = segments.Length;
|
||||
for (int i = 0; i < segments.Length; i++)
|
||||
{
|
||||
name = string.Join("/", segments, 0, i);
|
||||
alias = aliases.Find(item => item.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
|
||||
if (segments[i] == "api" || segments[i] == "pages" || segments[i] == "*")
|
||||
{
|
||||
start = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// iterate segments in reverse order to find alias match
|
||||
for (int i = start; i > 0; i--)
|
||||
{
|
||||
alias = aliases.Find(item => item.Name.Equals(string.Join("/", segments, 0, i), StringComparison.OrdinalIgnoreCase));
|
||||
if (alias != null)
|
||||
{
|
||||
break; // found a matching alias
|
||||
}
|
||||
}
|
||||
// return fallback alias
|
||||
|
||||
// return fallback alias if none found
|
||||
return alias ?? aliases.Find(item => item.Name.Equals("*"));
|
||||
}
|
||||
|
||||
|
@ -8,9 +8,10 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Oqtane.Extensions;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Interfaces;
|
||||
using Oqtane.Migrations.Framework;
|
||||
using Oqtane.Repository.Databases.Interfaces;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Shared;
|
||||
|
||||
// ReSharper disable BuiltInTypeReferenceStyleForMemberAccess
|
||||
@ -20,26 +21,27 @@ namespace Oqtane.Repository
|
||||
public class DBContextBase : IdentityUserContext<IdentityUser>
|
||||
{
|
||||
private readonly ITenantResolver _tenantResolver;
|
||||
private readonly ITenantManager _tenantManager;
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly IConfiguration _configuration;
|
||||
private string _connectionString;
|
||||
private string _databaseType;
|
||||
|
||||
public DBContextBase(ITenantResolver tenantResolver, IHttpContextAccessor httpContextAccessor)
|
||||
public DBContextBase(ITenantManager tenantManager, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_connectionString = String.Empty;
|
||||
_tenantResolver = tenantResolver;
|
||||
_tenantManager = tenantManager;
|
||||
_accessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public DBContextBase(IDbConfig dbConfig, ITenantResolver tenantResolver)
|
||||
public DBContextBase(IDbConfig dbConfig, ITenantManager tenantManager)
|
||||
{
|
||||
_accessor = dbConfig.Accessor;
|
||||
_configuration = dbConfig.Configuration;
|
||||
_connectionString = dbConfig.ConnectionString;
|
||||
_databaseType = dbConfig.DatabaseType;
|
||||
Databases = dbConfig.Databases;
|
||||
_tenantResolver = tenantResolver;
|
||||
_tenantManager = tenantManager;
|
||||
}
|
||||
|
||||
public IEnumerable<IOqtaneDatabase> Databases { get; }
|
||||
@ -48,9 +50,18 @@ namespace Oqtane.Repository
|
||||
{
|
||||
optionsBuilder.ReplaceService<IMigrationsAssembly, MultiDatabaseMigrationsAssembly>();
|
||||
|
||||
if (string.IsNullOrEmpty(_connectionString) && _tenantResolver != null)
|
||||
if (string.IsNullOrEmpty(_connectionString))
|
||||
{
|
||||
var tenant = _tenantResolver.GetTenant();
|
||||
|
||||
Tenant tenant;
|
||||
if (_tenantResolver != null)
|
||||
{
|
||||
tenant = _tenantResolver.GetTenant();
|
||||
}
|
||||
else
|
||||
{
|
||||
tenant = _tenantManager.GetTenant();
|
||||
}
|
||||
|
||||
if (tenant != null)
|
||||
{
|
||||
@ -103,5 +114,25 @@ namespace Oqtane.Repository
|
||||
|
||||
return base.SaveChanges();
|
||||
}
|
||||
|
||||
[Obsolete("This constructor is obsolete. Use DBContextBase(ITenantManager tenantManager, IHttpContextAccessor httpContextAccessor) instead.", false)]
|
||||
public DBContextBase(ITenantResolver tenantResolver, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_connectionString = String.Empty;
|
||||
_tenantResolver = tenantResolver;
|
||||
_accessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
[Obsolete("This constructor is obsolete. Use DBContextBase(IDbConfig dbConfig, ITenantManager tenantManager) instead.", false)]
|
||||
public DBContextBase(IDbConfig dbConfig, ITenantResolver tenantResolver)
|
||||
{
|
||||
_accessor = dbConfig.Accessor;
|
||||
_configuration = dbConfig.Configuration;
|
||||
_connectionString = dbConfig.ConnectionString;
|
||||
_databaseType = dbConfig.DatabaseType;
|
||||
Databases = dbConfig.Databases;
|
||||
_tenantResolver = tenantResolver;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Interfaces;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository.Databases.Interfaces;
|
||||
|
||||
@ -12,7 +11,7 @@ namespace Oqtane.Repository
|
||||
{
|
||||
public class TenantDBContext : DBContextBase, IMultiDatabase
|
||||
{
|
||||
public TenantDBContext(IDbConfig dbConfig, ITenantResolver tenantResolver) : base(dbConfig, tenantResolver) { }
|
||||
public TenantDBContext(IDbConfig dbConfig, ITenantManager tenantManager) : base(dbConfig, tenantManager) { }
|
||||
|
||||
public virtual DbSet<Site> Site { get; set; }
|
||||
public virtual DbSet<Page> Page { get; set; }
|
||||
|
@ -1,7 +1,8 @@
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
{
|
||||
// class deprecated and replaced by ITenantManager
|
||||
public interface ITenantResolver
|
||||
{
|
||||
Alias GetAlias();
|
||||
|
@ -1,78 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
{
|
||||
// class deprecated and replaced by ITenantManager
|
||||
public class TenantResolver : ITenantResolver
|
||||
{
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly IAliasRepository _aliasRepository;
|
||||
private readonly ITenantRepository _tenantRepository;
|
||||
private readonly SiteState _siteState;
|
||||
private readonly ITenantManager _tenantManager;
|
||||
|
||||
private Alias _alias;
|
||||
private Tenant _tenant;
|
||||
|
||||
public TenantResolver(IHttpContextAccessor accessor, IAliasRepository aliasRepository, ITenantRepository tenantRepository, SiteState siteState)
|
||||
public TenantResolver(ITenantManager tenantManager)
|
||||
{
|
||||
_accessor = accessor;
|
||||
_aliasRepository = aliasRepository;
|
||||
_tenantRepository = tenantRepository;
|
||||
_siteState = siteState;
|
||||
_tenantManager = tenantManager;
|
||||
}
|
||||
|
||||
public Alias GetAlias()
|
||||
{
|
||||
if (_alias == null) ResolveTenant();
|
||||
return _alias;
|
||||
return _tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
public Tenant GetTenant()
|
||||
{
|
||||
if (_tenant == null) ResolveTenant();
|
||||
return _tenant;
|
||||
}
|
||||
|
||||
private void ResolveTenant()
|
||||
{
|
||||
if (_siteState != null && _siteState.Alias != null)
|
||||
{
|
||||
// background processes can pass in an alias using the SiteState service
|
||||
_alias = _siteState.Alias;
|
||||
}
|
||||
else
|
||||
{
|
||||
int aliasId = -1;
|
||||
|
||||
// get aliasid identifier based on request
|
||||
if (_accessor.HttpContext != null)
|
||||
{
|
||||
string[] segments = _accessor.HttpContext.Request.Path.Value.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (segments.Length > 1 && (segments[1] == "api" || segments[1] == "pages") && segments[0] != "~")
|
||||
{
|
||||
aliasId = int.Parse(segments[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// get the alias
|
||||
IEnumerable<Alias> aliases = _aliasRepository.GetAliases().ToList(); // cached
|
||||
if (aliasId != -1)
|
||||
{
|
||||
_alias = aliases.FirstOrDefault(item => item.AliasId == aliasId);
|
||||
}
|
||||
}
|
||||
|
||||
if (_alias != null)
|
||||
{
|
||||
// get the tenant
|
||||
IEnumerable<Tenant> tenants = _tenantRepository.GetTenants(); // cached
|
||||
_tenant = tenants.FirstOrDefault(item => item.TenantId == _alias.TenantId);
|
||||
}
|
||||
|
||||
return _tenantManager.GetTenant();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -178,10 +178,10 @@ namespace Oqtane
|
||||
InstallationManager.InstallPackages("Modules,Themes,Packages", _env.WebRootPath, _env.ContentRootPath);
|
||||
|
||||
// register transient scoped core services
|
||||
services.AddTransient<ITenantManager, TenantManager>();
|
||||
services.AddTransient<IModuleDefinitionRepository, ModuleDefinitionRepository>();
|
||||
services.AddTransient<IThemeRepository, ThemeRepository>();
|
||||
services.AddTransient<IUserPermissions, UserPermissions>();
|
||||
services.AddTransient<ITenantResolver, TenantResolver>();
|
||||
services.AddTransient<IAliasRepository, AliasRepository>();
|
||||
services.AddTransient<ITenantRepository, TenantRepository>();
|
||||
services.AddTransient<ISiteRepository, SiteRepository>();
|
||||
@ -206,6 +206,8 @@ namespace Oqtane
|
||||
services.AddTransient<ISqlRepository, SqlRepository>();
|
||||
services.AddTransient<IUpgradeManager, UpgradeManager>();
|
||||
services.AddTransient<ILanguageRepository, LanguageRepository>();
|
||||
// obsolete - replaced by ITenantManager
|
||||
services.AddTransient<ITenantResolver, TenantResolver>();
|
||||
|
||||
// load the external assemblies into the app domain, install services
|
||||
services.AddOqtane(_runtime, _supportedCultures);
|
||||
@ -240,7 +242,8 @@ namespace Oqtane
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
// to allow install middleware it should be moved up
|
||||
|
||||
// execute any IServerStartup logic
|
||||
app.ConfigureOqtaneAssemblies(env);
|
||||
|
||||
// Allow oqtane localization middleware
|
||||
@ -248,6 +251,7 @@ namespace Oqtane
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseTenantResolution(); // must be declared directly after static files
|
||||
app.UseBlazorFrameworkFiles();
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
@ -255,7 +259,7 @@ namespace Oqtane
|
||||
if (_useSwagger)
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Oqtane V1"); });
|
||||
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Oqtane " + Constants.Version); });
|
||||
}
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
|
Reference in New Issue
Block a user