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:
parent
6a781ac5da
commit
5dc559205d
@ -1,4 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
#nullable enable
|
||||
|
||||
using System.Diagnostics;
|
||||
using Bit.Core.AdminConsole.Enums.Provider;
|
||||
using Bit.Core.Auth.Enums;
|
||||
using Bit.Core.Enums;
|
||||
@ -11,8 +13,18 @@ namespace Bit.Infrastructure.EntityFramework.Repositories;
|
||||
|
||||
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)
|
||||
{
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentException("Invalid 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.");
|
||||
user.AccountRevisionDate = DateTime.UtcNow;
|
||||
|
@ -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)
|
||||
{
|
||||
ciphers = ciphers.ToList();
|
||||
if (!ciphers.Any())
|
||||
{
|
||||
return;
|
||||
@ -156,7 +157,14 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
|
||||
await dbContext.BulkCopyAsync(base.DefaultBulkCopyOptions, folderEntities);
|
||||
var cipherEntities = Mapper.Map<List<Cipher>>(ciphers);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user