Merge pull request #278 from sbwalker/master

optimizations and fixes
This commit is contained in:
Shaun Walker 2020-03-11 14:40:08 -04:00 committed by GitHub
commit afd4471b87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 159 additions and 88 deletions

View File

@ -117,7 +117,7 @@
{ {
await logger.LogInformation("Login Successful For Username {Username}", Username); await logger.LogInformation("Login Successful For Username {Username}", Username);
authstateprovider.NotifyAuthenticationChanged(); authstateprovider.NotifyAuthenticationChanged();
NavigationManager.NavigateTo(NavigateUrl(ReturnUrl)); NavigationManager.NavigateTo(NavigateUrl(ReturnUrl, "reload"));
} }
else else
{ {

View File

@ -85,7 +85,7 @@
string name = ""; string name = "";
string type = "LocalDB"; string type = "LocalDB";
string server = "(LocalDb)\\MSSQLLocalDB"; string server = "(LocalDb)\\MSSQLLocalDB";
string database = "Oqtane-" + DateTime.Now.ToString("yyyyMMddHHmm"); string database = "Oqtane-" + DateTime.UtcNow.ToString("yyyyMMddHHmm");
string username = ""; string username = "";
string password = ""; string password = "";
string schema = ""; string schema = "";

View File

@ -81,7 +81,7 @@
notification.Subject = subject; notification.Subject = subject;
notification.Body = body; notification.Body = body;
notification.ParentId = null; notification.ParentId = null;
notification.CreatedOn = DateTime.Now; notification.CreatedOn = DateTime.UtcNow;
notification.IsDelivered = false; notification.IsDelivered = false;
notification.DeliveredOn = null; notification.DeliveredOn = null;

View File

@ -140,7 +140,7 @@
notification.Subject = subject; notification.Subject = subject;
notification.Body = body; notification.Body = body;
notification.ParentId = notificationid; notification.ParentId = notificationid;
notification.CreatedOn = DateTime.Now; notification.CreatedOn = DateTime.UtcNow;
notification.IsDelivered = false; notification.IsDelivered = false;
notification.DeliveredOn = null; notification.DeliveredOn = null;

View File

@ -37,6 +37,6 @@ else
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
WeatherForecastService forecastservice = new WeatherForecastService(); WeatherForecastService forecastservice = new WeatherForecastService();
forecasts = await forecastservice.GetForecastAsync(DateTime.Now); forecasts = await forecastservice.GetForecastAsync(DateTime.UtcNow);
} }
} }

View File

@ -9,6 +9,7 @@ namespace Oqtane.Services
Task<List<Page>> GetPagesAsync(int SiteId); Task<List<Page>> GetPagesAsync(int SiteId);
Task<Page> GetPageAsync(int PageId); Task<Page> GetPageAsync(int PageId);
Task<Page> GetPageAsync(int PageId, int UserId); Task<Page> GetPageAsync(int PageId, int UserId);
Task<Page> GetPageAsync(string Path, int SiteId);
Task<Page> AddPageAsync(Page Page); Task<Page> AddPageAsync(Page Page);
Task<Page> AddPageAsync(int PageId, int UserId); Task<Page> AddPageAsync(int PageId, int UserId);
Task<Page> UpdatePageAsync(Page Page); Task<Page> UpdatePageAsync(Page Page);

View File

