1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-11 15:17:44 +01:00

enable nullable, delete only user that pass validation

This commit is contained in:
Brandon 2024-11-25 12:36:43 -05:00
parent 4578afcd7a
commit 18926765d3
No known key found for this signature in database
GPG Key ID: A0E0EF0B207BA40D
2 changed files with 9 additions and 1 deletions

View File

@ -45,7 +45,9 @@ public interface IUserService
Task<string> GenerateUserTokenAsync(User user, string tokenProvider, string purpose);
Task<IdentityResult> DeleteAsync(User user);
Task<IdentityResult> DeleteAsync(User user, string token);
#nullable enable
Task<IEnumerable<(Guid UserId, string? ErrorMessage)>> DeleteManyAsync(IEnumerable<User> users);
#nullable disable
Task SendDeleteConfirmationAsync(string email);
Task<Tuple<bool, string>> SignUpPremiumAsync(User user, string paymentToken,
PaymentMethodType paymentMethodType, short additionalStorageGb, UserLicense license,

View File

@ -243,11 +243,14 @@ public class UserService : UserManager<User>, IUserService, IDisposable
}
}
#nullable enable
public async Task<IEnumerable<(Guid UserId, string? ErrorMessage)>> DeleteManyAsync(IEnumerable<User> users)
{
var results = await ValidateDeleteUsersAsync(users.ToList());
await _userRepository.DeleteManyAsync(users);
var usersToDelete = users.Where(user => results.Select(r => r.UserId == user.Id && string.IsNullOrEmpty(r.ErrorMessage)).Count() > 1);
await _userRepository.DeleteManyAsync(usersToDelete);
foreach (var user in users)
{
await _referenceEventService.RaiseEventAsync(
@ -257,6 +260,7 @@ public class UserService : UserManager<User>, IUserService, IDisposable
return results;
}
#nullable disable
public async Task<IdentityResult> DeleteAsync(User user, string token)
{
@ -268,6 +272,7 @@ public class UserService : UserManager<User>, IUserService, IDisposable
return await DeleteAsync(user);
}
#nullable enable
private async Task<IEnumerable<(Guid UserId, string? ErrorMessage)>> ValidateDeleteUsersAsync(List<User> users)
{
var userResult = new List<(Guid UserId, string? ErrorMessage)>();
@ -322,6 +327,7 @@ public class UserService : UserManager<User>, IUserService, IDisposable
}
return userResult;
}
#nullable disable
public async Task SendDeleteConfirmationAsync(string email)
{