mirror of
https://github.com/bitwarden/server.git
synced 2025-04-07 05:58:13 -05:00
calculate storage updates
This commit is contained in:
parent
5bb440563f
commit
bc0901348b
@ -49,10 +49,28 @@ namespace Bit.Core.Repositories.EntityFramework
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task UpdateStorageAsync(Guid id)
|
public async Task UpdateStorageAsync(Guid id)
|
||||||
{
|
{
|
||||||
// TODO
|
using(var scope = ServiceScopeFactory.CreateScope())
|
||||||
return Task.FromResult(0);
|
{
|
||||||
|
var dbContext = GetDatabaseContext(scope);
|
||||||
|
var ciphers = await dbContext.Ciphers
|
||||||
|
.Where(e => e.UserId == null && e.OrganizationId == id).ToListAsync();
|
||||||
|
var storage = ciphers.Sum(e => e.AttachmentsJson?.RootElement.EnumerateArray()
|
||||||
|
.Sum(p => p.GetProperty("Size").GetInt64()) ?? 0);
|
||||||
|
var organization = new EFModel.Organization
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
RevisionDate = DateTime.UtcNow,
|
||||||
|
Storage = storage,
|
||||||
|
};
|
||||||
|
var set = GetDbSet(dbContext);
|
||||||
|
set.Attach(organization);
|
||||||
|
var entry = dbContext.Entry(organization);
|
||||||
|
entry.Property(e => e.RevisionDate).IsModified = true;
|
||||||
|
entry.Property(e => e.Storage).IsModified = true;
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ICollection<DataModel.OrganizationAbility>> GetManyAbilitiesAsync()
|
public async Task<ICollection<DataModel.OrganizationAbility>> GetManyAbilitiesAsync()
|
||||||
|
@ -83,10 +83,27 @@ namespace Bit.Core.Repositories.EntityFramework
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task UpdateStorageAsync(Guid id)
|
public async Task UpdateStorageAsync(Guid id)
|
||||||
{
|
{
|
||||||
// TODO
|
using(var scope = ServiceScopeFactory.CreateScope())
|
||||||
return Task.FromResult(0);
|
{
|
||||||
|
var dbContext = GetDatabaseContext(scope);
|
||||||
|
var ciphers = await dbContext.Ciphers.Where(e => e.UserId == id).ToListAsync();
|
||||||
|
var storage = ciphers.Sum(e => e.AttachmentsJson?.RootElement.EnumerateArray()
|
||||||
|
.Sum(p => p.GetProperty("Size").GetInt64()) ?? 0);
|
||||||
|
var user = new EFModel.User
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
RevisionDate = DateTime.UtcNow,
|
||||||
|
Storage = storage,
|
||||||
|
};
|
||||||
|
var set = GetDbSet(dbContext);
|
||||||
|
set.Attach(user);
|
||||||
|
var entry = dbContext.Entry(user);
|
||||||
|
entry.Property(e => e.RevisionDate).IsModified = true;
|
||||||
|
entry.Property(e => e.Storage).IsModified = true;
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateRenewalReminderDateAsync(Guid id, DateTime renewalReminderDate)
|
public async Task UpdateRenewalReminderDateAsync(Guid id, DateTime renewalReminderDate)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user