fix(rd21): guard career and job saves with durable revisions
This commit is contained in:
@@ -72,10 +72,35 @@ namespace JobTrackerApi.Data
|
||||
public DbSet<AccountDeletionRequest> AccountDeletionRequests => Set<AccountDeletionRequest>();
|
||||
public DbSet<AccountDeletionFile> AccountDeletionFiles => Set<AccountDeletionFile>();
|
||||
|
||||
private void AdvanceJobRevisions()
|
||||
{
|
||||
ChangeTracker.DetectChanges();
|
||||
foreach (var entry in ChangeTracker.Entries<JobApplication>().Where(x => x.State == EntityState.Modified))
|
||||
{
|
||||
// All writers share this guard, including partial updates and background workers.
|
||||
entry.Entity.Version = checked(entry.Property(x => x.Version).OriginalValue + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public override int SaveChanges(bool acceptAllChangesOnSuccess)
|
||||
{
|
||||
AdvanceJobRevisions();
|
||||
return base.SaveChanges(acceptAllChangesOnSuccess);
|
||||
}
|
||||
|
||||
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
|
||||
{
|
||||
AdvanceJobRevisions();
|
||||
return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<JobApplication>().Property(x => x.Version).IsConcurrencyToken().HasDefaultValue(1);
|
||||
modelBuilder.Entity<CareerProfile>().Property(x => x.Version).IsConcurrencyToken();
|
||||
|
||||
modelBuilder.Entity<ApplicationUser>()
|
||||
.Property(x => x.PendingEmail)
|
||||
.HasMaxLength(320);
|
||||
|
||||
Reference in New Issue
Block a user