Update GetLanguagePermissions to pull out proper backofficeUser if possible
This commit is contained in:
@@ -218,12 +218,23 @@ public class ContentVariantMapper
|
||||
{
|
||||
context.Items.TryGetValue("CurrentUser", out var currentBackofficeUser);
|
||||
|
||||
if (currentBackofficeUser is not IUser currentIUserBackofficeUser)
|
||||
IUser? currentUser = null;
|
||||
|
||||
if (currentBackofficeUser is IUser currentIUserBackofficeUser)
|
||||
{
|
||||
currentUser = currentIUserBackofficeUser;
|
||||
}
|
||||
else if(_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser is not null)
|
||||
{
|
||||
currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser;
|
||||
}
|
||||
|
||||
if (currentUser is null)
|
||||
{
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
IEnumerable<IReadOnlyUserGroup> userGroups = currentIUserBackofficeUser.Groups;
|
||||
IEnumerable<IReadOnlyUserGroup> userGroups = currentUser.Groups;
|
||||
|
||||
// Map allowed actions
|
||||
var hasAccess = false;
|
||||
@@ -274,14 +285,11 @@ public class ContentVariantMapper
|
||||
}
|
||||
|
||||
// A bit of a mess, but we need to ensure that all the required values are here AND that they're the right type.
|
||||
if (context.Items.TryGetValue("CurrentUser", out var userObject) &&
|
||||
context.Items.TryGetValue("Permissions", out var permissionsObject) &&
|
||||
userObject is IUser currentUser &&
|
||||
permissionsObject is Dictionary<string, EntityPermissionSet> permissionsDict)
|
||||
if (context.Items.TryGetValue("Permissions", out var permissionsObject) && permissionsObject is Dictionary<string, EntityPermissionSet> permissionsDict)
|
||||
{
|
||||
// If we already have permissions for a given path,
|
||||
// and the current user is the same as was used to generate the permissions, return the stored permissions.
|
||||
if (currentIUserBackofficeUser.Id == currentUser.Id &&
|
||||
if (_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Id == currentUser.Id &&
|
||||
permissionsDict.TryGetValue(path, out EntityPermissionSet? permissions))
|
||||
{
|
||||
return permissions.GetAllPermissions();
|
||||
@@ -292,6 +300,6 @@ public class ContentVariantMapper
|
||||
// with the IUmbracoContextAccessor. In the meantime, if used outside of a web app this will throw a null
|
||||
// reference exception :(
|
||||
|
||||
return _userService.GetPermissionsForPath(currentIUserBackofficeUser, path).GetAllPermissions();
|
||||
return _userService.GetPermissionsForPath(currentUser, path).GetAllPermissions();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user