install/upgrade refactoring to consolidate all use cases and implement IInstallable interface for modules, moved tenant creation to site management UI, fixed z-order issues in Blazor theme, enhanced JS Interop methods to support integrity and crossorigin

This commit is contained in:
Shaun Walker
2020-04-30 13:58:04 -04:00
parent 099fddf2b6
commit 34538dd945
44 changed files with 1051 additions and 912 deletions

View File

@ -5,8 +5,6 @@ using Oqtane.Models;
using Oqtane.Shared;
using Oqtane.Infrastructure;
// ReSharper disable StringIndexOfIsCultureSpecific.1
namespace Oqtane.Controllers
{
[Route("{site}/api/[controller]")]
@ -14,9 +12,9 @@ namespace Oqtane.Controllers
{
private readonly IConfigurationRoot _config;
private readonly IInstallationManager _installationManager;
private readonly DatabaseManager _databaseManager;
private readonly IDatabaseManager _databaseManager;
public InstallationController(IConfigurationRoot config, IInstallationManager installationManager, DatabaseManager databaseManager)
public InstallationController(IConfigurationRoot config, IInstallationManager installationManager, IDatabaseManager databaseManager)
{
_config = config;
_installationManager = installationManager;
@ -27,33 +25,17 @@ namespace Oqtane.Controllers
[HttpPost]
public Installation Post([FromBody] InstallConfig config)
{
//TODO Security ????
var installation = new Installation {Success = false, Message = ""};
if (ModelState.IsValid && (!_databaseManager.IsInstalled || !config.IsMaster))
if (ModelState.IsValid && (User.IsInRole(Constants.HostRole) || string.IsNullOrEmpty(_config.GetConnectionString(SettingKeys.ConnectionStringKey))))
{
bool master = config.IsMaster;
config.Alias = config.Alias ?? HttpContext.Request.Host.Value;
var result = DatabaseManager.InstallDatabase(config);
if (result.Success)
{
if (master)
{
_config.Reload();
}
_databaseManager.BuildDefaultSite(config.Password, config.HostEmail);
installation.Success = true;
return installation;
}
installation.Message = result.Message;
return installation;
installation = _databaseManager.Install(config);
}
else
{
installation.Message = "Installation Not Authorized";
}
installation.Message = "Application Is Already Installed";
return installation;
}
@ -61,12 +43,8 @@ namespace Oqtane.Controllers
[HttpGet("installed")]
public Installation IsInstalled()
{
var installation = new Installation {Success = false, Message = ""};
installation.Success = _databaseManager.IsInstalled;
installation.Message = _databaseManager.Message;
return installation;
bool isInstalled = _databaseManager.IsInstalled();
return new Installation {Success = isInstalled, Message = string.Empty};
}
[HttpGet("upgrade")]

View File

@ -22,16 +22,18 @@ namespace Oqtane.Controllers
{
private readonly IModuleDefinitionRepository _moduleDefinitions;
private readonly IModuleRepository _modules;
private readonly ITenantRepository _tenants;
private readonly IUserPermissions _userPermissions;
private readonly IInstallationManager _installationManager;
private readonly IWebHostEnvironment _environment;
private readonly IServiceProvider _serviceProvider;
private readonly ILogManager _logger;
public ModuleDefinitionController(IModuleDefinitionRepository moduleDefinitions, IModuleRepository modules, IUserPermissions userPermissions, IInstallationManager installationManager, IWebHostEnvironment environment, IServiceProvider serviceProvider, ILogManager logger)
public ModuleDefinitionController(IModuleDefinitionRepository moduleDefinitions, IModuleRepository modules,ITenantRepository tenants, IUserPermissions userPermissions, IInstallationManager installationManager, IWebHostEnvironment environment, IServiceProvider serviceProvider, ILogManager logger)
{
_moduleDefinitions = moduleDefinitions;
_modules = modules;
_tenants = tenants;
_userPermissions = userPermissions;
_installationManager = installationManager;
_environment = environment;
@ -104,8 +106,18 @@ namespace Oqtane.Controllers
Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
if (moduletype != null && moduletype.GetInterface("IInstallable") != null)
{
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
((IInstallable)moduleobject).Uninstall();
foreach (Tenant tenant in _tenants.GetTenants())
{
try
{
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
((IInstallable)moduleobject).Uninstall(tenant);
}
catch
{
// an error occurred executing the uninstall
}
}
}
}
@ -190,6 +202,11 @@ namespace Oqtane.Controllers
module.ModuleDefinitionName = moduleDefinition.ModuleDefinitionName;
_modules.UpdateModule(module);
if (moduleDefinition.Template == "internal")
{
// need logic to add embedded scripts to Oqtane.Server.csproj - also you need to remove them on uninstall
}
_installationManager.RestartApplication();
}
}