Fix remove and enable issues with non-last-admin

"Remove" issue likely due to multiple context instances. "Enable" issue due to conditional check.

Discovered bug with users when first disabling, then marking as admin, which remains an issue.
This commit is contained in:
rustywave 2022-06-03 22:10:08 -07:00 committed by Andrew Camilleri
parent f2aa4d4484
commit a443426d83

View File

@ -109,6 +109,7 @@ namespace BTCPayServer.Services
await Task.WhenAll(files.Select(file => _fileService.RemoveFile(file.Id, userId))); await Task.WhenAll(files.Select(file => _fileService.RemoveFile(file.Id, userId)));
user = await _userManager.FindByIdAsync(userId);
await _userManager.DeleteAsync(user); await _userManager.DeleteAsync(user);
await _storeRepository.CleanUnreachableStores(); await _storeRepository.CleanUnreachableStores();
} }
@ -127,7 +128,12 @@ namespace BTCPayServer.Services
return false; return false;
} }
return (await _userManager.GetUsersInRoleAsync(Roles.ServerAdmin)).Count(applicationUser => !IsDisabled(applicationUser)) == 1; var adminUsers = await _userManager.GetUsersInRoleAsync(Roles.ServerAdmin);
var enabledAdminUsers = adminUsers
.Where(applicationUser => !IsDisabled(applicationUser))
.Select(applicationUser => applicationUser.Id).ToList();
return enabledAdminUsers.Count == 1 && enabledAdminUsers.Contains(user.Id);
} }
} }
} }