extensibility enhancements for site templates
This commit is contained in:
@ -17,12 +17,14 @@ 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, ILogManager logger)
|
||||
public FolderController(IFolderRepository folders, IUserPermissions userPermissions, IPermissionRepository permissionRepository, ILogManager logger)
|
||||
{
|
||||
_folders = folders;
|
||||
_userPermissions = userPermissions;
|
||||
_permissionRepository = permissionRepository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -98,7 +100,9 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
permissions = UserSecurity.SetPermissionStrings(new List<PermissionString> { new PermissionString { PermissionName = PermissionNames.Edit, Permissions = Constants.AdminRole } });
|
||||
permissions = _permissionRepository.EncodePermissions(new List<Permission> {
|
||||
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
|
||||
});
|
||||
}
|
||||
if (_userPermissions.IsAuthorized(User,PermissionNames.Edit, permissions))
|
||||
{
|
||||
|
@ -31,9 +31,9 @@ namespace Oqtane.Controllers
|
||||
|
||||
// POST api/<controller>
|
||||
[HttpPost]
|
||||
public GenericResponse Post([FromBody] string connectionString)
|
||||
public Installation Post([FromBody] string connectionString)
|
||||
{
|
||||
var response = new GenericResponse { Success = false, Message = "" };
|
||||
var installation = new Installation { Success = false, Message = "" };
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
@ -110,7 +110,7 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.Message = "Can Not Create Database - " + ex.Message;
|
||||
installation.Message = "Can Not Create Database - " + ex.Message;
|
||||
}
|
||||
|
||||
// sleep to allow SQL server to attach new database
|
||||
@ -140,7 +140,7 @@ namespace Oqtane.Controllers
|
||||
var result = dbUpgrade.PerformUpgrade();
|
||||
if (!result.Successful)
|
||||
{
|
||||
response.Message = result.Error.Message;
|
||||
installation.Message = result.Error.Message;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -161,24 +161,24 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
_config.Reload();
|
||||
}
|
||||
response.Success = true;
|
||||
installation.Success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Message = "Application Is Already Installed";
|
||||
installation.Message = "Application Is Already Installed";
|
||||
}
|
||||
}
|
||||
return response;
|
||||
return installation;
|
||||
}
|
||||
|
||||
// GET api/<controller>/installed
|
||||
[HttpGet("installed")]
|
||||
public GenericResponse IsInstalled()
|
||||
public Installation IsInstalled()
|
||||
{
|
||||
var response = new GenericResponse { Success = false, Message = "" };
|
||||
var installation = new Installation { Success = false, Message = "" };
|
||||
|
||||
string datadirectory = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
|
||||
string connectionString = _config.GetConnectionString("DefaultConnection");
|
||||
@ -193,28 +193,28 @@ namespace Oqtane.Controllers
|
||||
{
|
||||
connection.Open();
|
||||
}
|
||||
response.Success = true;
|
||||
installation.Success = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// database does not exist
|
||||
response.Message = "Database Does Not Exist";
|
||||
installation.Message = "Database Does Not Exist";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.Message = "Connection String Has Not Been Specified In Oqtane.Server\\appsettings.json";
|
||||
installation.Message = "Connection String Has Not Been Specified In Oqtane.Server\\appsettings.json";
|
||||
}
|
||||
|
||||
if (response.Success)
|
||||
if (installation.Success)
|
||||
{
|
||||
var dbUpgradeConfig = DeployChanges.To.SqlDatabase(connectionString)
|
||||
.WithScript(new DbUp.Engine.SqlScript("Master.sql", ""));
|
||||
var dbUpgrade = dbUpgradeConfig.Build();
|
||||
response.Success = !dbUpgrade.IsUpgradeRequired();
|
||||
if (!response.Success)
|
||||
installation.Success = !dbUpgrade.IsUpgradeRequired();
|
||||
if (!installation.Success)
|
||||
{
|
||||
response.Message = "Master Installation Scripts Have Not Been Executed";
|
||||
installation.Message = "Master Installation Scripts Have Not Been Executed";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -264,7 +264,7 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
return installation;
|
||||
}
|
||||
|
||||
private void InstallModule(Assembly assembly, string connectionstring)
|
||||
@ -284,11 +284,11 @@ namespace Oqtane.Controllers
|
||||
|
||||
[HttpGet("upgrade")]
|
||||
[Authorize(Roles = Constants.HostRole)]
|
||||
public GenericResponse Upgrade()
|
||||
public Installation Upgrade()
|
||||
{
|
||||
var response = new GenericResponse { Success = true, Message = "" };
|
||||
var installation = new Installation { Success = true, Message = "" };
|
||||
_installationManager.UpgradeFramework();
|
||||
return response;
|
||||
return installation;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,15 +19,17 @@ 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, ISyncManager syncManager, ILogManager logger)
|
||||
public PageController(IPageRepository pages, IModuleRepository modules, IPageModuleRepository pageModules, IUserPermissions userPermissions, IPermissionRepository permissionRepository, ISyncManager syncManager, ILogManager logger)
|
||||
{
|
||||
_pages = pages;
|
||||
_modules = modules;
|
||||
_pageModules = pageModules;
|
||||
_userPermissions = userPermissions;
|
||||
_permissionRepository = permissionRepository;
|
||||
_syncManager = syncManager;
|
||||
_logger = logger;
|
||||
}
|
||||
@ -111,7 +113,9 @@ namespace Oqtane.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
permissions = UserSecurity.SetPermissionStrings(new List<PermissionString> { new PermissionString { PermissionName = PermissionNames.Edit, Permissions = Constants.AdminRole } });
|
||||
permissions = _permissionRepository.EncodePermissions(new List<Permission> {
|
||||
new Permission(PermissionNames.Edit, Constants.AdminRole, true)
|
||||
});
|
||||
}
|
||||
|
||||
if (_userPermissions.IsAuthorized(User,PermissionNames.Edit, permissions))
|
||||
@ -150,10 +154,10 @@ namespace Oqtane.Controllers
|
||||
page.ThemeType = parent.ThemeType;
|
||||
page.LayoutType = parent.LayoutType;
|
||||
page.Icon = parent.Icon;
|
||||
List<PermissionString> permissions = new List<PermissionString>();
|
||||
permissions.Add(new PermissionString { PermissionName = PermissionNames.View, Permissions = "[" + userid + "]" });
|
||||
permissions.Add(new PermissionString { PermissionName = PermissionNames.Edit, Permissions = "[" + userid + "]" });
|
||||
page.Permissions = UserSecurity.SetPermissionStrings(permissions);
|
||||
page.Permissions = _permissionRepository.EncodePermissions(new List<Permission> {
|
||||
new Permission(PermissionNames.View, userid, true),
|
||||
new Permission(PermissionNames.Edit, userid, true)
|
||||
});
|
||||
page.IsPersonalizable = false;
|
||||
page.UserId = int.Parse(userid);
|
||||
page = _pages.AddPage(page);
|
||||
@ -167,10 +171,10 @@ namespace Oqtane.Controllers
|
||||
module.SiteId = page.SiteId;
|
||||
module.PageId = page.PageId;
|
||||
module.ModuleDefinitionName = pm.Module.ModuleDefinitionName;
|
||||
permissions = new List<PermissionString>();
|
||||
permissions.Add(new PermissionString { PermissionName = PermissionNames.View, Permissions = "[" + userid + "]" });
|
||||
permissions.Add(new PermissionString { PermissionName = PermissionNames.Edit, Permissions = "[" + userid + "]" });
|
||||
module.Permissions = UserSecurity.SetPermissionStrings(permissions);
|
||||
module.Permissions = _permissionRepository.EncodePermissions(new List<Permission> {
|
||||
new Permission(PermissionNames.View, userid, true),
|
||||
new Permission(PermissionNames.Edit, userid, true)
|
||||
});
|
||||
module = _modules.AddModule(module);
|
||||
|
||||
string content = _modules.ExportModule(pm.ModuleId);
|
||||
|
25
Oqtane.Server/Controllers/SiteTemplateController.cs
Normal file
25
Oqtane.Server/Controllers/SiteTemplateController.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route("{site}/api/[controller]")]
|
||||
public class SiteTemplateController : Controller
|
||||
{
|
||||
private readonly ISiteTemplateRepository _siteTemplates;
|
||||
|
||||
public SiteTemplateController(ISiteTemplateRepository siteTemplates)
|
||||
{
|
||||
_siteTemplates = siteTemplates;
|
||||
}
|
||||
|
||||
// GET: api/<controller>
|
||||
[HttpGet]
|
||||
public IEnumerable<SiteTemplate> Get()
|
||||
{
|
||||
return _siteTemplates.GetSiteTemplates();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user