mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-02-21 22:24:23 +01:00
Fix bug where store was not properly deleted
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<Version>1.0.2.51</Version>
|
||||
<Version>1.0.2.52</Version>
|
||||
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -114,17 +114,34 @@ namespace BTCPayServer.Services.Stores
|
||||
|
||||
public async Task RemoveStoreUser(string storeId, string userId)
|
||||
{
|
||||
bool delete = false;
|
||||
using (var ctx = _ContextFactory.CreateContext())
|
||||
{
|
||||
var userStore = new UserStore() { StoreDataId = storeId, ApplicationUserId = userId };
|
||||
ctx.UserStore.Add(userStore);
|
||||
ctx.Entry<UserStore>(userStore).State = EntityState.Deleted;
|
||||
await ctx.SaveChangesAsync();
|
||||
delete = await ctx.UserStore.Where(u => u.StoreDataId == storeId && u.Role == StoreRoles.Owner).CountAsync() == 0;
|
||||
|
||||
}
|
||||
await DeleteStoreIfOrphan(storeId);
|
||||
}
|
||||
|
||||
private async Task DeleteStoreIfOrphan(string storeId)
|
||||
{
|
||||
using (var ctx = _ContextFactory.CreateContext())
|
||||
{
|
||||
if (ctx.Database.SupportDropForeignKey())
|
||||
{
|
||||
if (await ctx.UserStore.Where(u => u.StoreDataId == storeId && u.Role == StoreRoles.Owner).CountAsync() == 0)
|
||||
{
|
||||
var store = await ctx.Stores.FindAsync(storeId);
|
||||
if (store != null)
|
||||
{
|
||||
ctx.Stores.Remove(store);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (delete)
|
||||
await DeleteStore(storeId);
|
||||
}
|
||||
|
||||
public async Task<StoreData> CreateStore(string ownerId, string name)
|
||||
@@ -162,6 +179,7 @@ namespace BTCPayServer.Services.Stores
|
||||
ctx.UserStore.Remove(storeUser);
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
await DeleteStoreIfOrphan(storeId);
|
||||
}
|
||||
|
||||
public async Task UpdateStore(StoreData store)
|
||||
|
||||
Reference in New Issue
Block a user