diff --git a/src/Infrastructure.EntityFramework/Repositories/CipherRepository.cs b/src/Infrastructure.EntityFramework/Repositories/CipherRepository.cs index 096c90518405..49b407018c0e 100644 --- a/src/Infrastructure.EntityFramework/Repositories/CipherRepository.cs +++ b/src/Infrastructure.EntityFramework/Repositories/CipherRepository.cs @@ -29,7 +29,7 @@ public CipherRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper var dbContext = GetDatabaseContext(scope); if (cipher.OrganizationId.HasValue) { - await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId); + await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.Value); } else if (cipher.UserId.HasValue) { @@ -59,7 +59,7 @@ public override async Task DeleteAsync(Core.Entities.Cipher cipher) await OrganizationUpdateStorage(cipherInfo.OrganizationId.Value); } - await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipherInfo.OrganizationId); + await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipherInfo.OrganizationId.Value); } else if (cipherInfo?.UserId != null) { @@ -107,7 +107,16 @@ private async Task CreateAsyncReturnCipher(CipherDetails cipher) null; var entity = Mapper.Map((Core.Entities.Cipher)cipher); await dbContext.AddAsync(entity); - await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.GetValueOrDefault()); + + if (cipher.OrganizationId.HasValue) + { + await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.Value); + } + else if (cipher.UserId.HasValue) + { + await dbContext.UserBumpAccountRevisionDateAsync(cipher.UserId.Value); + } + await dbContext.SaveChangesAsync(); } return cipher; @@ -458,7 +467,16 @@ public async Task ReplaceAsync(CipherDetails cipher) } var mappedEntity = Mapper.Map((Core.Entities.Cipher)cipher); dbContext.Entry(entity).CurrentValues.SetValues(mappedEntity); - await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.GetValueOrDefault()); + + if (cipher.OrganizationId.HasValue) + { + await dbContext.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId.Value); + } + else if (cipher.UserId.HasValue) + { + await dbContext.UserBumpAccountRevisionDateAsync(cipher.UserId.Value); + } + await dbContext.SaveChangesAsync(); } } @@ -566,7 +584,15 @@ public async Task ReplaceAsync(Core.Entities.Cipher cipher, IEnumerable { private readonly Guid _cipherId; - private readonly Guid? _organizationId; + private readonly Guid _organizationId; - public UserBumpAccountRevisionDateByCipherIdQuery(Cipher cipher) - { - _cipherId = cipher.Id; - _organizationId = cipher.OrganizationId; - } - - public UserBumpAccountRevisionDateByCipherIdQuery(Guid cipherId, Guid? organizationId) + public UserBumpAccountRevisionDateByCipherIdQuery(Guid cipherId, Guid organizationId) { _cipherId = cipherId; _organizationId = organizationId; diff --git a/test/Infrastructure.EFIntegration.Test/Repositories/CipherRepositoryTests.cs b/test/Infrastructure.EFIntegration.Test/Repositories/CipherRepositoryTests.cs index 7868c7c0347c..19cef95ec093 100644 --- a/test/Infrastructure.EFIntegration.Test/Repositories/CipherRepositoryTests.cs +++ b/test/Infrastructure.EFIntegration.Test/Repositories/CipherRepositoryTests.cs @@ -159,7 +159,7 @@ public async void CreateAsync_BumpsOrgUserAccountRevisionDates(Cipher cipher, Li var postEfCipher = await sut.CreateAsync(cipher); sut.ClearChangeTracking(); - var query = new UserBumpAccountRevisionDateByCipherIdQuery(cipher); + var query = new UserBumpAccountRevisionDateByCipherIdQuery(cipher, cipher.OrganizationId.Value); var modifiedUsers = await sut.Run(query).ToListAsync(); Assert.True(modifiedUsers .All(u => u.AccountRevisionDate.ToShortDateString() ==