1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-06 21:48:12 -05:00

Fix AccountRevisionDate (#2467)

* Update AccountRevisionDate directly by userId
* Have special DateTime handling on postgres
This commit is contained in:
Justin Baur 2022-12-04 21:40:20 -05:00 committed by GitHub
parent 3a201e7520
commit c39736c583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 17 deletions

View File

@ -139,7 +139,7 @@ public class CipherRepository : Repository<Core.Entities.Cipher, Cipher, Guid>,
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.UserBumpAccountRevisionDateByCipherIdAsync(ciphers); await dbContext.UserBumpAccountRevisionDateAsync(ciphers.First().UserId.GetValueOrDefault());
await dbContext.SaveChangesAsync(); await dbContext.SaveChangesAsync();
} }
} }

View File

@ -141,11 +141,11 @@ public class DatabaseContext : DbContext
eOrganizationConnection.ToTable(nameof(OrganizationConnection)); eOrganizationConnection.ToTable(nameof(OrganizationConnection));
eAuthRequest.ToTable(nameof(AuthRequest)); eAuthRequest.ToTable(nameof(AuthRequest));
ConfigureDateTimeUTCQueries(builder); ConfigureDateTimeUtcQueries(builder);
} }
// Make sure this is called after configuring all the entities as it iterates through all setup entities. // Make sure this is called after configuring all the entities as it iterates through all setup entities.
private static void ConfigureDateTimeUTCQueries(ModelBuilder builder) private void ConfigureDateTimeUtcQueries(ModelBuilder builder)
{ {
foreach (var entityType in builder.Model.GetEntityTypes()) foreach (var entityType in builder.Model.GetEntityTypes())
{ {
@ -157,10 +157,20 @@ public class DatabaseContext : DbContext
{ {
if (property.ClrType == typeof(DateTime) || property.ClrType == typeof(DateTime?)) if (property.ClrType == typeof(DateTime) || property.ClrType == typeof(DateTime?))
{ {
property.SetValueConverter( if (Database.IsNpgsql())
new ValueConverter<DateTime, DateTime>( {
v => v, property.SetValueConverter(
v => new DateTime(v.Ticks, DateTimeKind.Utc))); new ValueConverter<DateTime, DateTime>(
v => v,
v => v.ToUniversalTime()));
}
else
{
property.SetValueConverter(
new ValueConverter<DateTime, DateTime>(
v => v,
v => new DateTime(v.Ticks, DateTimeKind.Utc)));
}
} }
} }
} }

View File

@ -1,5 +1,4 @@
using Bit.Core.Entities; using Bit.Core.Enums;
using Bit.Core.Enums;
using Bit.Core.Enums.Provider; using Bit.Core.Enums.Provider;
using Bit.Infrastructure.EntityFramework.Repositories.Queries; using Bit.Infrastructure.EntityFramework.Repositories.Queries;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@ -42,14 +41,6 @@ public static class DatabaseContextExtensions
UpdateUserRevisionDate(users); UpdateUserRevisionDate(users);
} }
public static async Task UserBumpAccountRevisionDateByCipherIdAsync(this DatabaseContext context, IEnumerable<Cipher> ciphers)
{
foreach (var cipher in ciphers)
{
await context.UserBumpAccountRevisionDateByCipherIdAsync(cipher.Id, cipher.OrganizationId);
}
}
public static async Task UserBumpAccountRevisionDateByCollectionIdAsync(this DatabaseContext context, Guid collectionId, Guid organizationId) public static async Task UserBumpAccountRevisionDateByCollectionIdAsync(this DatabaseContext context, Guid collectionId, Guid organizationId)
{ {
var query = from u in context.Users var query = from u in context.Users