forked from administration/panel
feat: make profile wipe functional
parent
78632d4a48
commit
4f6be05162
|
@ -28,6 +28,7 @@ import {
|
||||||
unsuspendUser,
|
unsuspendUser,
|
||||||
updateBotDiscoverability,
|
updateBotDiscoverability,
|
||||||
updateUserBadges,
|
updateUserBadges,
|
||||||
|
wipeUserProfile,
|
||||||
} from "@/lib/actions";
|
} from "@/lib/actions";
|
||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { useToast } from "../../ui/use-toast";
|
import { useToast } from "../../ui/use-toast";
|
||||||
|
@ -345,21 +346,21 @@ export function UserActions({ user, bot }: { user: User; bot?: Bot }) {
|
||||||
Reset user profile
|
Reset user profile
|
||||||
</AlertDialogTitle>
|
</AlertDialogTitle>
|
||||||
<AlertDialogDescription>
|
<AlertDialogDescription>
|
||||||
<Checkbox checked={wipeDraft.bio} onChange={(e) => setWipeDraft({ ...wipeDraft, bio: e == true })}>
|
|
||||||
Bio
|
|
||||||
</Checkbox>
|
|
||||||
<Checkbox checked={wipeDraft.status} onChange={(e) => setWipeDraft({ ...wipeDraft, status: e == true })}>
|
|
||||||
Status
|
|
||||||
</Checkbox>
|
|
||||||
<Checkbox checked={wipeDraft.displayName} onChange={(e) => setWipeDraft({ ...wipeDraft, displayName: e == true })}>
|
|
||||||
Display Name
|
|
||||||
</Checkbox>
|
|
||||||
<Checkbox checked={wipeDraft.avatar} onChange={(e) => setWipeDraft({ ...wipeDraft, avatar: e == true })}>
|
<Checkbox checked={wipeDraft.avatar} onChange={(e) => setWipeDraft({ ...wipeDraft, avatar: e == true })}>
|
||||||
Avatar
|
Avatar
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
<Checkbox checked={wipeDraft.banner} onChange={(e) => setWipeDraft({ ...wipeDraft, banner: e == true })}>
|
<Checkbox checked={wipeDraft.banner} onChange={(e) => setWipeDraft({ ...wipeDraft, banner: e == true })}>
|
||||||
Profile Banner
|
Profile Banner
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
|
<Checkbox checked={wipeDraft.displayName} onChange={(e) => setWipeDraft({ ...wipeDraft, displayName: e == true })}>
|
||||||
|
Display Name
|
||||||
|
</Checkbox>
|
||||||
|
<Checkbox checked={wipeDraft.bio} onChange={(e) => setWipeDraft({ ...wipeDraft, bio: e == true })}>
|
||||||
|
Bio
|
||||||
|
</Checkbox>
|
||||||
|
<Checkbox checked={wipeDraft.status} onChange={(e) => setWipeDraft({ ...wipeDraft, status: e == true })}>
|
||||||
|
Status
|
||||||
|
</Checkbox>
|
||||||
</AlertDialogDescription>
|
</AlertDialogDescription>
|
||||||
</AlertDialogHeader>
|
</AlertDialogHeader>
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter>
|
||||||
|
@ -367,7 +368,23 @@ export function UserActions({ user, bot }: { user: User; bot?: Bot }) {
|
||||||
<AlertDialogAction
|
<AlertDialogAction
|
||||||
disabled={!Object.values(wipeDraft).filter(i => i).length}
|
disabled={!Object.values(wipeDraft).filter(i => i).length}
|
||||||
onClick={() => {
|
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</AlertDialogAction>
|
>Reset</AlertDialogAction>
|
||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
|
|
|
@ -48,7 +48,7 @@ type Permission =
|
||||||
| "/relations"}`
|
| "/relations"}`
|
||||||
| `/create${"" | "/alert" | "/strike"}`
|
| `/create${"" | "/alert" | "/strike"}`
|
||||||
| `/update${"" | "/badges"}`
|
| `/update${"" | "/badges"}`
|
||||||
| `/action${"" | "/unsuspend" | "/suspend" | "/wipe" | "/ban"}`}`;
|
| `/action${"" | "/unsuspend" | "/suspend" | "/wipe" | "/ban" | "/wipe-profile"}`}`;
|
||||||
|
|
||||||
const PermissionSets = {
|
const PermissionSets = {
|
||||||
// Admin
|
// Admin
|
||||||
|
@ -130,6 +130,7 @@ const PermissionSets = {
|
||||||
"users/create/strike",
|
"users/create/strike",
|
||||||
"users/action/suspend",
|
"users/action/suspend",
|
||||||
"users/action/wipe",
|
"users/action/wipe",
|
||||||
|
"users/action/wipe-profile",
|
||||||
"users/action/ban",
|
"users/action/ban",
|
||||||
"users/action/unsuspend",
|
"users/action/unsuspend",
|
||||||
"accounts/disable",
|
"accounts/disable",
|
||||||
|
|
|
@ -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<User>("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) {
|
export async function updateServerFlags(serverId: string, flags: number) {
|
||||||
await checkPermission("servers/update/flags", serverId, { flags });
|
await checkPermission("servers/update/flags", serverId, { flags });
|
||||||
await mongo().db("revolt").collection<Server>("servers").updateOne(
|
await mongo().db("revolt").collection<Server>("servers").updateOne(
|
||||||
|
|
Loading…
Reference in New Issue