Merge branch 'master' into master
This commit is contained in:
@ -6,6 +6,7 @@ using Oqtane.Shared;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Extensions;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Security;
|
||||
@ -18,14 +19,12 @@ namespace Oqtane.Controllers
|
||||
{
|
||||
private readonly IFolderRepository _folders;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly IPermissionRepository _permissionRepository;
|
||||
private readonly ILogManager _logger;
|
||||
|
||||
public FolderController(IFolderRepository folders, IUserPermissions userPermissions, IPermissionRepository permissionRepository, ILogManager logger)
|
||||
public FolderController(IFolderRepository folders, IUserPermissions userPermissions, ILogManager logger)
|
||||
{
|
||||
_folders = folders;
|
||||
_userPermissions = userPermissions;
|
||||
_permissionRepository = permissionRepository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -101,9 +100,9 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
permissions = _permissionRepository.EncodePermissions(new List<Permission> {
|
||||
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
|
||||
});
|
||||
permissions = new List<Permission> {
|
||||
new Permission(PermissionNames.Edit, Constants.AdminRole, true),
|
||||
}.EncodePermissions();
|
||||
}
|
||||
if (_userPermissions.IsAuthorized(User,PermissionNames.Edit, permissions))
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Security;
|
||||
using System;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
// ReSharper disable StringIndexOfIsCultureSpecific.1
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
@ -25,21 +25,17 @@ namespace Oqtane.Controllers
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly IInstallationManager _installationManager;
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
private readonly ITenantResolver _resolver;
|
||||
private readonly ITenantRepository _tenants;
|
||||
private readonly ISqlRepository _sql;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ILogManager _logger;
|
||||
|
||||
public ModuleDefinitionController(IModuleDefinitionRepository moduleDefinitions, IModuleRepository modules, IUserPermissions userPermissions, IInstallationManager installationManager, IWebHostEnvironment environment, ITenantResolver resolver, ITenantRepository tenants, ISqlRepository sql, ILogManager logger)
|
||||
public ModuleDefinitionController(IModuleDefinitionRepository moduleDefinitions, IModuleRepository modules, IUserPermissions userPermissions, IInstallationManager installationManager, IWebHostEnvironment environment, IServiceProvider serviceProvider, ILogManager logger)
|
||||
{
|
||||
_moduleDefinitions = moduleDefinitions;
|
||||
_modules = modules;
|
||||
_userPermissions = userPermissions;
|
||||
_installationManager = installationManager;
|
||||
_environment = environment;
|
||||
_resolver = resolver;
|
||||
_tenants = tenants;
|
||||
_sql = sql;
|
||||
_serviceProvider = serviceProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -100,57 +96,44 @@ namespace Oqtane.Controllers
|
||||
[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();
|
||||
ModuleDefinition moduledefinition = _moduleDefinitions.GetModuleDefinition(id, siteid);
|
||||
if (moduledefinition != null)
|
||||
{
|
||||
// server assembly name should follow client naming convention
|
||||
string assemblyname = Utilities.GetAssemblyName(moduledefinition.ModuleDefinitionName).Replace(".Client",".Server");
|
||||
|
||||
string uninstallScript = "";
|
||||
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(a => a.GetName().Name == assemblyname);
|
||||
if (assembly != null)
|
||||
if (!string.IsNullOrEmpty(moduledefinition.ServerManagerType))
|
||||
{
|
||||
Stream resourceStream = assembly.GetManifestResourceStream(assemblyname + ".Scripts.Uninstall.sql");
|
||||
if (resourceStream != null)
|
||||
Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
|
||||
if (moduletype != null && moduletype.GetInterface("IInstallable") != null)
|
||||
{
|
||||
using (var reader = new StreamReader(resourceStream))
|
||||
{
|
||||
uninstallScript = reader.ReadToEnd();
|
||||
}
|
||||
var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
|
||||
((IInstallable)moduleobject).Uninstall();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Tenant tenant in _tenants.GetTenants())
|
||||
{
|
||||
// uninstall module database schema
|
||||
if (!string.IsNullOrEmpty(uninstallScript))
|
||||
{
|
||||
_sql.ExecuteScript(tenant, uninstallScript);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Uninstall Script Executed For {AssemblyName}", assemblyname);
|
||||
}
|
||||
// clean up module schema versions
|
||||
_sql.ExecuteNonQuery(tenant, "DELETE FROM [dbo].[SchemaVersions] WHERE ScriptName LIKE '" + assemblyname + "%'");
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Schema Versions Removed For {AssemblyName}", assemblyname);
|
||||
}
|
||||
|
||||
// format root assembly name
|
||||
assemblyname = assemblyname.Replace(".Server", "");
|
||||
|
||||
// clean up module static resource folder
|
||||
string folder = Path.Combine(_environment.WebRootPath, Path.Combine("Modules",assemblyname));
|
||||
if (Directory.Exists(folder))
|
||||
string assemblyname = Utilities.GetAssemblyName(moduledefinition.ModuleDefinitionName);
|
||||
if (assemblyname != "Oqtane.Client")
|
||||
{
|
||||
Directory.Delete(folder, true);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Static Resources Removed For {AssemblynName}", assemblyname);
|
||||
}
|
||||
assemblyname = assemblyname.Replace(".Client", "");
|
||||
|
||||
// remove module assembly from /bin
|
||||
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
foreach (string file in Directory.EnumerateFiles(binfolder, assemblyname + "*.*"))
|
||||
{
|
||||
System.IO.File.Delete(file);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Assembly Removed {Filename}", file);
|
||||
// clean up module static resource folder
|
||||
string folder = Path.Combine(_environment.WebRootPath, Path.Combine("Modules",assemblyname));
|
||||
if (Directory.Exists(folder))
|
||||
{
|
||||
Directory.Delete(folder, true);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Static Resources Removed For {AssemblynName}", assemblyname);
|
||||
}
|
||||
|
||||
// remove module assembly from /bin
|
||||
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
foreach (string file in Directory.EnumerateFiles(binfolder, assemblyname + "*.*"))
|
||||
{
|
||||
System.IO.File.Delete(file);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Assembly Removed {Filename}", file);
|
||||
}
|
||||
|
||||
// clean up module schema versions
|
||||
_sql.ExecuteNonQuery(tenant, "DELETE FROM [dbo].[SchemaVersions] WHERE ScriptName LIKE '" + assemblyname + "%'");
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Module Schema Versions Removed For {AssemblyName}", assemblyname);
|
||||
}
|
||||
|
||||
// remove module definition
|
||||
@ -247,12 +230,6 @@ namespace Oqtane.Controllers
|
||||
text = text.Replace("[File]", Path.GetFileName(filePath));
|
||||
text = text.Replace("[FrameworkVersion]", Constants.Version);
|
||||
System.IO.File.WriteAllText(filePath, text);
|
||||
|
||||
if (Path.GetExtension(filePath).ToLower() == ".sql" && !filePath.ToLower().Contains("uninstall"))
|
||||
{
|
||||
// execute installation script in curent tenant
|
||||
_sql.ExecuteScript(_resolver.GetTenant(), text);
|
||||
}
|
||||
}
|
||||
|
||||
DirectoryInfo[] folders = current.GetDirectories();
|
||||
|
@ -7,6 +7,7 @@ using System.Linq;
|
||||
using Oqtane.Security;
|
||||
using System.Net;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Extensions;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository;
|
||||
|
||||
@ -19,17 +20,15 @@ namespace Oqtane.Controllers
|
||||
private readonly IModuleRepository _modules;
|
||||
private readonly IPageModuleRepository _pageModules;
|
||||
private readonly IUserPermissions _userPermissions;
|
||||
private readonly IPermissionRepository _permissionRepository;
|
||||
private readonly ISyncManager _syncManager;
|
||||
private readonly ILogManager _logger;
|
||||
|
||||
public PageController(IPageRepository pages, IModuleRepository modules, IPageModuleRepository pageModules, IUserPermissions userPermissions, IPermissionRepository permissionRepository, ISyncManager syncManager, ILogManager logger)
|
||||
public PageController(IPageRepository pages, IModuleRepository modules, IPageModuleRepository pageModules, IUserPermissions userPermissions, ISyncManager syncManager, ILogManager logger)
|
||||
{
|
||||
_pages = pages;
|
||||
_modules = modules;
|
||||
_pageModules = pageModules;
|
||||
_userPermissions = userPermissions;
|
||||
_permissionRepository = permissionRepository;
|
||||
_syncManager = syncManager;
|
||||
_logger = logger;
|
||||
}
|
||||
@ -113,9 +112,9 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
permissions = _permissionRepository.EncodePermissions(new List<Permission> {
|
||||
permissions = new List<Permission> {
|
||||
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
|
||||
});
|
||||
}.EncodePermissions();
|
||||
}
|
||||
|
||||
if (_userPermissions.IsAuthorized(User,PermissionNames.Edit, permissions))
|
||||
@ -156,10 +155,10 @@ namespace Oqtane.Controllers
|
||||
page.ThemeType = parent.ThemeType;
|
||||
page.LayoutType = parent.LayoutType;
|
||||
page.Icon = parent.Icon;
|
||||
page.Permissions = _permissionRepository.EncodePermissions(new List<Permission> {
|
||||
page.Permissions = new List<Permission> {
|
||||
new Permission(PermissionNames.View, userid, true),
|
||||
new Permission(PermissionNames.Edit, userid, true)
|
||||
});
|
||||
}.EncodePermissions();
|
||||
page.IsPersonalizable = false;
|
||||
page.UserId = int.Parse(userid);
|
||||
page = _pages.AddPage(page);
|
||||
@ -173,10 +172,10 @@ namespace Oqtane.Controllers
|
||||
module.SiteId = page.SiteId;
|
||||
module.PageId = page.PageId;
|
||||
module.ModuleDefinitionName = pm.Module.ModuleDefinitionName;
|
||||
module.Permissions = _permissionRepository.EncodePermissions(new List<Permission> {
|
||||
module.Permissions = new List<Permission> {
|
||||
new Permission(PermissionNames.View, userid, true),
|
||||
new Permission(PermissionNames.Edit, userid, true)
|
||||
});
|
||||
}.EncodePermissions();
|
||||
module = _modules.AddModule(module);
|
||||
|
||||
string content = _modules.ExportModule(pm.ModuleId);
|
||||
|
@ -70,7 +70,7 @@ namespace Oqtane.Controllers
|
||||
|
||||
// PUT api/<controller>/5
|
||||
[HttpPut("{id}")]
|
||||
[Authorize(Roles = Constants.HostRole)]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
public Site Put(int id, [FromBody] Site site)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
|
35
Oqtane.Server/Controllers/SystemController.cs
Normal file
35
Oqtane.Server/Controllers/SystemController.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Shared;
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route("{site}/api/[controller]")]
|
||||
public class SystemController : Controller
|
||||
{
|
||||
private readonly IWebHostEnvironment _environment;
|
||||
|
||||
public SystemController(IWebHostEnvironment environment)
|
||||
{
|
||||
_environment = environment;
|
||||
}
|
||||
|
||||
// GET: api/<controller>
|
||||
[HttpGet]
|
||||
[Authorize(Roles = Constants.HostRole)]
|
||||
public Dictionary<string, string> Get()
|
||||
{
|
||||
Dictionary<string, string> systeminfo = new Dictionary<string, string>();
|
||||
systeminfo.Add("clrversion", Environment.Version.ToString());
|
||||
systeminfo.Add("osversion", Environment.OSVersion.ToString());
|
||||
systeminfo.Add("machinename", Environment.MachineName);
|
||||
systeminfo.Add("serverpath", _environment.ContentRootPath);
|
||||
systeminfo.Add("servertime", DateTime.Now.ToString());
|
||||
return systeminfo;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ namespace Oqtane.Controllers
|
||||
|
||||
// GET: api/<controller>
|
||||
[HttpGet]
|
||||
[Authorize(Roles = Constants.HostRole)]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
public IEnumerable<Tenant> Get()
|
||||
{
|
||||
return _tenants.GetTenants();
|
||||
@ -31,7 +31,7 @@ namespace Oqtane.Controllers
|
||||
|
||||
// GET api/<controller>/5
|
||||
[HttpGet("{id}")]
|
||||
[Authorize(Roles = Constants.HostRole)]
|
||||
[Authorize(Roles = Constants.AdminRole)]
|
||||
public Tenant Get(int id)
|
||||
{
|
||||
return _tenants.GetTenant(id);
|
||||
|
@ -93,14 +93,14 @@ namespace Oqtane.Controllers
|
||||
|
||||
bool verified;
|
||||
bool allowregistration;
|
||||
if (user.Username == Constants.HostUser)
|
||||
if (user.Username == Constants.HostUser || User.IsInRole(Constants.AdminRole))
|
||||
{
|
||||
verified = true;
|
||||
allowregistration = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
verified = User.IsInRole(Constants.AdminRole); // only users created by administrators are verified
|
||||
{
|
||||
verified = false;
|
||||
allowregistration = _sites.GetSite(user.SiteId).AllowRegistration;
|
||||
}
|
||||
|
||||
@ -308,7 +308,7 @@ namespace Oqtane.Controllers
|
||||
public async Task Logout([FromBody] User user)
|
||||
{
|
||||
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Logout {Username}", user.Username);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Logout {Username}", (user != null) ? user.Username : "");
|
||||
}
|
||||
|
||||
// POST api/<controller>/verify
|
||||
|
Reference in New Issue
Block a user