Merge pull request #120 from sbwalker/master

improvements to module/theme installation and removal
This commit is contained in:
Shaun Walker 2019-10-09 12:06:59 -04:00 committed by GitHub
commit 6a60c16f57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 169 additions and 37 deletions

View File

@ -103,7 +103,7 @@
private async Task InstallModules()
{
await ModuleDefinitionService.InstallModulesAsync();
await ModuleDefinitionService.InstallModuleDefinitionsAsync();
NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
}

View File

@ -24,7 +24,12 @@ else
<td>@context.Name</td>
<td>@context.Version</td>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.ModuleDefinitionId.ToString())" /></td>
<td><ActionLink Action="Delete" Parameters="@($"id=" + context.ModuleDefinitionId.ToString())" Class="btn btn-danger" /></td>
<td>
@if (context.AssemblyName != "Oqtane.Client")
{
<button type="button" class="btn btn-danger" @onclick=@(async () => await DeleteModule(context.ModuleDefinitionId, context.SiteId))>Delete</button>
}
</td>
<td>
@if (UpgradeAvailable(context.ModuleDefinitionName, context.Version))
{
@ -61,7 +66,13 @@ else
private async Task DownloadModule(string moduledefinitionname, string version)
{
await PackageService.DownloadPackageAsync(moduledefinitionname, version, "Modules");
await ModuleDefinitionService.InstallModulesAsync();
await ModuleDefinitionService.InstallModuleDefinitionsAsync();
NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
}
private async Task DeleteModule(int moduledefinitionid, int siteid)
{
await ModuleDefinitionService.DeleteModuleDefinitionAsync(moduledefinitionid, siteid);
NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
}
}

View File

@ -108,9 +108,10 @@ else
private async Task SaveSite()
{
if (name != "" && urls != "" && themetype != "")
if (tenantid != "-1" && name != "" && urls != "" && themetype != "")
{
Site site = new Site();
site.TenantId = int.Parse(tenantid);
site.Name = name;
site.Logo = (logo == null ? "" : logo);
site.DefaultThemeType = themetype;
@ -131,7 +132,7 @@ else
}
else
{
ModuleInstance.AddModuleMessage("You Must Provide A Site Name, Alias, And Default Theme", MessageType.Warning);
ModuleInstance.AddModuleMessage("You Must Provide A Tenant, Site Name, Alias, And Default Theme", MessageType.Warning);
}
}

View File

@ -115,7 +115,7 @@ else
if (site != null)
{
name = site.Name;
aliases = PageState.Aliases.Where(item => item.SiteId == site.SiteId).ToList();
aliases = PageState.Aliases.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList();
foreach (Alias alias in aliases)
{
urls += alias.Name + "\n";

View File

@ -117,7 +117,7 @@ else
if (site != null)
{
name = site.Name;
aliases = PageState.Aliases.Where(item => item.SiteId == site.SiteId).ToList();
aliases = PageState.Aliases.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList();
foreach (Alias alias in aliases)
{
urls += alias.Name + "\n";
@ -173,7 +173,7 @@ else
{
Alias alias = new Alias();
alias.Name = name;
alias.TenantId = PageState.Alias.TenantId;
alias.TenantId = site.TenantId;
alias.SiteId = site.SiteId;
await AliasService.AddAliasAsync(alias);
}

View File

@ -22,7 +22,12 @@ else
<Row>
<td>@context.Name</td>
<td>@context.Version</td>
<td><ActionLink Action="Delete" Parameters="@($"id=" + context.ThemeName)" Class="btn btn-danger" /></td>
<td>
@if (context.AssemblyName != "Oqtane.Client")
{
<button type="button" class="btn btn-danger" @onclick=@(async () => await DeleteTheme(context.ThemeName))>Delete</button>
}
</td>
<td>
@if (UpgradeAvailable(context.ThemeName, context.Version))
{
@ -62,4 +67,10 @@ else
await ThemeService.InstallThemesAsync();
NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
}
private async Task DeleteTheme(string themename)
{
await ThemeService.DeleteThemeAsync(themename);
NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
}
}

View File

@ -49,7 +49,7 @@ else
}
if (!upgradeavailable)
{
ModuleInstance.AddModuleMessage("Framework Up To Date", MessageType.Info);
ModuleInstance.AddModuleMessage("Framework Is Up To Date", MessageType.Info);
}
}

View File

@ -8,6 +8,7 @@ namespace Oqtane.Services
{
Task<List<ModuleDefinition>> GetModuleDefinitionsAsync(int SiteId);
Task UpdateModuleDefinitionAsync(ModuleDefinition ModuleDefinition);
Task InstallModulesAsync();
Task InstallModuleDefinitionsAsync();
Task DeleteModuleDefinitionAsync(int ModuleDefinitionId, int SiteId);
}
}

