mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-02 16:25:52 +00:00
Merge pull request #649 from Infisical/environment-paywall
Update implementation for environment limit paywall
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
} from '../../models';
|
} from '../../models';
|
||||||
import { SecretVersion } from '../../ee/models';
|
import { SecretVersion } from '../../ee/models';
|
||||||
import { EELicenseService } from '../../ee/services';
|
import { EELicenseService } from '../../ee/services';
|
||||||
import { BadRequestError } from '../../utils/errors';
|
import { BadRequestError, WorkspaceNotFoundError } from '../../utils/errors';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { PERMISSION_READ_SECRETS, PERMISSION_WRITE_SECRETS } from '../../variables';
|
import { PERMISSION_READ_SECRETS, PERMISSION_WRITE_SECRETS } from '../../variables';
|
||||||
|
|
||||||
@@ -23,9 +23,26 @@ export const createWorkspaceEnvironment = async (
|
|||||||
req: Request,
|
req: Request,
|
||||||
res: Response
|
res: Response
|
||||||
) => {
|
) => {
|
||||||
|
|
||||||
const { workspaceId } = req.params;
|
const { workspaceId } = req.params;
|
||||||
const { environmentName, environmentSlug } = req.body;
|
const { environmentName, environmentSlug } = req.body;
|
||||||
const workspace = await Workspace.findById(workspaceId).exec();
|
const workspace = await Workspace.findById(workspaceId).exec();
|
||||||
|
|
||||||
|
if (!workspace) throw WorkspaceNotFoundError();
|
||||||
|
|
||||||
|
const plan = await EELicenseService.getPlan(workspace.organization.toString());
|
||||||
|
|
||||||
|
if (plan.environmentLimit !== null) {
|
||||||
|
// case: limit imposed on number of environments allowed
|
||||||
|
if (workspace.environments.length >= plan.environmentLimit) {
|
||||||
|
// case: number of environments used exceeds the number of environments allowed
|
||||||
|
|
||||||
|
return res.status(400).send({
|
||||||
|
message: 'Failed to create environment due to environment limit reached. Upgrade plan to create more environments.'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!workspace ||
|
!workspace ||
|
||||||
workspace?.environments.find(
|
workspace?.environments.find(
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ export const ProjectSettingsPage = () => {
|
|||||||
|
|
||||||
// get user subscription
|
// get user subscription
|
||||||
const { subscription } = useSubscription();
|
const { subscription } = useSubscription();
|
||||||
const host = window.location.origin;
|
|
||||||
const isEnvServiceAllowed = (((currentWorkspace?.environments || []).length < (subscription?.environmentLimit || 3)) || host !== 'https://app.infisical.com');
|
const isEnvServiceAllowed = (subscription?.environmentLimit && currentWorkspace?.environments) ? (currentWorkspace.environments.length < subscription.environmentLimit) : true;
|
||||||
|
|
||||||
const onRenameWorkspace = async (name: string) => {
|
const onRenameWorkspace = async (name: string) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user