forked from administration/panel
chore: reduce permissions required to wipe / update badges
parent
70133ff82b
commit
a896884593
|
@ -18,6 +18,7 @@ import {
|
|||
AccountInfo,
|
||||
AccountStrike,
|
||||
Bot,
|
||||
Channel,
|
||||
File,
|
||||
Member,
|
||||
Message,
|
||||
|
@ -281,10 +282,7 @@ export async function suspendUser(userId: string) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function updateUserBadges(
|
||||
userId: string,
|
||||
badges: number
|
||||
): Promise<{ updatePublished: boolean }> {
|
||||
export async function updateUserBadges(userId: string, badges: number) {
|
||||
await checkPermission("users/update/badges", userId, { badges });
|
||||
await mongo().db("revolt").collection<User>("users").updateOne(
|
||||
{
|
||||
|
@ -297,8 +295,12 @@ export async function updateUserBadges(
|
|||
}
|
||||
);
|
||||
|
||||
try {
|
||||
const memberships = await fetchMembershipsByUser(userId);
|
||||
const memberships = await mongo()
|
||||
.db("revolt")
|
||||
.collection<{ _id: { user: string; server: string } }>("server_members")
|
||||
.find({ "_id.user": userId })
|
||||
.toArray();
|
||||
|
||||
for (const topic of [userId, ...memberships.map((x) => x._id.server)]) {
|
||||
await publishMessage(topic, {
|
||||
type: "UserUpdate",
|
||||
|
@ -309,11 +311,6 @@ export async function updateUserBadges(
|
|||
clear: [],
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
return { updatePublished: false };
|
||||
}
|
||||
|
||||
return { updatePublished: true };
|
||||
}
|
||||
|
||||
export async function wipeUser(userId: string, flags = 4) {
|
||||
|
@ -321,16 +318,39 @@ export async function wipeUser(userId: string, flags = 4) {
|
|||
|
||||
await checkPermission("users/action/wipe", userId, { flags });
|
||||
|
||||
const user = await mongo()
|
||||
.db("revolt")
|
||||
.collection<User>("users")
|
||||
.findOne({ _id: userId });
|
||||
|
||||
const messages = await mongo()
|
||||
.db("revolt")
|
||||
.collection<Message>("messages")
|
||||
.find({ author: userId }, { sort: { _id: -1 } })
|
||||
.toArray();
|
||||
|
||||
const dms = await mongo()
|
||||
.db("revolt")
|
||||
.collection<Channel>("channels")
|
||||
.find({
|
||||
channel_type: "DirectMessage",
|
||||
recipients: userId,
|
||||
})
|
||||
.toArray();
|
||||
|
||||
const memberships = await mongo()
|
||||
.db("revolt")
|
||||
.collection<{ _id: { user: string; server: string } }>("server_members")
|
||||
.find({ "_id.user": userId })
|
||||
.toArray();
|
||||
|
||||
// retrieve messages, dm channels, relationships, server memberships
|
||||
const backup = {
|
||||
_event: "wipe",
|
||||
user: await fetchUserById(userId),
|
||||
messages: await fetchMessages({ author: userId }, undefined),
|
||||
dms: await fetchChannels({
|
||||
channel_type: "DirectMessage",
|
||||
recipients: userId,
|
||||
}),
|
||||
memberships: await fetchMembershipsByUser(userId),
|
||||
user,
|
||||
messages,
|
||||
dms,
|
||||
memberships,
|
||||
};
|
||||
|
||||
await writeFile(
|
||||
|
|
Loading…
Reference in New Issue