diff --git a/src/Umbraco.Cms.Api.Management/Controllers/User/UserOrCurrentUserControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/User/UserOrCurrentUserControllerBase.cs index 3cad4367ca..7e5488a20c 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/User/UserOrCurrentUserControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/User/UserOrCurrentUserControllerBase.cs @@ -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.") diff --git a/src/Umbraco.Core/Services/OperationStatus/UserOperationStatus.cs b/src/Umbraco.Core/Services/OperationStatus/UserOperationStatus.cs index c26398b8c3..d3bac8615a 100644 --- a/src/Umbraco.Core/Services/OperationStatus/UserOperationStatus.cs +++ b/src/Umbraco.Core/Services/OperationStatus/UserOperationStatus.cs @@ -34,6 +34,7 @@ public enum UserOperationStatus MediaStartNodeNotFound, ContentNodeNotFound, MediaNodeNotFound, + NodeNotFound, UnknownFailure, CannotPasswordReset, NotInInviteState, diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index 6992f80465..cf58ec20ef 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -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 idKeyMap = new(); + foreach (Guid key in keys) + { + IEntitySlim? entity = _entityService.Get(key); + + if (entity is null) + { + return Attempt.FailWithStatus(UserOperationStatus.NodeNotFound, Enumerable.Empty()); + } + + idKeyMap[entity.Id] = key; + } EntityPermissionCollection permissionCollection = _userGroupRepository.GetPermissions(user.Groups.ToArray(), true, idKeyMap.Keys.ToArray());