Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 committed Sep 27, 2024
1 parent 96d30e5 commit 51ec081
Show file tree
Hide file tree
Showing 13 changed files with 591 additions and 584 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- "--Identity --UserPictures --TrackingBase"
- "--Identity --MicrosoftAuth --AuditLogs"
# Tenancy variants:
- "--Identity --Tenancy --TenantCreateExternal --MicrosoftAuth"
- "--Identity --Tenancy --TenantCreateExternal --GoogleAuth"
- "--Identity --Tenancy --TenantCreateSelf --TenantMemberInvites --AuditLogs" # todo: add local accounts to this case when we add it
- "--Identity --Tenancy --TenantCreateAdmin --TenantMemberInvites --MicrosoftAuth" # todo: add local accounts to this case when we add it

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- feat: better "not found" messages from data sources when the ID is null or empty string. (#447)
- fix(template): adjust manual chunking configuration to avoid circular deps. (#455)
- fix(audit): key props now respect configured property exclusions
- fix: c-admin-method now preserves newlines when display success messages

# 5.0.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public string? TenantId
{
if (_TenantId != null && value != _TenantId && ChangeTracker.Entries().Any())
{
throw new InvalidOperationException("Cannot change the TenantId of an active DbContext. Make a new one through DbContextFactory to perform operations on different tenants, or call ForceSetTenant().");
throw new InvalidOperationException("Cannot change the TenantId of an active DbContext. Make a new one through IDbContextFactory to perform operations on different tenants, or call ForceSetTenant().");
}
_TenantId = value;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
.ExcludeProperty<TrackingBase>(x => new { x.CreatedBy, x.CreatedById, x.CreatedOn, x.ModifiedBy, x.ModifiedById, x.ModifiedOn })
#endif
#if Identity
.ExcludeProperty<User>(x => new { x.PasswordHash })
.Format<User>(x => x.PasswordHash, x => "<password changed>")
#endif
#if Tenancy
.ExcludeProperty<ITenanted>(x => new { x.TenantId })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static bool Can(this ClaimsPrincipal user, params Permission[] permission
#if Tenancy
public static string? GetTenantId(this ClaimsPrincipal user)
=> user.FindFirstValue(AppClaimTypes.TenantId);

public static bool HasTenant(this ClaimsPrincipal user)
=> user.GetTenantId() is string tid && !string.IsNullOrWhiteSpace(tid) && tid != AppClaimValues.NullTenantId;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ public void Seed()
{
#if Tenancy
#if (!TenantCreateExternal && !TenantCreateSelf)
if (!db.Tenants.Any())
{
var tenant = new Tenant { Name = "Demo Tenant" };
db.Add(tenant);
db.SaveChanges();
if (!db.Tenants.Any())
{
var tenant = new Tenant { Name = "Demo Tenant" };
db.Add(tenant);
db.SaveChanges();

SeedNewTenant(tenant);
}
SeedNewTenant(tenant);
}
#endif
#elif Identity
SeedRoles();
SeedRoles();
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace Coalesce.Starter.Vue.Data.Models;
[Edit(DenyAll)]
[Delete(DenyAll)]
[Create(DenyAll)]
#if Identity
[Read(nameof(Permission.ViewAuditLogs))]
#endif
public class AuditLog : DefaultAuditLog
{
#if Identity
Expand All @@ -16,8 +18,8 @@ public class AuditLog : DefaultAuditLog
#endif

#if Tenancy
// NOTE: Audit logs are not strictly tenanted because they can log changes
// to non-tenanted entities as well.
// NOTE: Audit logs are *optionally* tenanted because they can log changes
// to non-tenanted entities as well. Read security is implemented in the below datasource.

[InternalUse]
public string? TenantId { get; set; }
Expand All @@ -33,9 +35,9 @@ public override IQueryable<AuditLog> GetQuery(IDataSourceParameters parameters)
{
return base.GetQuery(parameters)
.AsNoTracking()
.Where(al =>
// All users can see logs in the current tenant
al.TenantId == User.GetTenantId() ||
.Where(al =>
// All ViewAuditLogs users can see logs in the current tenant
al.TenantId == User.GetTenantId() ||
// Global admins can see logs that happened outside a tenant.
(User.IsInRole(AppClaimValues.GlobalAdminRole) && al.TenantId == null)
);
Expand Down
Loading

0 comments on commit 51ec081

Please sign in to comment.