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:
@ -258,42 +258,51 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool isAdminOrHost = false;
|
||||
if(user != null)
|
||||
{
|
||||
isAdminOrHost = user.Roles.Contains(RoleNames.Host) || user.Roles.Contains(RoleNames.Admin);
|
||||
}
|
||||
|
||||
if (page != null)
|
||||
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))
|
||||
{
|
||||
// load additional metadata for current page
|
||||
page = ProcessPage(page, site, user, SiteState.Alias);
|
||||
|
||||
// load additional metadata for modules
|
||||
(page, site.Modules) = ProcessModules(page, site.Modules, moduleid, action, (!string.IsNullOrEmpty(page.DefaultContainerType)) ? page.DefaultContainerType : site.DefaultContainerType, SiteState.Alias);
|
||||
|
||||
// populate page state (which acts as a client-side cache for subsequent requests)
|
||||
_pagestate = new PageState
|
||||
if (isAdminOrHost || IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate))
|
||||
{
|
||||
Alias = SiteState.Alias,
|
||||
Site = site,
|
||||
Page = page,
|
||||
User = user,
|
||||
Uri = new Uri(_absoluteUri, UriKind.Absolute),
|
||||
Route = route,
|
||||
QueryString = querystring,
|
||||
UrlParameters = route.UrlParameters,
|
||||
ModuleId = moduleid,
|
||||
Action = action,
|
||||
EditMode = editmode,
|
||||
LastSyncDate = lastsyncdate,
|
||||
Runtime = runtime,
|
||||
VisitorId = VisitorId,
|
||||
RemoteIPAddress = SiteState.RemoteIPAddress,
|
||||
ReturnUrl = returnurl,
|
||||
IsInternalNavigation = _isInternalNavigation
|
||||
};
|
||||
// load additional metadata for current page
|
||||
page = ProcessPage(page, site, user, SiteState.Alias);
|
||||
|
||||
OnStateChange?.Invoke(_pagestate);
|
||||
await ScrollToFragment(_pagestate.Uri);
|
||||
// load additional metadata for modules
|
||||
(page, site.Modules) = ProcessModules(page, site.Modules, moduleid, action, (!string.IsNullOrEmpty(page.DefaultContainerType)) ? page.DefaultContainerType : site.DefaultContainerType, SiteState.Alias);
|
||||
|
||||
// populate page state (which acts as a client-side cache for subsequent requests)
|
||||
_pagestate = new PageState
|
||||
{
|
||||
Alias = SiteState.Alias,
|
||||
Site = site,
|
||||
Page = page,
|
||||
User = user,
|
||||
Uri = new Uri(_absoluteUri, UriKind.Absolute),
|
||||
Route = route,
|
||||
QueryString = querystring,
|
||||
UrlParameters = route.UrlParameters,
|
||||
ModuleId = moduleid,
|
||||
Action = action,
|
||||
EditMode = editmode,
|
||||
LastSyncDate = lastsyncdate,
|
||||
Runtime = runtime,
|
||||
VisitorId = VisitorId,
|
||||
RemoteIPAddress = SiteState.RemoteIPAddress,
|
||||
ReturnUrl = returnurl,
|
||||
IsInternalNavigation = _isInternalNavigation
|
||||
};
|
||||
|
||||
OnStateChange?.Invoke(_pagestate);
|
||||
await ScrollToFragment(_pagestate.Uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
else // page not found
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user