Implemented centralised audit logging
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
using PostFundManagement.Domain.Abstractions;
|
||||
using PostFundManagement.Domain.Entities;
|
||||
|
||||
namespace PostFundManagement.Infrastructure.Database;
|
||||
|
||||
public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : DbContext(options)
|
||||
public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options,
|
||||
ITenantContextService tenantService) : DbContext(options)
|
||||
{
|
||||
private bool BypassFilter => tenantService.IsAdmin;
|
||||
private long CurrentTenantId => tenantService.TenantId;
|
||||
|
||||
public DbSet<TenantUser> TenantUsers => Set<TenantUser>();
|
||||
|
||||
public DbSet<TenantOrganisation> TenantOrganisations => Set<TenantOrganisation>();
|
||||
@@ -17,13 +22,13 @@ public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext>
|
||||
public DbSet<Activity> Activities => Set<Activity>();
|
||||
|
||||
public DbSet<AuditLog> AuditLogs => Set<AuditLog>();
|
||||
|
||||
|
||||
public DbSet<SiteVisit> SiteVisits => Set<SiteVisit>();
|
||||
|
||||
|
||||
public DbSet<ChangeRequest> ChangeRequests => Set<ChangeRequest>();
|
||||
|
||||
public DbSet<ComplianceItem> ComplianceItems => Set<ComplianceItem>();
|
||||
|
||||
|
||||
public DbSet<Issue> Issues => Set<Issue>();
|
||||
|
||||
public DbSet<Outcome> Outcomes => Set<Outcome>();
|
||||
@@ -31,13 +36,13 @@ public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext>
|
||||
public DbSet<Beneficiary> Beneficiaries => Set<Beneficiary>();
|
||||
|
||||
public DbSet<Evidence> Evidences => Set<Evidence>();
|
||||
|
||||
|
||||
public DbSet<Risk> Risks => Set<Risk>();
|
||||
|
||||
|
||||
public DbSet<Indicator> Indicators => Set<Indicator>();
|
||||
|
||||
|
||||
public DbSet<Disbursement> Disbursements => Set<Disbursement>();
|
||||
|
||||
|
||||
public DbSet<Milestone> Milestones => Set<Milestone>();
|
||||
|
||||
public DbSet<Budget> Budgets => Set<Budget>();
|
||||
@@ -57,6 +62,38 @@ public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext>
|
||||
public DbSet<Portfolio> Portfolios => Set<Portfolio>();
|
||||
|
||||
public DbSet<Instrument> Instruments => Set<Instrument>();
|
||||
|
||||
|
||||
public DbSet<User> Users => Set<User>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Portfolio>()
|
||||
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
||||
|
||||
modelBuilder.Entity<Programme>()
|
||||
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
||||
|
||||
modelBuilder.Entity<Project>()
|
||||
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
||||
|
||||
modelBuilder.Entity<Award>()
|
||||
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
||||
|
||||
modelBuilder.Entity<Notification>()
|
||||
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
||||
|
||||
modelBuilder.Entity<TenantOrganisation>()
|
||||
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
||||
|
||||
modelBuilder.Entity<TenantUser>()
|
||||
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
||||
|
||||
modelBuilder.Entity<AuditLog>()
|
||||
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
||||
|
||||
modelBuilder.Entity<Organisation>().HasQueryFilter(o => BypassFilter ||
|
||||
Set<TenantOrganisation>().Any(to => to.TenantId == CurrentTenantId && to.OrganisationId == o.Id));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user