diff --git a/Foxnouns.Backend/Dto/User.cs b/Foxnouns.Backend/Dto/User.cs index c681001..f193811 100644 --- a/Foxnouns.Backend/Dto/User.cs +++ b/Foxnouns.Backend/Dto/User.cs @@ -48,6 +48,7 @@ public record UserResponse( [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] Instant? LastActive, [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] Instant? LastSidReroll, [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] string? Timezone, + [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] bool? Suspended, [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] bool? Deleted ); diff --git a/Foxnouns.Backend/Middleware/LimitMiddleware.cs b/Foxnouns.Backend/Middleware/LimitMiddleware.cs index 82613c5..1c5f522 100644 --- a/Foxnouns.Backend/Middleware/LimitMiddleware.cs +++ b/Foxnouns.Backend/Middleware/LimitMiddleware.cs @@ -23,25 +23,29 @@ public class LimitMiddleware : IMiddleware Endpoint? endpoint = ctx.GetEndpoint(); LimitAttribute? attribute = endpoint?.Metadata.GetMetadata(); + Token? token = ctx.GetToken(); + if (attribute == null) { + // Check for authorize attribute + // If it exists, and the user is deleted, throw an error. + if ( + endpoint?.Metadata.GetMetadata() != null + && token?.User.Deleted == true + ) + { + throw new ApiError.Forbidden("Deleted users cannot access this endpoint."); + } + await next(ctx); return; } - Token? token = ctx.GetToken(); - if ( - token?.User.Deleted == true - && (!attribute.UsableBySuspendedUsers || token.User.DeletedBy == null) - ) - { + if (token?.User.Deleted == true && !attribute.UsableBySuspendedUsers) throw new ApiError.Forbidden("Deleted users cannot access this endpoint."); - } if (attribute.RequireAdmin && token?.User.Role != UserRole.Admin) - { throw new ApiError.Forbidden("This endpoint can only be used by admins."); - } if ( attribute.RequireModerator diff --git a/Foxnouns.Backend/Services/ModerationRendererService.cs b/Foxnouns.Backend/Services/ModerationRendererService.cs index e5d8165..deed9c5 100644 --- a/Foxnouns.Backend/Services/ModerationRendererService.cs +++ b/Foxnouns.Backend/Services/ModerationRendererService.cs @@ -21,7 +21,6 @@ using Newtonsoft.Json.Linq; namespace Foxnouns.Backend.Services; public class ModerationRendererService( - DatabaseContext db, UserRendererService userRenderer, MemberRendererService memberRenderer ) diff --git a/Foxnouns.Backend/Services/UserRendererService.cs b/Foxnouns.Backend/Services/UserRendererService.cs index 7a00328..df40e1a 100644 --- a/Foxnouns.Backend/Services/UserRendererService.cs +++ b/Foxnouns.Backend/Services/UserRendererService.cs @@ -115,6 +115,7 @@ public class UserRendererService( tokenHidden ? user.LastActive : null, tokenHidden ? user.LastSidReroll : null, tokenHidden ? user.Timezone ?? "" : null, + tokenHidden ? user is { Deleted: true, DeletedBy: not null } : null, tokenHidden ? user.Deleted : null ); } diff --git a/Foxnouns.Frontend/src/lib/api/models/user.ts b/Foxnouns.Frontend/src/lib/api/models/user.ts index 29740e6..6cd8e4c 100644 --- a/Foxnouns.Frontend/src/lib/api/models/user.ts +++ b/Foxnouns.Frontend/src/lib/api/models/user.ts @@ -26,6 +26,7 @@ export type MeUser = UserWithMembers & { last_active: string; last_sid_reroll: string; timezone: string; + suspended: boolean; deleted: boolean; }; diff --git a/Foxnouns.Frontend/src/lib/components/Navbar.svelte b/Foxnouns.Frontend/src/lib/components/Navbar.svelte index 365ede2..68c1b14 100644 --- a/Foxnouns.Frontend/src/lib/components/Navbar.svelte +++ b/Foxnouns.Frontend/src/lib/components/Navbar.svelte @@ -21,10 +21,17 @@ {#if user && user.deleted} -
- {$t("nav.suspended-account-hint")} -
- {$t("nav.appeal-suspension-link")} +
+ {#if user.suspended} + {$t("nav.suspended-account-hint")} +
+ {$t("nav.appeal-suspension-link")} + {:else} + {$t("nav.deleted-account-hint")} +
+ {$t("nav.reactivate-account-link")} • + {$t("nav.delete-permanently-link")} + {/if}
{/if} @@ -66,7 +73,7 @@