diff --git a/Foxnouns.Backend/Controllers/MembersController.cs b/Foxnouns.Backend/Controllers/MembersController.cs index 44bb9ce..8438161 100644 --- a/Foxnouns.Backend/Controllers/MembersController.cs +++ b/Foxnouns.Backend/Controllers/MembersController.cs @@ -54,7 +54,8 @@ public class MembersController( ("avatar", ValidationUtils.ValidateAvatar(req.Avatar)), .. ValidationUtils.ValidateFields(req.Fields, CurrentUser!.CustomPreferences), .. ValidationUtils.ValidateFieldEntries(req.Names?.ToArray(), CurrentUser!.CustomPreferences, "names"), - .. ValidationUtils.ValidatePronouns(req.Pronouns?.ToArray(), CurrentUser!.CustomPreferences) + .. ValidationUtils.ValidatePronouns(req.Pronouns?.ToArray(), CurrentUser!.CustomPreferences), + .. ValidationUtils.ValidateLinks(req.Links) ]); var member = new Member @@ -64,6 +65,7 @@ public class MembersController( Name = req.Name, DisplayName = req.DisplayName, Bio = req.Bio, + Links = req.Links ?? [], Fields = req.Fields ?? [], Names = req.Names ?? [], Pronouns = req.Pronouns ?? [], @@ -113,6 +115,7 @@ public class MembersController( string? Bio, string? Avatar, bool? Unlisted, + string[]? Links, List? Names, List? Pronouns, List? Fields); diff --git a/Foxnouns.Backend/Controllers/UsersController.cs b/Foxnouns.Backend/Controllers/UsersController.cs index 05bccdd..c976183 100644 --- a/Foxnouns.Backend/Controllers/UsersController.cs +++ b/Foxnouns.Backend/Controllers/UsersController.cs @@ -64,7 +64,7 @@ public class UsersController( if (req.HasProperty(nameof(req.Links))) { - // TODO: validate link length + errors.AddRange(ValidationUtils.ValidateLinks(req.Links)); user.Links = req.Links ?? []; } @@ -238,7 +238,7 @@ public class UsersController( .SetProperty(u => u.Sid, _ => db.FindFreeUserSid()) .SetProperty(u => u.LastSidReroll, clock.GetCurrentInstant()) .SetProperty(u => u.LastActive, clock.GetCurrentInstant())); - + var user = await db.ResolveUserAsync(CurrentUser.Id); return Ok(await userRenderer.RenderUserAsync(user, CurrentUser, CurrentToken, renderMembers: false)); } diff --git a/Foxnouns.Backend/Database/DatabaseContext.cs b/Foxnouns.Backend/Database/DatabaseContext.cs index 81866fe..dbf38c5 100644 --- a/Foxnouns.Backend/Database/DatabaseContext.cs +++ b/Foxnouns.Backend/Database/DatabaseContext.cs @@ -21,7 +21,7 @@ public class DatabaseContext : DbContext public DbSet Tokens { get; set; } public DbSet Applications { get; set; } public DbSet TemporaryKeys { get; set; } - + public DbSet PrideFlags { get; set; } public DbSet UserFlags { get; set; } public DbSet MemberFlags { get; set; } diff --git a/Foxnouns.Backend/Services/MemberRendererService.cs b/Foxnouns.Backend/Services/MemberRendererService.cs index 11416f0..0fdaa53 100644 --- a/Foxnouns.Backend/Services/MemberRendererService.cs +++ b/Foxnouns.Backend/Services/MemberRendererService.cs @@ -37,7 +37,8 @@ public class MemberRendererService(DatabaseContext db, Config config) private UserRendererService.PartialUser RenderPartialUser(User user) => new(user.Id, user.Sid, user.Username, user.DisplayName, AvatarUrlFor(user), user.CustomPreferences); - public PartialMember RenderPartialMember(Member member, bool renderUnlisted = false) => new(member.Id, member.Sid, member.Name, + public PartialMember RenderPartialMember(Member member, bool renderUnlisted = false) => new(member.Id, member.Sid, + member.Name, member.DisplayName, member.Bio, AvatarUrlFor(member), member.Names, member.Pronouns, renderUnlisted ? member.Unlisted : null); diff --git a/Foxnouns.Backend/Utils/ValidationUtils.cs b/Foxnouns.Backend/Utils/ValidationUtils.cs index f29dd24..1650860 100644 --- a/Foxnouns.Backend/Utils/ValidationUtils.cs +++ b/Foxnouns.Backend/Utils/ValidationUtils.cs @@ -99,6 +99,34 @@ public static class ValidationUtils }; } + private const int MaxLinks = 25; + private const int MaxLinkLength = 256; + + public static IEnumerable<(string, ValidationError?)> ValidateLinks(string[]? links) + { + if (links == null) return []; + if (links.Length > MaxLinks) + return [("links", ValidationError.LengthError("Too many links", 0, MaxLinks, links.Length))]; + + var errors = new List<(string, ValidationError?)>(); + foreach (var (link, idx) in links.Select((l, i) => (l, i))) + { + switch (link.Length) + { + case 0: + errors.Add(($"links.{idx}", + ValidationError.LengthError("Link cannot be empty", 1, 256, 0))); + break; + case > MaxLinkLength: + errors.Add(($"links.{idx}", + ValidationError.LengthError("Link is too long", 1, MaxLinkLength, link.Length))); + break; + } + } + + return errors; + } + public static ValidationError? ValidateBio(string? bio) { return bio?.Length switch