mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 18:11:36 +01:00
Delete store if no owner
This commit is contained in:
parent
bbd19a96ec
commit
8d3b45bdec
@ -67,7 +67,7 @@ namespace BTCPayServer.HostedServices
|
||||
{
|
||||
if (!ctx.Database.SupportDropForeignKey())
|
||||
return;
|
||||
foreach (var store in await ctx.Stores.Where(s => s.UserStores.Count() == 0).ToArrayAsync())
|
||||
foreach (var store in await ctx.Stores.Where(s => s.UserStores.Where(u => u.Role == StoreRoles.Owner).Count() == 0).ToArrayAsync())
|
||||
{
|
||||
ctx.Stores.Remove(store);
|
||||
}
|
||||
|
@ -114,13 +114,17 @@ 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;
|
||||
}
|
||||
if (delete)
|
||||
await DeleteStore(storeId);
|
||||
}
|
||||
|
||||
public async Task<StoreData> CreateStore(string ownerId, string name)
|
||||
|
Loading…
Reference in New Issue
Block a user