feat: allow suspended *and* self-deleted users to access a handful of pages
This commit is contained in:
parent
36cb1d2043
commit
f766a2054b
7 changed files with 32 additions and 16 deletions
|
@ -48,6 +48,7 @@ public record UserResponse(
|
||||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] Instant? LastActive,
|
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] Instant? LastActive,
|
||||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] Instant? LastSidReroll,
|
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] Instant? LastSidReroll,
|
||||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] string? Timezone,
|
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] string? Timezone,
|
||||||
|
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] bool? Suspended,
|
||||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] bool? Deleted
|
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] bool? Deleted
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -23,26 +23,30 @@ public class LimitMiddleware : IMiddleware
|
||||||
Endpoint? endpoint = ctx.GetEndpoint();
|
Endpoint? endpoint = ctx.GetEndpoint();
|
||||||
LimitAttribute? attribute = endpoint?.Metadata.GetMetadata<LimitAttribute>();
|
LimitAttribute? attribute = endpoint?.Metadata.GetMetadata<LimitAttribute>();
|
||||||
|
|
||||||
|
Token? token = ctx.GetToken();
|
||||||
|
|
||||||
if (attribute == null)
|
if (attribute == null)
|
||||||
{
|
{
|
||||||
await next(ctx);
|
// Check for authorize attribute
|
||||||
return;
|
// If it exists, and the user is deleted, throw an error.
|
||||||
}
|
|
||||||
|
|
||||||
Token? token = ctx.GetToken();
|
|
||||||
if (
|
if (
|
||||||
token?.User.Deleted == true
|
endpoint?.Metadata.GetMetadata<AuthorizeAttribute>() != null
|
||||||
&& (!attribute.UsableBySuspendedUsers || token.User.DeletedBy == null)
|
&& token?.User.Deleted == true
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
throw new ApiError.Forbidden("Deleted users cannot access this endpoint.");
|
throw new ApiError.Forbidden("Deleted users cannot access this endpoint.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attribute.RequireAdmin && token?.User.Role != UserRole.Admin)
|
await next(ctx);
|
||||||
{
|
return;
|
||||||
throw new ApiError.Forbidden("This endpoint can only be used by admins.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 (
|
if (
|
||||||
attribute.RequireModerator
|
attribute.RequireModerator
|
||||||
&& token?.User.Role is not (UserRole.Admin or UserRole.Moderator)
|
&& token?.User.Role is not (UserRole.Admin or UserRole.Moderator)
|
||||||
|
|
|
@ -21,7 +21,6 @@ using Newtonsoft.Json.Linq;
|
||||||
namespace Foxnouns.Backend.Services;
|
namespace Foxnouns.Backend.Services;
|
||||||
|
|
||||||
public class ModerationRendererService(
|
public class ModerationRendererService(
|
||||||
DatabaseContext db,
|
|
||||||
UserRendererService userRenderer,
|
UserRendererService userRenderer,
|
||||||
MemberRendererService memberRenderer
|
MemberRendererService memberRenderer
|
||||||
)
|
)
|
||||||
|
|
|
@ -115,6 +115,7 @@ public class UserRendererService(
|
||||||
tokenHidden ? user.LastActive : null,
|
tokenHidden ? user.LastActive : null,
|
||||||
tokenHidden ? user.LastSidReroll : null,
|
tokenHidden ? user.LastSidReroll : null,
|
||||||
tokenHidden ? user.Timezone ?? "<none>" : null,
|
tokenHidden ? user.Timezone ?? "<none>" : null,
|
||||||
|
tokenHidden ? user is { Deleted: true, DeletedBy: not null } : null,
|
||||||
tokenHidden ? user.Deleted : null
|
tokenHidden ? user.Deleted : null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ export type MeUser = UserWithMembers & {
|
||||||
last_active: string;
|
last_active: string;
|
||||||
last_sid_reroll: string;
|
last_sid_reroll: string;
|
||||||
timezone: string;
|
timezone: string;
|
||||||
|
suspended: boolean;
|
||||||
deleted: boolean;
|
deleted: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,17 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if user && user.deleted}
|
{#if user && user.deleted}
|
||||||
<div class="suspended-alert text-center py-3 mb-2 px-2">
|
<div class="deleted-alert text-center py-3 mb-2 px-2">
|
||||||
|
{#if user.suspended}
|
||||||
<strong>{$t("nav.suspended-account-hint")}</strong>
|
<strong>{$t("nav.suspended-account-hint")}</strong>
|
||||||
<br />
|
<br />
|
||||||
<a href="/contact">{$t("nav.appeal-suspension-link")}</a>
|
<a href="/contact">{$t("nav.appeal-suspension-link")}</a>
|
||||||
|
{:else}
|
||||||
|
<strong>{$t("nav.deleted-account-hint")}</strong>
|
||||||
|
<br />
|
||||||
|
<a href="/settings/reactivate">{$t("nav.reactivate-account-link")}</a> •
|
||||||
|
<a href="/contact">{$t("nav.delete-permanently-link")}</a>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
@ -66,7 +73,7 @@
|
||||||
</Navbar>
|
</Navbar>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.suspended-alert {
|
.deleted-alert {
|
||||||
color: var(--bs-danger-text-emphasis);
|
color: var(--bs-danger-text-emphasis);
|
||||||
background-color: var(--bs-danger-bg-subtle);
|
background-color: var(--bs-danger-bg-subtle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
"log-in": "Log in or sign up",
|
"log-in": "Log in or sign up",
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
"suspended-account-hint": "Your account has been suspended. Your profile has been hidden and you will not be able to change any settings.",
|
"suspended-account-hint": "Your account has been suspended. Your profile has been hidden and you will not be able to change any settings.",
|
||||||
"appeal-suspension-link": "I want to appeal"
|
"appeal-suspension-link": "I want to appeal",
|
||||||
|
"deleted-account-hint": "You have requested deletion of your account. If you want to reactivate it, click the link below.",
|
||||||
|
"reactivate-account-link": "Reactivate account",
|
||||||
|
"delete-permanently-link": "I want my account deleted permanently"
|
||||||
},
|
},
|
||||||
"avatar-tooltip": "Avatar for {{name}}",
|
"avatar-tooltip": "Avatar for {{name}}",
|
||||||
"profile": {
|
"profile": {
|
||||||
|
|
Loading…
Reference in a new issue