Add limit of 10 webhooks/team
This commit is contained in:
@@ -7,8 +7,11 @@ import {
|
|||||||
NotEmpty,
|
NotEmpty,
|
||||||
DataType,
|
DataType,
|
||||||
IsUrl,
|
IsUrl,
|
||||||
|
BeforeCreate,
|
||||||
} from "sequelize-typescript";
|
} from "sequelize-typescript";
|
||||||
import { SaveOptions } from "sequelize/types";
|
import { SaveOptions } from "sequelize/types";
|
||||||
|
import { WebhookSubscriptionValidation } from "@shared/validations";
|
||||||
|
import { ValidationError } from "@server/errors";
|
||||||
import { Event } from "@server/types";
|
import { Event } from "@server/types";
|
||||||
import Team from "./Team";
|
import Team from "./Team";
|
||||||
import User from "./User";
|
import User from "./User";
|
||||||
@@ -55,6 +58,20 @@ class WebhookSubscription extends ParanoidModel {
|
|||||||
@Column
|
@Column
|
||||||
teamId: string;
|
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
|
// methods
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,3 +41,8 @@ export const TeamValidation = {
|
|||||||
/** The maximum number of domains per team */
|
/** The maximum number of domains per team */
|
||||||
maxDomains: 10,
|
maxDomains: 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const WebhookSubscriptionValidation = {
|
||||||
|
/** The maximum number of webhooks per team */
|
||||||
|
maxSubscriptions: 10,
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user