Security #1

Merged
khwezi merged 50 commits from security into main 2026-08-21 11:47:37 +02:00
7 changed files with 64 additions and 7 deletions
Showing only changes of commit dc574ee971 - Show all commits
@@ -16,7 +16,8 @@ public sealed class Instrument : IEntityTypeConfiguration<Entities.Instrument>
builder.HasOne(f => f.Creator) builder.HasOne(f => f.Creator)
.WithMany() .WithMany()
.HasForeignKey(f => f.CreatedBy) .HasForeignKey(fk => fk.CreatedBy)
.IsRequired()
.OnDelete(DeleteBehavior.NoAction); .OnDelete(DeleteBehavior.NoAction);
} }
} }
@@ -15,13 +15,14 @@ public sealed class Portfolio : IEntityTypeConfiguration<Entities.Portfolio>
builder.HasOne(f => f.Creator) builder.HasOne(f => f.Creator)
.WithMany() .WithMany()
.HasForeignKey(f => f.CreatedBy) .HasForeignKey(fk => fk.CreatedBy)
.IsRequired() .IsRequired()
.OnDelete(DeleteBehavior.NoAction); .OnDelete(DeleteBehavior.NoAction);
builder.HasOne(f => f.Owner) builder.HasOne(f => f.Owner)
.WithMany() .WithMany()
.HasForeignKey(f => f.OwnedBy) .HasForeignKey(fk => fk.OwnedBy)
.IsRequired(false)
.OnDelete(DeleteBehavior.NoAction); .OnDelete(DeleteBehavior.NoAction);
} }
} }
@@ -19,25 +19,26 @@ public sealed class Programme : IEntityTypeConfiguration<Entities.Programme>
builder.HasOne(f => f.Portfolio) builder.HasOne(f => f.Portfolio)
.WithMany(f => f.Programmes) .WithMany(f => f.Programmes)
.HasForeignKey(f => f.PortfolioId) .HasForeignKey(fk => fk.PortfolioId)
.IsRequired() .IsRequired()
.OnDelete(DeleteBehavior.NoAction); .OnDelete(DeleteBehavior.NoAction);
builder.HasOne(f => f.Instrument) builder.HasOne(f => f.Instrument)
.WithMany(f => f.Programmes) .WithMany(f => f.Programmes)
.HasForeignKey(f => f.InstrumentId) .HasForeignKey(fk => fk.InstrumentId)
.IsRequired() .IsRequired()
.OnDelete(DeleteBehavior.NoAction); .OnDelete(DeleteBehavior.NoAction);
builder.HasOne(f => f.Creator) builder.HasOne(f => f.Creator)
.WithMany() .WithMany()
.HasForeignKey(f => f.CreatedBy) .HasForeignKey(fk => fk.CreatedBy)
.IsRequired() .IsRequired()
.OnDelete(DeleteBehavior.NoAction); .OnDelete(DeleteBehavior.NoAction);
builder.HasOne(f => f.Owner) builder.HasOne(f => f.Owner)
.WithMany() .WithMany()
.HasForeignKey(f => f.OwnedBy) .IsRequired(false)
.HasForeignKey(fk => fk.OwnedBy)
.OnDelete(DeleteBehavior.NoAction); .OnDelete(DeleteBehavior.NoAction);
} }
} }
@@ -0,0 +1,37 @@
namespace PostFundManagement.Domain.Configuration;
public sealed class Rule : IEntityTypeConfiguration<Entities.Rule>
{
public void Configure(EntityTypeBuilder<Entities.Rule> builder)
{
builder.ToTable(nameof(Entities.Rule).Pluralize());
builder.HasKey(fk => fk.Id);
builder.Property(f => f.ProgrammeId).IsRequired();
builder.Property(f => f.CreatedBy).IsRequired();
builder.Property(f => f.UpdatedBy).IsRequired(false);
builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()");
builder.Property(f => f.UpdatedAt).IsRequired(false);
builder.Property(f => f.Name).IsRequired().HasMaxLength(256);
builder.Property(f => f.Version).IsRequired().HasDefaultValue(1);
builder.Property(f => f.Status).IsRequired().HasDefaultValue(ActivityStatus.Inactive);
builder.HasOne(f => f.Programme)
.WithMany(f => f.Rules)
.HasForeignKey(fk => fk.ProgrammeId)
.IsRequired()
.OnDelete(DeleteBehavior.NoAction);
builder.HasOne(f => f.Creator)
.WithMany()
.HasForeignKey(fk => fk.CreatedBy)
.IsRequired()
.OnDelete(DeleteBehavior.NoAction);
builder.HasOne(f => f.Updator)
.WithMany()
.HasForeignKey(fk => fk.UpdatedBy)
.IsRequired(false)
.OnDelete(DeleteBehavior.NoAction);
}
}
@@ -10,4 +10,6 @@ public class Programme : Models.Programme
public virtual Portfolio? Portfolio { get; set; } public virtual Portfolio? Portfolio { get; set; }
public virtual Instrument? Instrument { get; set; } public virtual Instrument? Instrument { get; set; }
public virtual ICollection<Rule> Rules { get; set; } = [];
} }
@@ -0,0 +1,11 @@
namespace PostFundManagement.Domain.Entities;
[EntityTypeConfiguration<Configuration.Rule, Rule>]
public class Rule : Models.Rule
{
public virtual User? Creator { get; set; }
public virtual User? Updator { get; set; }
public virtual Programme? Programme { get; set; }
}
@@ -4,6 +4,10 @@ namespace PostFundManagement.Infrastructure.Database;
public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : DbContext(options) public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : DbContext(options)
{ {
public DbSet<Rule> Rules => Set<Rule>();
public DbSet<Programme> Programmes => Set<Programme>();
public DbSet<Portfolio> Portfolios => Set<Portfolio>(); public DbSet<Portfolio> Portfolios => Set<Portfolio>();
public DbSet<Instrument> Instruments => Set<Instrument>(); public DbSet<Instrument> Instruments => Set<Instrument>();