1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-14 08:02:17 -05:00

Update method to throw, update possibly bugged cipher code

This commit is contained in:
Thomas Rittson 2025-05-14 13:37:43 +10:00
parent 6a781ac5da
commit 5dc559205d
No known key found for this signature in database
GPG Key ID: CDDDA03861C35E27
2 changed files with 22 additions and 2 deletions

View File

@ -1,4 +1,6 @@
using System.Diagnostics; #nullable enable
using System.Diagnostics;
using Bit.Core.AdminConsole.Enums.Provider; using Bit.Core.AdminConsole.Enums.Provider;
using Bit.Core.Auth.Enums; using Bit.Core.Auth.Enums;
using Bit.Core.Enums; using Bit.Core.Enums;
@ -11,8 +13,18 @@ namespace Bit.Infrastructure.EntityFramework.Repositories;
public static class DatabaseContextExtensions public static class DatabaseContextExtensions
{ {
/// <summary>
/// Bump the account revision date for the user.
/// The caller is responsible for providing a valid UserId (not a null or default Guid) for a user that exists
/// in the database.
/// </summary>
public static async Task UserBumpAccountRevisionDateAsync(this DatabaseContext context, Guid userId) public static async Task UserBumpAccountRevisionDateAsync(this DatabaseContext context, Guid userId)
{ {
if (userId == Guid.Empty)
{
throw new ArgumentException("Invalid UserId.");
}
var user = await context.Users.FindAsync(userId); var user = await context.Users.FindAsync(userId);
Debug.Assert(user is not null, "The user id is expected to be validated as a true-in database user before making this call."); Debug.Assert(user is not null, "The user id is expected to be validated as a true-in database user before making this call.");
user.AccountRevisionDate = DateTime.UtcNow; user.AccountRevisionDate = DateTime.UtcNow;

View File

@ -144,6 +144,7 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
public async Task CreateAsync(IEnumerable<Core.Vault.Entities.Cipher> ciphers, IEnumerable<Core.Vault.Entities.Folder> folders) public async Task CreateAsync(IEnumerable<Core.Vault.Entities.Cipher> ciphers, IEnumerable<Core.Vault.Entities.Folder> folders)
{ {
ciphers = ciphers.ToList();
if (!ciphers.Any()) if (!ciphers.Any())
{ {
return; return;
@ -156,7 +157,14 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, folderEntities); await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, folderEntities);
var cipherEntities = Mapper.Map<List<Cipher>>(ciphers); var cipherEntities = Mapper.Map<List<Cipher>>(ciphers);
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, cipherEntities); await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, cipherEntities);
await dbContext.UserBumpAccountRevisionDateAsync(ciphers.First().UserId.GetValueOrDefault());
// Assumption: all ciphers belong to the same user
var userId = ciphers.FirstOrDefault(c => c.UserId.HasValue)?.UserId;
if (userId != null)
{
await dbContext.UserBumpAccountRevisionDateAsync(userId.Value);
}
await dbContext.SaveChangesAsync(); await dbContext.SaveChangesAsync();
} }
} }