feat: Cleanup api keys and webhooks for suspended users (#3756)
This commit is contained in:
36
server/commands/userDemoter.ts
Normal file
36
server/commands/userDemoter.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { sequelize } from "@server/database/sequelize";
|
||||
import { ValidationError } from "@server/errors";
|
||||
import { Event, User } from "@server/models";
|
||||
import type { UserRole } from "@server/models/User";
|
||||
import CleanupDemotedUserTask from "@server/queues/tasks/CleanupDemotedUserTask";
|
||||
|
||||
type Props = {
|
||||
user: User;
|
||||
actorId: string;
|
||||
to: UserRole;
|
||||
ip: string;
|
||||
};
|
||||
|
||||
export default async function userDemoter({ user, actorId, to, ip }: Props) {
|
||||
if (user.id === actorId) {
|
||||
throw ValidationError("Unable to demote the current user");
|
||||
}
|
||||
|
||||
return sequelize.transaction(async (transaction) => {
|
||||
await user.demote(to, { transaction });
|
||||
await Event.create(
|
||||
{
|
||||
name: "users.demote",
|
||||
actorId,
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
data: {
|
||||
name: user.name,
|
||||
},
|
||||
ip,
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
await CleanupDemotedUserTask.schedule({ userId: user.id });
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Transaction } from "sequelize";
|
||||
import { sequelize } from "@server/database/sequelize";
|
||||
import { User, Event, GroupUser } from "@server/models";
|
||||
import CleanupDemotedUserTask from "@server/queues/tasks/CleanupDemotedUserTask";
|
||||
import { ValidationError } from "../errors";
|
||||
|
||||
type Props = {
|
||||
@@ -49,5 +50,7 @@ export default async function userSuspender({
|
||||
transaction,
|
||||
}
|
||||
);
|
||||
|
||||
await CleanupDemotedUserTask.schedule({ userId: user.id });
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user