fixed Theme install/uninstall issue, fixed Layout inheritance issue, fixed File server performance issue, cleaned up remaining hardcoded permission strings

This commit is contained in:
Shaun Walker 2020-09-16 15:24:07 -04:00
parent 7f15a5f464
commit 8196112a59
6 changed files with 33 additions and 32 deletions

View File

@ -390,6 +390,10 @@
if (string.IsNullOrEmpty(page.ThemeType)) if (string.IsNullOrEmpty(page.ThemeType))
{ {
page.ThemeType = site.DefaultThemeType; page.ThemeType = site.DefaultThemeType;
}
if (string.IsNullOrEmpty(page.LayoutType))
{
page.LayoutType = site.DefaultLayoutType; page.LayoutType = site.DefaultLayoutType;
} }

View File

@ -444,8 +444,8 @@ namespace Oqtane.Controllers
string filepath = Path.Combine(GetFolderPath(file.Folder), file.Name); string filepath = Path.Combine(GetFolderPath(file.Folder), file.Name);
if (System.IO.File.Exists(filepath)) if (System.IO.File.Exists(filepath))
{ {
byte[] filebytes = System.IO.File.ReadAllBytes(filepath); var stream = new FileStream(filepath, FileMode.Open);
return File(filebytes, "application/octet-stream", file.Name); return File(stream, "application/octet-stream", file.Name);
} }
else else
{ {
@ -453,8 +453,8 @@ namespace Oqtane.Controllers
HttpContext.Response.StatusCode = 404; HttpContext.Response.StatusCode = 404;
if (System.IO.File.Exists(errorpath)) if (System.IO.File.Exists(errorpath))
{ {
byte[] filebytes = System.IO.File.ReadAllBytes(errorpath); var stream = new FileStream(errorpath, FileMode.Open);
return File(filebytes, "application/octet-stream", file.Name); return File(stream, "application/octet-stream", file.Name);
} }
} }
} }
@ -462,16 +462,16 @@ namespace Oqtane.Controllers
{ {
_logger.Log(LogLevel.Error, this, LogFunction.Read, "User Not Authorized To Access File {FileId}", id); _logger.Log(LogLevel.Error, this, LogFunction.Read, "User Not Authorized To Access File {FileId}", id);
HttpContext.Response.StatusCode = 401; HttpContext.Response.StatusCode = 401;
byte[] filebytes = System.IO.File.ReadAllBytes(errorpath); var stream = new FileStream(errorpath, FileMode.Open);
return File(filebytes, "application/octet-stream", file.Name); return File(stream, "application/octet-stream", file.Name);
} }
} }
else else
{ {
_logger.Log(LogLevel.Error, this, LogFunction.Read, "File Not Found {FileId}", id); _logger.Log(LogLevel.Error, this, LogFunction.Read, "File Not Found {FileId}", id);
HttpContext.Response.StatusCode = 404; HttpContext.Response.StatusCode = 404;
byte[] filebytes = System.IO.File.ReadAllBytes(errorpath); var stream = new FileStream(errorpath, FileMode.Open);
return File(filebytes, "application/octet-stream", "error.png"); return File(stream, "application/octet-stream", file.Name);
} }
return null; return null;
} }

View File

@ -58,7 +58,7 @@ namespace Oqtane.Controllers
if (theme != null && Utilities.GetAssemblyName(theme.ThemeName) != "Oqtane.Client") if (theme != null && Utilities.GetAssemblyName(theme.ThemeName) != "Oqtane.Client")
{ {
// use assets.json to clean up file resources // use assets.json to clean up file resources
string assetfilepath = Path.Combine(_environment.WebRootPath, "Modules", Utilities.GetTypeName(theme.ThemeName), "assets.json"); string assetfilepath = Path.Combine(_environment.WebRootPath, "Themes", Utilities.GetTypeName(theme.ThemeName), "assets.json");
if (System.IO.File.Exists(assetfilepath)) if (System.IO.File.Exists(assetfilepath))
{ {
List<string> assets = JsonSerializer.Deserialize<List<string>>(System.IO.File.ReadAllText(assetfilepath)); List<string> assets = JsonSerializer.Deserialize<List<string>>(System.IO.File.ReadAllText(assetfilepath));
@ -84,23 +84,5 @@ namespace Oqtane.Controllers
} }
} }
// GET api/<controller>/load/assembyname
[HttpGet("load/{assemblyname}")]
public IActionResult Load(string assemblyname)
{
if (Path.GetExtension(assemblyname).ToLower() == ".dll")
{
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
byte[] file = System.IO.File.ReadAllBytes(Path.Combine(binfolder, assemblyname));
return File(file, "application/octet-stream", assemblyname);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Read, "User Not Authorized To Download Assembly {Assembly}", assemblyname);
HttpContext.Response.StatusCode = 401;
return null;
}
}
} }
} }

