V14: Fix null ref exception in current user permission endpoint (#16286)
* Fix null reference exception * Align behaviour with document and media version
This commit is contained in:
@@ -116,6 +116,10 @@ public abstract class UserOrCurrentUserControllerBase : ManagementApiControllerB
|
||||
.WithTitle("Content node not found")
|
||||
.WithDetail("The specified content node was not found.")
|
||||
.Build()),
|
||||
UserOperationStatus.NodeNotFound => NotFound(problemDetailsBuilder
|
||||
.WithTitle("Node not found")
|
||||
.WithDetail("The specified node was not found.")
|
||||
.Build()),
|
||||
UserOperationStatus.NotInInviteState => BadRequest(problemDetailsBuilder
|
||||
.WithTitle("Invalid user state")
|
||||
.WithDetail("The target user is not in the invite state.")
|
||||
|
||||
@@ -34,6 +34,7 @@ public enum UserOperationStatus
|
||||
MediaStartNodeNotFound,
|
||||
ContentNodeNotFound,
|
||||
MediaNodeNotFound,
|
||||
NodeNotFound,
|
||||
UnknownFailure,
|
||||
CannotPasswordReset,
|
||||
NotInInviteState,
|
||||
|
||||
@@ -13,6 +13,7 @@ using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Exceptions;
|
||||
using Umbraco.Cms.Core.IO;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.Entities;
|
||||
using Umbraco.Cms.Core.Models.Membership;
|
||||
using Umbraco.Cms.Core.Models.TemporaryFile;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
@@ -2339,7 +2340,18 @@ internal class UserService : RepositoryService, IUserService
|
||||
}
|
||||
|
||||
// We don't know what the entity type may be, so we have to get the entire entity :(
|
||||
var idKeyMap = keys.ToDictionary(key => _entityService.Get(key)!.Id);
|
||||
Dictionary<int, Guid> idKeyMap = new();
|
||||
foreach (Guid key in keys)
|
||||
{
|
||||
IEntitySlim? entity = _entityService.Get(key);
|
||||
|
||||
if (entity is null)
|
||||
{
|
||||
return Attempt.FailWithStatus(UserOperationStatus.NodeNotFound, Enumerable.Empty<NodePermissions>());
|
||||
}
|
||||
|
||||
idKeyMap[entity.Id] = key;
|
||||
}
|
||||
|
||||
EntityPermissionCollection permissionCollection = _userGroupRepository.GetPermissions(user.Groups.ToArray(), true, idKeyMap.Keys.ToArray());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user