@ -59,13 +59,13 @@ namespace Oqtane.Services
public async Task LoadModuleDefinitionsAsync(int SiteId) 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 // download assemblies to browser when running client-side Blazor
var authstateprovider = (IdentityAuthenticationStateProvider)_serviceProvider.GetService(typeof(IdentityAuthenticationStateProvider)); var authstateprovider = (IdentityAuthenticationStateProvider)_serviceProvider.GetService(typeof(IdentityAuthenticationStateProvider));
if (authstateprovider != null) 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 ) // 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(); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Components;
using System.Collections.Generic; using System.Collections.Generic;
using Oqtane.Shared; using Oqtane.Shared;
using System; using System;
using System.Net;
namespace Oqtane.Services namespace Oqtane.Services
{ {
@ -44,6 +45,18 @@ namespace Oqtane.Services
return await _http.GetJsonAsync<Page>(apiurl + "/" + PageId.ToString() + "?userid=" + UserId.ToString()); 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) public async Task<Page> AddPageAsync(Page Page)
{ {
return await _http.PostJsonAsync<Page>(apiurl, Page); return await _http.PostJsonAsync<Page>(apiurl, Page);

View File

@ -76,7 +76,7 @@
<div class="row"> <div class="row">
<div class="col text-center"> <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"> <select class="form-control" @bind="@_moduleType">
<option value="new">Add New Module</option> <option value="new">Add New Module</option>
<option value="existing">Add Existing Module</option> <option value="existing">Add Existing Module</option>

View File

@ -46,7 +46,7 @@
{ {
// client-side Blazor // client-side Blazor
authstateprovider.NotifyAuthenticationChanged(); authstateprovider.NotifyAuthenticationChanged();
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path)); NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "reload"));
} }
} }
} }

View File

@ -11,10 +11,10 @@
</div> </div>
</div> </div>
<hr class="app-rule" /> <hr class="app-rule" />
<h2 class="text-center">Database Configuration</h2> <div class="row justify-content-center">
<div class="row"> <div class="col text-center">
<div class="mx-auto text-center"> <h2>Database Configuration</h2><br />
<table class="form-group" cellpadding="4" cellspacing="4"> <table class="form-group" cellpadding="4" cellspacing="4" style="margin: auto;">
<tbody> <tbody>
<tr> <tr>
<td> <td>
@ -73,12 +73,9 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</div> <div class="col text-center">
<hr class="app-rule" /> <h2>Application Administrator</h2><br />
<h2 class="text-center">Application Administrator</h2> <table class="form-group" cellpadding="4" cellspacing="4" style="margin: auto;">
<div class="row">
<div class="mx-auto text-center">
<table class="form-group" cellpadding="4" cellspacing="4">
<tbody> <tbody>
<tr> <tr>
<td> <td>
@ -116,6 +113,7 @@
</table> </table>
</div> </div>
</div> </div>
<hr class="app-rule" />
<div class="row"> <div class="row">
<div class="mx-auto text-center"> <div class="mx-auto text-center">
<button type="button" class="btn btn-success" @onclick="Install">Install Now</button><br /><br /> <button type="button" class="btn btn-success" @onclick="Install">Install Now</button><br /><br />
@ -128,7 +126,7 @@
@code { @code {
private string DatabaseType = "LocalDB"; private string DatabaseType = "LocalDB";
private string ServerName = "(LocalDb)\\MSSQLLocalDB"; 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 Username = "";
private string Password = ""; private string Password = "";
private string HostUsername = Constants.HostUser; private string HostUsername = Constants.HostUser;

View File

@ -10,6 +10,7 @@
@inject IUserService UserService @inject IUserService UserService
@inject IModuleService ModuleService @inject IModuleService ModuleService
@inject IModuleDefinitionService ModuleDefinitionService @inject IModuleDefinitionService ModuleDefinitionService
@inject ILogService LogService
@implements IHandleAfterRender @implements IHandleAfterRender
@DynamicComponent @DynamicComponent
@ -75,7 +76,6 @@
int moduleid = -1; int moduleid = -1;
string action = ""; string action = "";
bool editmode = false; bool editmode = false;
int userid = -1;
Reload reload = Reload.None; Reload reload = Reload.None;
DateTime lastsyncdate = DateTime.UtcNow; DateTime lastsyncdate = DateTime.UtcNow;
@ -94,23 +94,39 @@
path = path.Substring(0, path.IndexOf("?")); 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) if (PageState != null)
{ {
editmode = PageState.EditMode; editmode = PageState.EditMode;
lastsyncdate = PageState.LastSyncDate; lastsyncdate = PageState.LastSyncDate;
if (PageState.User != null)
{
userid = PageState.User.UserId;
}
} }
alias = await AliasService.GetAliasAsync(_absoluteUri, lastsyncdate); alias = await AliasService.GetAliasAsync(_absoluteUri, lastsyncdate);
SiteState.Alias = alias; // set state for services SiteState.Alias = alias; // set state for services
lastsyncdate = alias.SyncDate; 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); site = await SiteService.GetSiteAsync(alias.SiteId, alias);
reload = Reload.Site;
} }
else else
{ {
@ -118,29 +134,24 @@
} }
if (site != null) if (site != null)
{ {
// get user if (PageState == null || reload == Reload.Site)
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState.User.Identity.IsAuthenticated)
{ {
user = await UserService.GetUserAsync(authState.User.Identity.Name, site.SiteId); // get user
if (user != null) var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState.User.Identity.IsAuthenticated)
{ {
userid = user.UserId; user = await UserService.GetUserAsync(authState.User.Identity.Name, site.SiteId);
} }
} }
else
// process sync events
if (alias.SyncEvents.Any())
{ {
if (PageState != null && alias.SyncEvents.Exists(item => item.EntityName == "Page" && item.EntityId == PageState.Page.PageId)) user = PageState.User;
{ }
reload = Reload.Page;
} // process any sync events for user
if (alias.SyncEvents.Exists(item => item.EntityName == "Site" && item.EntityId == alias.SiteId)) if (reload != Reload.Site && user != null && alias.SyncEvents.Any())
{ {
reload = Reload.Site; if (alias.SyncEvents.Exists(item => item.EntityName == "User" && item.EntityId == user.UserId))
}
if (alias.SyncEvents.Exists(item => item.EntityName == "User" && item.EntityId == userid))
{ {
reload = Reload.Site; reload = Reload.Site;
} }
@ -148,7 +159,7 @@
if (PageState == null || reload >= Reload.Site) if (PageState == null || reload >= Reload.Site)
{ {
await ModuleDefinitionService.LoadModuleDefinitionsAsync(site.SiteId); await ModuleDefinitionService.LoadModuleDefinitionsAsync(site.SiteId);
pages = await PageService.GetPagesAsync(site.SiteId); pages = await PageService.GetPagesAsync(site.SiteId);
} }
else else
@ -206,7 +217,7 @@
{ {
page = pages.Where(item => item.Path == path).FirstOrDefault(); page = pages.Where(item => item.Path == path).FirstOrDefault();
reload = Reload.Page; reload = Reload.Page;
if (page!=null) if (page != null)
{ {
editmode = page.EditMode; editmode = page.EditMode;
} }
@ -255,21 +266,23 @@
OnStateChange?.Invoke(pagestate); OnStateChange?.Invoke(pagestate);
} }
else
{
// user is not authorized to view page
if (path != "")
{
NavigationManager.NavigateTo("");
}
}
} }
else else
{ {
// page does not exist if (user == null)
if (path != "")
{ {
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, "", ""));
}
} }
} }
} }

