1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 16:42:50 -05:00

[PM-3797 Part 4] Add Sends to new Key Rotation (#3442)

* add send validation

* add send repo methods

* add send rotation to delegate list

* add success test
This commit is contained in:
Jake Fink
2023-12-12 11:58:34 -05:00
committed by GitHub
parent 6a6a29d881
commit ca8e3f496e
13 changed files with 424 additions and 7 deletions

View File

@ -1,6 +1,7 @@
#nullable enable
using AutoMapper;
using Bit.Core.Auth.UserFeatures.UserKey;
using Bit.Core.Tools.Repositories;
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.Repositories;
@ -69,4 +70,28 @@ public class SendRepository : Repository<Core.Tools.Entities.Send, Send, Guid>,
return Mapper.Map<List<Core.Tools.Entities.Send>>(results);
}
}
/// <inheritdoc />
public UpdateEncryptedDataForKeyRotation UpdateForKeyRotation(Guid userId,
IEnumerable<Core.Tools.Entities.Send> sends)
{
return async (_, _) =>
{
var newSends = sends.ToDictionary(s => s.Id);
using var scope = ServiceScopeFactory.CreateScope();
var dbContext = GetDatabaseContext(scope);
var userSends = await GetDbSet(dbContext)
.Where(s => s.UserId == userId)
.ToListAsync();
var validSends = userSends
.Where(send => newSends.ContainsKey(send.Id));
foreach (var send in validSends)
{
send.Key = newSends[send.Id].Key;
}
await dbContext.SaveChangesAsync();
};
}
}