feat: Cleanup api keys and webhooks for suspended users (#3756)

This commit is contained in:
Tom Moor
2022-07-13 09:59:31 +02:00
committed by GitHub
parent d1b01d28e6
commit 47e73cee4e
11 changed files with 264 additions and 29 deletions

View File

@@ -46,6 +46,11 @@ export enum UserFlag {
InviteReminderSent = "inviteReminderSent",
}
export enum UserRole {
Member = "member",
Viewer = "viewer",
}
@Scopes(() => ({
withAuthentications: {
include: [
@@ -373,10 +378,10 @@ class User extends ParanoidModel {
);
};
demote = async (teamId: string, to: "member" | "viewer") => {
demote = async (to: UserRole, options?: SaveOptions<User>) => {
const res = await (this.constructor as typeof User).findAndCountAll({
where: {
teamId,
teamId: this.teamId,
isAdmin: true,
id: {
[Op.ne]: this.id,
@@ -387,15 +392,21 @@ class User extends ParanoidModel {
if (res.count >= 1) {
if (to === "member") {
return this.update({
isAdmin: false,
isViewer: false,
});
return this.update(
{
isAdmin: false,
isViewer: false,
},
options
);
} else if (to === "viewer") {
return this.update({
isAdmin: false,
isViewer: true,
});
return this.update(
{
isAdmin: false,
isViewer: true,
},
options
);
}
return undefined;