View File

@ -312,8 +312,8 @@ namespace Oqtane.Controllers
fileparts = Directory.GetFiles(folder, "*" + token + "*"); fileparts = Directory.GetFiles(folder, "*" + token + "*");
foreach (string filepart in fileparts) foreach (string filepart in fileparts)
{ {
DateTime createddate = System.IO.File.GetCreationTime(filepart); DateTime createddate = System.IO.File.GetCreationTime(filepart).ToUniversalTime();
if (createddate < DateTime.Now.AddHours(-2)) if (createddate < DateTime.UtcNow.AddHours(-2))
{ {
System.IO.File.Delete(filepart); System.IO.File.Delete(filepart);
} }

View File

@ -224,7 +224,7 @@ namespace Oqtane.Controllers
{ {
version = new ApplicationVersion(); version = new ApplicationVersion();
version.Version = Constants.Version; version.Version = Constants.Version;
version.CreatedOn = DateTime.Now; version.CreatedOn = DateTime.UtcNow;
db.ApplicationVersion.Add(version); db.ApplicationVersion.Add(version);
db.SaveChanges(); db.SaveChanges();
} }

View File

@ -7,6 +7,7 @@ using Oqtane.Shared;
using System.Linq; using System.Linq;
using Oqtane.Infrastructure; using Oqtane.Infrastructure;
using Oqtane.Security; using Oqtane.Security;
using System.Net;
namespace Oqtane.Controllers 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> // POST api/<controller>
[HttpPost] [HttpPost]
[Authorize(Roles = Constants.RegisteredRole)] [Authorize(Roles = Constants.RegisteredRole)]

View File

@ -111,7 +111,7 @@ namespace Oqtane.Controllers
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.Now; notification.CreatedOn = DateTime.UtcNow;
notification.IsDelivered = false; notification.IsDelivered = false;
notification.DeliveredOn = null; notification.DeliveredOn = null;
_notifications.AddNotification(notification); _notifications.AddNotification(notification);
@ -240,10 +240,9 @@ namespace Oqtane.Controllers
if (identityuser.EmailConfirmed) if (identityuser.EmailConfirmed)
{ {
user.IsAuthenticated = true; user.IsAuthenticated = true;
user.LastLoginOn = DateTime.Now; user.LastLoginOn = DateTime.UtcNow;
user.LastIPAddress = HttpContext.Connection.RemoteIpAddress.ToString(); user.LastIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
_users.UpdateUser(user); _users.UpdateUser(user);
_syncManager.AddSyncEvent("User", user.UserId);
_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)
{ {
@ -272,7 +271,6 @@ namespace Oqtane.Controllers
public async Task Logout([FromBody] User User) public async Task Logout([FromBody] User User)
{ {
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme); await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
_syncManager.AddSyncEvent("User", User.UserId);
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Logout {Username}", User.Username); _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); 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.Now; notification.CreatedOn = DateTime.UtcNow;
notification.IsDelivered = false; notification.IsDelivered = false;
notification.DeliveredOn = null; notification.DeliveredOn = null;
_notifications.AddNotification(notification); _notifications.AddNotification(notification);

View File

@ -12,11 +12,13 @@ namespace Oqtane.Controllers
public class UserRoleController : Controller public class UserRoleController : Controller
{ {
private readonly IUserRoleRepository _userRoles; private readonly IUserRoleRepository _userRoles;
private readonly ISyncManager _syncManager;
private readonly ILogManager _logger; private readonly ILogManager _logger;
public UserRoleController(IUserRoleRepository userRoles, ILogManager logger) public UserRoleController(IUserRoleRepository userRoles, ISyncManager syncManager, ILogManager logger)
{ {
_userRoles = userRoles; _userRoles = userRoles;
_syncManager = syncManager;
_logger = logger; _logger = logger;
} }
@ -44,6 +46,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
UserRole = _userRoles.AddUserRole(UserRole); UserRole = _userRoles.AddUserRole(UserRole);
_syncManager.AddSyncEvent("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;
@ -57,6 +60,7 @@ namespace Oqtane.Controllers
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
UserRole = _userRoles.UpdateUserRole(UserRole); UserRole = _userRoles.UpdateUserRole(UserRole);
_syncManager.AddSyncEvent("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;
@ -67,8 +71,10 @@ namespace Oqtane.Controllers
[Authorize(Roles = Constants.AdminRole)] [Authorize(Roles = Constants.AdminRole)]
public void Delete(int id) public void Delete(int id)
{ {
UserRole userRole = _userRoles.GetUserRole(id);
_userRoles.DeleteUserRole(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);
} }
} }
} }

View File

@ -50,19 +50,19 @@ namespace Oqtane.Infrastructure
} }
else else
{ {
Job.NextExecution = DateTime.Now; Job.NextExecution = DateTime.UtcNow;
} }
} }
// determine if the job should be run // 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>(); 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.Now; log.StartDate = DateTime.UtcNow;
log.FinishDate = null; log.FinishDate = null;
log.Succeeded = false; log.Succeeded = false;
log.Notes = ""; log.Notes = "";
@ -85,7 +85,7 @@ namespace Oqtane.Infrastructure
} }
// update the job log // update the job log
log.FinishDate = DateTime.Now; log.FinishDate = DateTime.UtcNow;
JobLogs.UpdateJobLog(log); JobLogs.UpdateJobLog(log);
// update the job // update the job
@ -132,9 +132,9 @@ namespace Oqtane.Infrastructure
NextExecution = NextExecution.AddMonths(Interval); NextExecution = NextExecution.AddMonths(Interval);
break; break;
} }
if (NextExecution < DateTime.Now) if (NextExecution < DateTime.UtcNow)
{ {
NextExecution = DateTime.Now; NextExecution = DateTime.UtcNow;
} }
return NextExecution; return NextExecution;
} }