View File

@ -7,9 +7,10 @@ namespace Oqtane.Services
public interface IThemeService
{
Task<List<Theme>> GetThemesAsync();
Dictionary<string, string> GetThemeTypes(List<Theme> themes);
Dictionary<string, string> GetPaneLayoutTypes(List<Theme> themes);
Dictionary<string, string> GetContainerTypes(List<Theme> themes);
Dictionary<string, string> GetThemeTypes(List<Theme> Themes);
Dictionary<string, string> GetPaneLayoutTypes(List<Theme> Themes);
Dictionary<string, string> GetContainerTypes(List<Theme> Themes);
Task InstallThemesAsync();
Task DeleteThemeAsync(string ThemeName);
}
}

View File

@ -69,9 +69,14 @@ namespace Oqtane.Services
await http.PutJsonAsync(apiurl + "/" + ModuleDefinition.ModuleDefinitionId.ToString(), ModuleDefinition);
}
public async Task InstallModulesAsync()
public async Task InstallModuleDefinitionsAsync()
{
await http.GetJsonAsync<List<string>>(apiurl + "/install");
}
public async Task DeleteModuleDefinitionAsync(int ModuleDefinitionId, int SiteId)
{
await http.DeleteAsync(apiurl + "/" + ModuleDefinitionId.ToString() + "?siteid=" + SiteId.ToString());
}
}
}

View File

