feat: Cleanup api keys and webhooks for suspended users (#3756)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
DataType,
|
||||
IsUrl,
|
||||
} from "sequelize-typescript";
|
||||
import { SaveOptions } from "sequelize/types";
|
||||
import { Event } from "@server/types";
|
||||
import Team from "./Team";
|
||||
import User from "./User";
|
||||
@@ -55,7 +56,18 @@ class WebhookSubscription extends ParanoidModel {
|
||||
teamId: string;
|
||||
|
||||
// methods
|
||||
validForEvent = (event: Event): bool => {
|
||||
|
||||
/**
|
||||
* Disables the webhook subscription
|
||||
*
|
||||
* @param options Save options
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
public async disable(options?: SaveOptions<WebhookSubscription>) {
|
||||
return this.update({ enabled: false }, options);
|
||||
}
|
||||
|
||||
public validForEvent = (event: Event): bool => {
|
||||
if (this.events.length === 1 && this.events[0] === "*") {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user