View File

@ -95,7 +95,7 @@ namespace Oqtane.Infrastructure
client.Send(mailMessage); client.Send(mailMessage);
sent = sent++; sent = sent++;
notification.IsDelivered = true; notification.IsDelivered = true;
notification.DeliveredOn = DateTime.Now; notification.DeliveredOn = DateTime.UtcNow;
Notifications.UpdateNotification(notification); Notifications.UpdateNotification(notification);
} }
catch (Exception ex) catch (Exception ex)

View File

@ -30,7 +30,7 @@ namespace Oqtane.Repository
{ {
username = _accessor.HttpContext.User.Identity.Name; username = _accessor.HttpContext.User.Identity.Name;
} }
DateTime date = DateTime.Now; DateTime date = DateTime.UtcNow;
var created = ChangeTracker.Entries() var created = ChangeTracker.Entries()
.Where(x => x.State == EntityState.Added); .Where(x => x.State == EntityState.Added);

View File

@ -10,6 +10,7 @@ namespace Oqtane.Repository
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);
void DeletePage(int PageId); void DeletePage(int PageId);
} }
} }

View File

@ -53,39 +53,43 @@ namespace Oqtane.Repository
{ {
List<ModuleDefinition> ModuleDefinitions; List<ModuleDefinition> ModuleDefinitions;
// 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();
}); });
// sync module definitions with database // get module defintion permissions for site
List<ModuleDefinition> moduledefs = _db.ModuleDefinition.ToList();
List<Permission> permissions = _permissions.GetPermissions(SiteId, "ModuleDefinition").ToList(); 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) 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)
{ {
// new module definition
moduledef = new ModuleDefinition { ModuleDefinitionName = moduledefinition.ModuleDefinitionName }; moduledef = new ModuleDefinition { ModuleDefinitionName = moduledefinition.ModuleDefinitionName };
_db.ModuleDefinition.Add(moduledef); _db.ModuleDefinition.Add(moduledef);
_db.SaveChanges(); _db.SaveChanges();
if (moduledefinition.Permissions != "") _permissions.UpdatePermissions(SiteId, "ModuleDefinition", moduledef.ModuleDefinitionId, moduledefinition.Permissions);
{
_permissions.UpdatePermissions(SiteId, "ModuleDefinition", moduledef.ModuleDefinitionId, moduledefinition.Permissions);
foreach(Permission permission in _permissions.GetPermissions("ModuleDefinition", moduledef.ModuleDefinitionId))
{
permissions.Add(permission);
}
}
} }
else 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.ModuleDefinitionId = moduledef.ModuleDefinitionId;
moduledefinition.SiteId = SiteId; moduledefinition.SiteId = SiteId;
moduledefinition.Permissions = _permissions.EncodePermissions(moduledefinition.ModuleDefinitionId, permissions);
moduledefinition.CreatedBy = moduledef.CreatedBy; moduledefinition.CreatedBy = moduledef.CreatedBy;
moduledefinition.CreatedOn = moduledef.CreatedOn; moduledefinition.CreatedOn = moduledef.CreatedOn;
moduledefinition.ModifiedBy = moduledef.ModifiedBy; moduledefinition.ModifiedBy = moduledef.ModifiedBy;

View File

@ -75,6 +75,17 @@ namespace Oqtane.Repository
return page; 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) public void DeletePage(int PageId)
{ {
Page Page = _db.Page.Find(PageId); Page Page = _db.Page.Find(PageId);