delete files on user delete (#1452)

fixes #1451
(I did not do a cascade delete for 2 reasons: Sqlite does not support the migration easily to alter a foreign key AND files would be orphaned in the storage with no record in the db)
This commit is contained in:
Andrew Camilleri 2020-04-09 15:17:06 +02:00 committed by GitHub
parent c7a4158a39
commit bb24c95e71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -348,6 +348,14 @@ namespace BTCPayServer.Controllers
var user = userId == null ? null : await _UserManager.FindByIdAsync(userId);
if (user == null)
return NotFound();
var files = await _StoredFileRepository.GetFiles(new StoredFileRepository.FilesQuery()
{
UserIds = new[] {userId},
});
await Task.WhenAll(files.Select(file => _FileService.RemoveFile(file.Id, userId)));
await _UserManager.DeleteAsync(user);
await _StoreRepository.CleanUnreachableStores();
TempData[WellKnownTempData.SuccessMessage] = "User deleted";