Server naming fixes and cleanup
Server is now completely cleaned up and without warnings
This commit is contained in:
parent
ab3f0853a7
commit
5b3feaf26f
@ -1,14 +1,14 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using System;
|
using System;
|
||||||
@ -15,6 +13,10 @@ using Oqtane.Security;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
|
// ReSharper disable StringIndexOfIsCultureSpecific.1
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -170,23 +172,23 @@ namespace Oqtane.Controllers
|
|||||||
Folder folder = _folders.GetFolder(int.Parse(folderid));
|
Folder folder = _folders.GetFolder(int.Parse(folderid));
|
||||||
if (folder != null && _userPermissions.IsAuthorized(User, PermissionNames.Edit, folder.Permissions))
|
if (folder != null && _userPermissions.IsAuthorized(User, PermissionNames.Edit, folder.Permissions))
|
||||||
{
|
{
|
||||||
string folderpath = GetFolderPath(folder);
|
string folderPath = GetFolderPath(folder);
|
||||||
CreateDirectory(folderpath);
|
CreateDirectory(folderPath);
|
||||||
string filename = url.Substring(url.LastIndexOf("/", StringComparison.Ordinal) + 1);
|
string filename = url.Substring(url.LastIndexOf("/", StringComparison.Ordinal) + 1);
|
||||||
// check for allowable file extensions
|
// check for allowable file extensions
|
||||||
if (Constants.UploadableFiles.Contains(Path.GetExtension(filename).Replace(".", "")))
|
if (Constants.UploadableFiles.Contains(Path.GetExtension(filename).Replace(".", "")))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var client = new System.Net.WebClient();
|
var client = new WebClient();
|
||||||
// remove file if it already exists
|
// remove file if it already exists
|
||||||
if (System.IO.File.Exists(folderpath + filename))
|
if (System.IO.File.Exists(folderPath + filename))
|
||||||
{
|
{
|
||||||
System.IO.File.Delete(folderpath + filename);
|
System.IO.File.Delete(folderPath + filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.DownloadFile(url, folderpath + filename);
|
client.DownloadFile(url, folderPath + filename);
|
||||||
_files.AddFile(CreateFile(filename, folder.FolderId, folderpath + filename));
|
_files.AddFile(CreateFile(filename, folder.FolderId, folderPath + filename));
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -202,7 +204,6 @@ namespace Oqtane.Controllers
|
|||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Download File {Url} {FolderId}", url, folderid);
|
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Download File {Url} {FolderId}", url, folderid);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
file = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
@ -214,36 +215,36 @@ namespace Oqtane.Controllers
|
|||||||
{
|
{
|
||||||
if (file.Length > 0)
|
if (file.Length > 0)
|
||||||
{
|
{
|
||||||
string folderpath = "";
|
string folderPath = "";
|
||||||
int folderid = -1;
|
|
||||||
if (int.TryParse(folder, out folderid))
|
if (int.TryParse(folder, out int folderId))
|
||||||
{
|
{
|
||||||
Folder Folder = _folders.GetFolder(folderid);
|
Folder virtualFolder = _folders.GetFolder(folderId);
|
||||||
if (Folder != null && _userPermissions.IsAuthorized(User, PermissionNames.Edit, Folder.Permissions))
|
if (virtualFolder != null && _userPermissions.IsAuthorized(User, PermissionNames.Edit, virtualFolder.Permissions))
|
||||||
{
|
{
|
||||||
folderpath = GetFolderPath(Folder);
|
folderPath = GetFolderPath(virtualFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (User.IsInRole(Constants.HostRole))
|
if (User.IsInRole(Constants.HostRole))
|
||||||
{
|
{
|
||||||
folderpath = GetFolderPath(folder);
|
folderPath = GetFolderPath(folder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (folderpath != "")
|
if (folderPath != "")
|
||||||
{
|
{
|
||||||
CreateDirectory(folderpath);
|
CreateDirectory(folderPath);
|
||||||
using (var stream = new FileStream(Path.Combine(folderpath, file.FileName), FileMode.Create))
|
using (var stream = new FileStream(Path.Combine(folderPath, file.FileName), FileMode.Create))
|
||||||
{
|
{
|
||||||
await file.CopyToAsync(stream);
|
await file.CopyToAsync(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
string upload = await MergeFile(folderpath, file.FileName);
|
string upload = await MergeFile(folderPath, file.FileName);
|
||||||
if (upload != "" && folderid != -1)
|
if (upload != "" && folderId != -1)
|
||||||
{
|
{
|
||||||
_files.AddFile(CreateFile(upload, folderid, folderpath + upload));
|
_files.AddFile(CreateFile(upload, folderId, folderPath + upload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -341,7 +342,7 @@ namespace Oqtane.Controllers
|
|||||||
{
|
{
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
bool locked = true;
|
bool locked = true;
|
||||||
while (attempts < 5 && locked == true)
|
while (attempts < 5 && locked)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -415,7 +416,7 @@ namespace Oqtane.Controllers
|
|||||||
if (!Directory.Exists(folderpath))
|
if (!Directory.Exists(folderpath))
|
||||||
{
|
{
|
||||||
string path = "";
|
string path = "";
|
||||||
string[] folders = folderpath.Split(new char[] {'\\'}, StringSplitOptions.RemoveEmptyEntries);
|
string[] folders = folderpath.Split(new[] {'\\'}, StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (string folder in folders)
|
foreach (string folder in folders)
|
||||||
{
|
{
|
||||||
path += folder + "\\";
|
path += folder + "\\";
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
using Oqtane.Security;
|
using Oqtane.Security;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
@ -86,14 +86,14 @@ namespace Oqtane.Controllers
|
|||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public Folder Post([FromBody] Folder Folder)
|
public Folder Post([FromBody] Folder folder)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
string permissions;
|
string permissions;
|
||||||
if (Folder.ParentId != null)
|
if (folder.ParentId != null)
|
||||||
{
|
{
|
||||||
permissions = _folders.GetFolder(Folder.ParentId.Value).Permissions;
|
permissions = _folders.GetFolder(folder.ParentId.Value).Permissions;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -101,46 +101,46 @@ namespace Oqtane.Controllers
|
|||||||
}
|
}
|
||||||
if (_userPermissions.IsAuthorized(User,PermissionNames.Edit, permissions))
|
if (_userPermissions.IsAuthorized(User,PermissionNames.Edit, permissions))
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(Folder.Path) && Folder.ParentId != null)
|
if (string.IsNullOrEmpty(folder.Path) && folder.ParentId != null)
|
||||||
{
|
{
|
||||||
Folder parent = _folders.GetFolder(Folder.ParentId.Value);
|
Folder parent = _folders.GetFolder(folder.ParentId.Value);
|
||||||
Folder.Path = parent.Path + Folder.Name + "\\";
|
folder.Path = parent.Path + folder.Name + "\\";
|
||||||
}
|
}
|
||||||
Folder = _folders.AddFolder(Folder);
|
folder = _folders.AddFolder(folder);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Folder Added {Folder}", Folder);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Folder Added {Folder}", folder);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Folder {Folder}", Folder);
|
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Folder {Folder}", folder);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
Folder = null;
|
folder = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public Folder Put(int id, [FromBody] Folder Folder)
|
public Folder Put(int id, [FromBody] Folder folder)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Folder, Folder.FolderId, PermissionNames.Edit))
|
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Folder, folder.FolderId, PermissionNames.Edit))
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(Folder.Path) && Folder.ParentId != null)
|
if (string.IsNullOrEmpty(folder.Path) && folder.ParentId != null)
|
||||||
{
|
{
|
||||||
Folder parent = _folders.GetFolder(Folder.ParentId.Value);
|
Folder parent = _folders.GetFolder(folder.ParentId.Value);
|
||||||
Folder.Path = parent.Path + Folder.Name + "\\";
|
folder.Path = parent.Path + folder.Name + "\\";
|
||||||
}
|
}
|
||||||
Folder = _folders.UpdateFolder(Folder);
|
folder = _folders.UpdateFolder(folder);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Folder Updated {Folder}", Folder);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Folder Updated {Folder}", folder);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update Folder {Folder}", Folder);
|
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update Folder {Folder}", folder);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
Folder = null;
|
folder = null;
|
||||||
}
|
}
|
||||||
return Folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/?siteid=x&folderid=y&parentid=z
|
// PUT api/<controller>/?siteid=x&folderid=y&parentid=z
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
using DbUp;
|
using DbUp;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using System;
|
using System;
|
||||||
@ -13,6 +11,9 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
|
||||||
|
// ReSharper disable StringIndexOfIsCultureSpecific.1
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -30,7 +31,7 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public GenericResponse Post([FromBody] string connectionstring)
|
public GenericResponse Post([FromBody] string connectionString)
|
||||||
{
|
{
|
||||||
var response = new GenericResponse { Success = false, Message = "" };
|
var response = new GenericResponse { Success = false, Message = "" };
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ namespace Oqtane.Controllers
|
|||||||
{
|
{
|
||||||
bool master = false;
|
bool master = false;
|
||||||
string defaultconnectionstring = _config.GetConnectionString("DefaultConnection");
|
string defaultconnectionstring = _config.GetConnectionString("DefaultConnection");
|
||||||
if (string.IsNullOrEmpty(defaultconnectionstring) || connectionstring == defaultconnectionstring)
|
if (string.IsNullOrEmpty(defaultconnectionstring) || connectionString == defaultconnectionstring)
|
||||||
{
|
{
|
||||||
master = true;
|
master = true;
|
||||||
}
|
}
|
||||||
@ -52,9 +53,9 @@ namespace Oqtane.Controllers
|
|||||||
if (!exists)
|
if (!exists)
|
||||||
{
|
{
|
||||||
string datadirectory = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
|
string datadirectory = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
|
||||||
connectionstring = connectionstring.Replace("|DataDirectory|", datadirectory);
|
connectionString = connectionString.Replace("|DataDirectory|", datadirectory);
|
||||||
|
|
||||||
SqlConnection connection = new SqlConnection(connectionstring);
|
SqlConnection connection = new SqlConnection(connectionString);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (connection)
|
using (connection)
|
||||||
@ -73,7 +74,7 @@ namespace Oqtane.Controllers
|
|||||||
{
|
{
|
||||||
string masterConnectionString = "";
|
string masterConnectionString = "";
|
||||||
string databaseName = "";
|
string databaseName = "";
|
||||||
string[] fragments = connectionstring.Split(';', StringSplitOptions.RemoveEmptyEntries);
|
string[] fragments = connectionString.Split(';', StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (string fragment in fragments)
|
foreach (string fragment in fragments)
|
||||||
{
|
{
|
||||||
if (fragment.ToLower().Contains("initial catalog=") || fragment.ToLower().Contains("database="))
|
if (fragment.ToLower().Contains("initial catalog=") || fragment.ToLower().Contains("database="))
|
||||||
@ -95,7 +96,7 @@ namespace Oqtane.Controllers
|
|||||||
{
|
{
|
||||||
connection.Open();
|
connection.Open();
|
||||||
SqlCommand command;
|
SqlCommand command;
|
||||||
if (connectionstring.ToLower().Contains("attachdbfilename=")) // LocalDB
|
if (connectionString.ToLower().Contains("attachdbfilename=")) // LocalDB
|
||||||
{
|
{
|
||||||
command = new SqlCommand("CREATE DATABASE [" + databaseName + "] ON ( NAME = '" + databaseName + "', FILENAME = '" + datadirectory + "\\" + databaseName + ".mdf')", connection);
|
command = new SqlCommand("CREATE DATABASE [" + databaseName + "] ON ( NAME = '" + databaseName + "', FILENAME = '" + datadirectory + "\\" + databaseName + ".mdf')", connection);
|
||||||
}
|
}
|
||||||
@ -126,11 +127,11 @@ namespace Oqtane.Controllers
|
|||||||
{
|
{
|
||||||
initializationScript = reader.ReadToEnd();
|
initializationScript = reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
initializationScript = initializationScript.Replace("{ConnectionString}", connectionstring.Replace(datadirectory, "|DataDirectory|"));
|
initializationScript = initializationScript.Replace("{ConnectionString}", connectionString.Replace(datadirectory, "|DataDirectory|"));
|
||||||
initializationScript = initializationScript.Replace("{Alias}", HttpContext.Request.Host.Value);
|
initializationScript = initializationScript.Replace("{Alias}", HttpContext.Request.Host.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var dbUpgradeConfig = DeployChanges.To.SqlDatabase(connectionstring)
|
var dbUpgradeConfig = DeployChanges.To.SqlDatabase(connectionString)
|
||||||
.WithScript(new DbUp.Engine.SqlScript("Master.sql", initializationScript))
|
.WithScript(new DbUp.Engine.SqlScript("Master.sql", initializationScript))
|
||||||
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()); // tenant scripts should be added to /Scripts folder as Embedded Resources
|
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()); // tenant scripts should be added to /Scripts folder as Embedded Resources
|
||||||
var dbUpgrade = dbUpgradeConfig.Build();
|
var dbUpgrade = dbUpgradeConfig.Build();
|
||||||
@ -151,9 +152,9 @@ namespace Oqtane.Controllers
|
|||||||
{
|
{
|
||||||
config = reader.ReadToEnd();
|
config = reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
connectionstring = connectionstring.Replace(datadirectory, "|DataDirectory|");
|
connectionString = connectionString.Replace(datadirectory, "|DataDirectory|");
|
||||||
connectionstring = connectionstring.Replace(@"\", @"\\");
|
connectionString = connectionString.Replace(@"\", @"\\");
|
||||||
config = config.Replace("DefaultConnection\": \"", "DefaultConnection\": \"" + connectionstring);
|
config = config.Replace("DefaultConnection\": \"", "DefaultConnection\": \"" + connectionString);
|
||||||
using (StreamWriter writer = new StreamWriter(Directory.GetCurrentDirectory() + "\\appsettings.json"))
|
using (StreamWriter writer = new StreamWriter(Directory.GetCurrentDirectory() + "\\appsettings.json"))
|
||||||
{
|
{
|
||||||
writer.WriteLine(config);
|
writer.WriteLine(config);
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -44,27 +44,27 @@ namespace Oqtane.Controllers
|
|||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.HostRole)]
|
[Authorize(Roles = Constants.HostRole)]
|
||||||
public Job Post([FromBody] Job Job)
|
public Job Post([FromBody] Job job)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
Job = _jobs.AddJob(Job);
|
job = _jobs.AddJob(job);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Job Added {Job}", Job);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Job Added {Job}", job);
|
||||||
}
|
}
|
||||||
return Job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.HostRole)]
|
[Authorize(Roles = Constants.HostRole)]
|
||||||
public Job Put(int id, [FromBody] Job Job)
|
public Job Put(int id, [FromBody] Job job)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
Job = _jobs.UpdateJob(Job);
|
job = _jobs.UpdateJob(job);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Job Updated {Job}", Job);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Job Updated {Job}", job);
|
||||||
}
|
}
|
||||||
return Job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -39,27 +39,27 @@ namespace Oqtane.Controllers
|
|||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.HostRole)]
|
[Authorize(Roles = Constants.HostRole)]
|
||||||
public JobLog Post([FromBody] JobLog JobLog)
|
public JobLog Post([FromBody] JobLog jobLog)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
JobLog = _jobLogs.AddJobLog(JobLog);
|
jobLog = _jobLogs.AddJobLog(jobLog);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Job Log Added {JobLog}", JobLog);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Job Log Added {JobLog}", jobLog);
|
||||||
}
|
}
|
||||||
return JobLog;
|
return jobLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.HostRole)]
|
[Authorize(Roles = Constants.HostRole)]
|
||||||
public JobLog Put(int id, [FromBody] JobLog JobLog)
|
public JobLog Put(int id, [FromBody] JobLog jobLog)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
JobLog = _jobLogs.UpdateJobLog(JobLog);
|
jobLog = _jobLogs.UpdateJobLog(jobLog);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Job Log Updated {JobLog}", JobLog);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Job Log Updated {JobLog}", jobLog);
|
||||||
}
|
}
|
||||||
return JobLog;
|
return jobLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
@ -39,11 +39,11 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Post([FromBody] Log Log)
|
public void Post([FromBody] Log log)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
_logger.Log(Log);
|
_logger.Log(log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Repository;
|
||||||
using Oqtane.Security;
|
using Oqtane.Security;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
@ -31,15 +30,15 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
// GET: api/<controller>?siteid=x
|
// GET: api/<controller>?siteid=x
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IEnumerable<Models.Module> Get(string siteid)
|
public IEnumerable<Module> Get(string siteid)
|
||||||
{
|
{
|
||||||
List<ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(int.Parse(siteid)).ToList();
|
List<ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(int.Parse(siteid)).ToList();
|
||||||
List<Models.Module> modules = new List<Models.Module>();
|
List<Module> modules = new List<Module>();
|
||||||
foreach (PageModule pagemodule in _pageModules.GetPageModules(int.Parse(siteid)))
|
foreach (PageModule pagemodule in _pageModules.GetPageModules(int.Parse(siteid)))
|
||||||
{
|
{
|
||||||
if (_userPermissions.IsAuthorized(User,PermissionNames.View, pagemodule.Module.Permissions))
|
if (_userPermissions.IsAuthorized(User,PermissionNames.View, pagemodule.Module.Permissions))
|
||||||
{
|
{
|
||||||
Models.Module module = new Models.Module();
|
Module module = new Module();
|
||||||
module.SiteId = pagemodule.Module.SiteId;
|
module.SiteId = pagemodule.Module.SiteId;
|
||||||
module.ModuleDefinitionName = pagemodule.Module.ModuleDefinitionName;
|
module.ModuleDefinitionName = pagemodule.Module.ModuleDefinitionName;
|
||||||
module.Permissions = pagemodule.Module.Permissions;
|
module.Permissions = pagemodule.Module.Permissions;
|
||||||
@ -67,9 +66,9 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
// GET api/<controller>/5
|
// GET api/<controller>/5
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public Models.Module Get(int id)
|
public Module Get(int id)
|
||||||
{
|
{
|
||||||
Models.Module module = _modules.GetModule(id);
|
Module module = _modules.GetModule(id);
|
||||||
if (_userPermissions.IsAuthorized(User,PermissionNames.View, module.Permissions))
|
if (_userPermissions.IsAuthorized(User,PermissionNames.View, module.Permissions))
|
||||||
{
|
{
|
||||||
List<ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
|
List<ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
|
||||||
@ -87,39 +86,39 @@ namespace Oqtane.Controllers
|
|||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public Models.Module Post([FromBody] Models.Module Module)
|
public Module Post([FromBody] Module module)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, Module.PageId, PermissionNames.Edit))
|
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, module.PageId, PermissionNames.Edit))
|
||||||
{
|
{
|
||||||
Module = _modules.AddModule(Module);
|
module = _modules.AddModule(module);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Module Added {Module}", Module);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Module Added {Module}", module);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Module {Module}", Module);
|
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Module {Module}", module);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
Module = null;
|
module = null;
|
||||||
}
|
}
|
||||||
return Module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public Models.Module Put(int id, [FromBody] Models.Module Module)
|
public Module Put(int id, [FromBody] Module module)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Module, Module.ModuleId, PermissionNames.Edit))
|
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Module, module.ModuleId, PermissionNames.Edit))
|
||||||
{
|
{
|
||||||
Module = _modules.UpdateModule(Module);
|
module = _modules.UpdateModule(module);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Module Updated {Module}", Module);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Module Updated {Module}", module);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update Module {Module}", Module);
|
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update Module {Module}", module);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
Module = null;
|
module = null;
|
||||||
}
|
}
|
||||||
return Module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
@ -160,12 +159,12 @@ namespace Oqtane.Controllers
|
|||||||
// POST api/<controller>/import?moduleid=x
|
// POST api/<controller>/import?moduleid=x
|
||||||
[HttpPost("import")]
|
[HttpPost("import")]
|
||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public bool Import(int moduleid, [FromBody] string Content)
|
public bool Import(int moduleid, [FromBody] string content)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Module, moduleid, PermissionNames.Edit))
|
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Module, moduleid, PermissionNames.Edit))
|
||||||
{
|
{
|
||||||
success = _modules.ImportModule(moduleid, Content);
|
success = _modules.ImportModule(moduleid, content);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
using Oqtane.Security;
|
using Oqtane.Security;
|
||||||
|
// ReSharper disable StringIndexOfIsCultureSpecific.1
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -66,12 +67,12 @@ namespace Oqtane.Controllers
|
|||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.AdminRole)]
|
[Authorize(Roles = Constants.AdminRole)]
|
||||||
public void Put(int id, [FromBody] ModuleDefinition ModuleDefinition)
|
public void Put(int id, [FromBody] ModuleDefinition moduleDefinition)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
_moduleDefinitions.UpdateModuleDefinition(ModuleDefinition);
|
_moduleDefinitions.UpdateModuleDefinition(moduleDefinition);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Module Definition Updated {ModuleDefinition}", ModuleDefinition);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Module Definition Updated {ModuleDefinition}", moduleDefinition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Oqtane.Repository;
|
||||||
using Oqtane.Security;
|
using Oqtane.Security;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
@ -49,38 +48,38 @@ namespace Oqtane.Controllers
|
|||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public Notification Get(int id)
|
public Notification Get(int id)
|
||||||
{
|
{
|
||||||
Notification Notification = _notifications.GetNotification(id);
|
Notification notification = _notifications.GetNotification(id);
|
||||||
if (!(IsAuthorized(Notification.FromUserId) || IsAuthorized(Notification.ToUserId)))
|
if (!(IsAuthorized(notification.FromUserId) || IsAuthorized(notification.ToUserId)))
|
||||||
{
|
{
|
||||||
Notification = null;
|
notification = null;
|
||||||
}
|
}
|
||||||
return Notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public Notification Post([FromBody] Notification Notification)
|
public Notification Post([FromBody] Notification notification)
|
||||||
{
|
{
|
||||||
if (IsAuthorized(Notification.FromUserId))
|
if (IsAuthorized(notification.FromUserId))
|
||||||
{
|
{
|
||||||
Notification = _notifications.AddNotification(Notification);
|
notification = _notifications.AddNotification(notification);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Notification Added {Notification}", Notification);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Notification Added {Notification}", notification);
|
||||||
}
|
}
|
||||||
return Notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public Notification Put(int id, [FromBody] Notification Notification)
|
public Notification Put(int id, [FromBody] Notification notification)
|
||||||
{
|
{
|
||||||
if (IsAuthorized(Notification.FromUserId))
|
if (IsAuthorized(notification.FromUserId))
|
||||||
{
|
{
|
||||||
Notification = _notifications.UpdateNotification(Notification);
|
notification = _notifications.UpdateNotification(notification);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Notification Updated {Folder}", Notification);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Notification Updated {Folder}", notification);
|
||||||
}
|
}
|
||||||
return Notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
@ -88,8 +87,8 @@ namespace Oqtane.Controllers
|
|||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public void Delete(int id)
|
public void Delete(int id)
|
||||||
{
|
{
|
||||||
Notification Notification = _notifications.GetNotification(id);
|
Notification notification = _notifications.GetNotification(id);
|
||||||
if (IsAuthorized(Notification.FromUserId) || IsAuthorized(Notification.ToUserId))
|
if (IsAuthorized(notification.FromUserId) || IsAuthorized(notification.ToUserId))
|
||||||
{
|
{
|
||||||
_notifications.DeleteNotification(id);
|
_notifications.DeleteNotification(id);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Notification Deleted {NotificationId}", id);
|
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Notification Deleted {NotificationId}", id);
|
||||||
|
@ -11,6 +11,7 @@ using System.Linq;
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
|
// ReSharper disable PartialTypeWithSinglePart
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
using Oqtane.Security;
|
using Oqtane.Security;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -99,14 +99,14 @@ namespace Oqtane.Controllers
|
|||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public Page Post([FromBody] Page Page)
|
public Page Post([FromBody] Page page)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
string permissions;
|
string permissions;
|
||||||
if (Page.ParentId != null)
|
if (page.ParentId != null)
|
||||||
{
|
{
|
||||||
permissions = _pages.GetPage(Page.ParentId.Value).Permissions;
|
permissions = _pages.GetPage(page.ParentId.Value).Permissions;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -115,18 +115,18 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
if (_userPermissions.IsAuthorized(User,PermissionNames.Edit, permissions))
|
if (_userPermissions.IsAuthorized(User,PermissionNames.Edit, permissions))
|
||||||
{
|
{
|
||||||
Page = _pages.AddPage(Page);
|
page = _pages.AddPage(page);
|
||||||
_syncManager.AddSyncEvent(EntityNames.Site, Page.SiteId);
|
_syncManager.AddSyncEvent(EntityNames.Site, page.SiteId);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Added {Page}", Page);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Added {Page}", page);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Page {Page}", Page);
|
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Page {Page}", page);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
Page = null;
|
page = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST api/<controller>/5?userid=x
|
// POST api/<controller>/5?userid=x
|
||||||
@ -195,21 +195,21 @@ namespace Oqtane.Controllers
|
|||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public Page Put(int id, [FromBody] Page Page)
|
public Page Put(int id, [FromBody] Page page)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, Page.PageId, PermissionNames.Edit))
|
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, page.PageId, PermissionNames.Edit))
|
||||||
{
|
{
|
||||||
Page = _pages.UpdatePage(Page);
|
page = _pages.UpdatePage(page);
|
||||||
_syncManager.AddSyncEvent(EntityNames.Site, Page.SiteId);
|
_syncManager.AddSyncEvent(EntityNames.Site, page.SiteId);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Updated {Page}", Page);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Updated {Page}", page);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update Page {Page}", Page);
|
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update Page {Page}", page);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
Page = null;
|
page = null;
|
||||||
}
|
}
|
||||||
return Page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/?siteid=x&pageid=y&parentid=z
|
// PUT api/<controller>/?siteid=x&pageid=y&parentid=z
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
using Oqtane.Security;
|
using Oqtane.Security;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
@ -14,15 +14,13 @@ namespace Oqtane.Controllers
|
|||||||
public class PageModuleController : Controller
|
public class PageModuleController : Controller
|
||||||
{
|
{
|
||||||
private readonly IPageModuleRepository _pageModules;
|
private readonly IPageModuleRepository _pageModules;
|
||||||
private readonly IModuleRepository _modules;
|
|
||||||
private readonly IUserPermissions _userPermissions;
|
private readonly IUserPermissions _userPermissions;
|
||||||
private readonly ISyncManager _syncManager;
|
private readonly ISyncManager _syncManager;
|
||||||
private readonly ILogManager _logger;
|
private readonly ILogManager _logger;
|
||||||
|
|
||||||
public PageModuleController(IPageModuleRepository pageModules, IModuleRepository modules, IUserPermissions userPermissions, ISyncManager syncManager, ILogManager logger)
|
public PageModuleController(IPageModuleRepository pageModules, IUserPermissions userPermissions, ISyncManager syncManager, ILogManager logger)
|
||||||
{
|
{
|
||||||
_pageModules = pageModules;
|
_pageModules = pageModules;
|
||||||
_modules = modules;
|
|
||||||
_userPermissions = userPermissions;
|
_userPermissions = userPermissions;
|
||||||
_syncManager = syncManager;
|
_syncManager = syncManager;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@ -65,41 +63,41 @@ namespace Oqtane.Controllers
|
|||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public PageModule Post([FromBody] PageModule PageModule)
|
public PageModule Post([FromBody] PageModule pageModule)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, PageModule.PageId, PermissionNames.Edit))
|
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, pageModule.PageId, PermissionNames.Edit))
|
||||||
{
|
{
|
||||||
PageModule = _pageModules.AddPageModule(PageModule);
|
pageModule = _pageModules.AddPageModule(pageModule);
|
||||||
_syncManager.AddSyncEvent(EntityNames.Page, PageModule.PageId);
|
_syncManager.AddSyncEvent(EntityNames.Page, pageModule.PageId);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Module Added {PageModule}", PageModule);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Page Module Added {PageModule}", pageModule);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add PageModule {PageModule}", PageModule);
|
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add PageModule {PageModule}", pageModule);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
PageModule = null;
|
pageModule = null;
|
||||||
}
|
}
|
||||||
return PageModule;
|
return pageModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.RegisteredRole)]
|
[Authorize(Roles = Constants.RegisteredRole)]
|
||||||
public PageModule Put(int id, [FromBody] PageModule PageModule)
|
public PageModule Put(int id, [FromBody] PageModule pageModule)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Module, PageModule.ModuleId, PermissionNames.Edit))
|
if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Module, pageModule.ModuleId, PermissionNames.Edit))
|
||||||
{
|
{
|
||||||
PageModule = _pageModules.UpdatePageModule(PageModule);
|
pageModule = _pageModules.UpdatePageModule(pageModule);
|
||||||
_syncManager.AddSyncEvent(EntityNames.Page, PageModule.PageId);
|
_syncManager.AddSyncEvent(EntityNames.Page, pageModule.PageId);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Module Updated {PageModule}", PageModule);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Page Module Updated {PageModule}", pageModule);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update PageModule {PageModule}", PageModule);
|
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update PageModule {PageModule}", pageModule);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
PageModule = null;
|
pageModule = null;
|
||||||
}
|
}
|
||||||
return PageModule;
|
return pageModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/?pageid=x&pane=y
|
// PUT api/<controller>/?pageid=x&pane=y
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -37,27 +37,27 @@ namespace Oqtane.Controllers
|
|||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.AdminRole)]
|
[Authorize(Roles = Constants.AdminRole)]
|
||||||
public Profile Post([FromBody] Profile Profile)
|
public Profile Post([FromBody] Profile profile)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
Profile = _profiles.AddProfile(Profile);
|
profile = _profiles.AddProfile(profile);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Profile Added {Profile}", Profile);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Profile Added {Profile}", profile);
|
||||||
}
|
}
|
||||||
return Profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.AdminRole)]
|
[Authorize(Roles = Constants.AdminRole)]
|
||||||
public Profile Put(int id, [FromBody] Profile Profile)
|
public Profile Put(int id, [FromBody] Profile profile)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
Profile = _profiles.UpdateProfile(Profile);
|
profile = _profiles.UpdateProfile(profile);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Profile Updated {Profile}", Profile);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Profile Updated {Profile}", profile);
|
||||||
}
|
}
|
||||||
return Profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -39,27 +39,27 @@ namespace Oqtane.Controllers
|
|||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.AdminRole)]
|
[Authorize(Roles = Constants.AdminRole)]
|
||||||
public Role Post([FromBody] Role Role)
|
public Role Post([FromBody] Role role)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
Role = _roles.AddRole(Role);
|
role = _roles.AddRole(role);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Role Added {Role}", Role);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Role Added {Role}", role);
|
||||||
}
|
}
|
||||||
return Role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.AdminRole)]
|
[Authorize(Roles = Constants.AdminRole)]
|
||||||
public Role Put(int id, [FromBody] Role Role)
|
public Role Put(int id, [FromBody] Role role)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
Role = _roles.UpdateRole(Role);
|
role = _roles.UpdateRole(role);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Role Updated {Role}", Role);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Role Updated {Role}", role);
|
||||||
}
|
}
|
||||||
return Role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Security;
|
using Oqtane.Security;
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -62,38 +61,38 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public Setting Post([FromBody] Setting Setting)
|
public Setting Post([FromBody] Setting setting)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && IsAuthorized(Setting.EntityName, Setting.EntityId, PermissionNames.Edit))
|
if (ModelState.IsValid && IsAuthorized(setting.EntityName, setting.EntityId, PermissionNames.Edit))
|
||||||
{
|
{
|
||||||
Setting = _settings.AddSetting(Setting);
|
setting = _settings.AddSetting(setting);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Setting Added {Setting}", Setting);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Setting Added {Setting}", setting);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Setting {Setting}", Setting);
|
_logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Setting {Setting}", setting);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
Setting = null;
|
setting = null;
|
||||||
}
|
}
|
||||||
return Setting;
|
return setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
public Setting Put(int id, [FromBody] Setting Setting)
|
public Setting Put(int id, [FromBody] Setting setting)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && IsAuthorized(Setting.EntityName, Setting.EntityId, PermissionNames.Edit))
|
if (ModelState.IsValid && IsAuthorized(setting.EntityName, setting.EntityId, PermissionNames.Edit))
|
||||||
{
|
{
|
||||||
Setting = _settings.UpdateSetting(Setting);
|
setting = _settings.UpdateSetting(setting);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Setting Updated {Setting}", Setting);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Setting Updated {Setting}", setting);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update Setting {Setting}", Setting);
|
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update Setting {Setting}", setting);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
Setting = null;
|
setting = null;
|
||||||
}
|
}
|
||||||
return Setting;
|
return setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
@ -113,15 +112,15 @@ namespace Oqtane.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsAuthorized(string EntityName, int EntityId, string PermissionName)
|
private bool IsAuthorized(string entityName, int entityId, string permissionName)
|
||||||
{
|
{
|
||||||
bool authorized = false;
|
bool authorized = false;
|
||||||
if (EntityName == EntityNames.PageModule)
|
if (entityName == EntityNames.PageModule)
|
||||||
{
|
{
|
||||||
EntityName = EntityNames.Module;
|
entityName = EntityNames.Module;
|
||||||
EntityId = _pageModules.GetPageModule(EntityId).ModuleId;
|
entityId = _pageModules.GetPageModule(entityId).ModuleId;
|
||||||
}
|
}
|
||||||
switch (EntityName)
|
switch (entityName)
|
||||||
{
|
{
|
||||||
case EntityNames.Host:
|
case EntityNames.Host:
|
||||||
authorized = User.IsInRole(Constants.HostRole);
|
authorized = User.IsInRole(Constants.HostRole);
|
||||||
@ -132,13 +131,13 @@ namespace Oqtane.Controllers
|
|||||||
case EntityNames.Page:
|
case EntityNames.Page:
|
||||||
case EntityNames.Module:
|
case EntityNames.Module:
|
||||||
case EntityNames.Folder:
|
case EntityNames.Folder:
|
||||||
authorized = _userPermissions.IsAuthorized(User, EntityName, EntityId, PermissionName);
|
authorized = _userPermissions.IsAuthorized(User, entityName, entityId, permissionName);
|
||||||
break;
|
break;
|
||||||
case EntityNames.User:
|
case EntityNames.User:
|
||||||
authorized = true;
|
authorized = true;
|
||||||
if (PermissionName == PermissionNames.Edit)
|
if (permissionName == PermissionNames.Edit)
|
||||||
{
|
{
|
||||||
authorized = User.IsInRole(Constants.AdminRole) || (_userPermissions.GetUser(User).UserId == EntityId);
|
authorized = User.IsInRole(Constants.AdminRole) || (_userPermissions.GetUser(User).UserId == entityId);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.IO;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Oqtane.Repository;
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -16,15 +14,13 @@ namespace Oqtane.Controllers
|
|||||||
{
|
{
|
||||||
private readonly ISiteRepository _sites;
|
private readonly ISiteRepository _sites;
|
||||||
private readonly ITenantResolver _tenants;
|
private readonly ITenantResolver _tenants;
|
||||||
private readonly IWebHostEnvironment _environment;
|
|
||||||
private readonly ISyncManager _syncManager;
|
private readonly ISyncManager _syncManager;
|
||||||
private readonly ILogManager _logger;
|
private readonly ILogManager _logger;
|
||||||
|
|
||||||
public SiteController(ISiteRepository sites, ITenantResolver tenants, IWebHostEnvironment environment, ISyncManager syncManager, ILogManager logger)
|
public SiteController(ISiteRepository sites, ITenantResolver tenants, ISyncManager syncManager, ILogManager logger)
|
||||||
{
|
{
|
||||||
_sites = sites;
|
_sites = sites;
|
||||||
_tenants = tenants;
|
_tenants = tenants;
|
||||||
_environment = environment;
|
|
||||||
_syncManager = syncManager;
|
_syncManager = syncManager;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
@ -46,7 +42,7 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public Site Post([FromBody] Site Site)
|
public Site Post([FromBody] Site site)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
@ -56,7 +52,7 @@ namespace Oqtane.Controllers
|
|||||||
// provision initial site during installation
|
// provision initial site during installation
|
||||||
authorized = true;
|
authorized = true;
|
||||||
Tenant tenant = _tenants.GetTenant();
|
Tenant tenant = _tenants.GetTenant();
|
||||||
Site.TenantId = tenant.TenantId;
|
site.TenantId = tenant.TenantId;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -64,25 +60,25 @@ namespace Oqtane.Controllers
|
|||||||
}
|
}
|
||||||
if (authorized)
|
if (authorized)
|
||||||
{
|
{
|
||||||
Site = _sites.AddSite(Site);
|
site = _sites.AddSite(site);
|
||||||
_logger.Log(Site.SiteId, LogLevel.Information, this, LogFunction.Create, "Site Added {Site}", Site);
|
_logger.Log(site.SiteId, LogLevel.Information, this, LogFunction.Create, "Site Added {Site}", site);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Site;
|
return site;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.HostRole)]
|
[Authorize(Roles = Constants.HostRole)]
|
||||||
public Site Put(int id, [FromBody] Site Site)
|
public Site Put(int id, [FromBody] Site site)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
Site = _sites.UpdateSite(Site);
|
site = _sites.UpdateSite(site);
|
||||||
_syncManager.AddSyncEvent(EntityNames.Site, Site.SiteId);
|
_syncManager.AddSyncEvent(EntityNames.Site, site.SiteId);
|
||||||
_logger.Log(Site.SiteId, LogLevel.Information, this, LogFunction.Update, "Site Updated {Site}", Site);
|
_logger.Log(site.SiteId, LogLevel.Information, this, LogFunction.Update, "Site Updated {Site}", site);
|
||||||
}
|
}
|
||||||
return Site;
|
return site;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -39,27 +39,27 @@ namespace Oqtane.Controllers
|
|||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.HostRole)]
|
[Authorize(Roles = Constants.HostRole)]
|
||||||
public Tenant Post([FromBody] Tenant Tenant)
|
public Tenant Post([FromBody] Tenant tenant)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
Tenant = _tenants.AddTenant(Tenant);
|
tenant = _tenants.AddTenant(tenant);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Tenant Added {TenantId}", Tenant.TenantId);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Tenant Added {TenantId}", tenant.TenantId);
|
||||||
}
|
}
|
||||||
return Tenant;
|
return tenant;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.HostRole)]
|
[Authorize(Roles = Constants.HostRole)]
|
||||||
public Tenant Put(int id, [FromBody] Tenant Tenant)
|
public Tenant Put(int id, [FromBody] Tenant tenant)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
Tenant = _tenants.UpdateTenant(Tenant);
|
tenant = _tenants.UpdateTenant(tenant);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Tenant Updated {TenantId}", Tenant.TenantId);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Tenant Updated {TenantId}", tenant.TenantId);
|
||||||
}
|
}
|
||||||
return Tenant;
|
return tenant;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
|
// ReSharper disable StringIndexOfIsCultureSpecific.1
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
|
@ -2,17 +2,16 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -73,43 +72,39 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<User> Post([FromBody] User User)
|
public async Task<User> Post([FromBody] User user)
|
||||||
{
|
{
|
||||||
User user = null;
|
User newUser = null;
|
||||||
|
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
bool verified = true;
|
|
||||||
// users created by non-administrators must be verified
|
// users created by non-administrators must be verified
|
||||||
if (!base.User.IsInRole(Constants.AdminRole) && User.Username != Constants.HostUser)
|
bool verified = !(!User.IsInRole(Constants.AdminRole) && user.Username != Constants.HostUser);
|
||||||
{
|
|
||||||
verified = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
|
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);
|
||||||
if (identityuser == null)
|
if (identityuser == null)
|
||||||
{
|
{
|
||||||
identityuser = new IdentityUser();
|
identityuser = new IdentityUser();
|
||||||
identityuser.UserName = User.Username;
|
identityuser.UserName = user.Username;
|
||||||
identityuser.Email = User.Email;
|
identityuser.Email = user.Email;
|
||||||
identityuser.EmailConfirmed = verified;
|
identityuser.EmailConfirmed = verified;
|
||||||
var result = await _identityUserManager.CreateAsync(identityuser, User.Password);
|
var result = await _identityUserManager.CreateAsync(identityuser, user.Password);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
User.LastLoginOn = null;
|
user.LastLoginOn = null;
|
||||||
User.LastIPAddress = "";
|
user.LastIPAddress = "";
|
||||||
user = _users.AddUser(User);
|
newUser = _users.AddUser(user);
|
||||||
if (!verified)
|
if (!verified)
|
||||||
{
|
{
|
||||||
Notification notification = new Notification();
|
Notification notification = new Notification();
|
||||||
notification.SiteId = User.SiteId;
|
notification.SiteId = user.SiteId;
|
||||||
notification.FromUserId = null;
|
notification.FromUserId = null;
|
||||||
notification.ToUserId = user.UserId;
|
notification.ToUserId = newUser.UserId;
|
||||||
notification.ToEmail = "";
|
notification.ToEmail = "";
|
||||||
notification.Subject = "User Account Verification";
|
notification.Subject = "User Account Verification";
|
||||||
string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser);
|
string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser);
|
||||||
string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/login?name=" + User.Username + "&token=" + WebUtility.UrlEncode(token);
|
string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
|
||||||
notification.Body = "Dear " + User.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!";
|
notification.Body = "Dear " + user.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!";
|
||||||
notification.ParentId = null;
|
notification.ParentId = null;
|
||||||
notification.CreatedOn = DateTime.UtcNow;
|
notification.CreatedOn = DateTime.UtcNow;
|
||||||
notification.IsDelivered = false;
|
notification.IsDelivered = false;
|
||||||
@ -118,11 +113,11 @@ namespace Oqtane.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// assign to host role if this is the host user ( initial installation )
|
// assign to host role if this is the host user ( initial installation )
|
||||||
if (User.Username == Constants.HostUser)
|
if (user.Username == Constants.HostUser)
|
||||||
{
|
{
|
||||||
int hostroleid = _roles.GetRoles(User.SiteId, true).Where(item => item.Name == Constants.HostRole).FirstOrDefault().RoleId;
|
int hostroleid = _roles.GetRoles(user.SiteId, true).Where(item => item.Name == Constants.HostRole).FirstOrDefault().RoleId;
|
||||||
UserRole userrole = new UserRole();
|
UserRole userrole = new UserRole();
|
||||||
userrole.UserId = user.UserId;
|
userrole.UserId = newUser.UserId;
|
||||||
userrole.RoleId = hostroleid;
|
userrole.RoleId = hostroleid;
|
||||||
userrole.EffectiveDate = null;
|
userrole.EffectiveDate = null;
|
||||||
userrole.ExpiryDate = null;
|
userrole.ExpiryDate = null;
|
||||||
@ -130,75 +125,79 @@ namespace Oqtane.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add folder for user
|
// add folder for user
|
||||||
Folder folder = _folders.GetFolder(User.SiteId, "Users\\");
|
Folder folder = _folders.GetFolder(user.SiteId, "Users\\");
|
||||||
if (folder != null)
|
if (folder != null)
|
||||||
{
|
{
|
||||||
_folders.AddFolder(new Folder { SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", Path = folder.Path + user.UserId.ToString() + "\\", Order = 1, IsSystem = true,
|
_folders.AddFolder(new Folder { SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", Path = folder.Path + newUser.UserId.ToString() + "\\", Order = 1, IsSystem = true,
|
||||||
Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"[" + user.UserId.ToString() + "]\"},{\"PermissionName\":\"View\",\"Permissions\":\"All Users\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"[" + user.UserId.ToString() + "]\"}]" });
|
Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"[" + newUser.UserId.ToString() + "]\"},{\"PermissionName\":\"View\",\"Permissions\":\"All Users\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"[" + newUser.UserId.ToString() + "]\"}]" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, User.Password, false);
|
var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, user.Password, false);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
user = _users.GetUser(User.Username);
|
newUser = _users.GetUser(user.Username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user != null && User.Username != Constants.HostUser)
|
if (newUser != null && user.Username != Constants.HostUser)
|
||||||
{
|
{
|
||||||
// add auto assigned roles to user for site
|
// add auto assigned roles to user for site
|
||||||
List<Role> roles = _roles.GetRoles(User.SiteId).Where(item => item.IsAutoAssigned == true).ToList();
|
List<Role> roles = _roles.GetRoles(user.SiteId).Where(item => item.IsAutoAssigned).ToList();
|
||||||
foreach (Role role in roles)
|
foreach (Role role in roles)
|
||||||
{
|
{
|
||||||
UserRole userrole = new UserRole();
|
UserRole userrole = new UserRole();
|
||||||
userrole.UserId = user.UserId;
|
userrole.UserId = newUser.UserId;
|
||||||
userrole.RoleId = role.RoleId;
|
userrole.RoleId = role.RoleId;
|
||||||
userrole.EffectiveDate = null;
|
userrole.EffectiveDate = null;
|
||||||
userrole.ExpiryDate = null;
|
userrole.ExpiryDate = null;
|
||||||
_userRoles.AddUserRole(userrole);
|
_userRoles.AddUserRole(userrole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user.Password = ""; // remove sensitive information
|
|
||||||
_logger.Log(User.SiteId, LogLevel.Information, this, LogFunction.Create, "User Added {User}", user);
|
if (newUser != null)
|
||||||
|
{
|
||||||
|
newUser.Password = ""; // remove sensitive information
|
||||||
|
_logger.Log(user.SiteId, LogLevel.Information, this, LogFunction.Create, "User Added {User}", newUser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return newUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<User> Put(int id, [FromBody] User User)
|
public async Task<User> Put(int id, [FromBody] User user)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
if (base.User.IsInRole(Constants.AdminRole) || base.User.Identity.Name == User.Username)
|
if (User.IsInRole(Constants.AdminRole) || User.Identity.Name == user.Username)
|
||||||
{
|
{
|
||||||
if (User.Password != "")
|
if (user.Password != "")
|
||||||
{
|
{
|
||||||
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
|
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);
|
||||||
if (identityuser != null)
|
if (identityuser != null)
|
||||||
{
|
{
|
||||||
identityuser.PasswordHash = _identityUserManager.PasswordHasher.HashPassword(identityuser, User.Password);
|
identityuser.PasswordHash = _identityUserManager.PasswordHasher.HashPassword(identityuser, user.Password);
|
||||||
await _identityUserManager.UpdateAsync(identityuser);
|
await _identityUserManager.UpdateAsync(identityuser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
User = _users.UpdateUser(User);
|
user = _users.UpdateUser(user);
|
||||||
_syncManager.AddSyncEvent(EntityNames.User, User.UserId);
|
_syncManager.AddSyncEvent(EntityNames.User, user.UserId);
|
||||||
User.Password = ""; // remove sensitive information
|
user.Password = ""; // remove sensitive information
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "User Updated {User}", User);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "User Updated {User}", user);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update User {User}", User);
|
_logger.Log(LogLevel.Error, this, LogFunction.Update, "User Not Authorized To Update User {User}", user);
|
||||||
HttpContext.Response.StatusCode = 401;
|
HttpContext.Response.StatusCode = 401;
|
||||||
User = null;
|
user = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return User;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5?siteid=x
|
// DELETE api/<controller>/5?siteid=x
|
||||||
@ -222,147 +221,147 @@ namespace Oqtane.Controllers
|
|||||||
|
|
||||||
// POST api/<controller>/login
|
// POST api/<controller>/login
|
||||||
[HttpPost("login")]
|
[HttpPost("login")]
|
||||||
public async Task<User> Login([FromBody] User User, bool SetCookie, bool IsPersistent)
|
public async Task<User> Login([FromBody] User user, bool setCookie, bool isPersistent)
|
||||||
{
|
{
|
||||||
User user = new Models.User { Username = User.Username, IsAuthenticated = false };
|
User loginUser = new User { Username = user.Username, IsAuthenticated = false };
|
||||||
|
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
|
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);
|
||||||
if (identityuser != null)
|
if (identityuser != null)
|
||||||
{
|
{
|
||||||
var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, User.Password, false);
|
var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, user.Password, false);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
user = _users.GetUser(identityuser.UserName);
|
loginUser = _users.GetUser(identityuser.UserName);
|
||||||
if (user != null)
|
if (loginUser != null)
|
||||||
{
|
{
|
||||||
if (identityuser.EmailConfirmed)
|
if (identityuser.EmailConfirmed)
|
||||||
{
|
{
|
||||||
user.IsAuthenticated = true;
|
loginUser.IsAuthenticated = true;
|
||||||
user.LastLoginOn = DateTime.UtcNow;
|
loginUser.LastLoginOn = DateTime.UtcNow;
|
||||||
user.LastIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
|
loginUser.LastIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
|
||||||
_users.UpdateUser(user);
|
_users.UpdateUser(loginUser);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Login Successful {Username}", User.Username);
|
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Login Successful {Username}", user.Username);
|
||||||
if (SetCookie)
|
if (setCookie)
|
||||||
{
|
{
|
||||||
await _identitySignInManager.SignInAsync(identityuser, IsPersistent);
|
await _identitySignInManager.SignInAsync(identityuser, isPersistent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Not Verified {Username}", User.Username);
|
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Not Verified {Username}", user.Username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "User Login Failed {Username}", User.Username);
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "User Login Failed {Username}", user.Username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return loginUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST api/<controller>/logout
|
// POST api/<controller>/logout
|
||||||
[HttpPost("logout")]
|
[HttpPost("logout")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task Logout([FromBody] User User)
|
public async Task Logout([FromBody] User user)
|
||||||
{
|
{
|
||||||
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
|
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.Username);
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST api/<controller>/verify
|
// POST api/<controller>/verify
|
||||||
[HttpPost("verify")]
|
[HttpPost("verify")]
|
||||||
public async Task<User> Verify([FromBody] User User, string token)
|
public async Task<User> Verify([FromBody] User user, string token)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
|
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);
|
||||||
if (identityuser != null)
|
if (identityuser != null)
|
||||||
{
|
{
|
||||||
var result = await _identityUserManager.ConfirmEmailAsync(identityuser, token);
|
var result = await _identityUserManager.ConfirmEmailAsync(identityuser, token);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Email Verified For {Username}", User.Username);
|
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Email Verified For {Username}", user.Username);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Email Verification Failed For {Username}", User.Username);
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Email Verification Failed For {Username}", user.Username);
|
||||||
User = null;
|
user = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Email Verification Failed For {Username}", User.Username);
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Email Verification Failed For {Username}", user.Username);
|
||||||
User = null;
|
user = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return User;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST api/<controller>/forgot
|
// POST api/<controller>/forgot
|
||||||
[HttpPost("forgot")]
|
[HttpPost("forgot")]
|
||||||
public async Task Forgot([FromBody] User User)
|
public async Task Forgot([FromBody] User user)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
|
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);
|
||||||
if (identityuser != null)
|
if (identityuser != null)
|
||||||
{
|
{
|
||||||
Notification notification = new Notification();
|
Notification notification = new Notification();
|
||||||
notification.SiteId = User.SiteId;
|
notification.SiteId = user.SiteId;
|
||||||
notification.FromUserId = null;
|
notification.FromUserId = null;
|
||||||
notification.ToUserId = User.UserId;
|
notification.ToUserId = user.UserId;
|
||||||
notification.ToEmail = "";
|
notification.ToEmail = "";
|
||||||
notification.Subject = "User Password Reset";
|
notification.Subject = "User Password Reset";
|
||||||
string token = await _identityUserManager.GeneratePasswordResetTokenAsync(identityuser);
|
string token = await _identityUserManager.GeneratePasswordResetTokenAsync(identityuser);
|
||||||
string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/reset?name=" + User.Username + "&token=" + WebUtility.UrlEncode(token);
|
string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/reset?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
|
||||||
notification.Body = "Dear " + User.DisplayName + ",\n\nPlease Click The Link Displayed Below To Reset Your Password:\n\n" + url + "\n\nThank You!";
|
notification.Body = "Dear " + user.DisplayName + ",\n\nPlease Click The Link Displayed Below To Reset Your Password:\n\n" + url + "\n\nThank You!";
|
||||||
notification.ParentId = null;
|
notification.ParentId = null;
|
||||||
notification.CreatedOn = DateTime.UtcNow;
|
notification.CreatedOn = DateTime.UtcNow;
|
||||||
notification.IsDelivered = false;
|
notification.IsDelivered = false;
|
||||||
notification.DeliveredOn = null;
|
notification.DeliveredOn = null;
|
||||||
_notifications.AddNotification(notification);
|
_notifications.AddNotification(notification);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset Notification Sent For {Username}", User.Username);
|
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset Notification Sent For {Username}", user.Username);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Notification Failed For {Username}", User.Username);
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Notification Failed For {Username}", user.Username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST api/<controller>/reset
|
// POST api/<controller>/reset
|
||||||
[HttpPost("reset")]
|
[HttpPost("reset")]
|
||||||
public async Task<User> Reset([FromBody] User User, string token)
|
public async Task<User> Reset([FromBody] User user, string token)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(User.Username);
|
IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username);
|
||||||
if (identityuser != null && !string.IsNullOrEmpty(token))
|
if (identityuser != null && !string.IsNullOrEmpty(token))
|
||||||
{
|
{
|
||||||
var result = await _identityUserManager.ResetPasswordAsync(identityuser, token, User.Password);
|
var result = await _identityUserManager.ResetPasswordAsync(identityuser, token, user.Password);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset For {Username}", User.Username);
|
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset For {Username}", user.Username);
|
||||||
User.Password = "";
|
user.Password = "";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Failed For {Username}", User.Username);
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Failed For {Username}", user.Username);
|
||||||
User = null;
|
user = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Failed For {Username}", User.Username);
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Password Reset Failed For {Username}", user.Username);
|
||||||
User = null;
|
user = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return User;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET api/<controller>/current
|
// GET api/<controller>/current
|
||||||
@ -382,10 +381,10 @@ namespace Oqtane.Controllers
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetUserRoles(int UserId, int SiteId)
|
private string GetUserRoles(int userId, int siteId)
|
||||||
{
|
{
|
||||||
string roles = "";
|
string roles = "";
|
||||||
List<UserRole> userroles = _userRoles.GetUserRoles(UserId, SiteId).ToList();
|
List<UserRole> userroles = _userRoles.GetUserRoles(userId, siteId).ToList();
|
||||||
foreach (UserRole userrole in userroles)
|
foreach (UserRole userrole in userroles)
|
||||||
{
|
{
|
||||||
roles += userrole.Role.Name + ";";
|
roles += userrole.Role.Name + ";";
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Controllers
|
namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
@ -41,29 +41,29 @@ namespace Oqtane.Controllers
|
|||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Roles = Constants.AdminRole)]
|
[Authorize(Roles = Constants.AdminRole)]
|
||||||
public UserRole Post([FromBody] UserRole UserRole)
|
public UserRole Post([FromBody] UserRole userRole)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
UserRole = _userRoles.AddUserRole(UserRole);
|
userRole = _userRoles.AddUserRole(userRole);
|
||||||
_syncManager.AddSyncEvent(EntityNames.User, UserRole.UserId);
|
_syncManager.AddSyncEvent(EntityNames.User, userRole.UserId);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", UserRole);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", userRole);
|
||||||
}
|
}
|
||||||
return UserRole;
|
return userRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = Constants.AdminRole)]
|
[Authorize(Roles = Constants.AdminRole)]
|
||||||
public UserRole Put(int id, [FromBody] UserRole UserRole)
|
public UserRole Put(int id, [FromBody] UserRole userRole)
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
UserRole = _userRoles.UpdateUserRole(UserRole);
|
userRole = _userRoles.UpdateUserRole(userRole);
|
||||||
_syncManager.AddSyncEvent(EntityNames.User, UserRole.UserId);
|
_syncManager.AddSyncEvent(EntityNames.User, userRole.UserId);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "User Role Updated {UserRole}", UserRole);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "User Role Updated {UserRole}", userRole);
|
||||||
}
|
}
|
||||||
return UserRole;
|
return userRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE api/<controller>/5
|
// DELETE api/<controller>/5
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
// ReSharper disable once CheckNamespace
|
||||||
namespace System.Reflection
|
namespace System.Reflection
|
||||||
{
|
{
|
||||||
public static class AssemblyExtensions
|
public static class AssemblyExtensions
|
||||||
|
@ -3,6 +3,7 @@ using System.Linq;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
||||||
|
|
||||||
|
// ReSharper disable once CheckNamespace
|
||||||
namespace Microsoft.Extensions.DependencyInjection
|
namespace Microsoft.Extensions.DependencyInjection
|
||||||
{
|
{
|
||||||
public static class OqtaneMvcBuilderExtensions
|
public static class OqtaneMvcBuilderExtensions
|
||||||
|
@ -8,15 +8,16 @@ using Microsoft.Extensions.Hosting;
|
|||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure;
|
||||||
using Oqtane.Modules;
|
using Oqtane.Modules;
|
||||||
|
|
||||||
|
// ReSharper disable once CheckNamespace
|
||||||
namespace Microsoft.Extensions.DependencyInjection
|
namespace Microsoft.Extensions.DependencyInjection
|
||||||
{
|
{
|
||||||
public static class OqtaneServiceCollectionExtensions
|
public static class OqtaneServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
private static readonly IList<Assembly> _oqtaneModuleAssemblies = new List<Assembly>();
|
private static readonly IList<Assembly> OqtaneModuleAssemblies = new List<Assembly>();
|
||||||
|
|
||||||
private static Assembly[] Assemblies => AppDomain.CurrentDomain.GetAssemblies();
|
private static Assembly[] Assemblies => AppDomain.CurrentDomain.GetAssemblies();
|
||||||
|
|
||||||
internal static IEnumerable<Assembly> GetOqtaneModuleAssemblies() => _oqtaneModuleAssemblies;
|
internal static IEnumerable<Assembly> GetOqtaneModuleAssemblies() => OqtaneModuleAssemblies;
|
||||||
|
|
||||||
public static IServiceCollection AddOqtaneModules(this IServiceCollection services)
|
public static IServiceCollection AddOqtaneModules(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
@ -50,17 +51,19 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dynamically register module services, contexts, and repository classes
|
// dynamically register module services, contexts, and repository classes
|
||||||
var assemblies = Assemblies.
|
var assemblies = Assemblies.Where(item => item.FullName != null && (item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Module."))).ToArray();
|
||||||
Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Module.")).ToArray();
|
|
||||||
foreach (var assembly in assemblies)
|
foreach (var assembly in assemblies)
|
||||||
{
|
{
|
||||||
var implementationTypes = assembly.GetInterfaces<IService>();
|
var implementationTypes = assembly.GetInterfaces<IService>();
|
||||||
foreach (var implementationType in implementationTypes)
|
foreach (var implementationType in implementationTypes)
|
||||||
|
{
|
||||||
|
if (implementationType.AssemblyQualifiedName != null)
|
||||||
{
|
{
|
||||||
var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}"));
|
var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}"));
|
||||||
services.AddScoped(serviceType ?? implementationType, implementationType);
|
services.AddScoped(serviceType ?? implementationType, implementationType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
@ -91,14 +94,16 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||||||
|
|
||||||
private static void LoadAssemblies(string pattern)
|
private static void LoadAssemblies(string pattern)
|
||||||
{
|
{
|
||||||
var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
||||||
|
if (assemblyPath == null) return;
|
||||||
|
|
||||||
var assembliesFolder = new DirectoryInfo(assemblyPath);
|
var assembliesFolder = new DirectoryInfo(assemblyPath);
|
||||||
|
|
||||||
// iterate through Oqtane theme assemblies in /bin ( filter is narrow to optimize loading process )
|
// iterate through Oqtane theme assemblies in /bin ( filter is narrow to optimize loading process )
|
||||||
foreach (var file in assembliesFolder.EnumerateFiles($"*.{pattern}.*.dll"))
|
foreach (var file in assembliesFolder.EnumerateFiles($"*.{pattern}.*.dll"))
|
||||||
{
|
{
|
||||||
// check if assembly is already loaded
|
// check if assembly is already loaded
|
||||||
var assembly = Assemblies.Where(a => a.Location == file.FullName).FirstOrDefault();
|
var assembly = Assemblies.FirstOrDefault(a => a.Location == file.FullName);
|
||||||
if (assembly == null)
|
if (assembly == null)
|
||||||
{
|
{
|
||||||
// load assembly from stream to prevent locking file ( as long as dependencies are in /bin they will load as well )
|
// load assembly from stream to prevent locking file ( as long as dependencies are in /bin they will load as well )
|
||||||
@ -106,7 +111,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||||||
if (pattern == "Module")
|
if (pattern == "Module")
|
||||||
{
|
{
|
||||||
// build a list of module assemblies
|
// build a list of module assemblies
|
||||||
_oqtaneModuleAssemblies.Add(assembly);
|
OqtaneModuleAssemblies.Add(assembly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ using System.Xml;
|
|||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
|
||||||
namespace Oqtane.Infrastructure
|
namespace Oqtane.Infrastructure
|
||||||
{
|
{
|
||||||
@ -21,27 +22,27 @@ namespace Oqtane.Infrastructure
|
|||||||
_environment = environment;
|
_environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InstallPackages(string Folders, bool Restart)
|
public void InstallPackages(string folders, bool restart)
|
||||||
{
|
{
|
||||||
bool install = false;
|
bool install = false;
|
||||||
string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
string binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
||||||
|
|
||||||
foreach (string Folder in Folders.Split(','))
|
foreach (string folder in folders.Split(','))
|
||||||
{
|
{
|
||||||
string folder = Path.Combine(_environment.WebRootPath, Folder);
|
string sourceFolder = Path.Combine(_environment.WebRootPath, folder);
|
||||||
|
|
||||||
// create folder if it does not exist
|
// create folder if it does not exist
|
||||||
if (!Directory.Exists(folder))
|
if (!Directory.Exists(sourceFolder))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(folder);
|
Directory.CreateDirectory(sourceFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate through packages
|
// iterate through packages
|
||||||
foreach (string packagename in Directory.GetFiles(folder, "*.nupkg"))
|
foreach (string packagename in Directory.GetFiles(sourceFolder, "*.nupkg"))
|
||||||
{
|
{
|
||||||
string name = Path.GetFileNameWithoutExtension(packagename);
|
string name = Path.GetFileNameWithoutExtension(packagename);
|
||||||
string[] segments = name.Split('.');
|
string[] segments = name?.Split('.');
|
||||||
name = string.Join('.', segments, 0, segments.Length - 3);
|
if (segments != null) name = string.Join('.', segments, 0, segments.Length - 3);
|
||||||
|
|
||||||
// iterate through files
|
// iterate through files
|
||||||
using (ZipArchive archive = ZipFile.OpenRead(packagename))
|
using (ZipArchive archive = ZipFile.OpenRead(packagename))
|
||||||
@ -78,7 +79,7 @@ namespace Oqtane.Infrastructure
|
|||||||
{
|
{
|
||||||
case ".pdb":
|
case ".pdb":
|
||||||
case ".dll":
|
case ".dll":
|
||||||
entry.ExtractToFile(Path.Combine(binfolder, filename), true);
|
if (binFolder != null) entry.ExtractToFile(Path.Combine(binFolder, filename), true);
|
||||||
break;
|
break;
|
||||||
case ".png":
|
case ".png":
|
||||||
case ".jpg":
|
case ".jpg":
|
||||||
@ -87,7 +88,7 @@ namespace Oqtane.Infrastructure
|
|||||||
case ".svg":
|
case ".svg":
|
||||||
case ".js":
|
case ".js":
|
||||||
case ".css":
|
case ".css":
|
||||||
filename = folder + "\\" + entry.FullName.Replace("wwwroot", name).Replace("/", "\\");
|
filename = sourceFolder + "\\" + entry.FullName.Replace("wwwroot", name).Replace("/", "\\");
|
||||||
if (!Directory.Exists(Path.GetDirectoryName(filename)))
|
if (!Directory.Exists(Path.GetDirectoryName(filename)))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(filename));
|
Directory.CreateDirectory(Path.GetDirectoryName(filename));
|
||||||
@ -104,7 +105,7 @@ namespace Oqtane.Infrastructure
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (install && Restart)
|
if (install && restart)
|
||||||
{
|
{
|
||||||
// restart application
|
// restart application
|
||||||
RestartApplication();
|
RestartApplication();
|
||||||
@ -165,27 +166,30 @@ namespace Oqtane.Infrastructure
|
|||||||
|
|
||||||
private void FinishUpgrade()
|
private void FinishUpgrade()
|
||||||
{
|
{
|
||||||
string folder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
string folder = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
|
||||||
|
|
||||||
// check if upgrade application exists
|
// check if upgrade application exists
|
||||||
if (File.Exists(Path.Combine(folder, "Oqtane.Upgrade.exe")))
|
if (folder == null || !File.Exists(Path.Combine(folder, "Oqtane.Upgrade.exe"))) return;
|
||||||
{
|
|
||||||
// run upgrade application
|
// run upgrade application
|
||||||
var process = new Process();
|
var process = new Process
|
||||||
process.StartInfo.FileName = Path.Combine(folder, "Oqtane.Upgrade.exe");
|
{
|
||||||
process.StartInfo.Arguments = "";
|
StartInfo =
|
||||||
process.StartInfo.ErrorDialog = false;
|
{
|
||||||
process.StartInfo.UseShellExecute = false;
|
FileName = Path.Combine(folder, "Oqtane.Upgrade.exe"),
|
||||||
process.StartInfo.CreateNoWindow = true;
|
Arguments = "",
|
||||||
process.StartInfo.RedirectStandardOutput = false;
|
ErrorDialog = false,
|
||||||
process.StartInfo.RedirectStandardError = false;
|
UseShellExecute = false,
|
||||||
|
CreateNoWindow = true,
|
||||||
|
RedirectStandardOutput = false,
|
||||||
|
RedirectStandardError = false
|
||||||
|
}
|
||||||
|
};
|
||||||
process.Start();
|
process.Start();
|
||||||
process.Dispose();
|
process.Dispose();
|
||||||
|
|
||||||
// stop application so upgrade application can proceed
|
// stop application so upgrade application can proceed
|
||||||
RestartApplication();
|
RestartApplication();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void RestartApplication()
|
public void RestartApplication()
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
namespace Oqtane.Infrastructure
|
namespace Oqtane.Infrastructure.Interfaces
|
||||||
{
|
{
|
||||||
public interface IInstallationManager
|
public interface IInstallationManager
|
||||||
{
|
{
|
||||||
void InstallPackages(string Folders, bool Restart);
|
void InstallPackages(string folders, bool restart);
|
||||||
void UpgradeFramework();
|
void UpgradeFramework();
|
||||||
void RestartApplication();
|
void RestartApplication();
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
using Oqtane.Models;
|
using System;
|
||||||
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Oqtane.Infrastructure
|
namespace Oqtane.Infrastructure.Interfaces
|
||||||
{
|
{
|
||||||
public interface ILogManager
|
public interface ILogManager
|
||||||
{
|
{
|
||||||
void Log(LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args);
|
void Log(LogLevel level, object @class, LogFunction function, string message, params object[] args);
|
||||||
void Log(LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args);
|
void Log(LogLevel level, object @class, LogFunction function, Exception exception, string message, params object[] args);
|
||||||
void Log(int SiteId, LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args);
|
void Log(int siteId, LogLevel level, object @class, LogFunction function, string message, params object[] args);
|
||||||
void Log(int SiteId, LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args);
|
void Log(int siteId, LogLevel level, object @class, LogFunction function, Exception exception, string message, params object[] args);
|
||||||
void Log(Log Log);
|
void Log(Log log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
using Oqtane.Models;
|
using System;
|
||||||
using Oqtane.Shared;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Infrastructure
|
namespace Oqtane.Infrastructure.Interfaces
|
||||||
{
|
{
|
||||||
public interface ISyncManager
|
public interface ISyncManager
|
||||||
{
|
{
|
||||||
List<SyncEvent> GetSyncEvents(DateTime LastSyncDate);
|
List<SyncEvent> GetSyncEvents(DateTime lastSyncDate);
|
||||||
void AddSyncEvent(string EntityName, int EntityId);
|
void AddSyncEvent(string entityName, int entityId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ namespace Oqtane.Infrastructure
|
|||||||
{
|
{
|
||||||
public abstract class HostedServiceBase : IHostedService, IDisposable
|
public abstract class HostedServiceBase : IHostedService, IDisposable
|
||||||
{
|
{
|
||||||
private Task ExecutingTask;
|
private Task _executingTask;
|
||||||
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
|
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
|
||||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||||
|
|
||||||
@ -34,43 +34,43 @@ namespace Oqtane.Infrastructure
|
|||||||
using (var scope = _serviceScopeFactory.CreateScope())
|
using (var scope = _serviceScopeFactory.CreateScope())
|
||||||
{
|
{
|
||||||
// get name of job
|
// get name of job
|
||||||
string JobType = Utilities.GetFullTypeName(GetType().AssemblyQualifiedName);
|
string jobType = Utilities.GetFullTypeName(GetType().AssemblyQualifiedName);
|
||||||
|
|
||||||
// load jobs and find current job
|
// load jobs and find current job
|
||||||
IJobRepository Jobs = scope.ServiceProvider.GetRequiredService<IJobRepository>();
|
IJobRepository jobs = scope.ServiceProvider.GetRequiredService<IJobRepository>();
|
||||||
Job Job = Jobs.GetJobs().Where(item => item.JobType == JobType).FirstOrDefault();
|
Job job = jobs.GetJobs().Where(item => item.JobType == jobType).FirstOrDefault();
|
||||||
if (Job != null && Job.IsEnabled && !Job.IsExecuting)
|
if (job != null && job.IsEnabled && !job.IsExecuting)
|
||||||
{
|
{
|
||||||
// set next execution date
|
// set next execution date
|
||||||
if (Job.NextExecution == null)
|
if (job.NextExecution == null)
|
||||||
{
|
{
|
||||||
if (Job.StartDate != null)
|
if (job.StartDate != null)
|
||||||
{
|
{
|
||||||
Job.NextExecution = Job.StartDate;
|
job.NextExecution = job.StartDate;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Job.NextExecution = DateTime.UtcNow;
|
job.NextExecution = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine if the job should be run
|
// determine if the job should be run
|
||||||
if (Job.NextExecution <= DateTime.UtcNow && (Job.EndDate == null || Job.EndDate >= DateTime.UtcNow))
|
if (job.NextExecution <= DateTime.UtcNow && (job.EndDate == null || job.EndDate >= DateTime.UtcNow))
|
||||||
{
|
{
|
||||||
IJobLogRepository JobLogs = scope.ServiceProvider.GetRequiredService<IJobLogRepository>();
|
IJobLogRepository jobLogs = scope.ServiceProvider.GetRequiredService<IJobLogRepository>();
|
||||||
|
|
||||||
// create a job log entry
|
// create a job log entry
|
||||||
JobLog log = new JobLog();
|
JobLog log = new JobLog();
|
||||||
log.JobId = Job.JobId;
|
log.JobId = job.JobId;
|
||||||
log.StartDate = DateTime.UtcNow;
|
log.StartDate = DateTime.UtcNow;
|
||||||
log.FinishDate = null;
|
log.FinishDate = null;
|
||||||
log.Succeeded = false;
|
log.Succeeded = false;
|
||||||
log.Notes = "";
|
log.Notes = "";
|
||||||
log = JobLogs.AddJobLog(log);
|
log = jobLogs.AddJobLog(log);
|
||||||
|
|
||||||
// update the job to indicate it is running
|
// update the job to indicate it is running
|
||||||
Job.IsExecuting = true;
|
job.IsExecuting = true;
|
||||||
Jobs.UpdateJob(Job);
|
jobs.UpdateJob(job);
|
||||||
|
|
||||||
// execute the job
|
// execute the job
|
||||||
try
|
try
|
||||||
@ -86,19 +86,19 @@ namespace Oqtane.Infrastructure
|
|||||||
|
|
||||||
// update the job log
|
// update the job log
|
||||||
log.FinishDate = DateTime.UtcNow;
|
log.FinishDate = DateTime.UtcNow;
|
||||||
JobLogs.UpdateJobLog(log);
|
jobLogs.UpdateJobLog(log);
|
||||||
|
|
||||||
// update the job
|
// update the job
|
||||||
Job.NextExecution = CalculateNextExecution(Job.NextExecution.Value, Job.Frequency, Job.Interval);
|
job.NextExecution = CalculateNextExecution(job.NextExecution.Value, job.Frequency, job.Interval);
|
||||||
Job.IsExecuting = false;
|
job.IsExecuting = false;
|
||||||
Jobs.UpdateJob(Job);
|
jobs.UpdateJob(job);
|
||||||
|
|
||||||
// trim the job log
|
// trim the job log
|
||||||
List<JobLog> logs = JobLogs.GetJobLogs().Where(item => item.JobId == Job.JobId)
|
List<JobLog> logs = jobLogs.GetJobLogs().Where(item => item.JobId == job.JobId)
|
||||||
.OrderByDescending(item => item.JobLogId).ToList();
|
.OrderByDescending(item => item.JobLogId).ToList();
|
||||||
for (int i = logs.Count; i > Job.RetentionHistory; i--)
|
for (int i = logs.Count; i > job.RetentionHistory; i--)
|
||||||
{
|
{
|
||||||
JobLogs.DeleteJobLog(logs[i - 1].JobLogId);
|
jobLogs.DeleteJobLog(logs[i - 1].JobLogId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,28 +115,28 @@ namespace Oqtane.Infrastructure
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DateTime CalculateNextExecution(DateTime NextExecution, string Frequency, int Interval)
|
private DateTime CalculateNextExecution(DateTime nextExecution, string frequency, int interval)
|
||||||
{
|
{
|
||||||
switch (Frequency)
|
switch (frequency)
|
||||||
{
|
{
|
||||||
case "m": // minutes
|
case "m": // minutes
|
||||||
NextExecution = NextExecution.AddMinutes(Interval);
|
nextExecution = nextExecution.AddMinutes(interval);
|
||||||
break;
|
break;
|
||||||
case "H": // hours
|
case "H": // hours
|
||||||
NextExecution = NextExecution.AddHours(Interval);
|
nextExecution = nextExecution.AddHours(interval);
|
||||||
break;
|
break;
|
||||||
case "d": // days
|
case "d": // days
|
||||||
NextExecution = NextExecution.AddDays(Interval);
|
nextExecution = nextExecution.AddDays(interval);
|
||||||
break;
|
break;
|
||||||
case "M": // months
|
case "M": // months
|
||||||
NextExecution = NextExecution.AddMonths(Interval);
|
nextExecution = nextExecution.AddMonths(interval);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (NextExecution < DateTime.UtcNow)
|
if (nextExecution < DateTime.UtcNow)
|
||||||
{
|
{
|
||||||
NextExecution = DateTime.UtcNow;
|
nextExecution = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
return NextExecution;
|
return nextExecution;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StartAsync(CancellationToken cancellationToken)
|
public Task StartAsync(CancellationToken cancellationToken)
|
||||||
@ -146,14 +146,14 @@ namespace Oqtane.Infrastructure
|
|||||||
// set IsExecuting to false in case this job was forcefully terminated previously
|
// set IsExecuting to false in case this job was forcefully terminated previously
|
||||||
using (var scope = _serviceScopeFactory.CreateScope())
|
using (var scope = _serviceScopeFactory.CreateScope())
|
||||||
{
|
{
|
||||||
string JobType = Utilities.GetFullTypeName(GetType().AssemblyQualifiedName);
|
string jobType = Utilities.GetFullTypeName(GetType().AssemblyQualifiedName);
|
||||||
IJobRepository Jobs = scope.ServiceProvider.GetRequiredService<IJobRepository>();
|
IJobRepository jobs = scope.ServiceProvider.GetRequiredService<IJobRepository>();
|
||||||
Job Job = Jobs.GetJobs().Where(item => item.JobType == JobType).FirstOrDefault();
|
Job job = jobs.GetJobs().Where(item => item.JobType == jobType).FirstOrDefault();
|
||||||
if (Job != null)
|
if (job != null)
|
||||||
{
|
{
|
||||||
Job.IsStarted = true;
|
job.IsStarted = true;
|
||||||
Job.IsExecuting = false;
|
job.IsExecuting = false;
|
||||||
Jobs.UpdateJob(Job);
|
jobs.UpdateJob(job);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,19 +162,19 @@ namespace Oqtane.Infrastructure
|
|||||||
// can occur during the initial installation as there is no DBContext
|
// can occur during the initial installation as there is no DBContext
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecutingTask = ExecuteAsync(_cancellationTokenSource.Token);
|
_executingTask = ExecuteAsync(_cancellationTokenSource.Token);
|
||||||
|
|
||||||
if (ExecutingTask.IsCompleted)
|
if (_executingTask.IsCompleted)
|
||||||
{
|
{
|
||||||
return ExecutingTask;
|
return _executingTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StopAsync(CancellationToken CancellationToken)
|
public async Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (ExecutingTask == null)
|
if (_executingTask == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -185,7 +185,7 @@ namespace Oqtane.Infrastructure
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
await Task.WhenAny(ExecutingTask, Task.Delay(Timeout.Infinite, CancellationToken));
|
await Task.WhenAny(_executingTask, Task.Delay(Timeout.Infinite, cancellationToken));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,34 +14,34 @@ namespace Oqtane.Infrastructure
|
|||||||
{
|
{
|
||||||
// JobType = "Oqtane.Infrastructure.NotificationJob, Oqtane.Server"
|
// JobType = "Oqtane.Infrastructure.NotificationJob, Oqtane.Server"
|
||||||
|
|
||||||
public NotificationJob(IServiceScopeFactory ServiceScopeFactory) : base(ServiceScopeFactory) {}
|
public NotificationJob(IServiceScopeFactory serviceScopeFactory) : base(serviceScopeFactory) {}
|
||||||
|
|
||||||
public override string ExecuteJob(IServiceProvider provider)
|
public override string ExecuteJob(IServiceProvider provider)
|
||||||
{
|
{
|
||||||
string log = "";
|
string log = "";
|
||||||
|
|
||||||
// iterate through aliases in this installation
|
// iterate through aliases in this installation
|
||||||
var Aliases = provider.GetRequiredService<IAliasRepository>();
|
var aliasRepository = provider.GetRequiredService<IAliasRepository>();
|
||||||
List<Alias> aliases = Aliases.GetAliases().ToList();
|
List<Alias> aliases = aliasRepository.GetAliases().ToList();
|
||||||
foreach (Alias alias in aliases)
|
foreach (Alias alias in aliases)
|
||||||
{
|
{
|
||||||
// use the SiteState to set the Alias explicitly so the tenant can be resolved
|
// use the SiteState to set the Alias explicitly so the tenant can be resolved
|
||||||
var sitestate = provider.GetRequiredService<SiteState>();
|
var siteState = provider.GetRequiredService<SiteState>();
|
||||||
sitestate.Alias = alias;
|
siteState.Alias = alias;
|
||||||
|
|
||||||
// get services which require tenant resolution
|
// get services which require tenant resolution
|
||||||
var Sites = provider.GetRequiredService<ISiteRepository>();
|
var siteRepository = provider.GetRequiredService<ISiteRepository>();
|
||||||
var Settings = provider.GetRequiredService<ISettingRepository>();
|
var settingRepository = provider.GetRequiredService<ISettingRepository>();
|
||||||
var Notifications = provider.GetRequiredService<INotificationRepository>();
|
var notificationRepository = provider.GetRequiredService<INotificationRepository>();
|
||||||
|
|
||||||
// iterate through sites
|
// iterate through sites
|
||||||
List<Site> sites = Sites.GetSites().ToList();
|
List<Site> sites = siteRepository.GetSites().ToList();
|
||||||
foreach (Site site in sites)
|
foreach (Site site in sites)
|
||||||
{
|
{
|
||||||
log += "Processing Notifications For Site: " + site.Name + "\n\n";
|
log += "Processing Notifications For Site: " + site.Name + "\n\n";
|
||||||
|
|
||||||
// get site settings
|
// get site settings
|
||||||
List<Setting> sitesettings = Settings.GetSettings("Site", site.SiteId).ToList();
|
List<Setting> sitesettings = settingRepository.GetSettings("Site", site.SiteId).ToList();
|
||||||
Dictionary<string, string> settings = GetSettings(sitesettings);
|
Dictionary<string, string> settings = GetSettings(sitesettings);
|
||||||
if (settings.ContainsKey("SMTPHost") && settings["SMTPHost"] != "")
|
if (settings.ContainsKey("SMTPHost") && settings["SMTPHost"] != "")
|
||||||
{
|
{
|
||||||
@ -61,7 +61,7 @@ namespace Oqtane.Infrastructure
|
|||||||
|
|
||||||
// iterate through notifications
|
// iterate through notifications
|
||||||
int sent = 0;
|
int sent = 0;
|
||||||
List<Notification> notifications = Notifications.GetNotifications(site.SiteId, -1, -1).ToList();
|
List<Notification> notifications = notificationRepository.GetNotifications(site.SiteId, -1, -1).ToList();
|
||||||
foreach (Notification notification in notifications)
|
foreach (Notification notification in notifications)
|
||||||
{
|
{
|
||||||
MailMessage mailMessage = new MailMessage();
|
MailMessage mailMessage = new MailMessage();
|
||||||
@ -75,7 +75,7 @@ namespace Oqtane.Infrastructure
|
|||||||
{
|
{
|
||||||
mailMessage.Body = "From: " + site.Name + "\n";
|
mailMessage.Body = "From: " + site.Name + "\n";
|
||||||
}
|
}
|
||||||
mailMessage.Body += "Sent: " + notification.CreatedOn.ToString() + "\n";
|
mailMessage.Body += "Sent: " + notification.CreatedOn + "\n";
|
||||||
if (notification.ToUserId != null)
|
if (notification.ToUserId != null)
|
||||||
{
|
{
|
||||||
mailMessage.To.Add(new MailAddress(notification.ToUser.Email, notification.ToUser.DisplayName));
|
mailMessage.To.Add(new MailAddress(notification.ToUser.Email, notification.ToUser.DisplayName));
|
||||||
@ -96,15 +96,15 @@ namespace Oqtane.Infrastructure
|
|||||||
sent = sent++;
|
sent = sent++;
|
||||||
notification.IsDelivered = true;
|
notification.IsDelivered = true;
|
||||||
notification.DeliveredOn = DateTime.UtcNow;
|
notification.DeliveredOn = DateTime.UtcNow;
|
||||||
Notifications.UpdateNotification(notification);
|
notificationRepository.UpdateNotification(notification);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// error
|
// error
|
||||||
log += ex.Message.ToString() + "\n\n";
|
log += ex.Message + "\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log += "Notifications Delivered: " + sent.ToString() + "\n\n";
|
log += "Notifications Delivered: " + sent + "\n\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -117,10 +117,10 @@ namespace Oqtane.Infrastructure
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Dictionary<string, string> GetSettings(List<Setting> Settings)
|
private Dictionary<string, string> GetSettings(List<Setting> settings)
|
||||||
{
|
{
|
||||||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||||||
foreach (Setting setting in Settings.OrderBy(item => item.SettingName).ToList())
|
foreach (Setting setting in settings.OrderBy(item => item.SettingName).ToList())
|
||||||
{
|
{
|
||||||
dictionary.Add(setting.SettingName, setting.SettingValue);
|
dictionary.Add(setting.SettingName, setting.SettingValue);
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
using Oqtane.Security;
|
using Oqtane.Security;
|
||||||
|
// ReSharper disable StringIndexOfIsCultureSpecific.2
|
||||||
|
// ReSharper disable StringIndexOfIsCultureSpecific.1
|
||||||
|
|
||||||
namespace Oqtane.Infrastructure
|
namespace Oqtane.Infrastructure
|
||||||
{
|
{
|
||||||
@ -27,25 +30,25 @@ namespace Oqtane.Infrastructure
|
|||||||
_accessor = accessor;
|
_accessor = accessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Log(LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args)
|
public void Log(LogLevel level, object @class, LogFunction function, string message, params object[] args)
|
||||||
{
|
{
|
||||||
Log(-1, Level, Class.GetType().AssemblyQualifiedName, Function, null, Message, Args);
|
Log(-1, level, @class.GetType().AssemblyQualifiedName, function, null, message, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Log(LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args)
|
public void Log(LogLevel level, object @class, LogFunction function, Exception exception, string message, params object[] args)
|
||||||
{
|
{
|
||||||
Log(-1, Level, Class.GetType().AssemblyQualifiedName, Function, Exception, Message, Args);
|
Log(-1, level, @class.GetType().AssemblyQualifiedName, function, exception, message, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Log(int SiteId, LogLevel Level, object Class, LogFunction Function, string Message, params object[] Args)
|
public void Log(int siteId, LogLevel level, object @class, LogFunction function, string message, params object[] args)
|
||||||
{
|
{
|
||||||
Log(SiteId, Level, Class.GetType().AssemblyQualifiedName, Function, null, Message, Args);
|
Log(siteId, level, @class.GetType().AssemblyQualifiedName, function, null, message, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Log(int SiteId, LogLevel Level, object Class, LogFunction Function, Exception Exception, string Message, params object[] Args)
|
public void Log(int siteId, LogLevel level, object @class, LogFunction function, Exception exception, string message, params object[] args)
|
||||||
{
|
{
|
||||||
Log log = new Log();
|
Log log = new Log();
|
||||||
if (SiteId == -1)
|
if (siteId == -1)
|
||||||
{
|
{
|
||||||
log.SiteId = null;
|
log.SiteId = null;
|
||||||
Alias alias = _tenantResolver.GetAlias();
|
Alias alias = _tenantResolver.GetAlias();
|
||||||
@ -56,7 +59,7 @@ namespace Oqtane.Infrastructure
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.SiteId = SiteId;
|
log.SiteId = siteId;
|
||||||
}
|
}
|
||||||
log.PageId = null;
|
log.PageId = null;
|
||||||
log.ModuleId = null;
|
log.ModuleId = null;
|
||||||
@ -69,10 +72,10 @@ namespace Oqtane.Infrastructure
|
|||||||
HttpRequest request = _accessor.HttpContext.Request;
|
HttpRequest request = _accessor.HttpContext.Request;
|
||||||
if (request != null)
|
if (request != null)
|
||||||
{
|
{
|
||||||
log.Url = request.Scheme.ToString() + "://" + request.Host.ToString() + request.Path.ToString() + request.QueryString.ToString();
|
log.Url = $"{request.Scheme}://{request.Host}{request.Path}{request.QueryString}";
|
||||||
}
|
}
|
||||||
|
|
||||||
Type type = Type.GetType(Class.ToString());
|
Type type = @class.GetType();
|
||||||
if (type != null)
|
if (type != null)
|
||||||
{
|
{
|
||||||
log.Category = type.AssemblyQualifiedName;
|
log.Category = type.AssemblyQualifiedName;
|
||||||
@ -80,20 +83,20 @@ namespace Oqtane.Infrastructure
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Category = Class.ToString();
|
log.Category = @class.ToString();
|
||||||
log.Feature = log.Category;
|
log.Feature = log.Category;
|
||||||
}
|
}
|
||||||
log.Function = Enum.GetName(typeof(LogFunction), Function);
|
log.Function = Enum.GetName(typeof(LogFunction), function);
|
||||||
log.Level = Enum.GetName(typeof(LogLevel), Level);
|
log.Level = Enum.GetName(typeof(LogLevel), level);
|
||||||
if (Exception != null)
|
if (exception != null)
|
||||||
{
|
{
|
||||||
log.Exception = Exception.ToString();
|
log.Exception = exception.ToString();
|
||||||
}
|
}
|
||||||
log.Message = Message;
|
log.Message = message;
|
||||||
log.MessageTemplate = "";
|
log.MessageTemplate = "";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
log.Properties = JsonSerializer.Serialize(Args);
|
log.Properties = JsonSerializer.Serialize(args);
|
||||||
}
|
}
|
||||||
catch // serialization error occurred
|
catch // serialization error occurred
|
||||||
{
|
{
|
||||||
@ -102,7 +105,7 @@ namespace Oqtane.Infrastructure
|
|||||||
Log(log);
|
Log(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Log(Log Log)
|
public void Log(Log log)
|
||||||
{
|
{
|
||||||
LogLevel minlevel = LogLevel.Information;
|
LogLevel minlevel = LogLevel.Information;
|
||||||
var section = _config.GetSection("Logging:LogLevel:Default");
|
var section = _config.GetSection("Logging:LogLevel:Default");
|
||||||
@ -111,15 +114,15 @@ namespace Oqtane.Infrastructure
|
|||||||
minlevel = Enum.Parse<LogLevel>(_config.GetSection("Logging:LogLevel:Default").ToString());
|
minlevel = Enum.Parse<LogLevel>(_config.GetSection("Logging:LogLevel:Default").ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Enum.Parse<LogLevel>(Log.Level) >= minlevel)
|
if (Enum.Parse<LogLevel>(log.Level) >= minlevel)
|
||||||
{
|
{
|
||||||
Log.LogDate = DateTime.UtcNow;
|
log.LogDate = DateTime.UtcNow;
|
||||||
Log.Server = Environment.MachineName;
|
log.Server = Environment.MachineName;
|
||||||
Log.MessageTemplate = Log.Message;
|
log.MessageTemplate = log.Message;
|
||||||
Log = ProcessStructuredLog(Log);
|
log = ProcessStructuredLog(log);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logs.AddLog(Log);
|
_logs.AddLog(log);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -128,16 +131,16 @@ namespace Oqtane.Infrastructure
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Log ProcessStructuredLog(Log Log)
|
private Log ProcessStructuredLog(Log log)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string message = Log.Message;
|
string message = log.Message;
|
||||||
string properties = "";
|
string properties = "";
|
||||||
if (!string.IsNullOrEmpty(message) && message.Contains("{") && message.Contains("}") && !string.IsNullOrEmpty(Log.Properties))
|
if (!string.IsNullOrEmpty(message) && message.Contains("{") && message.Contains("}") && !string.IsNullOrEmpty(log.Properties))
|
||||||
{
|
{
|
||||||
// get the named holes in the message and replace values
|
// get the named holes in the message and replace values
|
||||||
object[] values = JsonSerializer.Deserialize<object[]>(Log.Properties);
|
object[] values = JsonSerializer.Deserialize<object[]>(log.Properties);
|
||||||
List<string> names = new List<string>();
|
List<string> names = new List<string>();
|
||||||
int index = message.IndexOf("{");
|
int index = message.IndexOf("{");
|
||||||
while (index != -1)
|
while (index != -1)
|
||||||
@ -160,28 +163,28 @@ namespace Oqtane.Infrastructure
|
|||||||
index = message.IndexOf("{", index + 1);
|
index = message.IndexOf("{", index + 1);
|
||||||
}
|
}
|
||||||
// rebuild properties into dictionary
|
// rebuild properties into dictionary
|
||||||
Dictionary<string, object> propertydictionary = new Dictionary<string, object>();
|
Dictionary<string, object> propertyDictionary = new Dictionary<string, object>();
|
||||||
for (int i = 0; i < values.Length; i++)
|
for (int i = 0; i < values.Length; i++)
|
||||||
{
|
{
|
||||||
if (i < names.Count)
|
if (i < names.Count)
|
||||||
{
|
{
|
||||||
propertydictionary.Add(names[i], values[i]);
|
propertyDictionary.Add(names[i], values[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
propertydictionary.Add("Property" + i.ToString(), values[i]);
|
propertyDictionary.Add("Property" + i.ToString(), values[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
properties = JsonSerializer.Serialize(propertydictionary);
|
properties = JsonSerializer.Serialize(propertyDictionary);
|
||||||
}
|
}
|
||||||
Log.Message = message;
|
log.Message = message;
|
||||||
Log.Properties = properties;
|
log.Properties = properties;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Log.Properties = "";
|
log.Properties = "";
|
||||||
}
|
}
|
||||||
return Log;
|
return log;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,20 +1,21 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Repository;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Infrastructure
|
namespace Oqtane.Infrastructure
|
||||||
{
|
{
|
||||||
public class SyncManager : ISyncManager
|
public class SyncManager : ISyncManager
|
||||||
{
|
{
|
||||||
private readonly IServiceScopeFactory ServiceScopeFactory;
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||||
private List<SyncEvent> SyncEvents { get; set; }
|
private List<SyncEvent> SyncEvents { get; set; }
|
||||||
|
|
||||||
public SyncManager(IServiceScopeFactory ServiceScopeFactory)
|
public SyncManager(IServiceScopeFactory serviceScopeFactory)
|
||||||
{
|
{
|
||||||
this.ServiceScopeFactory = ServiceScopeFactory;
|
this._serviceScopeFactory = serviceScopeFactory;
|
||||||
SyncEvents = new List<SyncEvent>();
|
SyncEvents = new List<SyncEvent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,21 +23,21 @@ namespace Oqtane.Infrastructure
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
using (var scope = ServiceScopeFactory.CreateScope())
|
using (var scope = _serviceScopeFactory.CreateScope())
|
||||||
{
|
{
|
||||||
return scope.ServiceProvider.GetRequiredService<ITenantResolver>().GetTenant().TenantId;
|
return scope.ServiceProvider.GetRequiredService<ITenantResolver>().GetTenant().TenantId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SyncEvent> GetSyncEvents(DateTime LastSyncDate)
|
public List<SyncEvent> GetSyncEvents(DateTime lastSyncDate)
|
||||||
{
|
{
|
||||||
return SyncEvents.Where(item => item.TenantId == TenantId && item.ModifiedOn >= LastSyncDate).ToList();
|
return SyncEvents.Where(item => item.TenantId == TenantId && item.ModifiedOn >= lastSyncDate).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddSyncEvent(string EntityName, int EntityId)
|
public void AddSyncEvent(string entityName, int entityId)
|
||||||
{
|
{
|
||||||
SyncEvents.Add(new SyncEvent { TenantId = TenantId, EntityName = EntityName, EntityId = EntityId, ModifiedOn = DateTime.UtcNow });
|
SyncEvents.Add(new SyncEvent { TenantId = TenantId, EntityName = entityName, EntityId = entityId, ModifiedOn = DateTime.UtcNow });
|
||||||
// trim sync events
|
// trim sync events
|
||||||
SyncEvents.RemoveAll(item => item.ModifiedOn < DateTime.UtcNow.AddHours(-1));
|
SyncEvents.RemoveAll(item => item.ModifiedOn < DateTime.UtcNow.AddHours(-1));
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Oqtane.Modules.HtmlText.Models;
|
using Oqtane.Modules.HtmlText.Models;
|
||||||
using Oqtane.Modules.HtmlText.Repository;
|
using Oqtane.Modules.HtmlText.Repository;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Oqtane.Infrastructure;
|
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
|
||||||
namespace Oqtane.Modules.HtmlText.Controllers
|
namespace Oqtane.Modules.HtmlText.Controllers
|
||||||
{
|
{
|
||||||
@ -35,11 +35,11 @@ namespace Oqtane.Modules.HtmlText.Controllers
|
|||||||
var list = new List<HtmlTextInfo>();
|
var list = new List<HtmlTextInfo>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HtmlTextInfo HtmlText = null;
|
HtmlTextInfo htmlText = null;
|
||||||
if (_entityId == id)
|
if (_entityId == id)
|
||||||
{
|
{
|
||||||
HtmlText = _htmlText.GetHtmlText(id);
|
htmlText = _htmlText.GetHtmlText(id);
|
||||||
list.Add(HtmlText);
|
list.Add(htmlText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -53,16 +53,16 @@ namespace Oqtane.Modules.HtmlText.Controllers
|
|||||||
// POST api/<controller>
|
// POST api/<controller>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Authorize(Policy = "EditModule")]
|
[Authorize(Policy = "EditModule")]
|
||||||
public HtmlTextInfo Post([FromBody] HtmlTextInfo HtmlText)
|
public HtmlTextInfo Post([FromBody] HtmlTextInfo htmlText)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && HtmlText.ModuleId == _entityId)
|
if (ModelState.IsValid && htmlText.ModuleId == _entityId)
|
||||||
{
|
{
|
||||||
HtmlText = _htmlText.AddHtmlText(HtmlText);
|
htmlText = _htmlText.AddHtmlText(htmlText);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Html/Text Added {HtmlText}", HtmlText);
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Html/Text Added {HtmlText}", htmlText);
|
||||||
}
|
}
|
||||||
return HtmlText;
|
return htmlText;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -74,16 +74,16 @@ namespace Oqtane.Modules.HtmlText.Controllers
|
|||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Policy = "EditModule")]
|
[Authorize(Policy = "EditModule")]
|
||||||
public HtmlTextInfo Put(int id, [FromBody] HtmlTextInfo HtmlText)
|
public HtmlTextInfo Put(int id, [FromBody] HtmlTextInfo htmlText)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (ModelState.IsValid && HtmlText.ModuleId == _entityId)
|
if (ModelState.IsValid && htmlText.ModuleId == _entityId)
|
||||||
{
|
{
|
||||||
HtmlText = _htmlText.UpdateHtmlText(HtmlText);
|
htmlText = _htmlText.UpdateHtmlText(htmlText);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Html/Text Updated {HtmlText}", HtmlText);
|
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Html/Text Updated {HtmlText}", htmlText);
|
||||||
}
|
}
|
||||||
return HtmlText;
|
return htmlText;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -14,10 +14,10 @@ namespace Oqtane.Modules.HtmlText.Manager
|
|||||||
_htmlTexts = htmltexts;
|
_htmlTexts = htmltexts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ExportModule(Module Module)
|
public string ExportModule(Module module)
|
||||||
{
|
{
|
||||||
string content = "";
|
string content = "";
|
||||||
HtmlTextInfo htmltext = _htmlTexts.GetHtmlText(Module.ModuleId);
|
HtmlTextInfo htmltext = _htmlTexts.GetHtmlText(module.ModuleId);
|
||||||
if (htmltext != null)
|
if (htmltext != null)
|
||||||
{
|
{
|
||||||
content = WebUtility.HtmlEncode(htmltext.Content);
|
content = WebUtility.HtmlEncode(htmltext.Content);
|
||||||
@ -25,20 +25,20 @@ namespace Oqtane.Modules.HtmlText.Manager
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ImportModule(Module Module, string Content, string Version)
|
public void ImportModule(Module module, string content, string version)
|
||||||
{
|
{
|
||||||
Content = WebUtility.HtmlDecode(Content);
|
content = WebUtility.HtmlDecode(content);
|
||||||
HtmlTextInfo htmltext = _htmlTexts.GetHtmlText(Module.ModuleId);
|
HtmlTextInfo htmltext = _htmlTexts.GetHtmlText(module.ModuleId);
|
||||||
if (htmltext != null)
|
if (htmltext != null)
|
||||||
{
|
{
|
||||||
htmltext.Content = Content;
|
htmltext.Content = content;
|
||||||
_htmlTexts.UpdateHtmlText(htmltext);
|
_htmlTexts.UpdateHtmlText(htmltext);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
htmltext = new HtmlTextInfo();
|
htmltext = new HtmlTextInfo();
|
||||||
htmltext.ModuleId = Module.ModuleId;
|
htmltext.ModuleId = module.ModuleId;
|
||||||
htmltext.Content = Content;
|
htmltext.Content = content;
|
||||||
_htmlTexts.AddHtmlText(htmltext);
|
_htmlTexts.AddHtmlText(htmltext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace Oqtane.Modules.HtmlText.Repository
|
|||||||
{
|
{
|
||||||
public virtual DbSet<HtmlTextInfo> HtmlText { get; set; }
|
public virtual DbSet<HtmlTextInfo> HtmlText { get; set; }
|
||||||
|
|
||||||
public HtmlTextContext(ITenantResolver TenantResolver, IHttpContextAccessor accessor) : base(TenantResolver, accessor)
|
public HtmlTextContext(ITenantResolver tenantResolver, IHttpContextAccessor accessor) : base(tenantResolver, accessor)
|
||||||
{
|
{
|
||||||
// ContextBase handles multi-tenant database connections
|
// ContextBase handles multi-tenant database connections
|
||||||
}
|
}
|
||||||
|
@ -13,59 +13,31 @@ namespace Oqtane.Modules.HtmlText.Repository
|
|||||||
_db = context;
|
_db = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HtmlTextInfo GetHtmlText(int ModuleId)
|
public HtmlTextInfo GetHtmlText(int moduleId)
|
||||||
{
|
{
|
||||||
try
|
return _db.HtmlText.FirstOrDefault(item => item.ModuleId == moduleId);
|
||||||
{
|
|
||||||
return _db.HtmlText.Where(item => item.ModuleId == ModuleId).FirstOrDefault();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public HtmlTextInfo AddHtmlText(HtmlTextInfo HtmlText)
|
public HtmlTextInfo AddHtmlText(HtmlTextInfo htmlText)
|
||||||
{
|
{
|
||||||
try
|
_db.HtmlText.Add(htmlText);
|
||||||
{
|
|
||||||
_db.HtmlText.Add(HtmlText);
|
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return HtmlText;
|
return htmlText;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HtmlTextInfo UpdateHtmlText(HtmlTextInfo HtmlText)
|
public HtmlTextInfo UpdateHtmlText(HtmlTextInfo htmlText)
|
||||||
{
|
{
|
||||||
try
|
_db.Entry(htmlText).State = EntityState.Modified;
|
||||||
{
|
|
||||||
_db.Entry(HtmlText).State = EntityState.Modified;
|
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return HtmlText;
|
return htmlText;
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteHtmlText(int ModuleId)
|
public void DeleteHtmlText(int moduleId)
|
||||||
{
|
{
|
||||||
try
|
HtmlTextInfo htmlText = _db.HtmlText.FirstOrDefault(item => item.ModuleId == moduleId);
|
||||||
{
|
if (htmlText != null) _db.HtmlText.Remove(htmlText);
|
||||||
HtmlTextInfo HtmlText = _db.HtmlText.Where(item => item.ModuleId == ModuleId).FirstOrDefault();
|
|
||||||
_db.HtmlText.Remove(HtmlText);
|
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using Oqtane.Modules.HtmlText.Models;
|
||||||
using Oqtane.Modules.HtmlText.Models;
|
|
||||||
|
|
||||||
namespace Oqtane.Modules.HtmlText.Repository
|
namespace Oqtane.Modules.HtmlText.Repository
|
||||||
{
|
{
|
||||||
public interface IHtmlTextRepository
|
public interface IHtmlTextRepository
|
||||||
{
|
{
|
||||||
HtmlTextInfo GetHtmlText(int ModuleId);
|
HtmlTextInfo GetHtmlText(int moduleId);
|
||||||
HtmlTextInfo AddHtmlText(HtmlTextInfo HtmlText);
|
HtmlTextInfo AddHtmlText(HtmlTextInfo htmlText);
|
||||||
HtmlTextInfo UpdateHtmlText(HtmlTextInfo HtmlText);
|
HtmlTextInfo UpdateHtmlText(HtmlTextInfo htmlText);
|
||||||
void DeleteHtmlText(int ModuleId);
|
void DeleteHtmlText(int moduleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ namespace Oqtane.Modules
|
|||||||
{
|
{
|
||||||
// You Must Set The "ServerAssemblyName" In Your IModule Interface
|
// You Must Set The "ServerAssemblyName" In Your IModule Interface
|
||||||
|
|
||||||
string ExportModule(Module Module);
|
string ExportModule(Module module);
|
||||||
|
|
||||||
void ImportModule(Module Module, string Content, string Version);
|
void ImportModule(Module module, string content, string version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
@page "/"
|
@page "/"
|
||||||
@namespace Oqtane.Pages
|
@namespace Oqtane.Pages
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
@using Oqtane.Client
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.AspNetCore.Blazor.Hosting;
|
|
||||||
// used by client-side Blazor
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.AspNetCore;
|
|
||||||
|
|
||||||
namespace Oqtane.Server
|
// used by client-side Blazor
|
||||||
|
|
||||||
|
namespace Oqtane
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using System;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
@ -27,30 +27,30 @@ namespace Oqtane.Repository
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Alias AddAlias(Alias Alias)
|
public Alias AddAlias(Alias alias)
|
||||||
{
|
{
|
||||||
_db.Alias.Add(Alias);
|
_db.Alias.Add(alias);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_cache.Remove("aliases");
|
_cache.Remove("aliases");
|
||||||
return Alias;
|
return alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Alias UpdateAlias(Alias Alias)
|
public Alias UpdateAlias(Alias alias)
|
||||||
{
|
{
|
||||||
_db.Entry(Alias).State = EntityState.Modified;
|
_db.Entry(alias).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_cache.Remove("aliases");
|
_cache.Remove("aliases");
|
||||||
return Alias;
|
return alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Alias GetAlias(int AliasId)
|
public Alias GetAlias(int aliasId)
|
||||||
{
|
{
|
||||||
return _db.Alias.Find(AliasId);
|
return _db.Alias.Find(aliasId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteAlias(int AliasId)
|
public void DeleteAlias(int aliasId)
|
||||||
{
|
{
|
||||||
Alias alias = _db.Alias.Find(AliasId);
|
Alias alias = _db.Alias.Find(aliasId);
|
||||||
_db.Alias.Remove(alias);
|
_db.Alias.Remove(alias);
|
||||||
_cache.Remove("aliases");
|
_cache.Remove("aliases");
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
@ -53,7 +53,7 @@ namespace Oqtane.Repository
|
|||||||
|
|
||||||
foreach(var item in created)
|
foreach(var item in created)
|
||||||
{
|
{
|
||||||
if (item.Entity is IAuditable entity)
|
if (item.Entity is IAuditable)
|
||||||
{
|
{
|
||||||
item.CurrentValues[nameof(IAuditable.CreatedBy)] = username;
|
item.CurrentValues[nameof(IAuditable.CreatedBy)] = username;
|
||||||
item.CurrentValues[nameof(IAuditable.CreatedOn)] = date;
|
item.CurrentValues[nameof(IAuditable.CreatedOn)] = date;
|
||||||
@ -65,13 +65,13 @@ namespace Oqtane.Repository
|
|||||||
|
|
||||||
foreach (var item in modified)
|
foreach (var item in modified)
|
||||||
{
|
{
|
||||||
if (item.Entity is IAuditable entity)
|
if (item.Entity is IAuditable)
|
||||||
{
|
{
|
||||||
item.CurrentValues[nameof(IAuditable.ModifiedBy)] = username;
|
item.CurrentValues[nameof(IAuditable.ModifiedBy)] = username;
|
||||||
item.CurrentValues[nameof(IAuditable.ModifiedOn)] = date;
|
item.CurrentValues[nameof(IAuditable.ModifiedOn)] = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.Entity is IDeletable deleted && item.State != EntityState.Added)
|
if (item.Entity is IDeletable && item.State != EntityState.Added)
|
||||||
{
|
{
|
||||||
if ((bool)item.CurrentValues[nameof(IDeletable.IsDeleted)]
|
if ((bool)item.CurrentValues[nameof(IDeletable.IsDeleted)]
|
||||||
&& !item.GetDatabaseValues().GetValue<bool>(nameof(IDeletable.IsDeleted)))
|
&& !item.GetDatabaseValues().GetValue<bool>(nameof(IDeletable.IsDeleted)))
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ namespace Oqtane.Repository
|
|||||||
|
|
||||||
foreach (var item in created)
|
foreach (var item in created)
|
||||||
{
|
{
|
||||||
if (item.Entity is IAuditable entity)
|
if (item.Entity is IAuditable)
|
||||||
{
|
{
|
||||||
item.CurrentValues[nameof(IAuditable.CreatedBy)] = username;
|
item.CurrentValues[nameof(IAuditable.CreatedBy)] = username;
|
||||||
item.CurrentValues[nameof(IAuditable.CreatedOn)] = date;
|
item.CurrentValues[nameof(IAuditable.CreatedOn)] = date;
|
||||||
@ -49,7 +49,7 @@ namespace Oqtane.Repository
|
|||||||
|
|
||||||
foreach (var item in modified)
|
foreach (var item in modified)
|
||||||
{
|
{
|
||||||
if (item.Entity is IAuditable entity)
|
if (item.Entity is IAuditable)
|
||||||
{
|
{
|
||||||
item.CurrentValues[nameof(IAuditable.ModifiedBy)] = username;
|
item.CurrentValues[nameof(IAuditable.ModifiedBy)] = username;
|
||||||
item.CurrentValues[nameof(IAuditable.ModifiedOn)] = date;
|
item.CurrentValues[nameof(IAuditable.ModifiedOn)] = date;
|
||||||
|
@ -21,7 +21,7 @@ namespace Oqtane.Repository
|
|||||||
public virtual DbSet<Folder> Folder { get; set; }
|
public virtual DbSet<Folder> Folder { get; set; }
|
||||||
public virtual DbSet<File> File { get; set; }
|
public virtual DbSet<File> File { get; set; }
|
||||||
|
|
||||||
public TenantDBContext(ITenantResolver TenantResolver, IHttpContextAccessor accessor) : base(TenantResolver, accessor)
|
public TenantDBContext(ITenantResolver tenantResolver, IHttpContextAccessor accessor) : base(tenantResolver, accessor)
|
||||||
{
|
{
|
||||||
// DBContextBase handles multi-tenant database connections
|
// DBContextBase handles multi-tenant database connections
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -16,34 +16,34 @@ namespace Oqtane.Repository
|
|||||||
_permissions = permissions;
|
_permissions = permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<File> GetFiles(int FolderId)
|
public IEnumerable<File> GetFiles(int folderId)
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions("Folder", FolderId).ToList();
|
IEnumerable<Permission> permissions = _permissions.GetPermissions("Folder", folderId).ToList();
|
||||||
IEnumerable<File> files = _db.File.Where(item => item.FolderId == FolderId).Include(item => item.Folder);
|
IEnumerable<File> files = _db.File.Where(item => item.FolderId == folderId).Include(item => item.Folder);
|
||||||
foreach (File file in files)
|
foreach (File file in files)
|
||||||
{
|
{
|
||||||
file.Folder.Permissions = _permissions.EncodePermissions(FolderId, permissions);
|
file.Folder.Permissions = _permissions.EncodePermissions(folderId, permissions);
|
||||||
}
|
}
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File AddFile(File File)
|
public File AddFile(File file)
|
||||||
{
|
{
|
||||||
_db.File.Add(File);
|
_db.File.Add(file);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return File;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File UpdateFile(File File)
|
public File UpdateFile(File file)
|
||||||
{
|
{
|
||||||
_db.Entry(File).State = EntityState.Modified;
|
_db.Entry(file).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return File;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File GetFile(int FileId)
|
public File GetFile(int fileId)
|
||||||
{
|
{
|
||||||
File file = _db.File.Where(item => item.FileId == FileId).Include(item => item.Folder).FirstOrDefault();
|
File file = _db.File.Where(item => item.FileId == fileId).Include(item => item.Folder).FirstOrDefault();
|
||||||
if (file != null)
|
if (file != null)
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions("Folder", file.FolderId).ToList();
|
IEnumerable<Permission> permissions = _permissions.GetPermissions("Folder", file.FolderId).ToList();
|
||||||
@ -52,10 +52,10 @@ namespace Oqtane.Repository
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteFile(int FileId)
|
public void DeleteFile(int fileId)
|
||||||
{
|
{
|
||||||
File File = _db.File.Find(FileId);
|
File file = _db.File.Find(fileId);
|
||||||
_db.File.Remove(File);
|
_db.File.Remove(file);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -16,10 +16,10 @@ namespace Oqtane.Repository
|
|||||||
_permissions = permissions;
|
_permissions = permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Folder> GetFolders(int SiteId)
|
public IEnumerable<Folder> GetFolders(int siteId)
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions(SiteId, "Folder").ToList();
|
IEnumerable<Permission> permissions = _permissions.GetPermissions(siteId, "Folder").ToList();
|
||||||
IEnumerable<Folder> folders = _db.Folder.Where(item => item.SiteId == SiteId);
|
IEnumerable<Folder> folders = _db.Folder.Where(item => item.SiteId == siteId);
|
||||||
foreach(Folder folder in folders)
|
foreach(Folder folder in folders)
|
||||||
{
|
{
|
||||||
folder.Permissions = _permissions.EncodePermissions(folder.FolderId, permissions);
|
folder.Permissions = _permissions.EncodePermissions(folder.FolderId, permissions);
|
||||||
@ -27,25 +27,25 @@ namespace Oqtane.Repository
|
|||||||
return folders;
|
return folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Folder AddFolder(Folder Folder)
|
public Folder AddFolder(Folder folder)
|
||||||
{
|
{
|
||||||
_db.Folder.Add(Folder);
|
_db.Folder.Add(folder);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_permissions.UpdatePermissions(Folder.SiteId, "Folder", Folder.FolderId, Folder.Permissions);
|
_permissions.UpdatePermissions(folder.SiteId, "Folder", folder.FolderId, folder.Permissions);
|
||||||
return Folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Folder UpdateFolder(Folder Folder)
|
public Folder UpdateFolder(Folder folder)
|
||||||
{
|
{
|
||||||
_db.Entry(Folder).State = EntityState.Modified;
|
_db.Entry(folder).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_permissions.UpdatePermissions(Folder.SiteId, "Folder", Folder.FolderId, Folder.Permissions);
|
_permissions.UpdatePermissions(folder.SiteId, "Folder", folder.FolderId, folder.Permissions);
|
||||||
return Folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Folder GetFolder(int FolderId)
|
public Folder GetFolder(int folderId)
|
||||||
{
|
{
|
||||||
Folder folder = _db.Folder.Find(FolderId);
|
Folder folder = _db.Folder.Find(folderId);
|
||||||
if (folder != null)
|
if (folder != null)
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions("Folder", folder.FolderId).ToList();
|
IEnumerable<Permission> permissions = _permissions.GetPermissions("Folder", folder.FolderId).ToList();
|
||||||
@ -54,9 +54,9 @@ namespace Oqtane.Repository
|
|||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Folder GetFolder(int SiteId, string Path)
|
public Folder GetFolder(int siteId, string path)
|
||||||
{
|
{
|
||||||
Folder folder = _db.Folder.Where(item => item.SiteId == SiteId && item.Path == Path).FirstOrDefault();
|
Folder folder = _db.Folder.Where(item => item.SiteId == siteId && item.Path == path).FirstOrDefault();
|
||||||
if (folder != null)
|
if (folder != null)
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions("Folder", folder.FolderId).ToList();
|
IEnumerable<Permission> permissions = _permissions.GetPermissions("Folder", folder.FolderId).ToList();
|
||||||
@ -65,11 +65,11 @@ namespace Oqtane.Repository
|
|||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteFolder(int FolderId)
|
public void DeleteFolder(int folderId)
|
||||||
{
|
{
|
||||||
Folder Folder = _db.Folder.Find(FolderId);
|
Folder folder = _db.Folder.Find(folderId);
|
||||||
_permissions.DeletePermissions(Folder.SiteId, "Folder", FolderId);
|
_permissions.DeletePermissions(folder.SiteId, "Folder", folderId);
|
||||||
_db.Folder.Remove(Folder);
|
_db.Folder.Remove(folder);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ namespace Oqtane.Repository
|
|||||||
public interface IAliasRepository
|
public interface IAliasRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Alias> GetAliases();
|
IEnumerable<Alias> GetAliases();
|
||||||
Alias AddAlias(Alias Alias);
|
Alias AddAlias(Alias alias);
|
||||||
Alias UpdateAlias(Alias Alias);
|
Alias UpdateAlias(Alias alias);
|
||||||
Alias GetAlias(int AliasId);
|
Alias GetAlias(int aliasId);
|
||||||
void DeleteAlias(int AliasId);
|
void DeleteAlias(int aliasId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface IFileRepository
|
public interface IFileRepository
|
||||||
{
|
{
|
||||||
IEnumerable<File> GetFiles(int FolderId);
|
IEnumerable<File> GetFiles(int folderId);
|
||||||
File AddFile(File File);
|
File AddFile(File file);
|
||||||
File UpdateFile(File File);
|
File UpdateFile(File file);
|
||||||
File GetFile(int FileId);
|
File GetFile(int fileId);
|
||||||
void DeleteFile(int FileId);
|
void DeleteFile(int fileId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface IFolderRepository
|
public interface IFolderRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Folder> GetFolders(int SiteId);
|
IEnumerable<Folder> GetFolders(int siteId);
|
||||||
Folder AddFolder(Folder Folder);
|
Folder AddFolder(Folder folder);
|
||||||
Folder UpdateFolder(Folder Folder);
|
Folder UpdateFolder(Folder folder);
|
||||||
Folder GetFolder(int FolderId);
|
Folder GetFolder(int folderId);
|
||||||
Folder GetFolder(int SiteId, string Path);
|
Folder GetFolder(int siteId, string path);
|
||||||
void DeleteFolder(int FolderId);
|
void DeleteFolder(int folderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ namespace Oqtane.Repository
|
|||||||
public interface IJobLogRepository
|
public interface IJobLogRepository
|
||||||
{
|
{
|
||||||
IEnumerable<JobLog> GetJobLogs();
|
IEnumerable<JobLog> GetJobLogs();
|
||||||
JobLog AddJobLog(JobLog JobLog);
|
JobLog AddJobLog(JobLog jobLog);
|
||||||
JobLog UpdateJobLog(JobLog JobLog);
|
JobLog UpdateJobLog(JobLog jobLog);
|
||||||
JobLog GetJobLog(int JobLogId);
|
JobLog GetJobLog(int jobLogId);
|
||||||
void DeleteJobLog(int JobLogId);
|
void DeleteJobLog(int jobLogId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ namespace Oqtane.Repository
|
|||||||
public interface IJobRepository
|
public interface IJobRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Job> GetJobs();
|
IEnumerable<Job> GetJobs();
|
||||||
Job AddJob(Job Job);
|
Job AddJob(Job job);
|
||||||
Job UpdateJob(Job Job);
|
Job UpdateJob(Job job);
|
||||||
Job GetJob(int JobId);
|
Job GetJob(int jobId);
|
||||||
void DeleteJob(int JobId);
|
void DeleteJob(int jobId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
using Oqtane.Models;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
public interface ILogRepository
|
public interface ILogRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Log> GetLogs(int SiteId, string Level, string Function, int Rows);
|
IEnumerable<Log> GetLogs(int siteId, string level, string function, int rows);
|
||||||
Log GetLog(int LogId);
|
Log GetLog(int logId);
|
||||||
void AddLog(Log Log);
|
void AddLog(Log log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface IModuleDefinitionRepository
|
public interface IModuleDefinitionRepository
|
||||||
{
|
{
|
||||||
IEnumerable<ModuleDefinition> GetModuleDefinitions(int SideId);
|
IEnumerable<ModuleDefinition> GetModuleDefinitions(int sideId);
|
||||||
ModuleDefinition GetModuleDefinition(int ModuleDefinitionId, int SideId);
|
ModuleDefinition GetModuleDefinition(int moduleDefinitionId, int sideId);
|
||||||
void UpdateModuleDefinition(ModuleDefinition ModuleDefinition);
|
void UpdateModuleDefinition(ModuleDefinition moduleDefinition);
|
||||||
void DeleteModuleDefinition(int ModuleDefinitionId, int SiteId);
|
void DeleteModuleDefinition(int moduleDefinitionId, int siteId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface IModuleRepository
|
public interface IModuleRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Module> GetModules(int SiteId);
|
IEnumerable<Module> GetModules(int siteId);
|
||||||
Module AddModule(Module Module);
|
Module AddModule(Module module);
|
||||||
Module UpdateModule(Module Module);
|
Module UpdateModule(Module module);
|
||||||
Module GetModule(int ModuleId);
|
Module GetModule(int moduleId);
|
||||||
void DeleteModule(int ModuleId);
|
void DeleteModule(int moduleId);
|
||||||
string ExportModule(int ModuleId);
|
string ExportModule(int moduleId);
|
||||||
bool ImportModule(int ModuleId, string Content);
|
bool ImportModule(int moduleId, string content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface INotificationRepository
|
public interface INotificationRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Notification> GetNotifications(int SiteId, int FromUserId, int ToUserId);
|
IEnumerable<Notification> GetNotifications(int siteId, int fromUserId, int toUserId);
|
||||||
Notification AddNotification(Notification Notification);
|
Notification AddNotification(Notification notification);
|
||||||
Notification UpdateNotification(Notification Notification);
|
Notification UpdateNotification(Notification notification);
|
||||||
Notification GetNotification(int NotificationId);
|
Notification GetNotification(int notificationId);
|
||||||
void DeleteNotification(int NotificationId);
|
void DeleteNotification(int notificationId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface IPageModuleRepository
|
public interface IPageModuleRepository
|
||||||
{
|
{
|
||||||
IEnumerable<PageModule> GetPageModules(int SiteId);
|
IEnumerable<PageModule> GetPageModules(int siteId);
|
||||||
IEnumerable<PageModule> GetPageModules(int PageId, string Pane);
|
IEnumerable<PageModule> GetPageModules(int pageId, string pane);
|
||||||
PageModule AddPageModule(PageModule PageModule);
|
PageModule AddPageModule(PageModule pageModule);
|
||||||
PageModule UpdatePageModule(PageModule PageModule);
|
PageModule UpdatePageModule(PageModule pageModule);
|
||||||
PageModule GetPageModule(int PageModuleId);
|
PageModule GetPageModule(int pageModuleId);
|
||||||
PageModule GetPageModule(int PageId, int ModuleId);
|
PageModule GetPageModule(int pageId, int moduleId);
|
||||||
void DeletePageModule(int PageModuleId);
|
void DeletePageModule(int pageModuleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface IPageRepository
|
public interface IPageRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Page> GetPages(int SiteId);
|
IEnumerable<Page> GetPages(int siteId);
|
||||||
Page AddPage(Page Page);
|
Page AddPage(Page page);
|
||||||
Page UpdatePage(Page Page);
|
Page UpdatePage(Page page);
|
||||||
Page GetPage(int PageId);
|
Page GetPage(int pageId);
|
||||||
Page GetPage(int PageId, int UserId);
|
Page GetPage(int pageId, int userId);
|
||||||
Page GetPage(string Path, int SiteId);
|
Page GetPage(string path, int siteId);
|
||||||
void DeletePage(int PageId);
|
void DeletePage(int pageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,16 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface IPermissionRepository
|
public interface IPermissionRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> GetPermissions(int SiteId, string EntityName);
|
IEnumerable<Permission> GetPermissions(int siteId, string entityName);
|
||||||
IEnumerable<Permission> GetPermissions(string EntityName, int EntityId);
|
IEnumerable<Permission> GetPermissions(string entityName, int entityId);
|
||||||
IEnumerable<Permission> GetPermissions(string EntityName, int EntityId, string PermissionName);
|
IEnumerable<Permission> GetPermissions(string entityName, int entityId, string permissionName);
|
||||||
Permission AddPermission(Permission Permission);
|
Permission AddPermission(Permission permission);
|
||||||
Permission UpdatePermission(Permission Permission);
|
Permission UpdatePermission(Permission permission);
|
||||||
void UpdatePermissions(int SiteId, string EntityName, int EntityId, string Permissions);
|
void UpdatePermissions(int siteId, string entityName, int entityId, string permissionStrings);
|
||||||
Permission GetPermission(int PermissionId);
|
Permission GetPermission(int permissionId);
|
||||||
void DeletePermission(int PermissionId);
|
void DeletePermission(int permissionId);
|
||||||
void DeletePermissions(int SiteId, string EntityName, int EntityId);
|
void DeletePermissions(int siteId, string entityName, int entityId);
|
||||||
string EncodePermissions(int EntityId, IEnumerable<Permission> Permissions);
|
string EncodePermissions(int entityId, IEnumerable<Permission> permissionList);
|
||||||
IEnumerable<Permission> DecodePermissions(string Permissions, int SiteId, string EntityName, int EntityId);
|
IEnumerable<Permission> DecodePermissions(string permissions, int siteId, string entityName, int entityId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface IProfileRepository
|
public interface IProfileRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Profile> GetProfiles(int SiteId);
|
IEnumerable<Profile> GetProfiles(int siteId);
|
||||||
Profile AddProfile(Profile Profile);
|
Profile AddProfile(Profile profile);
|
||||||
Profile UpdateProfile(Profile Profile);
|
Profile UpdateProfile(Profile profile);
|
||||||
Profile GetProfile(int ProfileId);
|
Profile GetProfile(int profileId);
|
||||||
void DeleteProfile(int ProfileId);
|
void DeleteProfile(int profileId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface IRoleRepository
|
public interface IRoleRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Role> GetRoles(int SiteId);
|
IEnumerable<Role> GetRoles(int siteId);
|
||||||
IEnumerable<Role> GetRoles(int SiteId, bool IncludeGlobalRoles);
|
IEnumerable<Role> GetRoles(int siteId, bool includeGlobalRoles);
|
||||||
Role AddRole(Role Role);
|
Role AddRole(Role role);
|
||||||
Role UpdateRole(Role Role);
|
Role UpdateRole(Role role);
|
||||||
Role GetRole(int RoleId);
|
Role GetRole(int roleId);
|
||||||
void DeleteRole(int RoleId);
|
void DeleteRole(int roleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface ISettingRepository
|
public interface ISettingRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Setting> GetSettings(string EntityName, int EntityId);
|
IEnumerable<Setting> GetSettings(string entityName, int entityId);
|
||||||
Setting AddSetting(Setting Setting);
|
Setting AddSetting(Setting setting);
|
||||||
Setting UpdateSetting(Setting Setting);
|
Setting UpdateSetting(Setting setting);
|
||||||
Setting GetSetting(int SettingId);
|
Setting GetSetting(int settingId);
|
||||||
void DeleteSetting(int SettingId);
|
void DeleteSetting(int settingId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ namespace Oqtane.Repository
|
|||||||
public interface ISiteRepository
|
public interface ISiteRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Site> GetSites();
|
IEnumerable<Site> GetSites();
|
||||||
Site AddSite(Site Site);
|
Site AddSite(Site site);
|
||||||
Site UpdateSite(Site Site);
|
Site UpdateSite(Site site);
|
||||||
Site GetSite(int SiteId);
|
Site GetSite(int siteId);
|
||||||
void DeleteSite(int SiteId);
|
void DeleteSite(int siteId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
using Oqtane.Models;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
public interface ITenantRepository
|
public interface ITenantRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Tenant> GetTenants();
|
IEnumerable<Tenant> GetTenants();
|
||||||
Tenant AddTenant(Tenant Tenant);
|
Tenant AddTenant(Tenant tenant);
|
||||||
Tenant UpdateTenant(Tenant Tenant);
|
Tenant UpdateTenant(Tenant tenant);
|
||||||
Tenant GetTenant(int TenantId);
|
Tenant GetTenant(int tenantId);
|
||||||
void DeleteTenant(int TenantId);
|
void DeleteTenant(int tenantId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ namespace Oqtane.Repository
|
|||||||
public interface IUserRepository
|
public interface IUserRepository
|
||||||
{
|
{
|
||||||
IEnumerable<User> GetUsers();
|
IEnumerable<User> GetUsers();
|
||||||
User AddUser(User User);
|
User AddUser(User user);
|
||||||
User UpdateUser(User User);
|
User UpdateUser(User user);
|
||||||
User GetUser(int UserId);
|
User GetUser(int userId);
|
||||||
User GetUser(string Username);
|
User GetUser(string username);
|
||||||
void DeleteUser(int UserId);
|
void DeleteUser(int userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
public interface IUserRoleRepository
|
public interface IUserRoleRepository
|
||||||
{
|
{
|
||||||
IEnumerable<UserRole> GetUserRoles(int SiteId);
|
IEnumerable<UserRole> GetUserRoles(int siteId);
|
||||||
IEnumerable<UserRole> GetUserRoles(int UserId, int SiteId);
|
IEnumerable<UserRole> GetUserRoles(int userId, int siteId);
|
||||||
UserRole AddUserRole(UserRole UserRole);
|
UserRole AddUserRole(UserRole userRole);
|
||||||
UserRole UpdateUserRole(UserRole UserRole);
|
UserRole UpdateUserRole(UserRole userRole);
|
||||||
UserRole GetUserRole(int UserRoleId);
|
UserRole GetUserRole(int userRoleId);
|
||||||
void DeleteUserRole(int UserRoleId);
|
void DeleteUserRole(int userRoleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
@ -21,30 +21,30 @@ namespace Oqtane.Repository
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JobLog AddJobLog(JobLog JobLog)
|
public JobLog AddJobLog(JobLog jobLog)
|
||||||
{
|
{
|
||||||
_db.JobLog.Add(JobLog);
|
_db.JobLog.Add(jobLog);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return JobLog;
|
return jobLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JobLog UpdateJobLog(JobLog JobLog)
|
public JobLog UpdateJobLog(JobLog jobLog)
|
||||||
{
|
{
|
||||||
_db.Entry(JobLog).State = EntityState.Modified;
|
_db.Entry(jobLog).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return JobLog;
|
return jobLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JobLog GetJobLog(int JobLogId)
|
public JobLog GetJobLog(int jobLogId)
|
||||||
{
|
{
|
||||||
return _db.JobLog.Include(item => item.Job) // eager load job
|
return _db.JobLog.Include(item => item.Job) // eager load job
|
||||||
.SingleOrDefault(item => item.JobLogId == JobLogId);
|
.SingleOrDefault(item => item.JobLogId == jobLogId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteJobLog(int JobLogId)
|
public void DeleteJobLog(int jobLogId)
|
||||||
{
|
{
|
||||||
JobLog Joblog = _db.JobLog.Find(JobLogId);
|
JobLog joblog = _db.JobLog.Find(jobLogId);
|
||||||
_db.JobLog.Remove(Joblog);
|
_db.JobLog.Remove(joblog);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
@ -27,29 +27,29 @@ namespace Oqtane.Repository
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Job AddJob(Job Job)
|
public Job AddJob(Job job)
|
||||||
{
|
{
|
||||||
_db.Job.Add(Job);
|
_db.Job.Add(job);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Job UpdateJob(Job Job)
|
public Job UpdateJob(Job job)
|
||||||
{
|
{
|
||||||
_db.Entry(Job).State = EntityState.Modified;
|
_db.Entry(job).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Job GetJob(int JobId)
|
public Job GetJob(int jobId)
|
||||||
{
|
{
|
||||||
return _db.Job.Find(JobId);
|
return _db.Job.Find(jobId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteJob(int JobId)
|
public void DeleteJob(int jobId)
|
||||||
{
|
{
|
||||||
Job Job = _db.Job.Find(JobId);
|
Job job = _db.Job.Find(jobId);
|
||||||
_db.Job.Remove(Job);
|
_db.Job.Remove(job);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
@ -14,44 +13,38 @@ namespace Oqtane.Repository
|
|||||||
_db = context;
|
_db = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Log> GetLogs(int SiteId, string Level, string Function, int Rows)
|
public IEnumerable<Log> GetLogs(int siteId, string level, string function, int rows)
|
||||||
{
|
{
|
||||||
if (Level == null)
|
if (level == null)
|
||||||
{
|
{
|
||||||
if (Function == null)
|
if (function == null)
|
||||||
{
|
{
|
||||||
return _db.Log.Where(item => item.SiteId == SiteId).
|
return _db.Log.Where(item => item.SiteId == siteId).
|
||||||
OrderByDescending(item => item.LogDate).Take(Rows);
|
OrderByDescending(item => item.LogDate).Take(rows);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return _db.Log.Where(item => item.SiteId == SiteId && item.Function == Function).
|
|
||||||
OrderByDescending(item => item.LogDate).Take(Rows);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Function == null)
|
|
||||||
{
|
|
||||||
return _db.Log.Where(item => item.SiteId == SiteId && item.Level == Level)
|
|
||||||
.OrderByDescending(item => item.LogDate).Take(Rows);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return _db.Log.Where(item => item.SiteId == SiteId && item.Level == Level && item.Function == Function)
|
|
||||||
.OrderByDescending(item => item.LogDate).Take(Rows);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log GetLog(int LogId)
|
return _db.Log.Where(item => item.SiteId == siteId && item.Function == function).
|
||||||
{
|
OrderByDescending(item => item.LogDate).Take(rows);
|
||||||
return _db.Log.Find(LogId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddLog(Log Log)
|
if (function == null)
|
||||||
{
|
{
|
||||||
_db.Log.Add(Log);
|
return _db.Log.Where(item => item.SiteId == siteId && item.Level == level)
|
||||||
|
.OrderByDescending(item => item.LogDate).Take(rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _db.Log.Where(item => item.SiteId == siteId && item.Level == level && item.Function == function)
|
||||||
|
.OrderByDescending(item => item.LogDate).Take(rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Log GetLog(int logId)
|
||||||
|
{
|
||||||
|
return _db.Log.Find(logId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddLog(Log log)
|
||||||
|
{
|
||||||
|
_db.Log.Add(log);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System;
|
|
||||||
using Oqtane.Modules;
|
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
using Oqtane.Models;
|
||||||
|
using Oqtane.Modules;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -23,51 +22,51 @@ namespace Oqtane.Repository
|
|||||||
_permissions = permissions;
|
_permissions = permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<ModuleDefinition> GetModuleDefinitions(int SiteId)
|
public IEnumerable<ModuleDefinition> GetModuleDefinitions(int siteId)
|
||||||
{
|
{
|
||||||
return LoadModuleDefinitions(SiteId);
|
return LoadModuleDefinitions(siteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModuleDefinition GetModuleDefinition(int ModuleDefinitionId, int SiteId)
|
public ModuleDefinition GetModuleDefinition(int moduleDefinitionId, int siteId)
|
||||||
{
|
{
|
||||||
List<ModuleDefinition> moduledefinitions = LoadModuleDefinitions(SiteId);
|
List<ModuleDefinition> moduledefinitions = LoadModuleDefinitions(siteId);
|
||||||
return moduledefinitions.Find(item => item.ModuleDefinitionId == ModuleDefinitionId);
|
return moduledefinitions.Find(item => item.ModuleDefinitionId == moduleDefinitionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateModuleDefinition(ModuleDefinition ModuleDefinition)
|
public void UpdateModuleDefinition(ModuleDefinition moduleDefinition)
|
||||||
{
|
{
|
||||||
_permissions.UpdatePermissions(ModuleDefinition.SiteId, "ModuleDefinition", ModuleDefinition.ModuleDefinitionId, ModuleDefinition.Permissions);
|
_permissions.UpdatePermissions(moduleDefinition.SiteId, "ModuleDefinition", moduleDefinition.ModuleDefinitionId, moduleDefinition.Permissions);
|
||||||
_cache.Remove("moduledefinitions");
|
_cache.Remove("moduledefinitions");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteModuleDefinition(int ModuleDefinitionId, int SiteId)
|
public void DeleteModuleDefinition(int moduleDefinitionId, int siteId)
|
||||||
{
|
{
|
||||||
ModuleDefinition ModuleDefinition = _db.ModuleDefinition.Find(ModuleDefinitionId);
|
ModuleDefinition moduleDefinition = _db.ModuleDefinition.Find(moduleDefinitionId);
|
||||||
_permissions.DeletePermissions(SiteId, "ModuleDefinition", ModuleDefinitionId);
|
_permissions.DeletePermissions(siteId, "ModuleDefinition", moduleDefinitionId);
|
||||||
_db.ModuleDefinition.Remove(ModuleDefinition);
|
_db.ModuleDefinition.Remove(moduleDefinition);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_cache.Remove("moduledefinitions");
|
_cache.Remove("moduledefinitions");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ModuleDefinition> LoadModuleDefinitions(int SiteId)
|
public List<ModuleDefinition> LoadModuleDefinitions(int siteId)
|
||||||
{
|
{
|
||||||
List<ModuleDefinition> ModuleDefinitions;
|
List<ModuleDefinition> moduleDefinitions;
|
||||||
|
|
||||||
// get run-time module definitions
|
// get run-time module definitions
|
||||||
ModuleDefinitions = _cache.GetOrCreate("moduledefinitions", entry =>
|
moduleDefinitions = _cache.GetOrCreate("moduledefinitions", entry =>
|
||||||
{
|
{
|
||||||
entry.SlidingExpiration = TimeSpan.FromMinutes(30);
|
entry.SlidingExpiration = TimeSpan.FromMinutes(30);
|
||||||
return LoadModuleDefinitionsFromAssemblies();
|
return LoadModuleDefinitionsFromAssemblies();
|
||||||
});
|
});
|
||||||
|
|
||||||
// get module defintion permissions for site
|
// get module defintion permissions for site
|
||||||
List<Permission> permissions = _permissions.GetPermissions(SiteId, "ModuleDefinition").ToList();
|
List<Permission> permissions = _permissions.GetPermissions(siteId, "ModuleDefinition").ToList();
|
||||||
|
|
||||||
// get module definitions in database
|
// get module definitions in database
|
||||||
List<ModuleDefinition> moduledefs = _db.ModuleDefinition.ToList();
|
List<ModuleDefinition> moduledefs = _db.ModuleDefinition.ToList();
|
||||||
|
|
||||||
// sync run-time module definitions with database
|
// sync run-time module definitions with database
|
||||||
foreach (ModuleDefinition moduledefinition in ModuleDefinitions)
|
foreach (ModuleDefinition moduledefinition in moduleDefinitions)
|
||||||
{
|
{
|
||||||
ModuleDefinition moduledef = moduledefs.Where(item => item.ModuleDefinitionName == moduledefinition.ModuleDefinitionName).FirstOrDefault();
|
ModuleDefinition moduledef = moduledefs.Where(item => item.ModuleDefinitionName == moduledefinition.ModuleDefinitionName).FirstOrDefault();
|
||||||
if (moduledef == null)
|
if (moduledef == null)
|
||||||
@ -76,14 +75,14 @@ namespace Oqtane.Repository
|
|||||||
moduledef = new ModuleDefinition { ModuleDefinitionName = moduledefinition.ModuleDefinitionName };
|
moduledef = new ModuleDefinition { ModuleDefinitionName = moduledefinition.ModuleDefinitionName };
|
||||||
_db.ModuleDefinition.Add(moduledef);
|
_db.ModuleDefinition.Add(moduledef);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_permissions.UpdatePermissions(SiteId, "ModuleDefinition", moduledef.ModuleDefinitionId, moduledefinition.Permissions);
|
_permissions.UpdatePermissions(siteId, "ModuleDefinition", moduledef.ModuleDefinitionId, moduledefinition.Permissions);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// existing module definition
|
// existing module definition
|
||||||
if (permissions.Count == 0)
|
if (permissions.Count == 0)
|
||||||
{
|
{
|
||||||
_permissions.UpdatePermissions(SiteId, "ModuleDefinition", moduledef.ModuleDefinitionId, moduledefinition.Permissions);
|
_permissions.UpdatePermissions(siteId, "ModuleDefinition", moduledef.ModuleDefinitionId, moduledefinition.Permissions);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -93,7 +92,7 @@ namespace Oqtane.Repository
|
|||||||
moduledefs.Remove(moduledef);
|
moduledefs.Remove(moduledef);
|
||||||
}
|
}
|
||||||
moduledefinition.ModuleDefinitionId = moduledef.ModuleDefinitionId;
|
moduledefinition.ModuleDefinitionId = moduledef.ModuleDefinitionId;
|
||||||
moduledefinition.SiteId = SiteId;
|
moduledefinition.SiteId = siteId;
|
||||||
moduledefinition.CreatedBy = moduledef.CreatedBy;
|
moduledefinition.CreatedBy = moduledef.CreatedBy;
|
||||||
moduledefinition.CreatedOn = moduledef.CreatedOn;
|
moduledefinition.CreatedOn = moduledef.CreatedOn;
|
||||||
moduledefinition.ModifiedBy = moduledef.ModifiedBy;
|
moduledefinition.ModifiedBy = moduledef.ModifiedBy;
|
||||||
@ -103,24 +102,24 @@ namespace Oqtane.Repository
|
|||||||
// any remaining module definitions are orphans
|
// any remaining module definitions are orphans
|
||||||
foreach (ModuleDefinition moduledefinition in moduledefs)
|
foreach (ModuleDefinition moduledefinition in moduledefs)
|
||||||
{
|
{
|
||||||
_permissions.DeletePermissions(SiteId, "ModuleDefinition", moduledefinition.ModuleDefinitionId);
|
_permissions.DeletePermissions(siteId, "ModuleDefinition", moduledefinition.ModuleDefinitionId);
|
||||||
_db.ModuleDefinition.Remove(moduledefinition); // delete
|
_db.ModuleDefinition.Remove(moduledefinition); // delete
|
||||||
}
|
}
|
||||||
|
|
||||||
return ModuleDefinitions;
|
return moduleDefinitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ModuleDefinition> LoadModuleDefinitionsFromAssemblies()
|
private List<ModuleDefinition> LoadModuleDefinitionsFromAssemblies()
|
||||||
{
|
{
|
||||||
List<ModuleDefinition> ModuleDefinitions = new List<ModuleDefinition>();
|
List<ModuleDefinition> moduleDefinitions = new List<ModuleDefinition>();
|
||||||
// iterate through Oqtane module assemblies
|
// iterate through Oqtane module assemblies
|
||||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies()
|
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies()
|
||||||
.Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Module.")).ToArray();
|
.Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Module.")).ToArray();
|
||||||
foreach (Assembly assembly in assemblies)
|
foreach (Assembly assembly in assemblies)
|
||||||
{
|
{
|
||||||
ModuleDefinitions = LoadModuleDefinitionsFromAssembly(ModuleDefinitions, assembly);
|
moduleDefinitions = LoadModuleDefinitionsFromAssembly(moduleDefinitions, assembly);
|
||||||
}
|
}
|
||||||
return ModuleDefinitions;
|
return moduleDefinitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ModuleDefinition> LoadModuleDefinitionsFromAssembly(List<ModuleDefinition> moduledefinitions, Assembly assembly)
|
private List<ModuleDefinition> LoadModuleDefinitionsFromAssembly(List<ModuleDefinition> moduledefinitions, Assembly assembly)
|
||||||
@ -134,25 +133,25 @@ namespace Oqtane.Repository
|
|||||||
string[] typename = modulecontroltype.AssemblyQualifiedName.Split(',').Select(item => item.Trim()).ToList().ToArray();
|
string[] typename = modulecontroltype.AssemblyQualifiedName.Split(',').Select(item => item.Trim()).ToList().ToArray();
|
||||||
string[] segments = typename[0].Split('.');
|
string[] segments = typename[0].Split('.');
|
||||||
Array.Resize(ref segments, segments.Length - 1);
|
Array.Resize(ref segments, segments.Length - 1);
|
||||||
string ModuleType = string.Join(".", segments);
|
string moduleType = string.Join(".", segments);
|
||||||
string QualifiedModuleType = ModuleType + ", " + typename[1];
|
string qualifiedModuleType = moduleType + ", " + typename[1];
|
||||||
|
|
||||||
int index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == QualifiedModuleType);
|
int index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
/// determine if this module implements IModule
|
// determine if this module implements IModule
|
||||||
Type moduletype = assembly.GetTypes()
|
Type moduletype = assembly
|
||||||
|
.GetTypes()
|
||||||
.Where(item => item.Namespace != null)
|
.Where(item => item.Namespace != null)
|
||||||
.Where(item => item.Namespace.StartsWith(ModuleType))
|
.Where(item => item.Namespace.StartsWith(moduleType))
|
||||||
.Where(item => item.GetInterfaces().Contains(typeof(IModule)))
|
.FirstOrDefault(item => item.GetInterfaces().Contains(typeof(IModule)));
|
||||||
.FirstOrDefault();
|
|
||||||
if (moduletype != null)
|
if (moduletype != null)
|
||||||
{
|
{
|
||||||
var moduleobject = Activator.CreateInstance(moduletype);
|
var moduleobject = Activator.CreateInstance(moduletype);
|
||||||
Dictionary<string, string> properties = (Dictionary<string, string>)moduletype.GetProperty("Properties").GetValue(moduleobject);
|
Dictionary<string, string> properties = (Dictionary<string, string>)moduletype.GetProperty("Properties").GetValue(moduleobject);
|
||||||
moduledefinition = new ModuleDefinition
|
moduledefinition = new ModuleDefinition
|
||||||
{
|
{
|
||||||
ModuleDefinitionName = QualifiedModuleType,
|
ModuleDefinitionName = qualifiedModuleType,
|
||||||
Name = GetProperty(properties, "Name"),
|
Name = GetProperty(properties, "Name"),
|
||||||
Description = GetProperty(properties, "Description"),
|
Description = GetProperty(properties, "Description"),
|
||||||
Categories = GetProperty(properties, "Categories"),
|
Categories = GetProperty(properties, "Categories"),
|
||||||
@ -164,7 +163,7 @@ namespace Oqtane.Repository
|
|||||||
Dependencies = GetProperty(properties, "Dependencies"),
|
Dependencies = GetProperty(properties, "Dependencies"),
|
||||||
PermissionNames = GetProperty(properties, "PermissionNames"),
|
PermissionNames = GetProperty(properties, "PermissionNames"),
|
||||||
ServerAssemblyName = GetProperty(properties, "ServerAssemblyName"),
|
ServerAssemblyName = GetProperty(properties, "ServerAssemblyName"),
|
||||||
ControlTypeTemplate = ModuleType + "." + Constants.ActionToken + ", " + typename[1],
|
ControlTypeTemplate = moduleType + "." + Constants.ActionToken + ", " + typename[1],
|
||||||
ControlTypeRoutes = "",
|
ControlTypeRoutes = "",
|
||||||
AssemblyName = assembly.FullName.Split(",")[0],
|
AssemblyName = assembly.FullName.Split(",")[0],
|
||||||
Permissions = ""
|
Permissions = ""
|
||||||
@ -174,10 +173,10 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
moduledefinition = new ModuleDefinition
|
moduledefinition = new ModuleDefinition
|
||||||
{
|
{
|
||||||
ModuleDefinitionName = QualifiedModuleType,
|
ModuleDefinitionName = qualifiedModuleType,
|
||||||
Name = ModuleType.Substring(ModuleType.LastIndexOf(".") + 1),
|
Name = moduleType.Substring(moduleType.LastIndexOf(".") + 1),
|
||||||
Description = ModuleType.Substring(ModuleType.LastIndexOf(".") + 1),
|
Description = moduleType.Substring(moduleType.LastIndexOf(".") + 1),
|
||||||
Categories = ((QualifiedModuleType.StartsWith("Oqtane.Modules.Admin.")) ? "Admin" : ""),
|
Categories = ((qualifiedModuleType.StartsWith("Oqtane.Modules.Admin.")) ? "Admin" : ""),
|
||||||
Version = new Version(1, 0, 0).ToString(),
|
Version = new Version(1, 0, 0).ToString(),
|
||||||
Owner = "",
|
Owner = "",
|
||||||
Url = "",
|
Url = "",
|
||||||
@ -186,7 +185,7 @@ namespace Oqtane.Repository
|
|||||||
Dependencies = "",
|
Dependencies = "",
|
||||||
PermissionNames = "",
|
PermissionNames = "",
|
||||||
ServerAssemblyName = "",
|
ServerAssemblyName = "",
|
||||||
ControlTypeTemplate = ModuleType + "." + Constants.ActionToken + ", " + typename[1],
|
ControlTypeTemplate = moduleType + "." + Constants.ActionToken + ", " + typename[1],
|
||||||
ControlTypeRoutes = "",
|
ControlTypeRoutes = "",
|
||||||
AssemblyName = assembly.FullName.Split(",")[0],
|
AssemblyName = assembly.FullName.Split(",")[0],
|
||||||
Permissions = ""
|
Permissions = ""
|
||||||
@ -202,7 +201,7 @@ namespace Oqtane.Repository
|
|||||||
moduledefinition.Permissions = "[{\"PermissionName\":\"Utilize\",\"Permissions\":\"" + Constants.AdminRole + ";" + Constants.RegisteredRole + "\"}]";
|
moduledefinition.Permissions = "[{\"PermissionName\":\"Utilize\",\"Permissions\":\"" + Constants.AdminRole + ";" + Constants.RegisteredRole + "\"}]";
|
||||||
}
|
}
|
||||||
moduledefinitions.Add(moduledefinition);
|
moduledefinitions.Add(moduledefinition);
|
||||||
index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == QualifiedModuleType);
|
index = moduledefinitions.FindIndex(item => item.ModuleDefinitionName == qualifiedModuleType);
|
||||||
}
|
}
|
||||||
moduledefinition = moduledefinitions[index];
|
moduledefinition = moduledefinitions[index];
|
||||||
// actions
|
// actions
|
||||||
@ -222,14 +221,14 @@ namespace Oqtane.Repository
|
|||||||
return moduledefinitions;
|
return moduledefinitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetProperty(Dictionary<string, string> Properties, string Key)
|
private string GetProperty(Dictionary<string, string> properties, string key)
|
||||||
{
|
{
|
||||||
string Value = "";
|
string value = "";
|
||||||
if (Properties.ContainsKey(Key))
|
if (properties.ContainsKey(key))
|
||||||
{
|
{
|
||||||
Value = Properties[Key];
|
value = properties[key];
|
||||||
}
|
}
|
||||||
return Value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System;
|
|
||||||
using Oqtane.Modules;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Oqtane.Models;
|
||||||
|
using Oqtane.Modules;
|
||||||
|
using Module = Oqtane.Models.Module;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
@ -25,30 +26,30 @@ namespace Oqtane.Repository
|
|||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Models.Module> GetModules(int SiteId)
|
public IEnumerable<Module> GetModules(int siteId)
|
||||||
{
|
{
|
||||||
return _db.Module.Where(item => item.SiteId == SiteId).ToList();
|
return _db.Module.Where(item => item.SiteId == siteId).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Models.Module AddModule(Models.Module Module)
|
public Module AddModule(Module module)
|
||||||
{
|
{
|
||||||
_db.Module.Add(Module);
|
_db.Module.Add(module);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_permissions.UpdatePermissions(Module.SiteId, "Module", Module.ModuleId, Module.Permissions);
|
_permissions.UpdatePermissions(module.SiteId, "Module", module.ModuleId, module.Permissions);
|
||||||
return Module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Models.Module UpdateModule(Models.Module Module)
|
public Module UpdateModule(Module module)
|
||||||
{
|
{
|
||||||
_db.Entry(Module).State = EntityState.Modified;
|
_db.Entry(module).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_permissions.UpdatePermissions(Module.SiteId, "Module", Module.ModuleId, Module.Permissions);
|
_permissions.UpdatePermissions(module.SiteId, "Module", module.ModuleId, module.Permissions);
|
||||||
return Module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Models.Module GetModule(int ModuleId)
|
public Module GetModule(int moduleId)
|
||||||
{
|
{
|
||||||
Models.Module module = _db.Module.Find(ModuleId);
|
Module module = _db.Module.Find(moduleId);
|
||||||
if (module != null)
|
if (module != null)
|
||||||
{
|
{
|
||||||
List<Permission> permissions = _permissions.GetPermissions("Module", module.ModuleId).ToList();
|
List<Permission> permissions = _permissions.GetPermissions("Module", module.ModuleId).ToList();
|
||||||
@ -57,20 +58,20 @@ namespace Oqtane.Repository
|
|||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteModule(int ModuleId)
|
public void DeleteModule(int moduleId)
|
||||||
{
|
{
|
||||||
Models.Module Module = _db.Module.Find(ModuleId);
|
Module module = _db.Module.Find(moduleId);
|
||||||
_permissions.DeletePermissions(Module.SiteId, "Module", ModuleId);
|
_permissions.DeletePermissions(module.SiteId, "Module", moduleId);
|
||||||
_db.Module.Remove(Module);
|
_db.Module.Remove(module);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ExportModule(int ModuleId)
|
public string ExportModule(int moduleId)
|
||||||
{
|
{
|
||||||
string content = "";
|
string content = "";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Models.Module module = GetModule(ModuleId);
|
Module module = GetModule(moduleId);
|
||||||
if (module != null)
|
if (module != null)
|
||||||
{
|
{
|
||||||
List<ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
|
List<ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
|
||||||
@ -110,19 +111,19 @@ namespace Oqtane.Repository
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ImportModule(int ModuleId, string Content)
|
public bool ImportModule(int moduleId, string content)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Models.Module module = GetModule(ModuleId);
|
Module module = GetModule(moduleId);
|
||||||
if (module != null)
|
if (module != null)
|
||||||
{
|
{
|
||||||
List<ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
|
List<ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
|
||||||
ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionName == module.ModuleDefinitionName).FirstOrDefault();
|
ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionName == module.ModuleDefinitionName).FirstOrDefault();
|
||||||
if (moduledefinition != null)
|
if (moduledefinition != null)
|
||||||
{
|
{
|
||||||
ModuleContent modulecontent = JsonSerializer.Deserialize<ModuleContent>(Content);
|
ModuleContent modulecontent = JsonSerializer.Deserialize<ModuleContent>(content);
|
||||||
if (modulecontent.ModuleDefinitionName == moduledefinition.ModuleDefinitionName)
|
if (modulecontent.ModuleDefinitionName == moduledefinition.ModuleDefinitionName)
|
||||||
{
|
{
|
||||||
if (moduledefinition.ServerAssemblyName != "")
|
if (moduledefinition.ServerAssemblyName != "")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -14,52 +14,50 @@ namespace Oqtane.Repository
|
|||||||
_db = context;
|
_db = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Notification> GetNotifications(int SiteId, int FromUserId, int ToUserId)
|
public IEnumerable<Notification> GetNotifications(int siteId, int fromUserId, int toUserId)
|
||||||
{
|
{
|
||||||
if (ToUserId == -1 && FromUserId == -1)
|
if (toUserId == -1 && fromUserId == -1)
|
||||||
{
|
{
|
||||||
return _db.Notification
|
return _db.Notification
|
||||||
.Where(item => item.SiteId == SiteId)
|
.Where(item => item.SiteId == siteId)
|
||||||
.Where(item => item.IsDelivered == false)
|
.Where(item => item.IsDelivered == false)
|
||||||
.Include(item => item.FromUser)
|
.Include(item => item.FromUser)
|
||||||
.Include(item => item.ToUser)
|
.Include(item => item.ToUser)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return _db.Notification
|
return _db.Notification
|
||||||
.Where(item => item.SiteId == SiteId)
|
.Where(item => item.SiteId == siteId)
|
||||||
.Where(item => item.ToUserId == ToUserId || ToUserId == -1)
|
.Where(item => item.ToUserId == toUserId || toUserId == -1)
|
||||||
.Where(item => item.FromUserId == FromUserId || FromUserId == -1)
|
.Where(item => item.FromUserId == fromUserId || fromUserId == -1)
|
||||||
.Include(item => item.FromUser)
|
.Include(item => item.FromUser)
|
||||||
.Include(item => item.ToUser)
|
.Include(item => item.ToUser)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public Notification AddNotification(Notification Notification)
|
public Notification AddNotification(Notification notification)
|
||||||
{
|
{
|
||||||
_db.Notification.Add(Notification);
|
_db.Notification.Add(notification);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Notification UpdateNotification(Notification Notification)
|
public Notification UpdateNotification(Notification notification)
|
||||||
{
|
{
|
||||||
_db.Entry(Notification).State = EntityState.Modified;
|
_db.Entry(notification).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Notification GetNotification(int NotificationId)
|
public Notification GetNotification(int notificationId)
|
||||||
{
|
{
|
||||||
return _db.Notification.Find(NotificationId);
|
return _db.Notification.Find(notificationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteNotification(int NotificationId)
|
public void DeleteNotification(int notificationId)
|
||||||
{
|
{
|
||||||
Notification Notification = _db.Notification.Find(NotificationId);
|
Notification notification = _db.Notification.Find(notificationId);
|
||||||
_db.Notification.Remove(Notification);
|
_db.Notification.Remove(notification);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -16,11 +16,11 @@ namespace Oqtane.Repository
|
|||||||
_permissions = permissions;
|
_permissions = permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<PageModule> GetPageModules(int SiteId)
|
public IEnumerable<PageModule> GetPageModules(int siteId)
|
||||||
{
|
{
|
||||||
IEnumerable<PageModule> pagemodules = _db.PageModule
|
IEnumerable<PageModule> pagemodules = _db.PageModule
|
||||||
.Include(item => item.Module) // eager load modules
|
.Include(item => item.Module) // eager load modules
|
||||||
.Where(item => item.Module.SiteId == SiteId);
|
.Where(item => item.Module.SiteId == siteId);
|
||||||
if (pagemodules != null && pagemodules.Any())
|
if (pagemodules != null && pagemodules.Any())
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions(pagemodules.FirstOrDefault().Module.SiteId, "Module").ToList();
|
IEnumerable<Permission> permissions = _permissions.GetPermissions(pagemodules.FirstOrDefault().Module.SiteId, "Module").ToList();
|
||||||
@ -32,14 +32,14 @@ namespace Oqtane.Repository
|
|||||||
return pagemodules;
|
return pagemodules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<PageModule> GetPageModules(int PageId, string Pane)
|
public IEnumerable<PageModule> GetPageModules(int pageId, string pane)
|
||||||
{
|
{
|
||||||
IEnumerable<PageModule> pagemodules = _db.PageModule
|
IEnumerable<PageModule> pagemodules = _db.PageModule
|
||||||
.Include(item => item.Module) // eager load modules
|
.Include(item => item.Module) // eager load modules
|
||||||
.Where(item => item.PageId == PageId);
|
.Where(item => item.PageId == pageId);
|
||||||
if (Pane != "" && pagemodules != null && pagemodules.Any())
|
if (pane != "" && pagemodules != null && pagemodules.Any())
|
||||||
{
|
{
|
||||||
pagemodules = pagemodules.Where(item => item.Pane == Pane);
|
pagemodules = pagemodules.Where(item => item.Pane == pane);
|
||||||
}
|
}
|
||||||
if (pagemodules != null && pagemodules.Any())
|
if (pagemodules != null && pagemodules.Any())
|
||||||
{
|
{
|
||||||
@ -52,24 +52,24 @@ namespace Oqtane.Repository
|
|||||||
return pagemodules;
|
return pagemodules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageModule AddPageModule(PageModule PageModule)
|
public PageModule AddPageModule(PageModule pageModule)
|
||||||
{
|
{
|
||||||
_db.PageModule.Add(PageModule);
|
_db.PageModule.Add(pageModule);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return PageModule;
|
return pageModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageModule UpdatePageModule(PageModule PageModule)
|
public PageModule UpdatePageModule(PageModule pageModule)
|
||||||
{
|
{
|
||||||
_db.Entry(PageModule).State = EntityState.Modified;
|
_db.Entry(pageModule).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return PageModule;
|
return pageModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageModule GetPageModule(int PageModuleId)
|
public PageModule GetPageModule(int pageModuleId)
|
||||||
{
|
{
|
||||||
PageModule pagemodule = _db.PageModule.Include(item => item.Module) // eager load modules
|
PageModule pagemodule = _db.PageModule.Include(item => item.Module) // eager load modules
|
||||||
.SingleOrDefault(item => item.PageModuleId == PageModuleId);
|
.SingleOrDefault(item => item.PageModuleId == pageModuleId);
|
||||||
if (pagemodule != null)
|
if (pagemodule != null)
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions("Module", pagemodule.ModuleId).ToList();
|
IEnumerable<Permission> permissions = _permissions.GetPermissions("Module", pagemodule.ModuleId).ToList();
|
||||||
@ -78,10 +78,10 @@ namespace Oqtane.Repository
|
|||||||
return pagemodule;
|
return pagemodule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageModule GetPageModule(int PageId, int ModuleId)
|
public PageModule GetPageModule(int pageId, int moduleId)
|
||||||
{
|
{
|
||||||
PageModule pagemodule = _db.PageModule.Include(item => item.Module) // eager load modules
|
PageModule pagemodule = _db.PageModule.Include(item => item.Module) // eager load modules
|
||||||
.SingleOrDefault(item => item.PageId == PageId && item.ModuleId == ModuleId);
|
.SingleOrDefault(item => item.PageId == pageId && item.ModuleId == moduleId);
|
||||||
if (pagemodule != null)
|
if (pagemodule != null)
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions("Module", pagemodule.ModuleId).ToList();
|
IEnumerable<Permission> permissions = _permissions.GetPermissions("Module", pagemodule.ModuleId).ToList();
|
||||||
@ -90,10 +90,10 @@ namespace Oqtane.Repository
|
|||||||
return pagemodule;
|
return pagemodule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeletePageModule(int PageModuleId)
|
public void DeletePageModule(int pageModuleId)
|
||||||
{
|
{
|
||||||
PageModule PageModule = _db.PageModule.Find(PageModuleId);
|
PageModule pageModule = _db.PageModule.Find(pageModuleId);
|
||||||
_db.PageModule.Remove(PageModule);
|
_db.PageModule.Remove(pageModule);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -18,10 +18,10 @@ namespace Oqtane.Repository
|
|||||||
_pageModules = pageModules;
|
_pageModules = pageModules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Page> GetPages(int SiteId)
|
public IEnumerable<Page> GetPages(int siteId)
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions(SiteId, "Page").ToList();
|
IEnumerable<Permission> permissions = _permissions.GetPermissions(siteId, "Page").ToList();
|
||||||
IEnumerable<Page> pages = _db.Page.Where(item => item.SiteId == SiteId && item.UserId == null);
|
IEnumerable<Page> pages = _db.Page.Where(item => item.SiteId == siteId && item.UserId == null);
|
||||||
foreach(Page page in pages)
|
foreach(Page page in pages)
|
||||||
{
|
{
|
||||||
page.Permissions = _permissions.EncodePermissions(page.PageId, permissions);
|
page.Permissions = _permissions.EncodePermissions(page.PageId, permissions);
|
||||||
@ -29,25 +29,25 @@ namespace Oqtane.Repository
|
|||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page AddPage(Page Page)
|
public Page AddPage(Page page)
|
||||||
{
|
{
|
||||||
_db.Page.Add(Page);
|
_db.Page.Add(page);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_permissions.UpdatePermissions(Page.SiteId, "Page", Page.PageId, Page.Permissions);
|
_permissions.UpdatePermissions(page.SiteId, "Page", page.PageId, page.Permissions);
|
||||||
return Page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page UpdatePage(Page Page)
|
public Page UpdatePage(Page page)
|
||||||
{
|
{
|
||||||
_db.Entry(Page).State = EntityState.Modified;
|
_db.Entry(page).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_permissions.UpdatePermissions(Page.SiteId, "Page", Page.PageId, Page.Permissions);
|
_permissions.UpdatePermissions(page.SiteId, "Page", page.PageId, page.Permissions);
|
||||||
return Page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page GetPage(int PageId)
|
public Page GetPage(int pageId)
|
||||||
{
|
{
|
||||||
Page page = _db.Page.Find(PageId);
|
Page page = _db.Page.Find(pageId);
|
||||||
if (page != null)
|
if (page != null)
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions("Page", page.PageId).ToList();
|
IEnumerable<Permission> permissions = _permissions.GetPermissions("Page", page.PageId).ToList();
|
||||||
@ -56,12 +56,12 @@ namespace Oqtane.Repository
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page GetPage(int PageId, int UserId)
|
public Page GetPage(int pageId, int userId)
|
||||||
{
|
{
|
||||||
Page page = _db.Page.Find(PageId);
|
Page page = _db.Page.Find(pageId);
|
||||||
if (page != null)
|
if (page != null)
|
||||||
{
|
{
|
||||||
Page personalized = _db.Page.Where(item => item.SiteId == page.SiteId && item.Path == page.Path && item.UserId == UserId).FirstOrDefault();
|
Page personalized = _db.Page.Where(item => item.SiteId == page.SiteId && item.Path == page.Path && item.UserId == userId).FirstOrDefault();
|
||||||
if (personalized != null)
|
if (personalized != null)
|
||||||
{
|
{
|
||||||
page = personalized;
|
page = personalized;
|
||||||
@ -75,9 +75,9 @@ namespace Oqtane.Repository
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page GetPage(string Path, int SiteId)
|
public Page GetPage(string path, int siteId)
|
||||||
{
|
{
|
||||||
Page page = _db.Page.Where(item => item.Path == Path && item.SiteId == SiteId).FirstOrDefault();
|
Page page = _db.Page.Where(item => item.Path == path && item.SiteId == siteId).FirstOrDefault();
|
||||||
if (page != null)
|
if (page != null)
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _permissions.GetPermissions("Page", page.PageId).ToList();
|
IEnumerable<Permission> permissions = _permissions.GetPermissions("Page", page.PageId).ToList();
|
||||||
@ -86,16 +86,16 @@ namespace Oqtane.Repository
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeletePage(int PageId)
|
public void DeletePage(int pageId)
|
||||||
{
|
{
|
||||||
Page Page = _db.Page.Find(PageId);
|
Page page = _db.Page.Find(pageId);
|
||||||
_permissions.DeletePermissions(Page.SiteId, "Page", PageId);
|
_permissions.DeletePermissions(page.SiteId, "Page", pageId);
|
||||||
IEnumerable<PageModule> pageModules = _db.PageModule.Where(item => item.PageId == PageId).ToList();
|
IEnumerable<PageModule> pageModules = _db.PageModule.Where(item => item.PageId == pageId).ToList();
|
||||||
foreach (var pageModule in pageModules)
|
foreach (var pageModule in pageModules)
|
||||||
{
|
{
|
||||||
_pageModules.DeletePageModule(pageModule.PageModuleId);
|
_pageModules.DeletePageModule(pageModule.PageModuleId);
|
||||||
}
|
}
|
||||||
_db.Page.Remove(Page);
|
_db.Page.Remove(page);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
@ -20,55 +19,55 @@ namespace Oqtane.Repository
|
|||||||
_roles = roles;
|
_roles = roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Permission> GetPermissions(int SiteId, string EntityName)
|
public IEnumerable<Permission> GetPermissions(int siteId, string entityName)
|
||||||
{
|
{
|
||||||
return _db.Permission.Where(item => item.SiteId == SiteId)
|
return _db.Permission.Where(item => item.SiteId == siteId)
|
||||||
.Where(item => item.EntityName == EntityName)
|
.Where(item => item.EntityName == entityName)
|
||||||
.Include(item => item.Role); // eager load roles
|
.Include(item => item.Role); // eager load roles
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Permission> GetPermissions(string EntityName, int EntityId)
|
public IEnumerable<Permission> GetPermissions(string entityName, int entityId)
|
||||||
{
|
{
|
||||||
return _db.Permission.Where(item => item.EntityName == EntityName)
|
return _db.Permission.Where(item => item.EntityName == entityName)
|
||||||
.Where(item => item.EntityId == EntityId)
|
.Where(item => item.EntityId == entityId)
|
||||||
.Include(item => item.Role); // eager load roles
|
.Include(item => item.Role); // eager load roles
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Permission> GetPermissions(string EntityName, int EntityId, string PermissionName)
|
public IEnumerable<Permission> GetPermissions(string entityName, int entityId, string permissionName)
|
||||||
{
|
{
|
||||||
return _db.Permission.Where(item => item.EntityName == EntityName)
|
return _db.Permission.Where(item => item.EntityName == entityName)
|
||||||
.Where(item => item.EntityId == EntityId)
|
.Where(item => item.EntityId == entityId)
|
||||||
.Where(item => item.PermissionName == PermissionName)
|
.Where(item => item.PermissionName == permissionName)
|
||||||
.Include(item => item.Role); // eager load roles
|
.Include(item => item.Role); // eager load roles
|
||||||
}
|
}
|
||||||
|
|
||||||
public Permission AddPermission(Permission Permission)
|
public Permission AddPermission(Permission permission)
|
||||||
{
|
{
|
||||||
_db.Permission.Add(Permission);
|
_db.Permission.Add(permission);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Permission UpdatePermission(Permission Permission)
|
public Permission UpdatePermission(Permission permission)
|
||||||
{
|
{
|
||||||
_db.Entry(Permission).State = EntityState.Modified;
|
_db.Entry(permission).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdatePermissions(int SiteId, string EntityName, int EntityId, string Permissions)
|
public void UpdatePermissions(int siteId, string entityName, int entityId, string permissionStrings)
|
||||||
{
|
{
|
||||||
// get current permissions and delete
|
// get current permissions and delete
|
||||||
IEnumerable<Permission> permissions = _db.Permission
|
IEnumerable<Permission> permissions = _db.Permission
|
||||||
.Where(item => item.EntityName == EntityName)
|
.Where(item => item.EntityName == entityName)
|
||||||
.Where(item => item.EntityId == EntityId)
|
.Where(item => item.EntityId == entityId)
|
||||||
.Where(item => item.SiteId == SiteId);
|
.Where(item => item.SiteId == siteId);
|
||||||
foreach (Permission permission in permissions)
|
foreach (Permission permission in permissions)
|
||||||
{
|
{
|
||||||
_db.Permission.Remove(permission);
|
_db.Permission.Remove(permission);
|
||||||
}
|
}
|
||||||
// add permissions
|
// add permissions
|
||||||
permissions = DecodePermissions(Permissions, SiteId, EntityName, EntityId);
|
permissions = DecodePermissions(permissionStrings, siteId, entityName, entityId);
|
||||||
foreach (Permission permission in permissions)
|
foreach (Permission permission in permissions)
|
||||||
{
|
{
|
||||||
_db.Permission.Add(permission);
|
_db.Permission.Add(permission);
|
||||||
@ -76,24 +75,24 @@ namespace Oqtane.Repository
|
|||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Permission GetPermission(int PermissionId)
|
public Permission GetPermission(int permissionId)
|
||||||
{
|
{
|
||||||
return _db.Permission.Find(PermissionId);
|
return _db.Permission.Find(permissionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeletePermission(int PermissionId)
|
public void DeletePermission(int permissionId)
|
||||||
{
|
{
|
||||||
Permission Permission = _db.Permission.Find(PermissionId);
|
Permission permission = _db.Permission.Find(permissionId);
|
||||||
_db.Permission.Remove(Permission);
|
_db.Permission.Remove(permission);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeletePermissions(int SiteId, string EntityName, int EntityId)
|
public void DeletePermissions(int siteId, string entityName, int entityId)
|
||||||
{
|
{
|
||||||
IEnumerable<Permission> permissions = _db.Permission
|
IEnumerable<Permission> permissions = _db.Permission
|
||||||
.Where(item => item.EntityName == EntityName)
|
.Where(item => item.EntityName == entityName)
|
||||||
.Where(item => item.EntityId == EntityId)
|
.Where(item => item.EntityId == entityId)
|
||||||
.Where(item => item.SiteId == SiteId);
|
.Where(item => item.SiteId == siteId);
|
||||||
foreach (Permission permission in permissions)
|
foreach (Permission permission in permissions)
|
||||||
{
|
{
|
||||||
_db.Permission.Remove(permission);
|
_db.Permission.Remove(permission);
|
||||||
@ -102,14 +101,14 @@ namespace Oqtane.Repository
|
|||||||
}
|
}
|
||||||
|
|
||||||
// permissions are stored in the format "{permissionname:!rolename1;![userid1];rolename2;rolename3;[userid2];[userid3]}" where "!" designates Deny permissions
|
// 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)
|
public string EncodePermissions(int entityId, IEnumerable<Permission> permissionList)
|
||||||
{
|
{
|
||||||
List<PermissionString> permissionstrings = new List<PermissionString>();
|
List<PermissionString> permissionstrings = new List<PermissionString>();
|
||||||
string permissionname = "";
|
string permissionname = "";
|
||||||
string permissions = "";
|
string permissions = "";
|
||||||
StringBuilder permissionsbuilder = new StringBuilder();
|
StringBuilder permissionsbuilder = new StringBuilder();
|
||||||
string securityid = "";
|
string securityid = "";
|
||||||
foreach (Permission permission in Permissions.Where(item => item.EntityId == EntityId).OrderBy(item => item.PermissionName))
|
foreach (Permission permission in permissionList.Where(item => item.EntityId == entityId).OrderBy(item => item.PermissionName))
|
||||||
{
|
{
|
||||||
// permission collections are grouped by permissionname
|
// permission collections are grouped by permissionname
|
||||||
if (permissionname != permission.PermissionName)
|
if (permissionname != permission.PermissionName)
|
||||||
@ -133,7 +132,7 @@ namespace Oqtane.Repository
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
securityid = prefix + "[" + permission.UserId.ToString() + "];";
|
securityid = prefix + "[" + permission.UserId + "];";
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert deny permissions at the beginning and append grant permissions at the end
|
// insert deny permissions at the beginning and append grant permissions at the end
|
||||||
@ -155,20 +154,20 @@ namespace Oqtane.Repository
|
|||||||
return JsonSerializer.Serialize(permissionstrings);
|
return JsonSerializer.Serialize(permissionstrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Permission> DecodePermissions(string PermissionStrings, int SiteId, string EntityName, int EntityId)
|
public IEnumerable<Permission> DecodePermissions(string permissionStrings, int siteId, string entityName, int entityId)
|
||||||
{
|
{
|
||||||
List<Permission> permissions = new List<Permission>();
|
List<Permission> permissions = new List<Permission>();
|
||||||
List<Role> roles = _roles.GetRoles(SiteId, true).ToList();
|
List<Role> roles = _roles.GetRoles(siteId, true).ToList();
|
||||||
string securityid = "";
|
string securityid = "";
|
||||||
foreach (PermissionString permissionstring in JsonSerializer.Deserialize<List<PermissionString>>(PermissionStrings))
|
foreach (PermissionString permissionstring in JsonSerializer.Deserialize<List<PermissionString>>(permissionStrings))
|
||||||
{
|
{
|
||||||
foreach (string id in permissionstring.Permissions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
foreach (string id in permissionstring.Permissions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||||
{
|
{
|
||||||
securityid = id;
|
securityid = id;
|
||||||
Permission permission = new Permission();
|
Permission permission = new Permission();
|
||||||
permission.SiteId = SiteId;
|
permission.SiteId = siteId;
|
||||||
permission.EntityName = EntityName;
|
permission.EntityName = entityName;
|
||||||
permission.EntityId = EntityId;
|
permission.EntityId = entityId;
|
||||||
permission.PermissionName = permissionstring.PermissionName;
|
permission.PermissionName = permissionstring.PermissionName;
|
||||||
permission.RoleId = null;
|
permission.RoleId = null;
|
||||||
permission.UserId = null;
|
permission.UserId = null;
|
||||||
@ -177,7 +176,7 @@ namespace Oqtane.Repository
|
|||||||
if (securityid.StartsWith("!"))
|
if (securityid.StartsWith("!"))
|
||||||
{
|
{
|
||||||
// deny permission
|
// deny permission
|
||||||
securityid.Replace("!", "");
|
securityid = securityid.Replace("!", "");
|
||||||
permission.IsAuthorized = false;
|
permission.IsAuthorized = false;
|
||||||
}
|
}
|
||||||
if (securityid.StartsWith("[") && securityid.EndsWith("]"))
|
if (securityid.StartsWith("[") && securityid.EndsWith("]"))
|
||||||
@ -189,7 +188,7 @@ namespace Oqtane.Repository
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// role name
|
// role name
|
||||||
Role role = roles.Where(item => item.Name == securityid).SingleOrDefault();
|
Role role = roles.SingleOrDefault(item => item.Name == securityid);
|
||||||
if (role != null)
|
if (role != null)
|
||||||
{
|
{
|
||||||
permission.RoleId = role.RoleId;
|
permission.RoleId = role.RoleId;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -14,34 +14,34 @@ namespace Oqtane.Repository
|
|||||||
_db = context;
|
_db = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Profile> GetProfiles(int SiteId)
|
public IEnumerable<Profile> GetProfiles(int siteId)
|
||||||
{
|
{
|
||||||
return _db.Profile.Where(item => item.SiteId == SiteId || item.SiteId == null);
|
return _db.Profile.Where(item => item.SiteId == siteId || item.SiteId == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profile AddProfile(Profile Profile)
|
public Profile AddProfile(Profile profile)
|
||||||
{
|
{
|
||||||
_db.Profile.Add(Profile);
|
_db.Profile.Add(profile);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profile UpdateProfile(Profile Profile)
|
public Profile UpdateProfile(Profile profile)
|
||||||
{
|
{
|
||||||
_db.Entry(Profile).State = EntityState.Modified;
|
_db.Entry(profile).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profile GetProfile(int ProfileId)
|
public Profile GetProfile(int profileId)
|
||||||
{
|
{
|
||||||
return _db.Profile.Find(ProfileId);
|
return _db.Profile.Find(profileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteProfile(int ProfileId)
|
public void DeleteProfile(int profileId)
|
||||||
{
|
{
|
||||||
Profile Profile = _db.Profile.Find(ProfileId);
|
Profile profile = _db.Profile.Find(profileId);
|
||||||
_db.Profile.Remove(Profile);
|
_db.Profile.Remove(profile);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -14,40 +14,40 @@ namespace Oqtane.Repository
|
|||||||
_db = context;
|
_db = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Role> GetRoles(int SiteId)
|
public IEnumerable<Role> GetRoles(int siteId)
|
||||||
{
|
{
|
||||||
return _db.Role.Where(item => item.SiteId == SiteId);
|
return _db.Role.Where(item => item.SiteId == siteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Role> GetRoles(int SiteId, bool IncludeGlobalRoles)
|
public IEnumerable<Role> GetRoles(int siteId, bool includeGlobalRoles)
|
||||||
{
|
{
|
||||||
return _db.Role.Where(item => item.SiteId == SiteId || item.SiteId == null);
|
return _db.Role.Where(item => item.SiteId == siteId || item.SiteId == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Role AddRole(Role Role)
|
public Role AddRole(Role role)
|
||||||
{
|
{
|
||||||
_db.Role.Add(Role);
|
_db.Role.Add(role);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Role UpdateRole(Role Role)
|
public Role UpdateRole(Role role)
|
||||||
{
|
{
|
||||||
_db.Entry(Role).State = EntityState.Modified;
|
_db.Entry(role).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Role GetRole(int RoleId)
|
public Role GetRole(int roleId)
|
||||||
{
|
{
|
||||||
return _db.Role.Find(RoleId);
|
return _db.Role.Find(roleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteRole(int RoleId)
|
public void DeleteRole(int roleId)
|
||||||
{
|
{
|
||||||
Role Role = _db.Role.Find(RoleId);
|
Role role = _db.Role.Find(roleId);
|
||||||
_db.Role.Remove(Role);
|
_db.Role.Remove(role);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -14,35 +14,35 @@ namespace Oqtane.Repository
|
|||||||
_db = context;
|
_db = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Setting> GetSettings(string EntityName, int EntityId)
|
public IEnumerable<Setting> GetSettings(string entityName, int entityId)
|
||||||
{
|
{
|
||||||
return _db.Setting.Where(item => item.EntityName == EntityName)
|
return _db.Setting.Where(item => item.EntityName == entityName)
|
||||||
.Where(item => item.EntityId == EntityId);
|
.Where(item => item.EntityId == entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Setting AddSetting(Setting Setting)
|
public Setting AddSetting(Setting setting)
|
||||||
{
|
{
|
||||||
_db.Setting.Add(Setting);
|
_db.Setting.Add(setting);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Setting;
|
return setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Setting UpdateSetting(Setting Setting)
|
public Setting UpdateSetting(Setting setting)
|
||||||
{
|
{
|
||||||
_db.Entry(Setting).State = EntityState.Modified;
|
_db.Entry(setting).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Setting;
|
return setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Setting GetSetting(int SettingId)
|
public Setting GetSetting(int settingId)
|
||||||
{
|
{
|
||||||
return _db.Setting.Find(SettingId);
|
return _db.Setting.Find(settingId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteSetting(int SettingId)
|
public void DeleteSetting(int settingId)
|
||||||
{
|
{
|
||||||
Setting Setting = _db.Setting.Find(SettingId);
|
Setting setting = _db.Setting.Find(settingId);
|
||||||
_db.Setting.Remove(Setting);
|
_db.Setting.Remove(setting);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
|
||||||
using Oqtane.Shared;
|
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Oqtane.Modules;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Oqtane.Models;
|
||||||
|
using Oqtane.Modules;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
using Module = Oqtane.Models.Module;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
@ -130,19 +131,19 @@ namespace Oqtane.Repository
|
|||||||
return _db.Site;
|
return _db.Site;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Site AddSite(Site Site)
|
public Site AddSite(Site site)
|
||||||
{
|
{
|
||||||
_db.Site.Add(Site);
|
_db.Site.Add(site);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
CreateSite(Site);
|
CreateSite(site);
|
||||||
return Site;
|
return site;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Site UpdateSite(Site Site)
|
public Site UpdateSite(Site site)
|
||||||
{
|
{
|
||||||
_db.Entry(Site).State = EntityState.Modified;
|
_db.Entry(site).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return Site;
|
return site;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Site GetSite(int siteId)
|
public Site GetSite(int siteId)
|
||||||
@ -226,7 +227,7 @@ namespace Oqtane.Repository
|
|||||||
ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionName == pagetemplatemodule.ModuleDefinitionName).FirstOrDefault();
|
ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionName == pagetemplatemodule.ModuleDefinitionName).FirstOrDefault();
|
||||||
if (moduledefinition != null)
|
if (moduledefinition != null)
|
||||||
{
|
{
|
||||||
Models.Module module = new Models.Module
|
Module module = new Module
|
||||||
{
|
{
|
||||||
SiteId = site.SiteId,
|
SiteId = site.SiteId,
|
||||||
ModuleDefinitionName = pagetemplatemodule.ModuleDefinitionName,
|
ModuleDefinitionName = pagetemplatemodule.ModuleDefinitionName,
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
@ -28,30 +27,30 @@ namespace Oqtane.Repository
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tenant AddTenant(Tenant Tenant)
|
public Tenant AddTenant(Tenant tenant)
|
||||||
{
|
{
|
||||||
_db.Tenant.Add(Tenant);
|
_db.Tenant.Add(tenant);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_cache.Remove("tenants");
|
_cache.Remove("tenants");
|
||||||
return Tenant;
|
return tenant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tenant UpdateTenant(Tenant Tenant)
|
public Tenant UpdateTenant(Tenant tenant)
|
||||||
{
|
{
|
||||||
_db.Entry(Tenant).State = EntityState.Modified;
|
_db.Entry(tenant).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_cache.Remove("tenants");
|
_cache.Remove("tenants");
|
||||||
return Tenant;
|
return tenant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tenant GetTenant(int TenantId)
|
public Tenant GetTenant(int tenantId)
|
||||||
{
|
{
|
||||||
return _db.Tenant.Find(TenantId);
|
return _db.Tenant.Find(tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteTenant(int TenantId)
|
public void DeleteTenant(int tenantId)
|
||||||
{
|
{
|
||||||
Tenant tenant = _db.Tenant.Find(TenantId);
|
Tenant tenant = _db.Tenant.Find(tenantId);
|
||||||
_db.Tenant.Remove(tenant);
|
_db.Tenant.Remove(tenant);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
_cache.Remove("tenants");
|
_cache.Remove("tenants");
|
||||||
|
@ -1,70 +1,70 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using System;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
{
|
{
|
||||||
public class TenantResolver : ITenantResolver
|
public class TenantResolver : ITenantResolver
|
||||||
{
|
{
|
||||||
private readonly Alias _alias = null;
|
private readonly Alias _alias;
|
||||||
private readonly Tenant _tenant = null;
|
private readonly Tenant _tenant;
|
||||||
|
|
||||||
public TenantResolver(IHttpContextAccessor Accessor, IAliasRepository Aliases, ITenantRepository Tenants, SiteState SiteState)
|
public TenantResolver(IHttpContextAccessor accessor, IAliasRepository aliasRepository, ITenantRepository tenantRepository, SiteState siteState)
|
||||||
{
|
{
|
||||||
int aliasid = -1;
|
int aliasId = -1;
|
||||||
string aliasname = "";
|
string aliasName = "";
|
||||||
|
|
||||||
// get alias identifier based on request context
|
// get alias identifier based on request context
|
||||||
if (Accessor.HttpContext != null)
|
if (accessor.HttpContext != null)
|
||||||
{
|
{
|
||||||
// check if an alias is passed as a querystring parameter ( for cross tenant access )
|
// check if an alias is passed as a querystring parameter ( for cross tenant access )
|
||||||
if (Accessor.HttpContext.Request.Query.ContainsKey("aliasid"))
|
if (accessor.HttpContext.Request.Query.ContainsKey("aliasid"))
|
||||||
{
|
{
|
||||||
aliasid = int.Parse(Accessor.HttpContext.Request.Query["aliasid"]);
|
aliasId = int.Parse(accessor.HttpContext.Request.Query["aliasid"]);
|
||||||
}
|
}
|
||||||
else // get the alias from the request url
|
else // get the alias from the request url
|
||||||
{
|
{
|
||||||
aliasname = Accessor.HttpContext.Request.Host.Value;
|
aliasName = accessor.HttpContext.Request.Host.Value;
|
||||||
string path = Accessor.HttpContext.Request.Path.Value;
|
string path = accessor.HttpContext.Request.Path.Value;
|
||||||
string[] segments = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
string[] segments = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (segments.Length > 1 && segments[1] == "api" && segments[0] != "~")
|
if (segments.Length > 1 && segments[1] == "api" && segments[0] != "~")
|
||||||
{
|
{
|
||||||
aliasname += "/" + segments[0];
|
aliasName += "/" + segments[0];
|
||||||
}
|
}
|
||||||
if (aliasname.EndsWith("/"))
|
if (aliasName.EndsWith("/"))
|
||||||
{
|
{
|
||||||
aliasname = aliasname.Substring(0, aliasname.Length - 1);
|
aliasName = aliasName.Substring(0, aliasName.Length - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // background processes can pass in an alias using the SiteState service
|
else // background processes can pass in an alias using the SiteState service
|
||||||
{
|
{
|
||||||
if (SiteState != null)
|
if (siteState != null)
|
||||||
{
|
{
|
||||||
aliasid = SiteState.Alias.AliasId;
|
aliasId = siteState.Alias.AliasId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the alias and tenant
|
// get the alias and tenant
|
||||||
if (aliasid != -1 || aliasname != "")
|
if (aliasId != -1 || aliasName != "")
|
||||||
{
|
{
|
||||||
IEnumerable<Alias> aliases = Aliases.GetAliases(); // cached
|
IEnumerable<Alias> aliases = aliasRepository.GetAliases(); // cached
|
||||||
IEnumerable<Tenant> tenants = Tenants.GetTenants(); // cached
|
IEnumerable<Tenant> tenants = tenantRepository.GetTenants(); // cached
|
||||||
|
|
||||||
if (aliasid != -1)
|
if (aliasId != -1)
|
||||||
{
|
{
|
||||||
_alias = aliases.Where(item => item.AliasId == aliasid).FirstOrDefault();
|
_alias = aliases.FirstOrDefault(item => item.AliasId == aliasId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_alias = aliases.Where(item => item.Name == aliasname).FirstOrDefault();
|
_alias = aliases.FirstOrDefault(item => item.Name == aliasName);
|
||||||
}
|
}
|
||||||
if (_alias != null)
|
if (_alias != null)
|
||||||
{
|
{
|
||||||
_tenant = tenants.Where(item => item.TenantId == _alias.TenantId).FirstOrDefault();
|
_tenant = tenants.FirstOrDefault(item => item.TenantId == _alias.TenantId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System;
|
using Oqtane.Models;
|
||||||
using Oqtane.Themes;
|
using Oqtane.Themes;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -12,17 +11,17 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
private List<Theme> LoadThemes()
|
private List<Theme> LoadThemes()
|
||||||
{
|
{
|
||||||
List<Theme> Themes = new List<Theme>();
|
List<Theme> themes = new List<Theme>();
|
||||||
|
|
||||||
// iterate through Oqtane theme assemblies
|
// iterate through Oqtane theme assemblies
|
||||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies()
|
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies()
|
||||||
.Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Theme.")).ToArray();
|
.Where(item => item.FullName.StartsWith("Oqtane.") || item.FullName.Contains(".Theme.")).ToArray();
|
||||||
foreach (Assembly assembly in assemblies)
|
foreach (Assembly assembly in assemblies)
|
||||||
{
|
{
|
||||||
Themes = LoadThemesFromAssembly(Themes, assembly);
|
themes = LoadThemesFromAssembly(themes, assembly);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Themes;
|
return themes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Theme> LoadThemesFromAssembly(List<Theme> themes, Assembly assembly)
|
private List<Theme> LoadThemesFromAssembly(List<Theme> themes, Assembly assembly)
|
||||||
@ -36,15 +35,15 @@ namespace Oqtane.Repository
|
|||||||
string[] typename = themeControlType.AssemblyQualifiedName.Split(',').Select(item => item.Trim()).ToList().ToArray();
|
string[] typename = themeControlType.AssemblyQualifiedName.Split(',').Select(item => item.Trim()).ToList().ToArray();
|
||||||
string[] segments = typename[0].Split('.');
|
string[] segments = typename[0].Split('.');
|
||||||
Array.Resize(ref segments, segments.Length - 1);
|
Array.Resize(ref segments, segments.Length - 1);
|
||||||
string Namespace = string.Join(".", segments);
|
string @namespace = string.Join(".", segments);
|
||||||
|
|
||||||
int index = themes.FindIndex(item => item.ThemeName == Namespace);
|
int index = themes.FindIndex(item => item.ThemeName == @namespace);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
/// determine if this theme implements ITheme
|
// determine if this theme implements ITheme
|
||||||
Type themetype = assembly.GetTypes()
|
Type themetype = assembly.GetTypes()
|
||||||
.Where(item => item.Namespace != null)
|
.Where(item => item.Namespace != null)
|
||||||
.Where(item => item.Namespace.StartsWith(Namespace))
|
.Where(item => item.Namespace.StartsWith(@namespace))
|
||||||
.Where(item => item.GetInterfaces().Contains(typeof(ITheme))).FirstOrDefault();
|
.Where(item => item.GetInterfaces().Contains(typeof(ITheme))).FirstOrDefault();
|
||||||
if (themetype != null)
|
if (themetype != null)
|
||||||
{
|
{
|
||||||
@ -52,7 +51,7 @@ namespace Oqtane.Repository
|
|||||||
Dictionary<string, string> properties = (Dictionary<string, string>)themetype.GetProperty("Properties").GetValue(themeobject);
|
Dictionary<string, string> properties = (Dictionary<string, string>)themetype.GetProperty("Properties").GetValue(themeobject);
|
||||||
theme = new Theme
|
theme = new Theme
|
||||||
{
|
{
|
||||||
ThemeName = Namespace,
|
ThemeName = @namespace,
|
||||||
Name = GetProperty(properties, "Name"),
|
Name = GetProperty(properties, "Name"),
|
||||||
Version = GetProperty(properties, "Version"),
|
Version = GetProperty(properties, "Version"),
|
||||||
Owner = GetProperty(properties, "Owner"),
|
Owner = GetProperty(properties, "Owner"),
|
||||||
@ -70,7 +69,7 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
theme = new Theme
|
theme = new Theme
|
||||||
{
|
{
|
||||||
ThemeName = Namespace,
|
ThemeName = @namespace,
|
||||||
Name = themeControlType.Name,
|
Name = themeControlType.Name,
|
||||||
Version = new Version(1, 0, 0).ToString(),
|
Version = new Version(1, 0, 0).ToString(),
|
||||||
Owner = "",
|
Owner = "",
|
||||||
@ -85,7 +84,7 @@ namespace Oqtane.Repository
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
themes.Add(theme);
|
themes.Add(theme);
|
||||||
index = themes.FindIndex(item => item.ThemeName == Namespace);
|
index = themes.FindIndex(item => item.ThemeName == @namespace);
|
||||||
}
|
}
|
||||||
theme = themes[index];
|
theme = themes[index];
|
||||||
theme.ThemeControls += (themeControlType.FullName + ", " + typename[1] + ";");
|
theme.ThemeControls += (themeControlType.FullName + ", " + typename[1] + ";");
|
||||||
@ -93,7 +92,7 @@ namespace Oqtane.Repository
|
|||||||
// layouts
|
// layouts
|
||||||
Type[] layouttypes = assembly.GetTypes()
|
Type[] layouttypes = assembly.GetTypes()
|
||||||
.Where(item => item.Namespace != null)
|
.Where(item => item.Namespace != null)
|
||||||
.Where(item => item.Namespace.StartsWith(Namespace))
|
.Where(item => item.Namespace.StartsWith(@namespace))
|
||||||
.Where(item => item.GetInterfaces().Contains(typeof(ILayoutControl))).ToArray();
|
.Where(item => item.GetInterfaces().Contains(typeof(ILayoutControl))).ToArray();
|
||||||
foreach (Type layouttype in layouttypes)
|
foreach (Type layouttype in layouttypes)
|
||||||
{
|
{
|
||||||
@ -107,7 +106,7 @@ namespace Oqtane.Repository
|
|||||||
// containers
|
// containers
|
||||||
Type[] containertypes = assembly.GetTypes()
|
Type[] containertypes = assembly.GetTypes()
|
||||||
.Where(item => item.Namespace != null)
|
.Where(item => item.Namespace != null)
|
||||||
.Where(item => item.Namespace.StartsWith(Namespace))
|
.Where(item => item.Namespace.StartsWith(@namespace))
|
||||||
.Where(item => item.GetInterfaces().Contains(typeof(IContainerControl))).ToArray();
|
.Where(item => item.GetInterfaces().Contains(typeof(IContainerControl))).ToArray();
|
||||||
foreach (Type containertype in containertypes)
|
foreach (Type containertype in containertypes)
|
||||||
{
|
{
|
||||||
@ -124,14 +123,14 @@ namespace Oqtane.Repository
|
|||||||
return themes;
|
return themes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetProperty(Dictionary<string, string> Properties, string Key)
|
private string GetProperty(Dictionary<string, string> properties, string key)
|
||||||
{
|
{
|
||||||
string Value = "";
|
string value = "";
|
||||||
if (Properties.ContainsKey(Key))
|
if (properties.ContainsKey(key))
|
||||||
{
|
{
|
||||||
Value = Properties[Key];
|
value = properties[key];
|
||||||
}
|
}
|
||||||
return Value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Theme> GetThemes()
|
public IEnumerable<Theme> GetThemes()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -38,9 +38,9 @@ namespace Oqtane.Repository
|
|||||||
return _db.User.Find(userId);
|
return _db.User.Find(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public User GetUser(string Username)
|
public User GetUser(string username)
|
||||||
{
|
{
|
||||||
return _db.User.Where(item => item.Username == Username).FirstOrDefault();
|
return _db.User.Where(item => item.Username == username).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteUser(int userId)
|
public void DeleteUser(int userId)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
|
||||||
namespace Oqtane.Repository
|
namespace Oqtane.Repository
|
||||||
@ -14,48 +14,48 @@ namespace Oqtane.Repository
|
|||||||
_db = context;
|
_db = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<UserRole> GetUserRoles(int SiteId)
|
public IEnumerable<UserRole> GetUserRoles(int siteId)
|
||||||
{
|
{
|
||||||
return _db.UserRole
|
return _db.UserRole
|
||||||
.Include(item => item.Role) // eager load roles
|
.Include(item => item.Role) // eager load roles
|
||||||
.Include(item => item.User) // eager load users
|
.Include(item => item.User) // eager load users
|
||||||
.Where(item => item.Role.SiteId == SiteId || item.Role.SiteId == null);
|
.Where(item => item.Role.SiteId == siteId || item.Role.SiteId == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<UserRole> GetUserRoles(int UserId, int SiteId)
|
public IEnumerable<UserRole> GetUserRoles(int userId, int siteId)
|
||||||
{
|
{
|
||||||
return _db.UserRole.Where(item => item.UserId == UserId)
|
return _db.UserRole.Where(item => item.UserId == userId)
|
||||||
.Include(item => item.Role) // eager load roles
|
.Include(item => item.Role) // eager load roles
|
||||||
.Include(item => item.User) // eager load users
|
.Include(item => item.User) // eager load users
|
||||||
.Where(item => item.Role.SiteId == SiteId || item.Role.SiteId == null);
|
.Where(item => item.Role.SiteId == siteId || item.Role.SiteId == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserRole AddUserRole(UserRole UserRole)
|
public UserRole AddUserRole(UserRole userRole)
|
||||||
{
|
{
|
||||||
_db.UserRole.Add(UserRole);
|
_db.UserRole.Add(userRole);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return UserRole;
|
return userRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserRole UpdateUserRole(UserRole UserRole)
|
public UserRole UpdateUserRole(UserRole userRole)
|
||||||
{
|
{
|
||||||
_db.Entry(UserRole).State = EntityState.Modified;
|
_db.Entry(userRole).State = EntityState.Modified;
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
return UserRole;
|
return userRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserRole GetUserRole(int UserRoleId)
|
public UserRole GetUserRole(int userRoleId)
|
||||||
{
|
{
|
||||||
return _db.UserRole
|
return _db.UserRole
|
||||||
.Include(item => item.Role) // eager load roles
|
.Include(item => item.Role) // eager load roles
|
||||||
.Include(item => item.User) // eager load users
|
.Include(item => item.User) // eager load users
|
||||||
.SingleOrDefault(item => item.UserRoleId == UserRoleId);
|
.SingleOrDefault(item => item.UserRoleId == userRoleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteUserRole(int UserRoleId)
|
public void DeleteUserRole(int userRoleId)
|
||||||
{
|
{
|
||||||
UserRole UserRole = _db.UserRole.Find(UserRoleId);
|
UserRole userRole = _db.UserRole.Find(userRoleId);
|
||||||
_db.UserRole.Remove(UserRole);
|
_db.UserRole.Remove(userRole);
|
||||||
_db.SaveChanges();
|
_db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Oqtane.Repository;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Security
|
namespace Oqtane.Security
|
||||||
{
|
{
|
||||||
|
@ -5,9 +5,9 @@ namespace Oqtane.Security
|
|||||||
{
|
{
|
||||||
public interface IUserPermissions
|
public interface IUserPermissions
|
||||||
{
|
{
|
||||||
bool IsAuthorized(ClaimsPrincipal User, string EntityName, int EntityId, string PermissionName);
|
bool IsAuthorized(ClaimsPrincipal user, string entityName, int entityId, string permissionName);
|
||||||
bool IsAuthorized(ClaimsPrincipal User, string PermissionName, string Permissions);
|
bool IsAuthorized(ClaimsPrincipal user, string permissionName, string permissions);
|
||||||
User GetUser(ClaimsPrincipal User);
|
User GetUser(ClaimsPrincipal user);
|
||||||
User GetUser();
|
User GetUser();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
|
|
||||||
namespace Oqtane.Security
|
namespace Oqtane.Security
|
||||||
@ -25,14 +25,14 @@ namespace Oqtane.Security
|
|||||||
var ctx = _httpContextAccessor.HttpContext;
|
var ctx = _httpContextAccessor.HttpContext;
|
||||||
if (ctx != null && ctx.Request.Query.ContainsKey("entityid"))
|
if (ctx != null && ctx.Request.Query.ContainsKey("entityid"))
|
||||||
{
|
{
|
||||||
int EntityId = int.Parse(ctx.Request.Query["entityid"]);
|
int entityId = int.Parse(ctx.Request.Query["entityid"]);
|
||||||
if (_userPermissions.IsAuthorized(context.User, requirement.EntityName, EntityId, requirement.PermissionName))
|
if (_userPermissions.IsAuthorized(context.User, requirement.EntityName, entityId, requirement.PermissionName))
|
||||||
{
|
{
|
||||||
context.Succeed(requirement);
|
context.Succeed(requirement);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "User {User} Does Not Have {PermissionName} Permission For {EntityName}:{EntityId}", context.User, requirement.PermissionName, requirement.EntityName, EntityId);
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "User {User} Does Not Have {PermissionName} Permission For {EntityName}:{EntityId}", context.User, requirement.PermissionName, requirement.EntityName, entityId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Repository;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
|
||||||
namespace Oqtane.Security
|
namespace Oqtane.Security
|
||||||
{
|
{
|
||||||
@ -17,41 +17,40 @@ namespace Oqtane.Security
|
|||||||
_accessor = accessor;
|
_accessor = accessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsAuthorized(ClaimsPrincipal User, string EntityName, int EntityId, string PermissionName)
|
public bool IsAuthorized(ClaimsPrincipal user, string entityName, int entityId, string permissionName)
|
||||||
{
|
{
|
||||||
return IsAuthorized(User, PermissionName, _permissions.EncodePermissions(EntityId, _permissions.GetPermissions(EntityName, EntityId, PermissionName).ToList()));
|
return IsAuthorized(user, permissionName, _permissions.EncodePermissions(entityId, _permissions.GetPermissions(entityName, entityId, permissionName).ToList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsAuthorized(ClaimsPrincipal User, string PermissionName, string Permissions)
|
public bool IsAuthorized(ClaimsPrincipal user, string permissionName, string permissions)
|
||||||
{
|
{
|
||||||
return UserSecurity.IsAuthorized(GetUser(User), PermissionName, Permissions);
|
return UserSecurity.IsAuthorized(GetUser(user), permissionName, permissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public User GetUser(ClaimsPrincipal User)
|
public User GetUser(ClaimsPrincipal user)
|
||||||
{
|
{
|
||||||
User user = new User();
|
User resultUser = new User();
|
||||||
user.Username = "";
|
resultUser.Username = "";
|
||||||
user.IsAuthenticated = false;
|
resultUser.IsAuthenticated = false;
|
||||||
user.UserId = -1;
|
resultUser.UserId = -1;
|
||||||
user.Roles = "";
|
resultUser.Roles = "";
|
||||||
|
|
||||||
if (User != null)
|
if (user == null) return resultUser;
|
||||||
{
|
|
||||||
user.Username = User.Identity.Name;
|
resultUser.Username = user.Identity.Name;
|
||||||
user.IsAuthenticated = User.Identity.IsAuthenticated;
|
resultUser.IsAuthenticated = user.Identity.IsAuthenticated;
|
||||||
var idclaim = User.Claims.Where(item => item.Type == ClaimTypes.PrimarySid).FirstOrDefault();
|
var idclaim = user.Claims.FirstOrDefault(item => item.Type == ClaimTypes.PrimarySid);
|
||||||
if (idclaim != null)
|
if (idclaim != null)
|
||||||
{
|
{
|
||||||
user.UserId = int.Parse(idclaim.Value);
|
resultUser.UserId = int.Parse(idclaim.Value);
|
||||||
foreach (var claim in User.Claims.Where(item => item.Type == ClaimTypes.Role))
|
foreach (var claim in user.Claims.Where(item => item.Type == ClaimTypes.Role))
|
||||||
{
|
{
|
||||||
user.Roles += claim.Value + ";";
|
resultUser.Roles += claim.Value + ";";
|
||||||
}
|
|
||||||
if (user.Roles != "") user.Roles = ";" + user.Roles;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
if (resultUser.Roles != "") resultUser.Roles = ";" + resultUser.Roles;
|
||||||
|
}
|
||||||
|
return resultUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User GetUser()
|
public User GetUser()
|
||||||
|
@ -1,34 +1,27 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.ResponseCompression; // needed for WASM
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
using Oqtane.Modules;
|
|
||||||
using Oqtane.Repository;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.Loader;
|
using System.Linq;
|
||||||
using Oqtane.Services;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using Microsoft.AspNetCore.Components;
|
|
||||||
using Oqtane.Shared;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.OpenApi.Models;
|
|
||||||
using Oqtane.Security;
|
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using System.Net;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
using Oqtane.Infrastructure;
|
using Oqtane.Infrastructure;
|
||||||
|
using Oqtane.Infrastructure.Interfaces;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
using Oqtane.Security;
|
||||||
|
using Oqtane.Services;
|
||||||
|
using Oqtane.Shared; // needed for WASM
|
||||||
|
|
||||||
namespace Oqtane.Server
|
namespace Oqtane
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
@ -59,10 +52,10 @@ namespace Oqtane.Server
|
|||||||
// setup HttpClient for server side in a client side compatible fashion ( with auth cookie )
|
// setup HttpClient for server side in a client side compatible fashion ( with auth cookie )
|
||||||
if (!services.Any(x => x.ServiceType == typeof(HttpClient)))
|
if (!services.Any(x => x.ServiceType == typeof(HttpClient)))
|
||||||
{
|
{
|
||||||
services.AddScoped<HttpClient>(s =>
|
services.AddScoped(s =>
|
||||||
{
|
{
|
||||||
// creating the URI helper needs to wait until the JS Runtime is initialized, so defer it.
|
// creating the URI helper needs to wait until the JS Runtime is initialized, so defer it.
|
||||||
var NavigationManager = s.GetRequiredService<NavigationManager>();
|
var navigationManager = s.GetRequiredService<NavigationManager>();
|
||||||
var httpContextAccessor = s.GetRequiredService<IHttpContextAccessor>();
|
var httpContextAccessor = s.GetRequiredService<IHttpContextAccessor>();
|
||||||
var authToken = httpContextAccessor.HttpContext.Request.Cookies[".AspNetCore.Identity.Application"];
|
var authToken = httpContextAccessor.HttpContext.Request.Cookies[".AspNetCore.Identity.Application"];
|
||||||
var client = new HttpClient(new HttpClientHandler { UseCookies = false });
|
var client = new HttpClient(new HttpClientHandler { UseCookies = false });
|
||||||
@ -70,7 +63,7 @@ namespace Oqtane.Server
|
|||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Add("Cookie", ".AspNetCore.Identity.Application=" + authToken);
|
client.DefaultRequestHeaders.Add("Cookie", ".AspNetCore.Identity.Application=" + authToken);
|
||||||
}
|
}
|
||||||
client.BaseAddress = new Uri(NavigationManager.Uri);
|
client.BaseAddress = new Uri(navigationManager.Uri);
|
||||||
return client;
|
return client;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -78,13 +71,13 @@ namespace Oqtane.Server
|
|||||||
// register authorization services
|
// register authorization services
|
||||||
services.AddAuthorizationCore(options =>
|
services.AddAuthorizationCore(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("ViewPage", policy => policy.Requirements.Add(new PermissionRequirement("Page", PermissionNames.View)));
|
options.AddPolicy("ViewPage", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Page, PermissionNames.View)));
|
||||||
options.AddPolicy("EditPage", policy => policy.Requirements.Add(new PermissionRequirement("Page", PermissionNames.Edit)));
|
options.AddPolicy("EditPage", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Page, PermissionNames.Edit)));
|
||||||
options.AddPolicy("ViewModule", policy => policy.Requirements.Add(new PermissionRequirement("Module", PermissionNames.View)));
|
options.AddPolicy("ViewModule", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Module, PermissionNames.View)));
|
||||||
options.AddPolicy("EditModule", policy => policy.Requirements.Add(new PermissionRequirement("Module", PermissionNames.Edit)));
|
options.AddPolicy("EditModule", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Module, PermissionNames.Edit)));
|
||||||
options.AddPolicy("ViewFolder", policy => policy.Requirements.Add(new PermissionRequirement("Folder", PermissionNames.View)));
|
options.AddPolicy("ViewFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.View)));
|
||||||
options.AddPolicy("EditFolder", policy => policy.Requirements.Add(new PermissionRequirement("Folder", PermissionNames.Edit)));
|
options.AddPolicy("EditFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.Edit)));
|
||||||
options.AddPolicy("ListFolder", policy => policy.Requirements.Add(new PermissionRequirement("Folder", "List")));
|
options.AddPolicy("ListFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.Browse)));
|
||||||
});
|
});
|
||||||
|
|
||||||
// register scoped core services
|
// register scoped core services
|
||||||
@ -160,7 +153,7 @@ namespace Oqtane.Server
|
|||||||
services.AddTransient<IUserClaimsPrincipalFactory<IdentityUser>, ClaimsPrincipalFactory<IdentityUser>>();
|
services.AddTransient<IUserClaimsPrincipalFactory<IdentityUser>, ClaimsPrincipalFactory<IdentityUser>>();
|
||||||
|
|
||||||
// register singleton scoped core services
|
// register singleton scoped core services
|
||||||
services.AddSingleton<IConfigurationRoot>(Configuration);
|
services.AddSingleton(Configuration);
|
||||||
services.AddSingleton<IInstallationManager, InstallationManager>();
|
services.AddSingleton<IInstallationManager, InstallationManager>();
|
||||||
services.AddSingleton<ISyncManager, SyncManager>();
|
services.AddSingleton<ISyncManager, SyncManager>();
|
||||||
|
|
||||||
@ -206,7 +199,7 @@ namespace Oqtane.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IInstallationManager InstallationManager)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IInstallationManager installationManager)
|
||||||
{
|
{
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
@ -219,7 +212,7 @@ namespace Oqtane.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
// install any modules or themes
|
// install any modules or themes
|
||||||
InstallationManager.InstallPackages("Modules,Themes", false);
|
installationManager.InstallPackages("Modules,Themes", false);
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace Oqtane.Models
|
namespace Oqtane.Models
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
using Oqtane.Modules;
|
using Oqtane.Shared;
|
||||||
using Oqtane.Shared;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace Oqtane.Models
|
namespace Oqtane.Models
|
||||||
|
@ -9,21 +9,21 @@ namespace Oqtane.Security
|
|||||||
{
|
{
|
||||||
public class UserSecurity
|
public class UserSecurity
|
||||||
{
|
{
|
||||||
public static List<PermissionString> GetPermissionStrings(string PermissionStrings)
|
public static List<PermissionString> GetPermissionStrings(string permissionStrings)
|
||||||
{
|
{
|
||||||
return JsonSerializer.Deserialize<List<PermissionString>>(PermissionStrings);
|
return JsonSerializer.Deserialize<List<PermissionString>>(permissionStrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string SetPermissionStrings(List<PermissionString> PermissionStrings)
|
public static string SetPermissionStrings(List<PermissionString> permissionStrings)
|
||||||
{
|
{
|
||||||
return JsonSerializer.Serialize(PermissionStrings);
|
return JsonSerializer.Serialize(permissionStrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetPermissions(string PermissionName, string PermissionStrings)
|
public static string GetPermissions(string permissionName, string permissionStrings)
|
||||||
{
|
{
|
||||||
string permissions = "";
|
string permissions = "";
|
||||||
List<PermissionString> permissionstrings = JsonSerializer.Deserialize<List<PermissionString>>(PermissionStrings);
|
List<PermissionString> permissionstrings = JsonSerializer.Deserialize<List<PermissionString>>(permissionStrings);
|
||||||
PermissionString permissionstring = permissionstrings.FirstOrDefault(item => item.PermissionName == PermissionName);
|
PermissionString permissionstring = permissionstrings.FirstOrDefault(item => item.PermissionName == permissionName);
|
||||||
if (permissionstring != null)
|
if (permissionstring != null)
|
||||||
{
|
{
|
||||||
permissions = permissionstring.Permissions;
|
permissions = permissionstring.Permissions;
|
||||||
@ -31,68 +31,68 @@ namespace Oqtane.Security
|
|||||||
return permissions;
|
return permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsAuthorized(User User, string PermissionName, string PermissionStrings)
|
public static bool IsAuthorized(User user, string permissionName, string permissionStrings)
|
||||||
{
|
{
|
||||||
return IsAuthorized(User, GetPermissions(PermissionName, PermissionStrings));
|
return IsAuthorized(user, GetPermissions(permissionName, permissionStrings));
|
||||||
}
|
}
|
||||||
|
|
||||||
// permissions are stored in the format "!rolename1;![userid1];rolename2;rolename3;[userid2];[userid3]" where "!" designates Deny permissions
|
// permissions are stored in the format "!rolename1;![userid1];rolename2;rolename3;[userid2];[userid3]" where "!" designates Deny permissions
|
||||||
public static bool IsAuthorized(User User, string Permissions)
|
public static bool IsAuthorized(User user, string permissions)
|
||||||
{
|
{
|
||||||
bool authorized = false;
|
bool authorized = false;
|
||||||
if (Permissions != "")
|
if (permissions != "")
|
||||||
{
|
{
|
||||||
if (User == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
authorized = IsAuthorized(-1, "", Permissions); // user is not authenticated but may have access to resource
|
authorized = IsAuthorized(-1, "", permissions); // user is not authenticated but may have access to resource
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
authorized = IsAuthorized(User.UserId, User.Roles, Permissions);
|
authorized = IsAuthorized(user.UserId, user.Roles, permissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return authorized;
|
return authorized;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsAuthorized(int UserId, string Roles, string Permissions)
|
private static bool IsAuthorized(int userId, string roles, string permissions)
|
||||||
{
|
{
|
||||||
bool IsAuthorized = false;
|
bool isAuthorized = false;
|
||||||
|
|
||||||
if (Permissions != null)
|
if (permissions != null)
|
||||||
{
|
{
|
||||||
foreach (string permission in Permissions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
foreach (string permission in permissions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||||
{
|
{
|
||||||
bool? allowed = VerifyPermission(UserId, Roles, permission);
|
bool? allowed = VerifyPermission(userId, roles, permission);
|
||||||
if (allowed.HasValue)
|
if (allowed.HasValue)
|
||||||
{
|
{
|
||||||
IsAuthorized = allowed.Value;
|
isAuthorized = allowed.Value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return IsAuthorized;
|
return isAuthorized;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool? VerifyPermission(int UserId, string Roles, string Permission)
|
private static bool? VerifyPermission(int userId, string roles, string permission)
|
||||||
{
|
{
|
||||||
bool? allowed = null;
|
bool? allowed = null;
|
||||||
//permissions strings are encoded with deny permissions at the beginning and grant permissions at the end for optimal performance
|
//permissions strings are encoded with deny permissions at the beginning and grant permissions at the end for optimal performance
|
||||||
if (!String.IsNullOrEmpty(Permission))
|
if (!String.IsNullOrEmpty(permission))
|
||||||
{
|
{
|
||||||
// deny permission
|
// deny permission
|
||||||
if (Permission.StartsWith("!"))
|
if (permission.StartsWith("!"))
|
||||||
{
|
{
|
||||||
string denyRole = Permission.Replace("!", "");
|
string denyRole = permission.Replace("!", "");
|
||||||
if (denyRole == Constants.AllUsersRole || IsAllowed(UserId, Roles, denyRole))
|
if (denyRole == Constants.AllUsersRole || IsAllowed(userId, roles, denyRole))
|
||||||
{
|
{
|
||||||
allowed = false;
|
allowed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // grant permission
|
else // grant permission
|
||||||
{
|
{
|
||||||
if (Permission == Constants.AllUsersRole || IsAllowed(UserId, Roles, Permission))
|
if (permission == Constants.AllUsersRole || IsAllowed(userId, roles, permission))
|
||||||
{
|
{
|
||||||
allowed = true;
|
allowed = true;
|
||||||
}
|
}
|
||||||
@ -101,16 +101,16 @@ namespace Oqtane.Security
|
|||||||
return allowed;
|
return allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsAllowed(int UserId, string Roles, string Permission)
|
private static bool IsAllowed(int userId, string roles, string permission)
|
||||||
{
|
{
|
||||||
if ("[" + UserId + "]" == Permission)
|
if ("[" + userId + "]" == permission)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Roles != null)
|
if (roles != null)
|
||||||
{
|
{
|
||||||
return Roles.IndexOf(";" + Permission + ";") != -1;
|
return roles.IndexOf(";" + permission + ";") != -1;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -125,27 +125,25 @@ namespace Oqtane.Upgrade
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CanAccessFiles(List<string> files, string folder)
|
private static bool CanAccessFiles(List<string> files, string folder)
|
||||||
{
|
{
|
||||||
// ensure files are not locked by another process - the shutdownTimeLimit defines the duration for app shutdown
|
// ensure files are not locked by another process - the shutdownTimeLimit defines the duration for app shutdown
|
||||||
bool canaccess = true;
|
bool canAccess = true;
|
||||||
FileStream stream = null;
|
FileStream stream = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < (files.Count - 1) && canaccess)
|
while (i < (files.Count - 1) && canAccess)
|
||||||
{
|
{
|
||||||
string filepath = Path.Combine(folder, Path.GetFileName(files[i]));
|
string filepath = Path.Combine(folder, Path.GetFileName(files[i]));
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
bool locked = true;
|
bool locked = true;
|
||||||
// try up to 30 times
|
// try up to 30 times
|
||||||
while (attempts < 30 && locked == true)
|
while (attempts < 30 && locked)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
stream = System.IO.File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.None);
|
stream = File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.None);
|
||||||
locked = false;
|
locked = false;
|
||||||
}
|
}
|
||||||
catch // file is locked by another process
|
catch // file is locked by another process
|
||||||
@ -154,20 +152,17 @@ namespace Oqtane.Upgrade
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (stream != null)
|
stream?.Close();
|
||||||
{
|
|
||||||
stream.Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
attempts += 1;
|
attempts += 1;
|
||||||
}
|
}
|
||||||
if (locked && canaccess)
|
if (locked)
|
||||||
{
|
{
|
||||||
canaccess = false;
|
canAccess = false;
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
return canaccess;
|
return canAccess;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user