View File

@ -14,6 +14,7 @@ using System.Net;
using Oqtane.Enums; using Oqtane.Enums;
using Oqtane.Infrastructure; using Oqtane.Infrastructure;
using Oqtane.Repository; using Oqtane.Repository;
using Oqtane.Extensions;
namespace Oqtane.Controllers namespace Oqtane.Controllers
{ {
@ -186,8 +187,12 @@ namespace Oqtane.Controllers
Path = Utilities.PathCombine(folder.Path, newUser.UserId.ToString(),Path.DirectorySeparatorChar.ToString()), Path = Utilities.PathCombine(folder.Path, newUser.UserId.ToString(),Path.DirectorySeparatorChar.ToString()),
Order = 1, Order = 1,
IsSystem = true, IsSystem = true,
Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"[" + newUser.UserId.ToString() + "]\"},{\"PermissionName\":\"View\",\"Permissions\":\"All Users\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"[" + Permissions = new List<Permission>
newUser.UserId.ToString() + "]\"}]" {
new Permission(PermissionNames.Browse, newUser.UserId, true),
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
new Permission(PermissionNames.Edit, newUser.UserId, true)
}.EncodePermissions()
}); });
} }
} }

View File

@ -119,7 +119,7 @@ namespace Oqtane.Infrastructure
// save list of assets // save list of assets
if (assets.Count != 0) if (assets.Count != 0)
{ {
string assetfilepath = Path.Combine(webRootPath, "Modules", name, "assets.json"); string assetfilepath = Path.Combine(webRootPath, folder, name, "assets.json");
if (File.Exists(assetfilepath)) if (File.Exists(assetfilepath))
{ {
File.Delete(assetfilepath); File.Delete(assetfilepath);

View File

@ -673,12 +673,22 @@ namespace Oqtane.Repository
Folder folder = _folderRepository.AddFolder(new Folder Folder folder = _folderRepository.AddFolder(new Folder
{ {
SiteId = site.SiteId, ParentId = null, Name = "Root", Path = "", Order = 1, IsSystem = true, SiteId = site.SiteId, ParentId = null, Name = "Root", Path = "", Order = 1, IsSystem = true,
Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"View\",\"Permissions\":\"All Users\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]" Permissions = new List<Permission>
{
new Permission(PermissionNames.Browse, Constants.AdminRole, true),
new Permission(PermissionNames.View, Constants.AllUsersRole, true),
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
}.EncodePermissions()
}); });
_folderRepository.AddFolder(new Folder _folderRepository.AddFolder(new Folder
{ {
SiteId = site.SiteId, ParentId = folder.FolderId, Name = "Users", Path = Utilities.PathCombine("Users",Path.DirectorySeparatorChar.ToString()), Order = 1, IsSystem = true, SiteId = site.SiteId, ParentId = folder.FolderId, Name = "Users", Path = Utilities.PathCombine("Users",Path.DirectorySeparatorChar.ToString()), Order = 1, IsSystem = true,
Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]" Permissions = new List<Permission>
{
new Permission(PermissionNames.Browse, Constants.AdminRole, true),
new Permission(PermissionNames.View, Constants.AdminRole, true),
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
}.EncodePermissions()
}); });
// process site template first // process site template first