fix: PER_ACTIVE_USER Plan should be able to access everything above SCALE (#24352)
* Update managed-organizations.billing.service.ts * test: add plan restriction check for managed organization creation * test: add pay-per-user plan validation for managed organization creation * refactor: extract test setup to helpers * refactor: move helper functions below beforeAll for better test organization
This commit is contained in:
1 parent
aa48e72c12
commit
7601cc2194
2 files changed
+147
-49
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import { PlatformPlan } from "@/modules/billing/types";
|
||||
import { hasMinimumPlan } from "@/modules/auth/guards/billing/platform-plan.guard";
|
||||
import { orderedPlans, PlatformPlan } from "@/modules/billing/types";
|
||||
import { PrismaReadService } from "@/modules/prisma/prisma-read.service";
|
||||
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { ForbiddenException, Injectable, NotFoundException } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class ManagedOrganizationsBillingService {
|
||||
@@ -14,8 +15,18 @@ export class ManagedOrganizationsBillingService {
|
||||
if (!managerOrgBilling) {
|
||||
throw new NotFoundException("Manager organization billing not found.");
|
||||
}
|
||||
if (managerOrgBilling.plan !== PlatformPlan.SCALE) {
|
||||
throw new NotFoundException("Manager organization billing plan is not SCALE.");
|
||||
if (
|
||||
!hasMinimumPlan({
|
||||
currentPlan: managerOrgBilling.plan as PlatformPlan,
|
||||
minimumPlan: PlatformPlan.SCALE,
|
||||
plans: orderedPlans,
|
||||
})
|
||||
) {
|
||||
throw new ForbiddenException(
|
||||
`organization with id=${managerOrgId} does not have required plan for this operation. Minimum plan is ${
|
||||
PlatformPlan.SCALE
|
||||
} while the organization has ${managerOrgBilling.plan || "undefined"}.`
|
||||
);
|
||||
}
|
||||
|
||||
return this.dbWrite.prisma.platformBilling.create({
|
||||
|
||||
Reference in new issue
Block a user