a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[frontend/pages] Enforce limits for profile fields (ISH-768)

+36 -27
+5 -5
Iceshrimp.Backend/Controllers/Pleroma/Schemas/Entities/PleromaInstanceExtensions.cs
··· 1 - using Iceshrimp.Backend.Core.Configuration; 1 + using Iceshrimp.Shared.Configuration; 2 2 using J = System.Text.Json.Serialization.JsonPropertyNameAttribute; 3 3 4 4 namespace Iceshrimp.Backend.Controllers.Pleroma.Schemas.Entities; ··· 34 34 35 35 public class FieldsLimits 36 36 { 37 - [J("max_fields")] public int MaxFields => Constants.MaxProfileFields; 38 - [J("max_remote_fields")] public int MaxRemoteFields => Constants.MaxProfileFields; 39 - [J("name_length")] public int NameLength => Constants.MaxProfileFieldNameLength; 40 - [J("value_length")] public int ValueLength => Constants.MaxProfileFieldValueLength; 37 + [J("max_fields")] public int MaxFields => Limits.MaxProfileFields; 38 + [J("max_remote_fields")] public int MaxRemoteFields => Limits.MaxProfileFields; 39 + [J("name_length")] public int NameLength => Limits.MaxProfileFieldNameLength; 40 + [J("value_length")] public int ValueLength => Limits.MaxProfileFieldValueLength; 41 41 }
-4
Iceshrimp.Backend/Core/Configuration/Constants.cs
··· 63 63 "audio/flac", 64 64 "audio/vnd.wave" 65 65 ]; 66 - 67 - public const int MaxProfileFields = 10; 68 - public const int MaxProfileFieldNameLength = 1000; 69 - public const int MaxProfileFieldValueLength = 1000; 70 66 }
+10 -9
Iceshrimp.Backend/Core/Services/UserService.cs
··· 17 17 using Iceshrimp.Backend.Core.Queues; 18 18 using Iceshrimp.EntityFrameworkCore.Extensions; 19 19 using Iceshrimp.MfmSharp; 20 + using Iceshrimp.Shared.Configuration; 20 21 using Microsoft.EntityFrameworkCore; 21 22 using Microsoft.Extensions.Options; 22 23 ··· 322 323 }) 323 324 .Where(p => p is 324 325 { 325 - Name.Length: <= Constants.MaxProfileFieldNameLength, 326 - Value.Length: <= Constants.MaxProfileFieldValueLength 326 + Name.Length: <= Limits.MaxProfileFieldNameLength, 327 + Value.Length: <= Limits.MaxProfileFieldValueLength 327 328 }) 328 - .Take(Constants.MaxProfileFields); 329 + .Take(Limits.MaxProfileFields); 329 330 330 331 var pronouns = actor.Pronouns?.Values.ToDictionary(p => p.Key, p => p.Value ?? ""); 331 332 ··· 376 377 if (user.UserProfile == null) throw new Exception("user.UserProfile must not be null at this stage"); 377 378 378 379 // @formatter:off 379 - if (user.UserProfile.Fields.Length > Constants.MaxProfileFields) 380 - throw GracefulException.BadRequest($"Profile must not contain more than {Constants.MaxProfileFields} fields"); 381 - if (user.UserProfile.Fields.Any(p => p.Name.Length > Constants.MaxProfileFieldNameLength)) 382 - throw GracefulException.BadRequest($"Profile must not contain any fields with a name exceeding {Constants.MaxProfileFieldNameLength} characters"); 383 - if (user.UserProfile.Fields.Any(p => p.Value.Length > Constants.MaxProfileFieldValueLength)) 384 - throw GracefulException.BadRequest($"Profile must not contain any fields with a value exceeding {Constants.MaxProfileFieldValueLength} characters"); 380 + if (user.UserProfile.Fields.Length > Limits.MaxProfileFields) 381 + throw GracefulException.BadRequest($"Profile must not contain more than {Limits.MaxProfileFields} fields"); 382 + if (user.UserProfile.Fields.Any(p => p.Name.Length > Limits.MaxProfileFieldNameLength)) 383 + throw GracefulException.BadRequest($"Profile must not contain any fields with a name exceeding {Limits.MaxProfileFieldNameLength} characters"); 384 + if (user.UserProfile.Fields.Any(p => p.Value.Length > Limits.MaxProfileFieldValueLength)) 385 + throw GracefulException.BadRequest($"Profile must not contain any fields with a value exceeding {Limits.MaxProfileFieldValueLength} characters"); 385 386 // @formatter:on 386 387 387 388 user.DisplayName = user.DisplayName?.ReplaceLineEndings("\n").Trim();
+13 -9
Iceshrimp.Frontend/Pages/Settings/Profile.razor
··· 4 4 @using Iceshrimp.Frontend.Core.Miscellaneous 5 5 @using Iceshrimp.Frontend.Core.Services 6 6 @using Iceshrimp.Frontend.Localization 7 + @using Iceshrimp.Shared.Configuration 7 8 @using Iceshrimp.Shared.Schemas.Web 8 9 @using Microsoft.AspNetCore.Authorization 9 10 @using Microsoft.Extensions.Localization ··· 114 115 @foreach (var entry in UserProfile.Fields) 115 116 { 116 117 <div class="field"> 117 - <input class="input" placeholder="@Loc["Name"]" @bind="@entry.Name"/> 118 - <input class="input" placeholder="@Loc["Value"]" @bind="@entry.Value"/> 118 + <input class="input" placeholder="@Loc["Name"]" @bind="@entry.Name" maxlength="@Limits.MaxProfileFieldNameLength"/> 119 + <input class="input" placeholder="@Loc["Value"]" @bind="@entry.Value" maxlength="@Limits.MaxProfileFieldValueLength"/> 119 120 <button class="button" title="@Loc["Delete Field"]" @onclick="() => DeleteField(entry)"> 120 121 <Icon Name="Icons.Trash"/> 121 122 </button> ··· 124 125 </div> 125 126 </div> 126 127 127 - <div class="new-field"> 128 - <input class="input" placeholder="@Loc["Name"]" @bind="@FieldName"/> 129 - <input class="input" placeholder="@Loc["Value"]" @bind="@FieldValue"/> 130 - <button class="button" title="@Loc["Add Field"]" @onclick="AddField"> 131 - <Icon Name="Icons.Plus"/> 132 - </button> 133 - </div> 128 + @if (UserProfile.Fields.Count < Limits.MaxProfileFields) 129 + { 130 + <div class="new-field"> 131 + <input class="input" placeholder="@Loc["Name"]" @bind="@FieldName"/> 132 + <input class="input" placeholder="@Loc["Value"]" @bind="@FieldValue"/> 133 + <button class="button" title="@Loc["Add Field"]" @onclick="AddField"> 134 + <Icon Name="Icons.Plus"/> 135 + </button> 136 + </div> 137 + } 134 138 135 139 <div class="section"> 136 140 <h3>@Loc["Other"]</h3>
+8
Iceshrimp.Shared/Configuration/Limits.cs
··· 1 + namespace Iceshrimp.Shared.Configuration; 2 + 3 + public static class Limits 4 + { 5 + public const int MaxProfileFields = 10; 6 + public const int MaxProfileFieldNameLength = 1000; 7 + public const int MaxProfileFieldValueLength = 1000; 8 + }