Add limit of 10 webhooks/team

This commit is contained in:
Tom Moor
2022-08-08 10:58:47 +02:00
parent dca9bc1598
commit b37a848914
2 changed files with 22 additions and 0 deletions

View File

@@ -7,8 +7,11 @@ import {
NotEmpty,
DataType,
IsUrl,
BeforeCreate,
} from "sequelize-typescript";
import { SaveOptions } from "sequelize/types";
import { WebhookSubscriptionValidation } from "@shared/validations";
import { ValidationError } from "@server/errors";
import { Event } from "@server/types";
import Team from "./Team";
import User from "./User";
@@ -55,6 +58,20 @@ class WebhookSubscription extends ParanoidModel {
@Column
teamId: string;
// hooks
@BeforeCreate
static async checkLimit(model: WebhookSubscription) {
const count = await this.count({
where: { teamId: model.teamId },
});
if (count >= WebhookSubscriptionValidation.maxSubscriptions) {
throw ValidationError(
`You have reached the limit of ${WebhookSubscriptionValidation.maxSubscriptions} webhooks`
);
}
}
// methods
/**

View File

@@ -41,3 +41,8 @@ export const TeamValidation = {
/** The maximum number of domains per team */
maxDomains: 10,
};
export const WebhookSubscriptionValidation = {
/** The maximum number of webhooks per team */
maxSubscriptions: 10,
};