From dbfc0353f0ec622fc6e3f0f91c81a1003ffe60d9 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Thu, 3 Aug 2023 23:28:21 +0200 Subject: [PATCH] Added a limit check in the permission.ts controller --- src/controller/permission.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/controller/permission.ts b/src/controller/permission.ts index d1781af..e58e374 100644 --- a/src/controller/permission.ts +++ b/src/controller/permission.ts @@ -35,6 +35,9 @@ export const createPermission = async (userId: string, projectId: string, config const permission = await Permission.findOne({ projectId: encryptClearField(String(access._id)), permission: encryptClearField(configuration.permission) }); if (permission !== null) return { code: 4008, message: "The provided permission name is already in use" }; + const count = await Permission.countDocuments({ projectId: encryptClearField(String(access._id)) }); + if (count >= planLimits[access.plan].PERMISSIONS) return { code: 95, message: "You have exceeded the permission limit" }; + await Permission.create({ ...configuration, projectId }); return {};