@ -61,10 +61,10 @@ namespace Oqtane.Services
return themes.OrderBy(item => item.Name).ToList();
}
public Dictionary<string, string> GetThemeTypes(List<Theme> themes)
public Dictionary<string, string> GetThemeTypes(List<Theme> Themes)
{
var selectableThemes = new Dictionary<string, string>();
foreach (Theme theme in themes)
foreach (Theme theme in Themes)
{
foreach (string themecontrol in theme.ThemeControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
@ -74,10 +74,10 @@ namespace Oqtane.Services
return selectableThemes;
}
public Dictionary<string, string> GetPaneLayoutTypes(List<Theme> themes)
public Dictionary<string, string> GetPaneLayoutTypes(List<Theme> Themes)
{
var selectablePaneLayouts = new Dictionary<string, string>();
foreach (Theme theme in themes)
foreach (Theme theme in Themes)
{
foreach (string panelayout in theme.PaneLayouts.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
@ -87,10 +87,10 @@ namespace Oqtane.Services
return selectablePaneLayouts;
}
public Dictionary<string, string> GetContainerTypes(List<Theme> themes)
public Dictionary<string, string> GetContainerTypes(List<Theme> Themes)
{
var selectableContainers = new Dictionary<string, string>();
foreach (Theme theme in themes)
foreach (Theme theme in Themes)
{
foreach (string container in theme.ContainerControls.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
@ -104,5 +104,10 @@ namespace Oqtane.Services
{
await http.GetJsonAsync<List<string>>(apiurl + "/install");
}
public async Task DeleteThemeAsync(string ThemeName)
{
await http.DeleteAsync(apiurl + "/" + ThemeName);
}
}
}

View File

@ -2,7 +2,7 @@
@inject NavigationManager NavigationManager
@inject IInstallationService InstallationService
@inject ISiteService SiteService
@inject IAliasService AliasService
@inject ITenantService TenantService
@inject IUserService UserService
<div class="container">
@ -172,8 +172,10 @@
GenericResponse response = await InstallationService.Install(connectionstring);
if (response.Success)
{
List<Tenant> tenants = await TenantService.GetTenantsAsync();
Site site = new Site();
site.Name = "Site1";
site.TenantId = tenants.FirstOrDefault().TenantId;
site.Name = "Default Site";
site.Logo = "oqtane.png";
site.DefaultThemeType = "Oqtane.Themes.Theme2.Theme2, Oqtane.Client";
site.DefaultLayoutType = "";

View File

@ -7,6 +7,8 @@ using Microsoft.AspNetCore.Authorization;
using Oqtane.Infrastructure;
using System.IO;
using System.Reflection;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
namespace Oqtane.Controllers
{
@ -15,11 +17,13 @@ namespace Oqtane.Controllers
{
private readonly IModuleDefinitionRepository ModuleDefinitions;
private readonly IInstallationManager InstallationManager;
private readonly IWebHostEnvironment environment;
public ModuleDefinitionController(IModuleDefinitionRepository ModuleDefinitions, IInstallationManager InstallationManager)
public ModuleDefinitionController(IModuleDefinitionRepository ModuleDefinitions, IInstallationManager InstallationManager, IWebHostEnvironment environment)
{
this.ModuleDefinitions = ModuleDefinitions;
this.InstallationManager = InstallationManager;
this.environment = environment;
}
// GET: api/<controller>?siteid=x
@ -55,5 +59,34 @@ namespace Oqtane.Controllers
{
InstallationManager.InstallPackages("Modules");
}
// DELETE api/<controller>/5?siteid=x
[HttpDelete("{id}")]
[Authorize(Roles = Constants.HostRole)]
public void Delete(int id, int siteid)
{
List<ModuleDefinition> moduledefinitions = ModuleDefinitions.GetModuleDefinitions(siteid).ToList();
ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionId == id).FirstOrDefault();
if (moduledefinition != null)
{
string moduledefinitionname = moduledefinition.ModuleDefinitionName.Substring(0, moduledefinition.ModuleDefinitionName.IndexOf(","));
string folder = Path.Combine(environment.WebRootPath, "Modules\\" + moduledefinitionname);
if (Directory.Exists(folder))
{
Directory.Delete(folder, true);
}
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
foreach (string file in Directory.EnumerateFiles(binfolder, moduledefinitionname + "*.dll"))
{
System.IO.File.Delete(file);
}
ModuleDefinitions.DeleteModuleDefinition(id, siteid);
InstallationManager.RestartApplication();
}
}
}
}

View File

@ -7,6 +7,8 @@ using Oqtane.Shared;
using Oqtane.Infrastructure;
using System.IO;
using System.Reflection;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
namespace Oqtane.Controllers
{
@ -15,11 +17,13 @@ namespace Oqtane.Controllers
{
private readonly IThemeRepository Themes;
private readonly IInstallationManager InstallationManager;
private readonly IWebHostEnvironment environment;
public ThemeController(IThemeRepository Themes, IInstallationManager InstallationManager)
public ThemeController(IThemeRepository Themes, IInstallationManager InstallationManager, IWebHostEnvironment environment)
{
this.Themes = Themes;
this.InstallationManager = InstallationManager;
this.environment = environment;
}
// GET: api/<controller>
@ -44,5 +48,32 @@ namespace Oqtane.Controllers
{
InstallationManager.InstallPackages("Themes");
}
// DELETE api/<controller>/xxx
[HttpDelete("{themename}")]
[Authorize(Roles = Constants.HostRole)]
public void Delete(string themename)
{
List<Theme> themes = Themes.GetThemes().ToList();
Theme theme = themes.Where(item => item.ThemeName == themename).FirstOrDefault();
if (theme != null)
{
themename = theme.ThemeName.Substring(0, theme.ThemeName.IndexOf(","));
string folder = Path.Combine(environment.WebRootPath, "Themes\\" + themename);
if (Directory.Exists(folder))
{
Directory.Delete(folder, true);
}
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
foreach (string file in Directory.EnumerateFiles(binfolder, themename + "*.dll"))
{
System.IO.File.Delete(file);
}
InstallationManager.RestartApplication();
}
}
}
}

View File

@ -3,5 +3,6 @@
public interface IInstallationManager
{
void InstallPackages(string Folders);
void RestartApplication();
}
}

View File

@ -77,8 +77,13 @@ namespace Oqtane.Infrastructure
if (install)
{
// restart application
HostApplicationLifetime.StopApplication();
RestartApplication();
}
}
public void RestartApplication()
{
HostApplicationLifetime.StopApplication();
}
}
}

View File

@ -7,6 +7,7 @@ namespace Oqtane.Repository
{
IEnumerable<ModuleDefinition> GetModuleDefinitions(int SideId);
void UpdateModuleDefinition(ModuleDefinition ModuleDefinition);
void DeleteModuleDefinition(int ModuleDefinitionId, int SiteId);
}
}

View File

@ -13,6 +13,7 @@ namespace Oqtane.Repository
void UpdatePermissions(int SiteId, string EntityName, int EntityId, string Permissions);
Permission GetPermission(int PermissionId);
void DeletePermission(int PermissionId);
void DeletePermissions(int SiteId, string EntityName, int EntityId);
string EncodePermissions(int EntityId, IEnumerable<Permission> Permissions);
IEnumerable<Permission> DecodePermissions(string Permissions, int SiteId, string EntityName, int EntityId);
}

