optimizations and fixes
This commit is contained in:
parent
2436f74830
commit
fe98084324
|
@ -117,7 +117,7 @@
|
|||
{
|
||||
await logger.LogInformation("Login Successful For Username {Username}", Username);
|
||||
authstateprovider.NotifyAuthenticationChanged();
|
||||
NavigationManager.NavigateTo(NavigateUrl(ReturnUrl));
|
||||
NavigationManager.NavigateTo(NavigateUrl(ReturnUrl, "reload"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
string name = "";
|
||||
string type = "LocalDB";
|
||||
string server = "(LocalDb)\\MSSQLLocalDB";
|
||||
string database = "Oqtane-" + DateTime.Now.ToString("yyyyMMddHHmm");
|
||||
string database = "Oqtane-" + DateTime.UtcNow.ToString("yyyyMMddHHmm");
|
||||
string username = "";
|
||||
string password = "";
|
||||
string schema = "";
|
||||
|
|
|
@ -81,7 +81,7 @@
|
|||
notification.Subject = subject;
|
||||
notification.Body = body;
|
||||
notification.ParentId = null;
|
||||
notification.CreatedOn = DateTime.Now;
|
||||
notification.CreatedOn = DateTime.UtcNow;
|
||||
notification.IsDelivered = false;
|
||||
notification.DeliveredOn = null;
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@
|
|||
notification.Subject = subject;
|
||||
notification.Body = body;
|
||||
notification.ParentId = notificationid;
|
||||
notification.CreatedOn = DateTime.Now;
|
||||
notification.CreatedOn = DateTime.UtcNow;
|
||||
notification.IsDelivered = false;
|
||||
notification.DeliveredOn = null;
|
||||
|
||||
|
|
|
@ -37,6 +37,6 @@ else
|
|||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
WeatherForecastService forecastservice = new WeatherForecastService();
|
||||
forecasts = await forecastservice.GetForecastAsync(DateTime.Now);
|
||||
forecasts = await forecastservice.GetForecastAsync(DateTime.UtcNow);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ namespace Oqtane.Services
|
|||
Task<List<Page>> GetPagesAsync(int SiteId);
|
||||
Task<Page> GetPageAsync(int PageId);
|
||||
Task<Page> GetPageAsync(int PageId, int UserId);
|
||||
Task<Page> GetPageAsync(string Path, int SiteId);
|
||||
Task<Page> AddPageAsync(Page Page);
|
||||
Task<Page> AddPageAsync(int PageId, int UserId);
|
||||
Task<Page> UpdatePageAsync(Page Page);
|
||||
|
|
|
@ -59,13 +59,13 @@ namespace Oqtane.Services
|
|||
|
||||
public async Task LoadModuleDefinitionsAsync(int SiteId)
|
||||
{
|
||||
// get list of modules from the server
|
||||
List<ModuleDefinition> moduledefinitions = await GetModuleDefinitionsAsync(SiteId);
|
||||
|
||||
// download assemblies to browser when running client-side Blazor
|
||||
var authstateprovider = (IdentityAuthenticationStateProvider)_serviceProvider.GetService(typeof(IdentityAuthenticationStateProvider));
|
||||
if (authstateprovider != null)
|
||||
{
|
||||
// get list of modules from the server
|
||||
List<ModuleDefinition> moduledefinitions = await GetModuleDefinitionsAsync(SiteId);
|
||||
|
||||
// get list of loaded assemblies on the client ( in the client-side hosting module the browser client has its own app domain )
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Components;
|
|||
using System.Collections.Generic;
|
||||
using Oqtane.Shared;
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
|
@ -44,6 +45,18 @@ namespace Oqtane.Services
|
|||
return await _http.GetJsonAsync<Page>(apiurl + "/" + PageId.ToString() + "?userid=" + UserId.ToString());
|
||||
}
|
||||
|
||||
public async Task<Page> GetPageAsync(string Path, int SiteId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _http.GetJsonAsync<Page>(apiurl + "/path/" + SiteId.ToString() + "?path=" + WebUtility.UrlEncode(Path));
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Page> AddPageAsync(Page Page)
|
||||
{
|
||||
return await _http.PostJsonAsync<Page>(apiurl, Page);
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
|
||||
<div class="row">
|
||||
<div class="col text-center">
|
||||
<label for="Module" class="control-label">Module: </label>
|
||||
<label for="Module" class="control-label">Module Management: </label>
|
||||
<select class="form-control" @bind="@_moduleType">
|
||||
<option value="new">Add New Module</option>
|
||||
<option value="existing">Add Existing Module</option>
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
{
|
||||
// client-side Blazor
|
||||
authstateprovider.NotifyAuthenticationChanged();
|
||||
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path));
|
||||
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "reload"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
</div>
|
||||
</div>
|
||||
<hr class="app-rule" />
|
||||
<h2 class="text-center">Database Configuration</h2>
|
||||
<div class="row">
|
||||
<div class="mx-auto text-center">
|
||||
<table class="form-group" cellpadding="4" cellspacing="4">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col text-center">
|
||||
<h2>Database Configuration</h2><br />
|
||||
<table class="form-group" cellpadding="4" cellspacing="4" style="margin: auto;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
|
@ -73,12 +73,9 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<hr class="app-rule" />
|
||||
<h2 class="text-center">Application Administrator</h2>
|
||||
<div class="row">
|
||||
<div class="mx-auto text-center">
|
||||
<table class="form-group" cellpadding="4" cellspacing="4">
|
||||
<div class="col text-center">
|
||||
<h2>Application Administrator</h2><br />
|
||||
<table class="form-group" cellpadding="4" cellspacing="4" style="margin: auto;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
|
@ -116,6 +113,7 @@
|
|||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<hr class="app-rule" />
|
||||
<div class="row">
|
||||
<div class="mx-auto text-center">
|
||||
<button type="button" class="btn btn-success" @onclick="Install">Install Now</button><br /><br />
|
||||
|
@ -128,7 +126,7 @@
|
|||
@code {
|
||||
private string DatabaseType = "LocalDB";
|
||||
private string ServerName = "(LocalDb)\\MSSQLLocalDB";
|
||||
private string DatabaseName = "Oqtane-" + DateTime.Now.ToString("yyyyMMddHHmm");
|
||||
private string DatabaseName = "Oqtane-" + DateTime.UtcNow.ToString("yyyyMMddHHmm");
|
||||
private string Username = "";
|
||||
private string Password = "";
|
||||
private string HostUsername = Constants.HostUser;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
@inject IUserService UserService
|
||||
@inject IModuleService ModuleService
|
||||
@inject IModuleDefinitionService ModuleDefinitionService
|
||||
@inject ILogService LogService
|
||||
@implements IHandleAfterRender
|
||||
|
||||
@DynamicComponent
|
||||
|
@ -75,7 +76,6 @@
|
|||
int moduleid = -1;
|
||||
string action = "";
|
||||
bool editmode = false;
|
||||
int userid = -1;
|
||||
Reload reload = Reload.None;
|
||||
DateTime lastsyncdate = DateTime.UtcNow;
|
||||
|
||||
|
@ -94,23 +94,39 @@
|
|||
path = path.Substring(0, path.IndexOf("?"));
|
||||
}
|
||||
|
||||
// the reload parameter is used during user login/logout
|
||||
if (querystring.ContainsKey("reload"))
|
||||
{
|
||||
reload = Reload.Site;
|
||||
}
|
||||
|
||||
if (PageState != null)
|
||||
{
|
||||
editmode = PageState.EditMode;
|
||||
lastsyncdate = PageState.LastSyncDate;
|
||||
if (PageState.User != null)
|
||||
{
|
||||
userid = PageState.User.UserId;
|
||||
}
|
||||
}
|
||||
|
||||
alias = await AliasService.GetAliasAsync(_absoluteUri, lastsyncdate);
|
||||
SiteState.Alias = alias; // set state for services
|
||||
lastsyncdate = alias.SyncDate;
|
||||
|
||||
if (PageState == null || alias.SiteId != PageState.Alias.SiteId)
|
||||
// process any sync events for site or page
|
||||
if (reload != Reload.Site && alias.SyncEvents.Any())
|
||||
{
|
||||
if (PageState != null && alias.SyncEvents.Exists(item => item.EntityName == "Page" && item.EntityId == PageState.Page.PageId))
|
||||
{
|
||||
reload = Reload.Page;
|
||||
}
|
||||
if (alias.SyncEvents.Exists(item => item.EntityName == "Site" && item.EntityId == alias.SiteId))
|
||||
{
|
||||
reload = Reload.Site;
|
||||
}
|
||||
}
|
||||
|
||||
if (reload == Reload.Site || PageState == null || alias.SiteId != PageState.Alias.SiteId)
|
||||
{
|
||||
site = await SiteService.GetSiteAsync(alias.SiteId, alias);
|
||||
reload = Reload.Site;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -118,29 +134,24 @@
|
|||
}
|
||||
if (site != null)
|
||||
{
|
||||
// get user
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
if (authState.User.Identity.IsAuthenticated)
|
||||
if (PageState == null || reload == Reload.Site)
|
||||
{
|
||||
user = await UserService.GetUserAsync(authState.User.Identity.Name, site.SiteId);
|
||||
if (user != null)
|
||||
// get user
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
if (authState.User.Identity.IsAuthenticated)
|
||||
{
|
||||
userid = user.UserId;
|
||||
user = await UserService.GetUserAsync(authState.User.Identity.Name, site.SiteId);
|
||||
}
|
||||
}
|
||||
|
||||
// process sync events
|
||||
if (alias.SyncEvents.Any())
|
||||
else
|
||||
{
|
||||
if (PageState != null && alias.SyncEvents.Exists(item => item.EntityName == "Page" && item.EntityId == PageState.Page.PageId))
|
||||
{
|
||||
reload = Reload.Page;
|
||||
}
|
||||
if (alias.SyncEvents.Exists(item => item.EntityName == "Site" && item.EntityId == alias.SiteId))
|
||||
{
|
||||
reload = Reload.Site;
|
||||
}
|
||||
if (alias.SyncEvents.Exists(item => item.EntityName == "User" && item.EntityId == userid))
|
||||
user = PageState.User;
|
||||
}
|
||||
|
||||
// process any sync events for user
|
||||
if (reload != Reload.Site && user != null && alias.SyncEvents.Any())
|
||||
{
|
||||
if (alias.SyncEvents.Exists(item => item.EntityName == "User" && item.EntityId == user.UserId))
|
||||
{
|
||||
reload = Reload.Site;
|
||||
}
|
||||
|
@ -148,7 +159,7 @@
|
|||
|
||||
if (PageState == null || reload >= Reload.Site)
|
||||
{
|
||||
await ModuleDefinitionService.LoadModuleDefinitionsAsync(site.SiteId);
|
||||
await ModuleDefinitionService.LoadModuleDefinitionsAsync(site.SiteId);
|
||||
pages = await PageService.GetPagesAsync(site.SiteId);
|
||||
}
|
||||
else
|
||||
|
@ -206,7 +217,7 @@
|
|||
{
|
||||
page = pages.Where(item => item.Path == path).FirstOrDefault();
|
||||
reload = Reload.Page;
|
||||
if (page!=null)
|
||||
if (page != null)
|
||||
{
|
||||
editmode = page.EditMode;
|
||||
}
|
||||
|
@ -255,21 +266,23 @@
|
|||
|
||||
OnStateChange?.Invoke(pagestate);
|
||||
}
|
||||
else
|
||||
{
|
||||
// user is not authorized to view page
|
||||
if (path != "")
|
||||
{
|
||||
NavigationManager.NavigateTo("");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// page does not exist
|
||||
if (path != "")
|
||||
if (user == null)
|
||||
{
|
||||
NavigationManager.NavigateTo("");
|
||||
await LogService.Log(null, null, null, GetType().AssemblyQualifiedName, Utilities.GetTypeNameLastSegment(GetType().AssemblyQualifiedName, 1), LogFunction.Security, LogLevel.Error, null, "Page Does Not Exist Or User Is Not Authorized To View Page {Path}", path);
|
||||
// redirect to login page
|
||||
NavigationManager.NavigateTo(Utilities.NavigateUrl(alias.Path, "login", "returnurl=" + path));
|
||||
}
|
||||
else
|
||||
{
|
||||
await LogService.Log(null, null, user.UserId, GetType().AssemblyQualifiedName, Utilities.GetTypeNameLastSegment(GetType().AssemblyQualifiedName, 1), LogFunction.Security, LogLevel.Error, null, "Page Does Not Exist Or User Is Not Authorized To View Page {Path}", path);
|
||||
if (path != "")
|
||||
{
|
||||
// redirect to home page
|
||||
NavigationManager.NavigateTo(Utilities.NavigateUrl(alias.Path, "", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -312,8 +312,8 @@ namespace Oqtane.Controllers
|
|||
fileparts = Directory.GetFiles(folder, "*" + token + "*");
|
||||
foreach (string filepart in fileparts)
|
||||
{
|
||||
DateTime createddate = System.IO.File.GetCreationTime(filepart);
|
||||
if (createddate < DateTime.Now.AddHours(-2))
|
||||
DateTime createddate = System.IO.File.GetCreationTime(filepart).ToUniversalTime();
|
||||
if (createddate < DateTime.UtcNow.AddHours(-2))
|
||||
{
|
||||
System.IO.File.Delete(filepart);
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ namespace Oqtane.Controllers
|
|||
{
|
||||
version = new ApplicationVersion();
|
||||
version.Version = Constants.Version;
|
||||
version.CreatedOn = DateTime.Now;
|
||||
version.CreatedOn = DateTime.UtcNow;
|
||||
db.ApplicationVersion.Add(version);
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ using Oqtane.Shared;
|
|||
using System.Linq;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Security;
|
||||
using System.Net;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
|
@ -70,6 +71,31 @@ namespace Oqtane.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
// GET api/<controller>/path/x?path=y
|
||||
[HttpGet("path/{siteid}")]
|
||||
public Page Get(string path, int siteid)
|
||||
{
|
||||
Page page = _pages.GetPage(WebUtility.UrlDecode(path), siteid);
|
||||
if (page != null)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(User, "View", page.Permissions))
|
||||
{
|
||||
return page;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Read, "User Not Authorized To Access Page {Page}", page);
|
||||
HttpContext.Response.StatusCode = 401;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpContext.Response.StatusCode = 404;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// POST api/<controller>
|
||||
[HttpPost]
|
||||
[Authorize(Roles = Constants.RegisteredRole)]
|
||||
|
|
|
@ -111,7 +111,7 @@ namespace Oqtane.Controllers
|
|||
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.ParentId = null;
|
||||
notification.CreatedOn = DateTime.Now;
|
||||
notification.CreatedOn = DateTime.UtcNow;
|
||||
notification.IsDelivered = false;
|
||||
notification.DeliveredOn = null;
|
||||
_notifications.AddNotification(notification);
|
||||
|
@ -240,10 +240,9 @@ namespace Oqtane.Controllers
|
|||
if (identityuser.EmailConfirmed)
|
||||
{
|
||||
user.IsAuthenticated = true;
|
||||
user.LastLoginOn = DateTime.Now;
|
||||
user.LastLoginOn = DateTime.UtcNow;
|
||||
user.LastIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
|
||||
_users.UpdateUser(user);
|
||||
_syncManager.AddSyncEvent("User", user.UserId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Login Successful {Username}", User.Username);
|
||||
if (SetCookie)
|
||||
{
|
||||
|
@ -272,7 +271,6 @@ namespace Oqtane.Controllers
|
|||
public async Task Logout([FromBody] User User)
|
||||
{
|
||||
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
|
||||
_syncManager.AddSyncEvent("User", User.UserId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Logout {Username}", User.Username);
|
||||
}
|
||||
|
||||
|
@ -324,7 +322,7 @@ namespace Oqtane.Controllers
|
|||
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.ParentId = null;
|
||||
notification.CreatedOn = DateTime.Now;
|
||||
notification.CreatedOn = DateTime.UtcNow;
|
||||
notification.IsDelivered = false;
|
||||
notification.DeliveredOn = null;
|
||||
_notifications.AddNotification(notification);
|
||||
|
|
|
@ -12,11 +12,13 @@ namespace Oqtane.Controllers
|
|||
public class UserRoleController : Controller
|
||||
{
|
||||
private readonly IUserRoleRepository _userRoles;
|
||||
private readonly ISyncManager _syncManager;
|
||||
private readonly ILogManager _logger;
|
||||
|
||||
public UserRoleController(IUserRoleRepository userRoles, ILogManager logger)
|
||||
public UserRoleController(IUserRoleRepository userRoles, ISyncManager syncManager, ILogManager logger)
|
||||
{
|
||||
_userRoles = userRoles;
|
||||
_syncManager = syncManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
@ -44,6 +46,7 @@ namespace Oqtane.Controllers
|
|||
if (ModelState.IsValid)
|
||||
{
|
||||
UserRole = _userRoles.AddUserRole(UserRole);
|
||||
_syncManager.AddSyncEvent("User", UserRole.UserId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "User Role Added {UserRole}", UserRole);
|
||||
}
|
||||
return UserRole;
|
||||
|
@ -57,6 +60,7 @@ namespace Oqtane.Controllers
|
|||
if (ModelState.IsValid)
|
||||
{
|
||||
UserRole = _userRoles.UpdateUserRole(UserRole);
|
||||
_syncManager.AddSyncEvent("User", UserRole.UserId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Update, "User Role Updated {UserRole}", UserRole);
|
||||
}
|
||||
return UserRole;
|
||||
|
@ -67,8 +71,10 @@ namespace Oqtane.Controllers
|
|||
[Authorize(Roles = Constants.AdminRole)]
|
||||
public void Delete(int id)
|
||||
{
|
||||
UserRole userRole = _userRoles.GetUserRole(id);
|
||||
_userRoles.DeleteUserRole(id);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Role Deleted {UserRoleId}", id);
|
||||
_syncManager.AddSyncEvent("User", userRole.UserId);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Role Deleted {UserRole}", userRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,19 +50,19 @@ namespace Oqtane.Infrastructure
|
|||
}
|
||||
else
|
||||
{
|
||||
Job.NextExecution = DateTime.Now;
|
||||
Job.NextExecution = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
// determine if the job should be run
|
||||
if (Job.NextExecution <= DateTime.Now && (Job.EndDate == null || Job.EndDate >= DateTime.Now))
|
||||
if (Job.NextExecution <= DateTime.UtcNow && (Job.EndDate == null || Job.EndDate >= DateTime.UtcNow))
|
||||
{
|
||||
IJobLogRepository JobLogs = scope.ServiceProvider.GetRequiredService<IJobLogRepository>();
|
||||
|
||||
// create a job log entry
|
||||
JobLog log = new JobLog();
|
||||
log.JobId = Job.JobId;
|
||||
log.StartDate = DateTime.Now;
|
||||
log.StartDate = DateTime.UtcNow;
|
||||
log.FinishDate = null;
|
||||
log.Succeeded = false;
|
||||
log.Notes = "";
|
||||
|
@ -85,7 +85,7 @@ namespace Oqtane.Infrastructure
|
|||
}
|
||||
|
||||
// update the job log
|
||||
log.FinishDate = DateTime.Now;
|
||||
log.FinishDate = DateTime.UtcNow;
|
||||
JobLogs.UpdateJobLog(log);
|
||||
|
||||
// update the job
|
||||
|
@ -132,9 +132,9 @@ namespace Oqtane.Infrastructure
|
|||
NextExecution = NextExecution.AddMonths(Interval);
|
||||
break;
|
||||
}
|
||||
if (NextExecution < DateTime.Now)
|
||||
if (NextExecution < DateTime.UtcNow)
|
||||
{
|
||||
NextExecution = DateTime.Now;
|
||||
NextExecution = DateTime.UtcNow;
|
||||
}
|
||||
return NextExecution;
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace Oqtane.Infrastructure
|
|||
client.Send(mailMessage);
|
||||
sent = sent++;
|
||||
notification.IsDelivered = true;
|
||||
notification.DeliveredOn = DateTime.Now;
|
||||
notification.DeliveredOn = DateTime.UtcNow;
|
||||
Notifications.UpdateNotification(notification);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Oqtane.Repository
|
|||
{
|
||||
username = _accessor.HttpContext.User.Identity.Name;
|
||||
}
|
||||
DateTime date = DateTime.Now;
|
||||
DateTime date = DateTime.UtcNow;
|
||||
|
||||
var created = ChangeTracker.Entries()
|
||||
.Where(x => x.State == EntityState.Added);
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Oqtane.Repository
|
|||
Page UpdatePage(Page Page);
|
||||
Page GetPage(int PageId);
|
||||
Page GetPage(int PageId, int UserId);
|
||||
Page GetPage(string Path, int SiteId);
|
||||
void DeletePage(int PageId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,39 +53,43 @@ namespace Oqtane.Repository
|
|||
{
|
||||
List<ModuleDefinition> ModuleDefinitions;
|
||||
|
||||
// get run-time module definitions
|
||||
ModuleDefinitions = _cache.GetOrCreate("moduledefinitions", entry =>
|
||||
{
|
||||
entry.SlidingExpiration = TimeSpan.FromMinutes(30);
|
||||
return LoadModuleDefinitionsFromAssemblies();
|
||||
});
|
||||
|
||||
// sync module definitions with database
|
||||
List<ModuleDefinition> moduledefs = _db.ModuleDefinition.ToList();
|
||||
// get module defintion permissions for site
|
||||
List<Permission> permissions = _permissions.GetPermissions(SiteId, "ModuleDefinition").ToList();
|
||||
|
||||
// get module definitions in database
|
||||
List<ModuleDefinition> moduledefs = _db.ModuleDefinition.ToList();
|
||||
|
||||
// sync run-time module definitions with database
|
||||
foreach (ModuleDefinition moduledefinition in ModuleDefinitions)
|
||||
{
|
||||
ModuleDefinition moduledef = moduledefs.Where(item => item.ModuleDefinitionName == moduledefinition.ModuleDefinitionName).FirstOrDefault();
|
||||
if (moduledef == null)
|
||||
{
|
||||
// new module definition
|
||||
moduledef = new ModuleDefinition { ModuleDefinitionName = moduledefinition.ModuleDefinitionName };
|
||||
_db.ModuleDefinition.Add(moduledef);
|
||||
_db.SaveChanges();
|
||||
if (moduledefinition.Permissions != "")
|
||||
{
|
||||
_permissions.UpdatePermissions(SiteId, "ModuleDefinition", moduledef.ModuleDefinitionId, moduledefinition.Permissions);
|
||||
foreach(Permission permission in _permissions.GetPermissions("ModuleDefinition", moduledef.ModuleDefinitionId))
|
||||
{
|
||||
permissions.Add(permission);
|
||||
}
|
||||
}
|
||||
_permissions.UpdatePermissions(SiteId, "ModuleDefinition", moduledef.ModuleDefinitionId, moduledefinition.Permissions);
|
||||
}
|
||||
else
|
||||
{
|
||||
moduledefs.Remove(moduledef); // remove module definition from list
|
||||
// existing module definition
|
||||
if (permissions.Count == 0)
|
||||
{
|
||||
_permissions.UpdatePermissions(SiteId, "ModuleDefinition", moduledef.ModuleDefinitionId, moduledefinition.Permissions);
|
||||
}
|
||||
// remove module definition from list
|
||||
moduledefs.Remove(moduledef);
|
||||
}
|
||||
moduledefinition.ModuleDefinitionId = moduledef.ModuleDefinitionId;
|
||||
moduledefinition.SiteId = SiteId;
|
||||
moduledefinition.Permissions = _permissions.EncodePermissions(moduledefinition.ModuleDefinitionId, permissions);
|
||||
moduledefinition.CreatedBy = moduledef.CreatedBy;
|
||||
moduledefinition.CreatedOn = moduledef.CreatedOn;
|
||||
moduledefinition.ModifiedBy = moduledef.ModifiedBy;
|
||||
|
|
|
@ -75,6 +75,17 @@ namespace Oqtane.Repository
|
|||
return page;
|
||||
}
|
||||
|
||||
public Page GetPage(string Path, int SiteId)
|
||||
{
|
||||
Page page = _db.Page.Where(item => item.Path == Path && item.SiteId == SiteId).FirstOrDefault();
|
||||
if (page != null)
|
||||
{
|
||||
IEnumerable<Permission> permissions = _permissions.GetPermissions("Page", page.PageId).ToList();
|
||||
page.Permissions = _permissions.EncodePermissions(page.PageId, permissions);
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
public void DeletePage(int PageId)
|
||||
{
|
||||
Page Page = _db.Page.Find(PageId);
|
||||
|
|
Loading…
Reference in New Issue
Block a user