mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 00:52:49 -05:00
Add UpdateCiphersAsync Test (#5543)
* Add UpdateCiphersAsync Test * Fix UpdateCiphersAsync * Fix #2 * Fix SQL Server * Formatting
This commit is contained in:
@ -711,7 +711,7 @@ public class CipherRepository : Repository<Cipher, Guid>, ICipherRepository
|
||||
row[creationDateColumn] = cipher.CreationDate;
|
||||
row[revisionDateColumn] = cipher.RevisionDate;
|
||||
row[deletedDateColumn] = cipher.DeletedDate.HasValue ? (object)cipher.DeletedDate : DBNull.Value;
|
||||
row[repromptColumn] = cipher.Reprompt;
|
||||
row[repromptColumn] = cipher.Reprompt.HasValue ? cipher.Reprompt.Value : DBNull.Value;
|
||||
row[keyColummn] = cipher.Key;
|
||||
|
||||
ciphersTable.Rows.Add(row);
|
||||
|
@ -863,8 +863,30 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var entities = Mapper.Map<List<Cipher>>(ciphers);
|
||||
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, entities);
|
||||
var ciphersToUpdate = ciphers.ToDictionary(c => c.Id);
|
||||
|
||||
var existingCiphers = await dbContext.Ciphers
|
||||
.Where(c => c.UserId == userId && ciphersToUpdate.Keys.Contains(c.Id))
|
||||
.ToDictionaryAsync(c => c.Id);
|
||||
|
||||
foreach (var (cipherId, cipher) in ciphersToUpdate)
|
||||
{
|
||||
if (!existingCiphers.TryGetValue(cipherId, out var existingCipher))
|
||||
{
|
||||
// The Dapper version does not validate that the same amount of items given where updated.
|
||||
continue;
|
||||
}
|
||||
|
||||
existingCipher.UserId = cipher.UserId;
|
||||
existingCipher.OrganizationId = cipher.OrganizationId;
|
||||
existingCipher.Type = cipher.Type;
|
||||
existingCipher.Data = cipher.Data;
|
||||
existingCipher.Attachments = cipher.Attachments;
|
||||
existingCipher.RevisionDate = cipher.RevisionDate;
|
||||
existingCipher.DeletedDate = cipher.DeletedDate;
|
||||
existingCipher.Key = cipher.Key;
|
||||
}
|
||||
|
||||
await dbContext.UserBumpAccountRevisionDateAsync(userId);
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
Reference in New Issue
Block a user