Implemented centralised audit logging
This commit is contained in:
@@ -5,16 +5,19 @@ namespace PostFundManagement.Domain.Entities;
|
||||
[EntityTypeConfiguration<AuditLogConfiguration, AuditLog>]
|
||||
public class AuditLog : Models.AuditLog
|
||||
{
|
||||
public virtual User? Performer { get; set; }
|
||||
public virtual Tenant? Tenant { get; set; }
|
||||
|
||||
public virtual User? Performer { get; set; }
|
||||
}
|
||||
|
||||
public sealed class AuditLogConfiguration : IEntityTypeConfiguration<Domain.Entities.AuditLog>
|
||||
public sealed class AuditLogConfiguration : IEntityTypeConfiguration<AuditLog>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Domain.Entities.AuditLog> builder)
|
||||
public void Configure(EntityTypeBuilder<AuditLog> builder)
|
||||
{
|
||||
builder.ToTable(nameof(Domain.Entities.AuditLog).Pluralize());
|
||||
builder.ToTable(nameof(AuditLog).Pluralize());
|
||||
|
||||
builder.HasKey(pk => pk.Id);
|
||||
builder.Property(f => f.TenantId).IsRequired(false);
|
||||
builder.Property(f => f.EntityName).IsRequired().HasMaxLength(LabelLength);
|
||||
builder.Property(f => f.EntityId).IsRequired();
|
||||
builder.Property(f => f.Action).IsRequired().HasMaxLength(ShortLabelLength);
|
||||
@@ -22,6 +25,12 @@ public sealed class AuditLogConfiguration : IEntityTypeConfiguration<Domain.Enti
|
||||
builder.Property(f => f.PerformedBy).IsRequired();
|
||||
builder.Property(f => f.Timestamp).IsRequired().HasDefaultValueSql("now()");
|
||||
|
||||
builder.HasOne(f => f.Tenant)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.TenantId)
|
||||
.IsRequired(false)
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
|
||||
builder.HasOne(f => f.Performer)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.PerformedBy)
|
||||
|
||||
@@ -9,6 +9,8 @@ public class Award : Models.Award
|
||||
|
||||
public virtual User? Approver { get; set; }
|
||||
|
||||
public virtual Tenant? Tenant { get; set; }
|
||||
|
||||
public virtual Organisation? Organisation { get; set; }
|
||||
|
||||
public virtual Programme? Programme { get; set; }
|
||||
@@ -27,6 +29,7 @@ public sealed class AwardConfiguration : IEntityTypeConfiguration<Award>
|
||||
builder.HasKey(pk => pk.Id);
|
||||
builder.Property(f => f.OrganisationId).IsRequired();
|
||||
builder.Property(f => f.ProgrammeId).IsRequired();
|
||||
builder.Property(f => f.TenantId).IsRequired();
|
||||
builder.Property(f => f.ProjectId).IsRequired(false);
|
||||
builder.Property(f => f.CreatedBy).IsRequired();
|
||||
builder.Property(f => f.UpdatedBy).IsRequired(false);
|
||||
@@ -37,6 +40,12 @@ public sealed class AwardConfiguration : IEntityTypeConfiguration<Award>
|
||||
.HasSentinel(ApprovalStatus.Pending);
|
||||
builder.Property(f => f.Amount).IsRequired().HasPrecision(18, 2);
|
||||
|
||||
builder.HasOne(f => f.Tenant)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.TenantId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(f => f.Organisation)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.OrganisationId)
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace PostFundManagement.Domain.Entities;
|
||||
[EntityTypeConfiguration<NotificationConfiguration, Notification>]
|
||||
public class Notification : Models.Notification
|
||||
{
|
||||
public virtual Tenant? Tenant { get; set; }
|
||||
|
||||
public virtual Organisation? Organisation { get; set; }
|
||||
|
||||
public virtual User? RecipientUser { get; set; }
|
||||
@@ -22,6 +24,7 @@ public sealed class NotificationConfiguration : IEntityTypeConfiguration<Notific
|
||||
builder.Property(f => f.SentAt).IsRequired(false);
|
||||
builder.Property(f => f.Recipient).IsRequired();
|
||||
builder.Property(f => f.OrganisationId).IsRequired();
|
||||
builder.Property(f => f.TenantId).IsRequired();
|
||||
builder.Property(f => f.Platform).IsRequired().HasConversion<int>().HasDefaultValueSql("1")
|
||||
.HasSentinel(NotificationPlatform.Email);
|
||||
builder.Property(f => f.Status).IsRequired().HasConversion<int>().HasDefaultValueSql("1")
|
||||
@@ -31,6 +34,12 @@ public sealed class NotificationConfiguration : IEntityTypeConfiguration<Notific
|
||||
builder.Property(f => f.Destination).IsRequired().HasMaxLength(LabelLength);
|
||||
builder.Property(f => f.Error).IsRequired(false);
|
||||
|
||||
builder.HasOne(f => f.Tenant)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.TenantId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(f => f.Organisation)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.OrganisationId)
|
||||
|
||||
@@ -9,6 +9,8 @@ public class Portfolio : Models.Portfolio
|
||||
|
||||
public virtual User? Owner { get; set; }
|
||||
|
||||
public virtual Tenant? Tenant { get; set; }
|
||||
|
||||
public virtual Organisation? Organisation { get; set; }
|
||||
|
||||
public virtual ICollection<Programme> Programmes { get; set; } = [];
|
||||
@@ -21,6 +23,7 @@ public sealed class PortfolioConfiguration : IEntityTypeConfiguration<Portfolio>
|
||||
builder.ToTable(nameof(Portfolio).Pluralize());
|
||||
|
||||
builder.HasKey(pk => pk.Id);
|
||||
builder.Property(f => f.TenantId).IsRequired();
|
||||
builder.Property(f => f.OrganisationId).IsRequired();
|
||||
builder.Property(f => f.CreatedBy).IsRequired();
|
||||
builder.Property(f => f.OwnedBy).IsRequired();
|
||||
@@ -28,6 +31,12 @@ public sealed class PortfolioConfiguration : IEntityTypeConfiguration<Portfolio>
|
||||
builder.Property(f => f.Name).IsRequired().HasMaxLength(LabelLength);
|
||||
builder.Property(f => f.Description).IsRequired(false).HasMaxLength(TextLength);
|
||||
|
||||
builder.HasOne(f => f.Tenant)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.TenantId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(f => f.Organisation)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.OrganisationId)
|
||||
|
||||
@@ -8,6 +8,8 @@ public class Programme : Models.Programme
|
||||
public virtual User? Creator { get; set; }
|
||||
|
||||
public virtual User? Owner { get; set; }
|
||||
|
||||
public virtual Tenant? Tenant { get; set; }
|
||||
|
||||
public virtual Portfolio? Portfolio { get; set; }
|
||||
|
||||
@@ -27,6 +29,7 @@ public sealed class ProgrammeConfiguration : IEntityTypeConfiguration<Programme>
|
||||
builder.ToTable(nameof(Programme).Pluralize());
|
||||
|
||||
builder.HasKey(pk => pk.Id);
|
||||
builder.Property(f => f.TenantId).IsRequired();
|
||||
builder.Property(f => f.PortfolioId).IsRequired();
|
||||
builder.Property(f => f.OwnedBy).IsRequired();
|
||||
builder.Property(f => f.CreatedBy).IsRequired();
|
||||
@@ -37,6 +40,12 @@ public sealed class ProgrammeConfiguration : IEntityTypeConfiguration<Programme>
|
||||
builder.Property(f => f.Status).IsRequired().HasConversion<int>().HasDefaultValueSql("1")
|
||||
.HasSentinel(ApprovalStatus.Pending);
|
||||
|
||||
builder.HasOne(f => f.Tenant)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.TenantId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
|
||||
builder.HasOne(f => f.Portfolio)
|
||||
.WithMany(f => f.Programmes)
|
||||
.HasForeignKey(fk => fk.PortfolioId)
|
||||
|
||||
@@ -9,6 +9,8 @@ public class Project : Models.Project
|
||||
|
||||
public virtual User? Updator { get; set; }
|
||||
|
||||
public virtual Tenant? Tenant { get; set; }
|
||||
|
||||
public virtual Programme? Programme { get; set; }
|
||||
|
||||
public virtual ICollection<Award> Awards { get; set; } = [];
|
||||
@@ -21,6 +23,7 @@ public sealed class ProjectConfiguration : IEntityTypeConfiguration<Project>
|
||||
builder.ToTable(nameof(Project).Pluralize());
|
||||
|
||||
builder.HasKey(pk => pk.Id);
|
||||
builder.Property(f => f.TenantId).IsRequired();
|
||||
builder.Property(f => f.ProgrammeId).IsRequired();
|
||||
builder.Property(f => f.CreatedBy).IsRequired();
|
||||
builder.Property(f => f.UpdatedBy).IsRequired(false);
|
||||
@@ -37,6 +40,12 @@ public sealed class ProjectConfiguration : IEntityTypeConfiguration<Project>
|
||||
builder.Property(f => f.Status).IsRequired().HasConversion<int>().HasDefaultValueSql("1")
|
||||
.HasSentinel(ApprovalStatus.Pending);
|
||||
|
||||
builder.HasOne(f => f.Tenant)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.TenantId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(f => f.Programme)
|
||||
.WithMany(f => f.Projects)
|
||||
.HasForeignKey(fk => fk.ProgrammeId)
|
||||
|
||||
@@ -30,6 +30,12 @@ public sealed class TenantUserConfiguration : IEntityTypeConfiguration<TenantUse
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(f => f.User)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.UserId)
|
||||
.IsRequired()
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(f => f.Creator)
|
||||
.WithMany()
|
||||
.HasForeignKey(fk => fk.CreatedBy)
|
||||
|
||||
Reference in New Issue
Block a user