Updates
Loops tighter Updated Logout base SiteController corrected.
This commit is contained in:
@ -56,11 +56,12 @@ namespace Oqtane.Themes.Controls
|
|||||||
var url = route.PathAndQuery;
|
var url = route.PathAndQuery;
|
||||||
|
|
||||||
// verify if anonymous users can access page
|
// verify if anonymous users can access page
|
||||||
if (!UserSecurity.IsAuthorized(null, PermissionNames.View, PageState.Page.PermissionList))
|
if (!UserSecurity.IsAuthorized(null, PermissionNames.View, PageState.Page.PermissionList) || !Utilities.IsPageModuleVisible(PageState.Page.EffectiveDate, PageState.Page.ExpiryDate))
|
||||||
{
|
{
|
||||||
url = PageState.Alias.Path;
|
url = PageState.Alias.Path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (PageState.Runtime == Shared.Runtime.Hybrid)
|
if (PageState.Runtime == Shared.Runtime.Hybrid)
|
||||||
{
|
{
|
||||||
// hybrid apps utilize an interactive logout
|
// hybrid apps utilize an interactive logout
|
||||||
|
@ -259,19 +259,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isAdminOrHost = false;
|
if (page != null)
|
||||||
if(user != null)
|
|
||||||
{
|
|
||||||
isAdminOrHost = UserSecurity.IsAuthorized(user, RoleNames.Admin) || UserSecurity.IsAuthorized(user, PermissionNames.Edit, page.PermissionList);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (page != null && (isAdminOrHost || IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate)))
|
|
||||||
{
|
{
|
||||||
// check if user is authorized to view page
|
// check if user is authorized to view page
|
||||||
if (UserSecurity.IsAuthorized(user, PermissionNames.View, page.PermissionList))
|
if ((Utilities.IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate) || UserSecurity.IsAuthorized(user, PermissionNames.Edit, page.PermissionList)) || UserSecurity.IsAuthorized(user, PermissionNames.View, page.PermissionList))
|
||||||
{
|
{
|
||||||
if (isAdminOrHost || Utilities.ValidateEffectiveExpiryDates(page.EffectiveDate, page.ExpiryDate))
|
// if (UserSecurity.IsAuthorized(user, PermissionNames.Edit, page.PermissionList) || Utilities.ValidateEffectiveExpiryDates(page.EffectiveDate, page.ExpiryDate))
|
||||||
{
|
// {
|
||||||
// load additional metadata for current page
|
// load additional metadata for current page
|
||||||
page = ProcessPage(page, site, user, SiteState.Alias);
|
page = ProcessPage(page, site, user, SiteState.Alias);
|
||||||
|
|
||||||
@ -302,7 +296,7 @@
|
|||||||
|
|
||||||
OnStateChange?.Invoke(_pagestate);
|
OnStateChange?.Invoke(_pagestate);
|
||||||
await ScrollToFragment(_pagestate.Uri);
|
await ScrollToFragment(_pagestate.Uri);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // page not found
|
else // page not found
|
||||||
@ -316,7 +310,7 @@
|
|||||||
}
|
}
|
||||||
else // not mapped
|
else // not mapped
|
||||||
{
|
{
|
||||||
if (user == null && IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate))
|
if (user == null && Utilities.IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate))
|
||||||
{
|
{
|
||||||
// redirect to login page if user not logged in as they may need to be authenticated
|
// 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)));
|
NavigationManager.NavigateTo(Utilities.NavigateUrl(SiteState.Alias.Path, "login", "?returnurl=" + WebUtility.UrlEncode(route.PathAndQuery)));
|
||||||
@ -587,29 +581,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ namespace Oqtane.Controllers
|
|||||||
site.Pages = new List<Page>();
|
site.Pages = new List<Page>();
|
||||||
foreach (Page page in _pages.GetPages(site.SiteId))
|
foreach (Page page in _pages.GetPages(site.SiteId))
|
||||||
{
|
{
|
||||||
if (!page.IsDeleted && _userPermissions.IsAuthorized(User, PermissionNames.View, page.PermissionList))
|
if (!page.IsDeleted && _userPermissions.IsAuthorized(User, PermissionNames.View, page.PermissionList) && (Utilities.IsPageModuleVisible(page.EffectiveDate, page.ExpiryDate) || _userPermissions.IsAuthorized(User, PermissionNames.Edit, page.PermissionList)))
|
||||||
{
|
{
|
||||||
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))
|
.Where(item => !item.IsPrivate || _userPermissions.IsAuthorized(User, PermissionNames.Edit, page.PermissionList))
|
||||||
@ -116,7 +116,7 @@ namespace Oqtane.Controllers
|
|||||||
site.Modules = new List<Module>();
|
site.Modules = new List<Module>();
|
||||||
foreach (PageModule pagemodule in _pageModules.GetPageModules(site.SiteId).Where(pm => !pm.IsDeleted && _userPermissions.IsAuthorized(User, PermissionNames.View, pm.Module.PermissionList)))
|
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(Utilities.IsPageModuleVisible(pagemodule.EffectiveDate, pagemodule.ExpiryDate) || _userPermissions.IsAuthorized(User, PermissionNames.Edit, pagemodule.Module.PermissionList))
|
||||||
{
|
{
|
||||||
Module module = new Module
|
Module module = new Module
|
||||||
{
|
{
|
||||||
|
@ -572,34 +572,54 @@ namespace Oqtane.Shared
|
|||||||
|
|
||||||
return (localDateTime?.Date, localTime);
|
return (localDateTime?.Date, localTime);
|
||||||
}
|
}
|
||||||
|
public static bool IsPageModuleVisible(DateTime? effectiveDate, DateTime? expiryDate)
|
||||||
|
{
|
||||||
|
DateTime currentUtcTime = DateTime.UtcNow;
|
||||||
|
|
||||||
|
if (effectiveDate.HasValue && expiryDate.HasValue)
|
||||||
|
{
|
||||||
|
return currentUtcTime >= effectiveDate.Value && currentUtcTime <= expiryDate.Value;
|
||||||
|
}
|
||||||
|
else if (effectiveDate.HasValue)
|
||||||
|
{
|
||||||
|
return currentUtcTime >= effectiveDate.Value;
|
||||||
|
}
|
||||||
|
else if (expiryDate.HasValue)
|
||||||
|
{
|
||||||
|
// Include equality check here
|
||||||
|
return currentUtcTime <= expiryDate.Value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
public static bool ValidateEffectiveExpiryDates(DateTime? effectiveDate, DateTime? expiryDate)
|
public static bool ValidateEffectiveExpiryDates(DateTime? effectiveDate, DateTime? expiryDate)
|
||||||
{
|
{
|
||||||
// Check if both dates are null, in which case the validation passes
|
// Treat DateTime.MinValue as null
|
||||||
if (effectiveDate == DateTime.MinValue && expiryDate == DateTime.MinValue)
|
effectiveDate ??= DateTime.MinValue;
|
||||||
|
expiryDate ??= DateTime.MinValue;
|
||||||
|
|
||||||
|
// Check if both effectiveDate and expiryDate have values
|
||||||
|
if (effectiveDate != DateTime.MinValue && expiryDate != DateTime.MinValue)
|
||||||
|
{
|
||||||
|
return effectiveDate <= expiryDate;
|
||||||
|
}
|
||||||
|
// Check if only effectiveDate has a value
|
||||||
|
else if (effectiveDate != DateTime.MinValue)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// Check if only expiryDate has a value
|
||||||
// Check if EffectiveDate is not null and ExpiryDate is null
|
else if (expiryDate != DateTime.MinValue)
|
||||||
if (effectiveDate != DateTime.MinValue && expiryDate == DateTime.MinValue)
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// If neither effectiveDate nor expiryDate has a value, consider the page/module visible
|
||||||
// Check if EffectiveDate is null and ExpiryDate is not null
|
else
|
||||||
if (effectiveDate == DateTime.MinValue && expiryDate != DateTime.MinValue)
|
|
||||||
{
|
{
|
||||||
return true;
|
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;
|
|
||||||
}
|
}
|
||||||
[Obsolete("ContentUrl(Alias alias, int fileId) is deprecated. Use FileUrl(Alias alias, int fileId) instead.", false)]
|
[Obsolete("ContentUrl(Alias alias, int fileId) is deprecated. Use FileUrl(Alias alias, int fileId) instead.", false)]
|
||||||
public static string ContentUrl(Alias alias, int fileId)
|
public static string ContentUrl(Alias alias, int fileId)
|
||||||
|
Reference in New Issue
Block a user