mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-10 15:06:37 +00:00
Dont accept invite if over the limits
This commit is contained in:
@@ -97,7 +97,7 @@ export async function createRemoteExitNode(
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.FORBIDDEN,
|
||||
"Remote exit node limit exceeded. Please upgrade your plan or contact us at support@pangolin.net"
|
||||
"Remote node limit exceeded. Please upgrade your plan."
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ export async function createSite(
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.FORBIDDEN,
|
||||
"Sites limit exceeded. Please upgrade your plan."
|
||||
"Site limit exceeded. Please upgrade your plan."
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { verifySession } from "@server/auth/sessions/verifySession";
|
||||
import { usageService } from "@server/lib/billing/usageService";
|
||||
import { FeatureId } from "@server/lib/billing";
|
||||
import { calculateUserClientsForOrgs } from "@server/lib/calculateUserClientsForOrgs";
|
||||
import { build } from "@server/build";
|
||||
|
||||
const acceptInviteBodySchema = z.strictObject({
|
||||
token: z.string(),
|
||||
@@ -92,6 +93,35 @@ export async function acceptInvite(
|
||||
);
|
||||
}
|
||||
|
||||
if (build == "saas") {
|
||||
const usage = await usageService.getUsage(existingInvite.orgId, FeatureId.USERS);
|
||||
if (!usage) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.NOT_FOUND,
|
||||
"No usage data found for this organization"
|
||||
)
|
||||
);
|
||||
}
|
||||
const rejectUsers = await usageService.checkLimitSet(
|
||||
existingInvite.orgId,
|
||||
false,
|
||||
FeatureId.USERS,
|
||||
{
|
||||
...usage,
|
||||
instantaneousValue: (usage.instantaneousValue || 0) + 1
|
||||
} // We need to add one to know if we are violating the limit
|
||||
);
|
||||
if (rejectUsers) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.FORBIDDEN,
|
||||
"Can not accept because this org's user limit is exceeded. Please contact your administrator to upgrade their plan."
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let roleId: number;
|
||||
let totalUsers: UserOrg[] | undefined;
|
||||
// get the role to make sure it exists
|
||||
|
||||
Reference in New Issue
Block a user