From 1b75edf0d555aee1ed944a506a2184031856aa24 Mon Sep 17 00:00:00 2001 From: Kelly Adams Date: Thu, 14 Nov 2024 14:22:54 -0800 Subject: [PATCH] template: Constrain generated TenantId SQL field size (#488) --- .../content/Coalesce.Starter.Vue.Data/Auth/UserInfo.cs | 1 + .../content/Coalesce.Starter.Vue.Data/GlobalUsings.cs | 2 +- .../content/Coalesce.Starter.Vue.Data/Models/AuditLog.cs | 2 +- .../content/Coalesce.Starter.Vue.Data/Models/Role.cs | 2 ++ .../content/Coalesce.Starter.Vue.Data/Models/Tenancy/Tenant.cs | 1 + .../Models/Tenancy/TenantMembership.cs | 1 + .../Coalesce.Starter.Vue.Data/Models/Tenancy/TenantedBase.cs | 2 +- .../content/Coalesce.Starter.Vue.Data/Models/UserRole.cs | 1 + .../content/Coalesce.Starter.Vue.Web/Pages/_Layout.cshtml | 3 ++- .../content/Coalesce.Starter.Vue.Web/Program.cs | 1 + 10 files changed, 12 insertions(+), 4 deletions(-) diff --git a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Auth/UserInfo.cs b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Auth/UserInfo.cs index 21717894b..2b9500644 100644 --- a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Auth/UserInfo.cs +++ b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Auth/UserInfo.cs @@ -14,6 +14,7 @@ public class UserInfo public required ICollection Permissions { get; set; } #endif #if Tenancy + [MaxLength(36)] public string? TenantId { get; set; } public string? TenantName { get; set; } #endif diff --git a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/GlobalUsings.cs b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/GlobalUsings.cs index c8a1c4329..59d0f8d42 100644 --- a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/GlobalUsings.cs +++ b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/GlobalUsings.cs @@ -10,7 +10,7 @@ global using Coalesce.Starter.Vue.Data.Auth; global using Coalesce.Starter.Vue.Data.Coalesce; global using Coalesce.Starter.Vue.Data.Utilities; -#if (Identity || ExampleModel) +#if (Identity || ExampleModel || TrackingBase) global using Coalesce.Starter.Vue.Data.Models; #endif diff --git a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/AuditLog.cs b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/AuditLog.cs index 43b2bd8ef..c05b0147f 100644 --- a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/AuditLog.cs +++ b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/AuditLog.cs @@ -21,7 +21,7 @@ public class AuditLog : DefaultAuditLog // 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] + [InternalUse, MaxLength(36)] public string? TenantId { get; set; } [InternalUse] public Tenant? Tenant { get; set; } diff --git a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Role.cs b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Role.cs index 47318d66d..4b3a93d58 100644 --- a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Role.cs +++ b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Role.cs @@ -18,6 +18,7 @@ public class Role #if Tenancy [InternalUse] [DefaultOrderBy(FieldOrder = 0)] + [MaxLength(36)] public string TenantId { get; set; } = null!; [InternalUse] [ForeignKey(nameof(TenantId))] @@ -62,6 +63,7 @@ public class RoleClaim : IdentityRoleClaim, ITenanted [InternalUse] [DefaultOrderBy(FieldOrder = 0)] + [MaxLength(36)] public required string TenantId { get; set; } [InternalUse] [ForeignKey(nameof(TenantId))] diff --git a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/Tenant.cs b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/Tenant.cs index 5a4ec35b9..50d5f7271 100644 --- a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/Tenant.cs +++ b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/Tenant.cs @@ -12,6 +12,7 @@ namespace Coalesce.Starter.Vue.Data.Models; [Display(Name = "Organization")] public class Tenant { + [MaxLength(36)] public string TenantId { get; set; } = Guid.NewGuid().ToString(); public required string Name { get; set; } diff --git a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/TenantMembership.cs b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/TenantMembership.cs index 3b9e0f6ff..cb3f0fad2 100644 --- a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/TenantMembership.cs +++ b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/TenantMembership.cs @@ -4,6 +4,7 @@ [InternalUse] public class TenantMembership : TenantedBase { + [MaxLength(36)] public string TenantMembershipId { get; set; } = Guid.NewGuid().ToString(); [Required] diff --git a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/TenantedBase.cs b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/TenantedBase.cs index 6d547cb18..3deb3867c 100644 --- a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/TenantedBase.cs +++ b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/Tenancy/TenantedBase.cs @@ -7,7 +7,7 @@ public abstract class TenantedBase : ITenanted #endif { - [InternalUse, Required] + [InternalUse, Required, MaxLength(36)] public string TenantId { get; set; } = null!; [InternalUse] public Tenant? Tenant { get; set; } diff --git a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/UserRole.cs b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/UserRole.cs index 1bc1518c9..e7fd9553b 100644 --- a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/UserRole.cs +++ b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Data/Models/UserRole.cs @@ -27,6 +27,7 @@ public string Id #if Tenancy [InternalUse] [DefaultOrderBy(FieldOrder = 0)] + [MaxLength(36)] public string TenantId { get; set; } = null!; [InternalUse] public Tenant? Tenant { get; set; } diff --git a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Web/Pages/_Layout.cshtml b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Web/Pages/_Layout.cshtml index 46e32b716..4a854efbb 100644 --- a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Web/Pages/_Layout.cshtml +++ b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Web/Pages/_Layout.cshtml @@ -1,6 +1,7 @@ -@*#if (AppInsights) +@*#if (AppInsights) @inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet #endif*@ +@namespace Coalesce.Starter.Vue.Web.Pages diff --git a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Web/Program.cs b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Web/Program.cs index 3e3eeb430..34bbd97d5 100644 --- a/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Web/Program.cs +++ b/templates/Coalesce.Vue.Template/content/Coalesce.Starter.Vue.Web/Program.cs @@ -14,6 +14,7 @@ #if OpenAPI using Microsoft.OpenApi.Models; #endif +using System.Security.Claims; using System.Text.Json; using System.Text.Json.Serialization; using System.Text.RegularExpressions;