|
|
|
@ -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));
|
|
|
|
|