浏览代码

Properly remove profile images

Patrick Barron 5 年之前
父节点
当前提交
7fba0b778e

+ 10 - 1
Jellyfin.Server.Implementations/Users/UserManager.cs

@@ -22,7 +22,6 @@ using MediaBrowser.Model.Cryptography;
 using MediaBrowser.Model.Dto;
 using MediaBrowser.Model.Dto;
 using MediaBrowser.Model.Events;
 using MediaBrowser.Model.Events;
 using MediaBrowser.Model.Users;
 using MediaBrowser.Model.Users;
-using Microsoft.EntityFrameworkCore.Internal;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Logging;
 
 
 namespace Jellyfin.Server.Implementations.Users
 namespace Jellyfin.Server.Implementations.Users
@@ -668,6 +667,16 @@ namespace Jellyfin.Server.Implementations.Users
             dbContext.SaveChanges();
             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)
         private static bool IsValidUsername(string name)
         {
         {
             // This is some regex that matches only on unicode "word" characters, as well as -, _ and @
             // This is some regex that matches only on unicode "word" characters, as well as -, _ and @

+ 1 - 1
MediaBrowser.Api/Images/ImageService.cs

@@ -489,7 +489,7 @@ namespace MediaBrowser.Api.Images
                 Logger.LogError(e, "Error deleting user profile image:");
                 Logger.LogError(e, "Error deleting user profile image:");
             }
             }
 
 
-            user.ProfileImage = null;
+            _userManager.ClearProfileImage(user);
             _userManager.UpdateUser(user);
             _userManager.UpdateUser(user);
         }
         }
 
 

+ 8 - 2
MediaBrowser.Controller/Library/IUserManager.cs

@@ -175,7 +175,7 @@ namespace MediaBrowser.Controller.Library
         /// <summary>
         /// <summary>
         /// This method updates the user's configuration.
         /// This method updates the user's configuration.
         /// This is only included as a stopgap until the new API, using this internally is not recommended.
         /// 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 <see cref="UpdateUser"/>.
+        /// Instead, modify the user object directly, then call <see cref="UpdateUser"/>.
         /// </summary>
         /// </summary>
         /// <param name="userId">The user's Id.</param>
         /// <param name="userId">The user's Id.</param>
         /// <param name="config">The request containing the new user configuration.</param>
         /// <param name="config">The request containing the new user configuration.</param>
@@ -184,10 +184,16 @@ namespace MediaBrowser.Controller.Library
         /// <summary>
         /// <summary>
         /// This method updates the user's policy.
         /// This method updates the user's policy.
         /// This is only included as a stopgap until the new API, using this internally is not recommended.
         /// 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 <see cref="UpdateUser"/>.
+        /// Instead, modify the user object directly, then call <see cref="UpdateUser"/>.
         /// </summary>
         /// </summary>
         /// <param name="userId">The user's Id.</param>
         /// <param name="userId">The user's Id.</param>
         /// <param name="policy">The request containing the new user policy.</param>
         /// <param name="policy">The request containing the new user policy.</param>
         void UpdatePolicy(Guid userId, UserPolicy policy);
         void UpdatePolicy(Guid userId, UserPolicy policy);
+
+        /// <summary>
+        /// Clears the user's profile image.
+        /// </summary>
+        /// <param name="user">The user.</param>
+        void ClearProfileImage(User user);
     }
     }
 }
 }