diff --git a/Jellyfin.Server.Implementations/Users/UserManager.cs b/Jellyfin.Server.Implementations/Users/UserManager.cs index d05fc2549d..68f038ae82 100644 --- a/Jellyfin.Server.Implementations/Users/UserManager.cs +++ b/Jellyfin.Server.Implementations/Users/UserManager.cs @@ -22,7 +22,6 @@ using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Events; using MediaBrowser.Model.Users; -using Microsoft.EntityFrameworkCore.Internal; using Microsoft.Extensions.Logging; namespace Jellyfin.Server.Implementations.Users @@ -668,6 +667,16 @@ namespace Jellyfin.Server.Implementations.Users dbContext.SaveChanges(); } + public void ClearProfileImage(User user) + { +#nullable disable + // TODO: Remove these when User has nullable annotations + + // Can't just set the value to null, as it hasn't been loaded yet, so EF Core wouldn't see the change + _dbProvider.CreateContext().Entry(user).Reference(u => u.ProfileImage).CurrentValue = null; +#nullable enable + } + private static bool IsValidUsername(string name) { // This is some regex that matches only on unicode "word" characters, as well as -, _ and @ diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index d284dd55cb..fa73dca639 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -489,7 +489,7 @@ namespace MediaBrowser.Api.Images Logger.LogError(e, "Error deleting user profile image:"); } - user.ProfileImage = null; + _userManager.ClearProfileImage(user); _userManager.UpdateUser(user); } diff --git a/MediaBrowser.Controller/Library/IUserManager.cs b/MediaBrowser.Controller/Library/IUserManager.cs index 74f117f151..b5b2e47297 100644 --- a/MediaBrowser.Controller/Library/IUserManager.cs +++ b/MediaBrowser.Controller/Library/IUserManager.cs @@ -175,7 +175,7 @@ namespace MediaBrowser.Controller.Library /// /// This method updates the user's configuration. /// This is only included as a stopgap until the new API, using this internally is not recommended. - /// Instead, modify the user object directlu, then call . + /// Instead, modify the user object directly, then call . /// /// The user's Id. /// The request containing the new user configuration. @@ -184,10 +184,16 @@ namespace MediaBrowser.Controller.Library /// /// This method updates the user's policy. /// This is only included as a stopgap until the new API, using this internally is not recommended. - /// Instead, modify the user object directlu, then call . + /// Instead, modify the user object directly, then call . /// /// The user's Id. /// The request containing the new user policy. void UpdatePolicy(Guid userId, UserPolicy policy); + + /// + /// Clears the user's profile image. + /// + /// The user. + void ClearProfileImage(User user); } }