Refactored organisation entities and endpoints
This commit is contained in:
@@ -6,7 +6,7 @@ namespace PostFundManagement.Infrastructure.Database;
|
||||
public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options,
|
||||
ITenantContextService tenantService) : DbContext(options)
|
||||
{
|
||||
private bool BypassFilter => tenantService.IsAdmin || tenantService.ByPassTenantQueryFilter;
|
||||
private bool BypassFilter => tenantService.ByPassTenantQueryFilter;
|
||||
private long CurrentTenantId => tenantService.TenantId;
|
||||
|
||||
public DbSet<TenantUser> TenantUsers => Set<TenantUser>();
|
||||
@@ -84,14 +84,14 @@ public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext>
|
||||
}
|
||||
}
|
||||
|
||||
modelBuilder.Entity<Organisation>().HasQueryFilter(o => BypassFilter == false &&
|
||||
modelBuilder.Entity<Organisation>().HasQueryFilter(o => BypassFilter ||
|
||||
Set<TenantOrganisation>().Any(to => to.TenantId == CurrentTenantId && to.OrganisationId == o.Id));
|
||||
|
||||
modelBuilder.Entity<TenantOrganisation>()
|
||||
.HasQueryFilter(to => BypassFilter == false && to.TenantId == CurrentTenantId);
|
||||
.HasQueryFilter(to => BypassFilter || to.TenantId == CurrentTenantId);
|
||||
|
||||
modelBuilder.Entity<TenantUser>()
|
||||
.HasQueryFilter(to => BypassFilter == false && to.TenantId == CurrentTenantId);
|
||||
.HasQueryFilter(to => BypassFilter || to.TenantId == CurrentTenantId);
|
||||
}
|
||||
|
||||
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||
|
||||
Reference in New Issue
Block a user