aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations/Users/UserManager.cs
diff options
context:
space:
mode:
authorPatrick Barron <barronpm@gmail.com>2020-06-24 20:19:47 -0400
committerPatrick Barron <barronpm@gmail.com>2020-06-24 20:19:47 -0400
commit9a01cd8590ffcae8ce561e6f733bf59fe54932fa (patch)
tree1943d76893558bf142b2be9ef7a4b52b0f59840d /Jellyfin.Server.Implementations/Users/UserManager.cs
parent7da49d57b1e976ca9af7dbd226d9887de5c7ffad (diff)
Fix user deletion.
Diffstat (limited to 'Jellyfin.Server.Implementations/Users/UserManager.cs')
-rw-r--r--Jellyfin.Server.Implementations/Users/UserManager.cs19
1 files changed, 14 insertions, 5 deletions
diff --git a/Jellyfin.Server.Implementations/Users/UserManager.cs b/Jellyfin.Server.Implementations/Users/UserManager.cs
index 904114758..d86b25f81 100644
--- a/Jellyfin.Server.Implementations/Users/UserManager.cs
+++ b/Jellyfin.Server.Implementations/Users/UserManager.cs
@@ -192,15 +192,15 @@ namespace Jellyfin.Server.Implementations.Users
}
/// <inheritdoc/>
- public void DeleteUser(User user)
+ public void DeleteUser(Guid userId)
{
+ var dbContext = _dbProvider.CreateContext();
+ var user = dbContext.Users.Find(userId);
if (user == null)
{
- throw new ArgumentNullException(nameof(user));
+ throw new ArgumentNullException(nameof(userId));
}
- var dbContext = _dbProvider.CreateContext();
-
if (dbContext.Users.Find(user.Id) == null)
{
throw new ArgumentException(string.Format(
@@ -226,9 +226,18 @@ namespace Jellyfin.Server.Implementations.Users
CultureInfo.InvariantCulture,
"The user '{0}' cannot be deleted because there must be at least one admin user in the system.",
user.Username),
- nameof(user));
+ nameof(userId));
+ }
+
+ // Clear all entities related to the user from the database.
+ if (user.ProfileImage != null)
+ {
+ dbContext.Remove(user.ProfileImage);
}
+ dbContext.RemoveRange(user.Permissions);
+ dbContext.RemoveRange(user.Preferences);
+ dbContext.RemoveRange(user.AccessSchedules);
dbContext.Users.Remove(user);
dbContext.SaveChanges();
OnUserDeleted?.Invoke(this, new GenericEventArgs<User>(user));