mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 21:27:10 +00:00
patch env delete bug
This commit is contained in:
@@ -27,16 +27,16 @@ export const createWorkspaceEnvironment = async (
|
|||||||
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();
|
if (!workspace) throw WorkspaceNotFoundError();
|
||||||
|
|
||||||
const plan = await EELicenseService.getPlan(workspace.organization.toString());
|
const plan = await EELicenseService.getPlan(workspace.organization.toString());
|
||||||
|
|
||||||
if (plan.environmentLimit !== null) {
|
if (plan.environmentLimit !== null) {
|
||||||
// case: limit imposed on number of environments allowed
|
// case: limit imposed on number of environments allowed
|
||||||
if (workspace.environments.length >= plan.environmentLimit) {
|
if (workspace.environments.length >= plan.environmentLimit) {
|
||||||
// case: number of environments used exceeds the number of environments allowed
|
// case: number of environments used exceeds the number of environments allowed
|
||||||
|
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
message: "Failed to create environment due to environment limit reached. Upgrade plan to create more environments.",
|
message: "Failed to create environment due to environment limit reached. Upgrade plan to create more environments.",
|
||||||
});
|
});
|
||||||
@@ -191,14 +191,21 @@ export const deleteWorkspaceEnvironment = async (
|
|||||||
workspace: workspaceId,
|
workspace: workspaceId,
|
||||||
environment: environmentSlug,
|
environment: environmentSlug,
|
||||||
});
|
});
|
||||||
await ServiceToken.deleteMany({
|
|
||||||
workspace: workspaceId,
|
// await ServiceToken.deleteMany({
|
||||||
environment: environmentSlug,
|
// workspace: workspaceId,
|
||||||
});
|
// environment: environmentSlug,
|
||||||
await ServiceTokenData.deleteMany({
|
// });
|
||||||
workspace: workspaceId,
|
|
||||||
environment: environmentSlug,
|
const result = await ServiceTokenData.updateMany(
|
||||||
});
|
{ workspace: workspaceId },
|
||||||
|
{ $pull: { scopes: { environment: environmentSlug } } }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.modifiedCount > 0) {
|
||||||
|
await ServiceTokenData.deleteMany({ workspace: workspaceId, scopes: { $size: 0 } });
|
||||||
|
}
|
||||||
|
|
||||||
await Integration.deleteMany({
|
await Integration.deleteMany({
|
||||||
workspace: workspaceId,
|
workspace: workspaceId,
|
||||||
environment: environmentSlug,
|
environment: environmentSlug,
|
||||||
|
|||||||
Reference in New Issue
Block a user