Skip to content

Commit

Permalink
fix(audit): improper default formatting for primitive collections. (#459
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ascott18 committed Sep 27, 2024
1 parent f915a1a commit 1cfefaa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- feat(template): Added multi-tenancy options to the template. (#441, #461)
- fix(template): adjust manual chunking configuration to avoid circular deps. (#455)
- fix(audit): key props now respect configured property exclusions.
- fix(audit): improper default formatting for primitive collections. (#459)
- fix: c-admin-method now preserves newlines when displaying success messages.
- fix: c-select not defaulting optional method parameters as clearable.
- fix: method object parameters passed sent as null on the client are received as a default instance of the object on the server. (#456)
Expand Down
17 changes: 17 additions & 0 deletions src/IntelliTect.Coalesce.AuditLogging.Tests/AuditTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using IntelliTect.Coalesce.DataAnnotations;
using IntelliTect.Coalesce.Utilities;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -406,6 +407,22 @@ public async Task PropertyDesc_OnlyLoadsPrincipalWhenChanged()
Assert.Null(user.Parent1);
}

[Fact]
public void FormatsPrimitiveCollections()
{
using var db = BuildDbContext(b => b
.UseCoalesceAuditLogging<TestAuditLog>(x => x
.WithAugmentation<TestOperationContext>()
));

db.Add(new AppUser { Name = "Bob", EnumArray = [SecurityPermissionLevels.DenyAll, SecurityPermissionLevels.AllowAuthenticated] });
db.SaveChanges();

var log = Assert.Single(db.AuditLogs);
var prop = Assert.Single(log.Properties!.Where(p => p.PropertyName == nameof(AppUser.EnumArray)));
Assert.Equal("[DenyAll, AllowAuthenticated]", prop.NewValue);
}

private WebApplicationBuilder CreateAppBuilder()
{
var builder = WebApplication.CreateBuilder();
Expand Down
2 changes: 2 additions & 0 deletions src/IntelliTect.Coalesce.AuditLogging.Tests/TestDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class AppUser
public DateTimeOffset? NullableValueType { get; set; }

public bool BoolProp { get; set; }

public SecurityPermissionLevels[]? EnumArray { get; set; }
}

class ParentWithMappedListText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public AuditConfiguration FormatType<T>(Func<T, string?> formatter)
return formatter(currentValue);
}
}

if (currentValue is System.Collections.ICollection collection)
{
return $"[{string.Join(", ", collection.OfType<object>())}]";
}

return currentValue.ToString();
}
Expand Down

0 comments on commit 1cfefaa

Please sign in to comment.