View File

@ -186,5 +186,13 @@ namespace Oqtane.Repository
{
Permissions.UpdatePermissions(ModuleDefinition.SiteId, "ModuleDefinition", ModuleDefinition.ModuleDefinitionId, ModuleDefinition.Permissions);
}
public void DeleteModuleDefinition(int ModuleDefinitionId, int SiteId)
{
ModuleDefinition ModuleDefinition = db.ModuleDefinition.Find(ModuleDefinitionId);
Permissions.DeletePermissions(SiteId, "ModuleDefinition", ModuleDefinitionId);
db.ModuleDefinition.Remove(ModuleDefinition);
db.SaveChanges();
}
}
}

View File

@ -61,8 +61,9 @@ namespace Oqtane.Repository
// get current permissions and delete
IEnumerable<Permission> permissions = db.Permission
.Where(item => item.EntityName == EntityName)
.Where(item => item.EntityId == EntityId);
foreach(Permission permission in permissions)
.Where(item => item.EntityId == EntityId)
.Where(item => item.SiteId == SiteId);
foreach (Permission permission in permissions)
{
db.Permission.Remove(permission);
}
@ -87,6 +88,19 @@ namespace Oqtane.Repository
db.SaveChanges();
}
public void DeletePermissions(int SiteId, string EntityName, int EntityId)
{
IEnumerable<Permission> permissions = db.Permission
.Where(item => item.EntityName == EntityName)
.Where(item => item.EntityId == EntityId)
.Where(item => item.SiteId == SiteId);
foreach (Permission permission in permissions)
{
db.Permission.Remove(permission);
}
db.SaveChanges();
}
// permissions are stored in the format "{permissionname:!rolename1;![userid1];rolename2;rolename3;[userid2];[userid3]}" where "!" designates Deny permissions
public string EncodePermissions(int EntityId, IEnumerable<Permission> Permissions)
{

View File

@ -6,6 +6,7 @@ Create tables
CREATE TABLE [dbo].[Site](
[SiteId] [int] IDENTITY(1,1) NOT NULL,
[TenantId] [int] NOT NULL,
[Name] [nvarchar](200) NOT NULL,
[Logo] [nvarchar](50) NOT NULL,
[DefaultThemeType] [nvarchar](200) NOT NULL,

View File

@ -187,8 +187,8 @@ namespace Oqtane.Server
Assembly assembly = assemblies.Where(item => item.Location == file.FullName).FirstOrDefault();
if (assembly == null)
{
// load assembly ( as long as dependencies are in /bin they will load as well )
assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(file.FullName);
// load assembly from stream to prevent locking file ( as long as dependencies are in /bin they will load as well )
assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(file.FullName)));
moduleassemblies.Add(assembly);
}
}
@ -200,8 +200,8 @@ namespace Oqtane.Server
Assembly assembly = assemblies.Where(item => item.Location == file.FullName).FirstOrDefault();
if (assembly == null)
{
// load assembly ( as long as dependencies are in /bin they will load as well )
assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(file.FullName);
// load assembly from stream to prevent locking file ( as long as dependencies are in /bin they will load as well )
assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(file.FullName)));
}
}
@ -374,9 +374,8 @@ namespace Oqtane.Server
Assembly assembly = assemblies.Where(item => item.Location == file.FullName).FirstOrDefault();
if (assembly == null)
{
// load assembly ( as long as dependencies are in /bin they will load as well )
assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(file.FullName);
moduleassemblies.Add(assembly);
// load assembly from stream to prevent locking file ( as long as dependencies are in /bin they will load as well )
assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(file.FullName)));
}
}
@ -387,8 +386,8 @@ namespace Oqtane.Server
Assembly assembly = assemblies.Where(item => item.Location == file.FullName).FirstOrDefault();
if (assembly == null)
{
// load assembly ( as long as dependencies are in /bin they will load as well )
assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(file.FullName);
// load assembly from stream to prevent locking file ( as long as dependencies are in /bin they will load as well )
assembly = AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(File.ReadAllBytes(file.FullName)));
}
}

View File

@ -5,6 +5,7 @@ namespace Oqtane.Models
public class Site : IAuditable, IDeletable
{
public int SiteId { get; set; }
public int TenantId { get; set; }
public string Name { get; set; }
public string Logo { get; set; }
public string DefaultThemeType { get; set; }