Start Date and Expiry Date for Module instances and Pages #3538
This is complete excluding Reporting and Notifications which can be added at a later date. I just really wanted to get the schema and the functionality into place.
This commit is contained in:
parent
b0a079dce9
commit
233f40f3e9
|
@ -48,6 +48,18 @@
|
|||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="effectiveDate" HelpText="The date that this module is active" ResourceKey="EffectiveDate">Effective Date: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input type="date" id="effectiveDate" class="form-control" @bind="@_effectivedate" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="expiryDate" HelpText="The date that this module expires" ResourceKey="ExpiryDate">Expiry Date: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input type="date" id="expiryDate" class="form-control" @bind="@_expirydate" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="allpages" HelpText="Indicate if this module should be displayed on all pages" ResourceKey="DisplayOnAllPages">Display On All Pages? </Label>
|
||||
<div class="col-sm-9">
|
||||
|
@ -141,7 +153,8 @@
|
|||
private DateTime createdon;
|
||||
private string modifiedby;
|
||||
private DateTime modifiedon;
|
||||
|
||||
private DateTime? _effectivedate = null;
|
||||
private DateTime? _expirydate = null;
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_module = ModuleState.ModuleDefinition.Name;
|
||||
|
@ -156,6 +169,8 @@
|
|||
createdon = ModuleState.CreatedOn;
|
||||
modifiedby = ModuleState.ModifiedBy;
|
||||
modifiedon = ModuleState.ModifiedOn;
|
||||
_effectivedate = ModuleState.EffectiveDate;
|
||||
_expirydate = ModuleState.ExpiryDate;
|
||||
|
||||
if (ModuleState.ModuleDefinition != null)
|
||||
{
|
||||
|
@ -214,12 +229,20 @@
|
|||
var interop = new Interop(JSRuntime);
|
||||
if (await interop.FormValid(form))
|
||||
{
|
||||
|
||||
if (!string.IsNullOrEmpty(_title))
|
||||
{
|
||||
if (!ValidateEffectiveExpiryDates(_effectivedate, _expirydate))
|
||||
{
|
||||
AddModuleMessage(SharedLocalizer["Message.EffectiveExpiryDateError"], MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
var pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId);
|
||||
pagemodule.PageId = int.Parse(_pageId);
|
||||
pagemodule.Title = _title;
|
||||
pagemodule.Pane = _pane;
|
||||
pagemodule.EffectiveDate = _effectivedate;
|
||||
pagemodule.ExpiryDate = _expirydate;
|
||||
pagemodule.ContainerType = (_containerType != "-") ? _containerType : string.Empty;
|
||||
if (!string.IsNullOrEmpty(pagemodule.ContainerType) && pagemodule.ContainerType == PageState.Page.DefaultContainerType)
|
||||
{
|
||||
|
@ -269,5 +292,33 @@
|
|||
AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ValidateEffectiveExpiryDates(DateTime? effectiveDate, DateTime? expiryDate)
|
||||
{
|
||||
// Check if both dates are null, in which case the validation passes
|
||||
if (effectiveDate == DateTime.MinValue && expiryDate == DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if EffectiveDate is not null and ExpiryDate is null
|
||||
if (effectiveDate != DateTime.MinValue && expiryDate == DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if EffectiveDate is null and ExpiryDate is not null
|
||||
if (effectiveDate == DateTime.MinValue && expiryDate != DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if ExpiryDate is not null and EffectiveDate is after ExpiryDate
|
||||
if (expiryDate != DateTime.MinValue && effectiveDate != DateTime.MinValue && effectiveDate > expiryDate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If none of the above conditions are met, validation passes
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,6 +119,18 @@
|
|||
<i class="@_icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="effectiveDate" HelpText="The date that this page is active" ResourceKey="EffectiveDate">Effective Date: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input type="date" id="effectiveDate" class="form-control" @bind="@_effectivedate" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="expiryDate" HelpText="The date that this page expires" ResourceKey="ExpiryDate">Expiry Date: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input type="date" id="expiryDate" class="form-control" @bind="@_expirydate" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="personalizable" HelpText="Select whether you would like users to be able to personalize this page with their own content" ResourceKey="Personalizable">Personalizable? </Label>
|
||||
<div class="col-sm-9">
|
||||
|
@ -233,6 +245,8 @@
|
|||
protected Page _parent = null;
|
||||
protected Dictionary<string, string> _icons;
|
||||
private string _iconresources = "";
|
||||
private DateTime? _effectivedate = null;
|
||||
private DateTime? _expirydate = null;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
|
@ -265,6 +279,8 @@
|
|||
_children.Add(p);
|
||||
}
|
||||
}
|
||||
_effectivedate = PageState.Page.EffectiveDate;
|
||||
_expirydate = PageState.Page.ExpiryDate;
|
||||
ThemeSettings();
|
||||
_initialized = true;
|
||||
}
|
||||
|
@ -347,6 +363,11 @@
|
|||
Page page = null;
|
||||
try
|
||||
{
|
||||
if (!ValidateEffectiveExpiryDates(_effectivedate, _expirydate))
|
||||
{
|
||||
AddModuleMessage(SharedLocalizer["Message.EffectiveExpiryDateError"], MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(_themetype) && !string.IsNullOrEmpty(_containertype))
|
||||
{
|
||||
page = new Page();
|
||||
|
@ -421,6 +442,8 @@
|
|||
page.IsClickable = (_isclickable == null ? true : Boolean.Parse(_isclickable));
|
||||
page.Url = _url;
|
||||
page.IsPersonalizable = (_ispersonalizable == null ? false : Boolean.Parse(_ispersonalizable));
|
||||
page.EffectiveDate = _effectivedate;
|
||||
page.ExpiryDate = _expirydate;
|
||||
page.UserId = null;
|
||||
|
||||
// appearance
|
||||
|
@ -490,4 +513,33 @@
|
|||
{
|
||||
_icon = NewIcon;
|
||||
}
|
||||
private bool ValidateEffectiveExpiryDates(DateTime? effectiveDate, DateTime? expiryDate)
|
||||
{
|
||||
// Check if both dates are null, in which case the validation passes
|
||||
if (effectiveDate == DateTime.MinValue && expiryDate == DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if EffectiveDate is not null and ExpiryDate is null
|
||||
if (effectiveDate != DateTime.MinValue && expiryDate == DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if EffectiveDate is null and ExpiryDate is not null
|
||||
if (effectiveDate == DateTime.MinValue && expiryDate != DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if ExpiryDate is not null and EffectiveDate is after ExpiryDate
|
||||
if (expiryDate != DateTime.MinValue && effectiveDate != DateTime.MinValue && effectiveDate > expiryDate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If none of the above conditions are met, validation passes
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,6 +134,18 @@
|
|||
<i class="@_icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="effectiveDate" HelpText="The date that this page is active" ResourceKey="EffectiveDate">Effective Date: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input type="date" id="effectiveDate" class="form-control" @bind="@_effectivedate" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="expiryDate" HelpText="The date that this page expires" ResourceKey="ExpiryDate">Expiry Date: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input type="date" id="expiryDate" class="form-control" @bind="@_expirydate" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="personalizable" HelpText="Select whether you would like users to be able to personalize this page with their own content" ResourceKey="Personalizable">Personalizable? </Label>
|
||||
<div class="col-sm-9">
|
||||
|
@ -322,6 +334,8 @@
|
|||
protected Page _parent = null;
|
||||
protected Dictionary<string, string> _icons;
|
||||
private string _iconresources = "";
|
||||
private DateTime? _effectivedate = null;
|
||||
private DateTime? _expirydate = null;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
|
@ -370,6 +384,8 @@
|
|||
}
|
||||
_url = _page.Url;
|
||||
_icon = _page.Icon;
|
||||
_effectivedate = _page.EffectiveDate;
|
||||
_expirydate = _page.ExpiryDate;
|
||||
_ispersonalizable = _page.IsPersonalizable.ToString();
|
||||
|
||||
// appearance
|
||||
|
@ -487,6 +503,11 @@
|
|||
{
|
||||
try
|
||||
{
|
||||
if (!ValidateEffectiveExpiryDates(_effectivedate, _expirydate))
|
||||
{
|
||||
AddModuleMessage(SharedLocalizer["Message.EffectiveExpiryDateError"], MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(_themetype) && _containertype != "-")
|
||||
{
|
||||
string currentPath = _page.Path;
|
||||
|
@ -563,6 +584,8 @@
|
|||
_page.IsClickable = (_isclickable == null ? true : Boolean.Parse(_isclickable));
|
||||
_page.Url = _url;
|
||||
_page.Icon = _icon ?? string.Empty;
|
||||
_page.EffectiveDate = _effectivedate;
|
||||
_page.ExpiryDate = _expirydate;
|
||||
_page.IsPersonalizable = (_ispersonalizable != null && Boolean.Parse(_ispersonalizable));
|
||||
|
||||
// appearance
|
||||
|
@ -666,4 +689,33 @@
|
|||
{
|
||||
_icon = NewIcon;
|
||||
}
|
||||
private bool ValidateEffectiveExpiryDates(DateTime? effectiveDate, DateTime? expiryDate)
|
||||
{
|
||||
// Check if both dates are null, in which case the validation passes
|
||||
if (effectiveDate == DateTime.MinValue && expiryDate == DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if EffectiveDate is not null and ExpiryDate is null
|
||||
if (effectiveDate != DateTime.MinValue && expiryDate == DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if EffectiveDate is null and ExpiryDate is not null
|
||||
if (effectiveDate == DateTime.MinValue && expiryDate != DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if ExpiryDate is not null and EffectiveDate is after ExpiryDate
|
||||
if (expiryDate != DateTime.MinValue && effectiveDate != DateTime.MinValue && effectiveDate > expiryDate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If none of the above conditions are met, validation passes
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,13 +34,13 @@ else
|
|||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="effectiveDate" HelpText="The date that this role assignment is active" ResourceKey="EffectiveDate">Effective Date: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input type="date" id="effectiveDate" class="form-control" @bind="@effectivedate" />
|
||||
<input type="date" id="effectiveDate" class="form-control" @bind="@_effectivedate" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="expiryDate" HelpText="The date that this role assignment expires" ResourceKey="ExpiryDate">Expiry Date: </Label>
|
||||
<div class="col-sm-9">
|
||||
<input type="date" id="expiryDate" class="form-control" @bind="@expirydate" />
|
||||
<input type="date" id="expiryDate" class="form-control" @bind="@_expirydate" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -75,8 +75,8 @@ else
|
|||
private string name = string.Empty;
|
||||
private List<Role> roles;
|
||||
private int roleid = -1;
|
||||
private DateTime? effectivedate = null;
|
||||
private DateTime? expirydate = null;
|
||||
private DateTime? _effectivedate = null;
|
||||
private DateTime? _expirydate = null;
|
||||
private List<UserRole> userroles;
|
||||
|
||||
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
|
||||
|
@ -127,11 +127,16 @@ else
|
|||
{
|
||||
if (roleid != -1)
|
||||
{
|
||||
if (!ValidateEffectiveExpiryDates(_effectivedate,_expirydate))
|
||||
{
|
||||
AddModuleMessage(SharedLocalizer["Message.EffectiveExpiryDateError"], MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
var userrole = userroles.Where(item => item.UserId == userid && item.RoleId == roleid).FirstOrDefault();
|
||||
if (userrole != null)
|
||||
{
|
||||
userrole.EffectiveDate = effectivedate;
|
||||
userrole.ExpiryDate = expirydate;
|
||||
userrole.EffectiveDate = _effectivedate;
|
||||
userrole.ExpiryDate = _expirydate;
|
||||
await UserRoleService.UpdateUserRoleAsync(userrole);
|
||||
}
|
||||
else
|
||||
|
@ -139,8 +144,8 @@ else
|
|||
userrole = new UserRole();
|
||||
userrole.UserId = userid;
|
||||
userrole.RoleId = roleid;
|
||||
userrole.EffectiveDate = effectivedate;
|
||||
userrole.ExpiryDate = expirydate;
|
||||
userrole.EffectiveDate = _effectivedate;
|
||||
userrole.ExpiryDate = _expirydate;
|
||||
await UserRoleService.AddUserRoleAsync(userrole);
|
||||
}
|
||||
|
||||
|
@ -177,4 +182,34 @@ else
|
|||
AddModuleMessage(Localizer["Error.User.RemoveRole"], MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ValidateEffectiveExpiryDates(DateTime? effectiveDate, DateTime? expiryDate)
|
||||
{
|
||||
// Check if both dates are null, in which case the validation passes
|
||||
if (effectiveDate == DateTime.MinValue && expiryDate == DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if EffectiveDate is not null and ExpiryDate is null
|
||||
if (effectiveDate != DateTime.MinValue && expiryDate == DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if EffectiveDate is null and ExpiryDate is not null
|
||||
if (effectiveDate == DateTime.MinValue && expiryDate != DateTime.MinValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if ExpiryDate is not null and EffectiveDate is after ExpiryDate
|
||||
if (expiryDate != DateTime.MinValue && effectiveDate != DateTime.MinValue && effectiveDate > expiryDate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If none of the above conditions are met, validation passes
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,4 +165,16 @@
|
|||
<data name="Pane.Text" xml:space="preserve">
|
||||
<value>Pane:</value>
|
||||
</data>
|
||||
<data name="EffectiveDate.HelpText" xml:space="preserve">
|
||||
<value>The date that this module is active</value>
|
||||
</data>
|
||||
<data name="EffectiveDate.Text" xml:space="preserve">
|
||||
<value>Effective Date: </value>
|
||||
</data>
|
||||
<data name="ExpiryDate.HelpText" xml:space="preserve">
|
||||
<value>The date that this module expires</value>
|
||||
</data>
|
||||
<data name="ExpiryDate.Text" xml:space="preserve">
|
||||
<value>Expiry Date: </value>
|
||||
</data>
|
||||
</root>
|
|
@ -255,4 +255,16 @@
|
|||
<data name="Theme.Heading" xml:space="preserve">
|
||||
<value>Theme Settings</value>
|
||||
</data>
|
||||
<data name="EffectiveDate.HelpText" xml:space="preserve">
|
||||
<value>The date that this page is active</value>
|
||||
</data>
|
||||
<data name="EffectiveDate.Text" xml:space="preserve">
|
||||
<value>Effective Date: </value>
|
||||
</data>
|
||||
<data name="ExpiryDate.HelpText" xml:space="preserve">
|
||||
<value>The date that this page expires</value>
|
||||
</data>
|
||||
<data name="ExpiryDate.Text" xml:space="preserve">
|
||||
<value>Expiry Date: </value>
|
||||
</data>
|
||||
</root>
|
|
@ -285,4 +285,16 @@
|
|||
<data name="ThemeChanged.Message" xml:space="preserve">
|
||||
<value>Please Note That Overriding The Default Site Theme With An Unrelated Page Theme May Result In Compatibility Issues For Your Site</value>
|
||||
</data>
|
||||
<data name="EffectiveDate.HelpText" xml:space="preserve">
|
||||
<value>The date that this page is active</value>
|
||||
</data>
|
||||
<data name="EffectiveDate.Text" xml:space="preserve">
|
||||
<value>Effective Date: </value>
|
||||
</data>
|
||||
<data name="ExpiryDate.HelpText" xml:space="preserve">
|
||||
<value>The date that this page expires</value>
|
||||
</data>
|
||||
<data name="ExpiryDate.Text" xml:space="preserve">
|
||||
<value>Expiry Date: </value>
|
||||
</data>
|
||||
</root>
|
|
@ -438,4 +438,7 @@
|
|||
<data name="Test" xml:space="preserve">
|
||||
<value>Test</value>
|
||||
</data>
|
||||
<data name="Message.EffectiveExpiryDateError" xml:space="preserve">
|
||||
<value>Effective Date cannot be after Expiry Date.</value>
|
||||
</data>
|
||||
</root>
|
|
@ -259,10 +259,18 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (page != null)
|
||||
bool isAdminOrHost = false;
|
||||
if(user != null)
|
||||
{
|
||||
isAdminOrHost = user.Roles.Contains(RoleNames.Host) || user.Roles.Contains(RoleNames.Admin);
|
||||
}
|
||||
|
||||
if (page != null && (isAdminOrHost || IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate)))
|
||||
{
|
||||
// check if user is authorized to view page
|
||||
if (UserSecurity.IsAuthorized(user, PermissionNames.View, page.PermissionList))
|
||||
{
|
||||
if (isAdminOrHost || IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate))
|
||||
{
|
||||
// load additional metadata for current page
|
||||
page = ProcessPage(page, site, user, SiteState.Alias);
|
||||
|
@ -296,6 +304,7 @@
|
|||
await ScrollToFragment(_pagestate.Uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
else // page not found
|
||||
{
|
||||
// look for url mapping
|
||||
|
@ -307,7 +316,7 @@
|
|||
}
|
||||
else // not mapped
|
||||
{
|
||||
if (user == null)
|
||||
if (user == null && IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate))
|
||||
{
|
||||
// redirect to login page if user not logged in as they may need to be authenticated
|
||||
NavigationManager.NavigateTo(Utilities.NavigateUrl(SiteState.Alias.Path, "login", "?returnurl=" + WebUtility.UrlEncode(route.PathAndQuery)));
|
||||
|
@ -578,4 +587,29 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
private bool IsPageModuleVisible(DateTime? effectiveDate, DateTime? expiryDate)
|
||||
{
|
||||
DateTime currentUtcTime = DateTime.UtcNow;
|
||||
|
||||
// Check if either effectiveDate or expiryDate is provided
|
||||
if (effectiveDate.HasValue && expiryDate.HasValue)
|
||||
{
|
||||
return currentUtcTime >= effectiveDate.Value && currentUtcTime <= expiryDate.Value;
|
||||
}
|
||||
// Check if only effectiveDate is provided
|
||||
else if (effectiveDate.HasValue)
|
||||
{
|
||||
return currentUtcTime >= effectiveDate.Value;
|
||||
}
|
||||
// Check if only expiryDate is provided
|
||||
else if (expiryDate.HasValue)
|
||||
{
|
||||
return currentUtcTime <= expiryDate.Value;
|
||||
}
|
||||
// If neither effectiveDate nor expiryDate is provided, consider the page/module visible
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,8 @@ namespace Oqtane.Controllers
|
|||
module.Pane = pagemodule.Pane;
|
||||
module.Order = pagemodule.Order;
|
||||
module.ContainerType = pagemodule.ContainerType;
|
||||
module.EffectiveDate = pagemodule.EffectiveDate;
|
||||
module.ExpiryDate = pagemodule.ExpiryDate;
|
||||
|
||||
module.ModuleDefinition = _moduleDefinitions.FilterModuleDefinition(moduledefinitions.Find(item => item.ModuleDefinitionName == module.ModuleDefinitionName));
|
||||
|
||||
|
@ -169,7 +171,7 @@ namespace Oqtane.Controllers
|
|||
{
|
||||
if (!pageModules.Exists(item => item.ModuleId == module.ModuleId && item.PageId == page.PageId) && !page.Path.StartsWith("admin/"))
|
||||
{
|
||||
_pageModules.AddPageModule(new PageModule { PageId = page.PageId, ModuleId = pageModule.ModuleId, Title = pageModule.Title, Pane = pageModule.Pane, Order = pageModule.Order, ContainerType = pageModule.ContainerType });
|
||||
_pageModules.AddPageModule(new PageModule { PageId = page.PageId, ModuleId = pageModule.ModuleId, Title = pageModule.Title, Pane = pageModule.Pane, Order = pageModule.Order, ContainerType = pageModule.ContainerType, EffectiveDate = pageModule.EffectiveDate, ExpiryDate = pageModule.ExpiryDate });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ using System.Globalization;
|
|||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Oqtane.Extensions;
|
||||
using System;
|
||||
using Oqtane.UI;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
|
@ -92,59 +94,71 @@ namespace Oqtane.Controllers
|
|||
site.UploadableFiles = site.Settings.ContainsKey("UploadableFiles") && !string.IsNullOrEmpty(site.Settings["UploadableFiles"])
|
||||
? site.Settings["UploadableFiles"] : Constants.UploadableFiles;
|
||||
|
||||
var modelsUser = _userPermissions.GetUser(User);
|
||||
var isAdminOrHost = modelsUser.Roles.Contains(RoleNames.Host) || modelsUser.Roles.Contains(RoleNames.Admin);
|
||||
|
||||
// pages
|
||||
List<Setting> settings = _settings.GetSettings(EntityNames.Page).ToList();
|
||||
site.Pages = new List<Page>();
|
||||
foreach (Page page in _pages.GetPages(site.SiteId))
|
||||
foreach (Page page in _pages.GetPages(site.SiteId).Where(p => !p.IsDeleted && _userPermissions.IsAuthorized(User, PermissionNames.View, p.PermissionList)))
|
||||
{
|
||||
if (!page.IsDeleted && _userPermissions.IsAuthorized(User, PermissionNames.View, page.PermissionList))
|
||||
if (isAdminOrHost || IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate))
|
||||
{
|
||||
page.Settings = settings.Where(item => item.EntityId == page.PageId)
|
||||
page.Settings = settings
|
||||
.Where(item => item.EntityId == page.PageId)
|
||||
.Where(item => !item.IsPrivate || _userPermissions.IsAuthorized(User, PermissionNames.Edit, page.PermissionList))
|
||||
.ToDictionary(setting => setting.SettingName, setting => setting.SettingValue);
|
||||
|
||||
site.Pages.Add(page);
|
||||
}
|
||||
}
|
||||
|
||||
site.Pages = GetPagesHierarchy(site.Pages);
|
||||
|
||||
// modules
|
||||
List<ModuleDefinition> moduledefinitions = _moduleDefinitions.GetModuleDefinitions(site.SiteId).ToList();
|
||||
settings = _settings.GetSettings(EntityNames.Module).ToList();
|
||||
site.Modules = new List<Module>();
|
||||
foreach (PageModule pagemodule in _pageModules.GetPageModules(site.SiteId))
|
||||
foreach (PageModule pagemodule in _pageModules.GetPageModules(site.SiteId).Where(pm => !pm.IsDeleted && _userPermissions.IsAuthorized(User, PermissionNames.View, pm.Module.PermissionList)))
|
||||
{
|
||||
if (!pagemodule.IsDeleted && _userPermissions.IsAuthorized(User, PermissionNames.View, pagemodule.Module.PermissionList))
|
||||
if (isAdminOrHost || IsPageModuleVisible(pagemodule.EffectiveDate, pagemodule.ExpiryDate))
|
||||
{
|
||||
Module module = new Module();
|
||||
module.SiteId = pagemodule.Module.SiteId;
|
||||
module.ModuleDefinitionName = pagemodule.Module.ModuleDefinitionName;
|
||||
module.AllPages = pagemodule.Module.AllPages;
|
||||
module.PermissionList = pagemodule.Module.PermissionList;
|
||||
module.CreatedBy = pagemodule.Module.CreatedBy;
|
||||
module.CreatedOn = pagemodule.Module.CreatedOn;
|
||||
module.ModifiedBy = pagemodule.Module.ModifiedBy;
|
||||
module.ModifiedOn = pagemodule.Module.ModifiedOn;
|
||||
module.DeletedBy = pagemodule.DeletedBy;
|
||||
module.DeletedOn = pagemodule.DeletedOn;
|
||||
module.IsDeleted = pagemodule.IsDeleted;
|
||||
Module module = new Module
|
||||
{
|
||||
SiteId = pagemodule.Module.SiteId,
|
||||
ModuleDefinitionName = pagemodule.Module.ModuleDefinitionName,
|
||||
AllPages = pagemodule.Module.AllPages,
|
||||
PermissionList = pagemodule.Module.PermissionList,
|
||||
CreatedBy = pagemodule.Module.CreatedBy,
|
||||
CreatedOn = pagemodule.Module.CreatedOn,
|
||||
ModifiedBy = pagemodule.Module.ModifiedBy,
|
||||
ModifiedOn = pagemodule.Module.ModifiedOn,
|
||||
DeletedBy = pagemodule.DeletedBy,
|
||||
DeletedOn = pagemodule.DeletedOn,
|
||||
IsDeleted = pagemodule.IsDeleted,
|
||||
|
||||
module.PageModuleId = pagemodule.PageModuleId;
|
||||
module.ModuleId = pagemodule.ModuleId;
|
||||
module.PageId = pagemodule.PageId;
|
||||
module.Title = pagemodule.Title;
|
||||
module.Pane = pagemodule.Pane;
|
||||
module.Order = pagemodule.Order;
|
||||
module.ContainerType = pagemodule.ContainerType;
|
||||
PageModuleId = pagemodule.PageModuleId,
|
||||
ModuleId = pagemodule.ModuleId,
|
||||
PageId = pagemodule.PageId,
|
||||
Title = pagemodule.Title,
|
||||
Pane = pagemodule.Pane,
|
||||
Order = pagemodule.Order,
|
||||
ContainerType = pagemodule.ContainerType,
|
||||
EffectiveDate = pagemodule.EffectiveDate,
|
||||
ExpiryDate = pagemodule.ExpiryDate,
|
||||
|
||||
module.ModuleDefinition = _moduleDefinitions.FilterModuleDefinition(moduledefinitions.Find(item => item.ModuleDefinitionName == module.ModuleDefinitionName));
|
||||
ModuleDefinition = _moduleDefinitions.FilterModuleDefinition(moduledefinitions.Find(item => item.ModuleDefinitionName == pagemodule.Module.ModuleDefinitionName)),
|
||||
|
||||
module.Settings = settings.Where(item => item.EntityId == pagemodule.ModuleId)
|
||||
Settings = settings
|
||||
.Where(item => item.EntityId == pagemodule.ModuleId)
|
||||
.Where(item => !item.IsPrivate || _userPermissions.IsAuthorized(User, PermissionNames.Edit, pagemodule.Module.PermissionList))
|
||||
.ToDictionary(setting => setting.SettingName, setting => setting.SettingValue);
|
||||
.ToDictionary(setting => setting.SettingName, setting => setting.SettingValue)
|
||||
};
|
||||
|
||||
site.Modules.Add(module);
|
||||
}
|
||||
}
|
||||
|
||||
site.Modules = site.Modules.OrderBy(item => item.PageId).ThenBy(item => item.Pane).ThenBy(item => item.Order).ToList();
|
||||
|
||||
// languages
|
||||
|
@ -277,5 +291,30 @@ namespace Oqtane.Controllers
|
|||
}
|
||||
return hierarchy;
|
||||
}
|
||||
private bool IsPageModuleVisible(DateTime? effectiveDate, DateTime? expiryDate)
|
||||
{
|
||||
DateTime currentUtcTime = DateTime.UtcNow;
|
||||
|
||||
// Check if either effectiveDate or expiryDate is provided
|
||||
if (effectiveDate.HasValue && expiryDate.HasValue)
|
||||
{
|
||||
return currentUtcTime >= effectiveDate.Value && currentUtcTime <= expiryDate.Value;
|
||||
}
|
||||
// Check if only effectiveDate is provided
|
||||
else if (effectiveDate.HasValue)
|
||||
{
|
||||
return currentUtcTime >= effectiveDate.Value;
|
||||
}
|
||||
// Check if only expiryDate is provided
|
||||
else if (expiryDate.HasValue)
|
||||
{
|
||||
return currentUtcTime <= expiryDate.Value;
|
||||
}
|
||||
// If neither effectiveDate nor expiryDate is provided, consider the page/module visible
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Databases.Interfaces;
|
||||
using Oqtane.Migrations.EntityBuilders;
|
||||
using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Migrations.Tenant
|
||||
{
|
||||
[DbContext(typeof(TenantDBContext))]
|
||||
[Migration("Tenant.05.01.00.01")]
|
||||
public class AddPageEffectiveExpiryDate : MultiDatabaseMigration
|
||||
{
|
||||
public AddPageEffectiveExpiryDate(IDatabase database) : base(database)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var pageEntityBuilder = new PageEntityBuilder(migrationBuilder, ActiveDatabase);;
|
||||
pageEntityBuilder.AddDateTimeColumn("EffectiveDate", true);
|
||||
pageEntityBuilder.AddDateTimeColumn("ExpiryDate", true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var pageEntityBuilder = new PageEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
pageEntityBuilder.DropColumn("EffectiveDate");
|
||||
pageEntityBuilder.DropColumn("ExpiryDate");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Databases.Interfaces;
|
||||
using Oqtane.Migrations.EntityBuilders;
|
||||
using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Migrations.Tenant
|
||||
{
|
||||
[DbContext(typeof(TenantDBContext))]
|
||||
[Migration("Tenant.05.01.00.02")]
|
||||
public class AddPageModuleEffectiveExpiryDate : MultiDatabaseMigration
|
||||
{
|
||||
public AddPageModuleEffectiveExpiryDate(IDatabase database) : base(database)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var pageModuleEntityBuilder = new PageModuleEntityBuilder(migrationBuilder, ActiveDatabase);;
|
||||
pageModuleEntityBuilder.AddDateTimeColumn("EffectiveDate", true);
|
||||
pageModuleEntityBuilder.AddDateTimeColumn("ExpiryDate", true);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var pageModuleEntityBuilder = new PageModuleEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
pageModuleEntityBuilder.DropColumn("EffectiveDate");
|
||||
pageModuleEntityBuilder.DropColumn("ExpiryDate");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -75,6 +75,12 @@ namespace Oqtane.Models
|
|||
[NotMapped]
|
||||
public string ContainerType { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public DateTime? EffectiveDate { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public DateTime? ExpiryDate { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region SiteRouter properties
|
||||
|
|
|
@ -82,6 +82,14 @@ namespace Oqtane.Models
|
|||
public bool IsNavigation { get; set; }
|
||||
public bool IsClickable { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
/// <summary>
|
||||
/// Start of when this assignment is valid. See also <see cref="ExpiryDate"/>
|
||||
/// </summary>
|
||||
public DateTime? EffectiveDate { get; set; }
|
||||
/// <summary>
|
||||
/// End of when this assignment is valid. See also <see cref="EffectiveDate"/>
|
||||
/// </summary>
|
||||
public DateTime? ExpiryDate { get; set; }
|
||||
public bool IsPersonalizable { get; set; }
|
||||
|
||||
#region IDeletable Properties
|
||||
|
|
|
@ -41,7 +41,14 @@ namespace Oqtane.Models
|
|||
/// Reference to a Razor Container which wraps this module instance.
|
||||
/// </summary>
|
||||
public string ContainerType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Start of when this assignment is valid. See also <see cref="ExpiryDate"/>
|
||||
/// </summary>
|
||||
public DateTime? EffectiveDate { get; set; }
|
||||
/// <summary>
|
||||
/// End of when this assignment is valid. See also <see cref="EffectiveDate"/>
|
||||
/// </summary>
|
||||
public DateTime? ExpiryDate { get; set; }
|
||||
#region IDeletable Properties
|
||||
|
||||
public string DeletedBy { get; set; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user