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:
parent
4578afcd7a
commit
18926765d3
@ -45,7 +45,9 @@ public interface IUserService
|
|||||||
Task<string> GenerateUserTokenAsync(User user, string tokenProvider, string purpose);
|
Task<string> GenerateUserTokenAsync(User user, string tokenProvider, string purpose);
|
||||||
Task<IdentityResult> DeleteAsync(User user);
|
Task<IdentityResult> DeleteAsync(User user);
|
||||||
Task<IdentityResult> DeleteAsync(User user, string token);
|
Task<IdentityResult> DeleteAsync(User user, string token);
|
||||||
|
#nullable enable
|
||||||
Task<IEnumerable<(Guid UserId, string? ErrorMessage)>> DeleteManyAsync(IEnumerable<User> users);
|
Task<IEnumerable<(Guid UserId, string? ErrorMessage)>> DeleteManyAsync(IEnumerable<User> users);
|
||||||
|
#nullable disable
|
||||||
Task SendDeleteConfirmationAsync(string email);
|
Task SendDeleteConfirmationAsync(string email);
|
||||||
Task<Tuple<bool, string>> SignUpPremiumAsync(User user, string paymentToken,
|
Task<Tuple<bool, string>> SignUpPremiumAsync(User user, string paymentToken,
|
||||||
PaymentMethodType paymentMethodType, short additionalStorageGb, UserLicense license,
|
PaymentMethodType paymentMethodType, short additionalStorageGb, UserLicense license,
|
||||||
|
@ -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)
|
public async Task<IEnumerable<(Guid UserId, string? ErrorMessage)>> DeleteManyAsync(IEnumerable<User> users)
|
||||||
{
|
{
|
||||||
var results = await ValidateDeleteUsersAsync(users.ToList());
|
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)
|
foreach (var user in users)
|
||||||
{
|
{
|
||||||
await _referenceEventService.RaiseEventAsync(
|
await _referenceEventService.RaiseEventAsync(
|
||||||
@ -257,6 +260,7 @@ public class UserService : UserManager<User>, IUserService, IDisposable
|
|||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
public async Task<IdentityResult> DeleteAsync(User user, string token)
|
public async Task<IdentityResult> DeleteAsync(User user, string token)
|
||||||
{
|
{
|
||||||
@ -268,6 +272,7 @@ public class UserService : UserManager<User>, IUserService, IDisposable
|
|||||||
return await DeleteAsync(user);
|
return await DeleteAsync(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
private async Task<IEnumerable<(Guid UserId, string? ErrorMessage)>> ValidateDeleteUsersAsync(List<User> users)
|
private async Task<IEnumerable<(Guid UserId, string? ErrorMessage)>> ValidateDeleteUsersAsync(List<User> users)
|
||||||
{
|
{
|
||||||
var userResult = new List<(Guid UserId, string? ErrorMessage)>();
|
var userResult = new List<(Guid UserId, string? ErrorMessage)>();
|
||||||
@ -322,6 +327,7 @@ public class UserService : UserManager<User>, IUserService, IDisposable
|
|||||||
}
|
}
|
||||||
return userResult;
|
return userResult;
|
||||||
}
|
}
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
public async Task SendDeleteConfirmationAsync(string email)
|
public async Task SendDeleteConfirmationAsync(string email)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user