mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01: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
|
||||
return Task.FromResult(0);
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
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()
|
||||
|
@ -83,10 +83,27 @@ namespace Bit.Core.Repositories.EntityFramework
|
||||
}
|
||||
}
|
||||
|
||||
public Task UpdateStorageAsync(Guid id)
|
||||
public async Task UpdateStorageAsync(Guid id)
|
||||
{
|
||||
// TODO
|
||||
return Task.FromResult(0);
|
||||
using(var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user