diff --git a/components/pages/inspector/UserActions.tsx b/components/pages/inspector/UserActions.tsx
index 8d0fb63..50fa40c 100644
--- a/components/pages/inspector/UserActions.tsx
+++ b/components/pages/inspector/UserActions.tsx
@@ -28,6 +28,7 @@ import {
unsuspendUser,
updateBotDiscoverability,
updateUserBadges,
+ wipeUserProfile,
} from "@/lib/actions";
import { useRef, useState } from "react";
import { useToast } from "../../ui/use-toast";
@@ -345,21 +346,21 @@ export function UserActions({ user, bot }: { user: User; bot?: Bot }) {
Reset user profile
- setWipeDraft({ ...wipeDraft, bio: e == true })}>
- Bio
-
- setWipeDraft({ ...wipeDraft, status: e == true })}>
- Status
-
- setWipeDraft({ ...wipeDraft, displayName: e == true })}>
- Display Name
-
setWipeDraft({ ...wipeDraft, avatar: e == true })}>
Avatar
setWipeDraft({ ...wipeDraft, banner: e == true })}>
Profile Banner
+ setWipeDraft({ ...wipeDraft, displayName: e == true })}>
+ Display Name
+
+ setWipeDraft({ ...wipeDraft, bio: e == true })}>
+ Bio
+
+ setWipeDraft({ ...wipeDraft, status: e == true })}>
+ Status
+
@@ -367,7 +368,23 @@ export function UserActions({ user, bot }: { user: User; bot?: Bot }) {
i).length}
onClick={() => {
- toast({ title: "todo" })
+ wipeUserProfile(user._id, wipeDraft)
+ .then(() => {
+ toast({ title: "Wiped selected fields" });
+ window.location.reload();
+ })
+ .catch((e) => toast({
+ title: "Failed to wipe profile",
+ description: String(e),
+ variant: "destructive",
+ }))
+ .finally(() => setWipeDraft({
+ avatar: false,
+ banner: false,
+ bio: false,
+ displayName: false,
+ status: false,
+ }));
}}
>Reset
diff --git a/lib/accessPermissions.ts b/lib/accessPermissions.ts
index 10d544d..9ed17b5 100644
--- a/lib/accessPermissions.ts
+++ b/lib/accessPermissions.ts
@@ -48,7 +48,7 @@ type Permission =
| "/relations"}`
| `/create${"" | "/alert" | "/strike"}`
| `/update${"" | "/badges"}`
- | `/action${"" | "/unsuspend" | "/suspend" | "/wipe" | "/ban"}`}`;
+ | `/action${"" | "/unsuspend" | "/suspend" | "/wipe" | "/ban" | "/wipe-profile"}`}`;
const PermissionSets = {
// Admin
@@ -130,6 +130,7 @@ const PermissionSets = {
"users/create/strike",
"users/action/suspend",
"users/action/wipe",
+ "users/action/wipe-profile",
"users/action/ban",
"users/action/unsuspend",
"accounts/disable",
diff --git a/lib/actions.ts b/lib/actions.ts
index 664207a..fadb8bc 100644
--- a/lib/actions.ts
+++ b/lib/actions.ts
@@ -382,6 +382,43 @@ export async function unsuspendUser(userId: string) {
);
}
+export async function wipeUserProfile(
+ userId: string,
+ fields: {
+ banner: boolean,
+ avatar: boolean,
+ bio: boolean,
+ displayName: boolean,
+ status: boolean,
+ }
+) {
+ await checkPermission("users/action/wipe-profile", userId);
+
+ const newDisplayName = (await fetchUserById(userId))?.username || "--";
+
+ await mongo()
+ .db("revolt")
+ .collection("users")
+ .updateOne(
+ {
+ _id: userId,
+ },
+ {
+ $unset: {
+ ...(fields.banner ? { "profile.background": 1 } : {}),
+ ...(fields.bio ? { "profile.content": 1 } : {}),
+ ...(fields.status ? { "status.text": 1 } : {}),
+ ...(fields.avatar ? { "avatar": 1 } : {}),
+ },
+ ...(fields.displayName ? {
+ $set: {
+ display_name: newDisplayName,
+ },
+ } : {}),
+ }
+ )
+}
+
export async function updateServerFlags(serverId: string, flags: number) {
await checkPermission("servers/update/flags", serverId, { flags });
await mongo().db("revolt").collection("servers").updateOne(