feat(rbac): fixed ip allow list api

This commit is contained in:
Akhil Mohan
2023-09-14 20:40:57 +05:30
parent 3d2a2651b8
commit 18d843f3e6
@@ -1,6 +1,14 @@
import { Request, Response } from "express"; import { Request, Response } from "express";
import { PipelineStage, Types } from "mongoose"; import { PipelineStage, Types } from "mongoose";
import { Folder, Membership, Secret, ServiceTokenData, TFolderSchema, User } from "../../../models"; import {
Folder,
Membership,
Secret,
ServiceTokenData,
TFolderSchema,
User,
Workspace
} from "../../../models";
import { import {
ActorType, ActorType,
AuditLog, AuditLog,
@@ -41,6 +49,7 @@ import {
getUserProjectPermissions getUserProjectPermissions
} from "../../services/ProjectRoleService"; } from "../../services/ProjectRoleService";
import { ForbiddenError } from "@casl/ability"; import { ForbiddenError } from "@casl/ability";
import { BadRequestError } from "../../../utils/errors";
/** /**
* Return secret snapshots for workspace with id [workspaceId] * Return secret snapshots for workspace with id [workspaceId]
@@ -781,7 +790,10 @@ export const addWorkspaceTrustedIp = async (req: Request, res: Response) => {
ProjectPermissionSub.IpAllowList ProjectPermissionSub.IpAllowList
); );
const plan = await EELicenseService.getPlan(req.workspace.organization); const workspace = await Workspace.findById(workspaceId);
if (!workspace) throw BadRequestError({ message: "Workspace not found" });
const plan = await EELicenseService.getPlan(workspace.organization);
if (!plan.ipAllowlisting) if (!plan.ipAllowlisting)
return res.status(400).send({ return res.status(400).send({
@@ -844,7 +856,10 @@ export const updateWorkspaceTrustedIp = async (req: Request, res: Response) => {
ProjectPermissionSub.IpAllowList ProjectPermissionSub.IpAllowList
); );
const plan = await EELicenseService.getPlan(req.workspace.organization); const workspace = await Workspace.findById(workspaceId);
if (!workspace) throw BadRequestError({ message: "Workspace not found" });
const plan = await EELicenseService.getPlan(workspace.organization);
if (!plan.ipAllowlisting) if (!plan.ipAllowlisting)
return res.status(400).send({ return res.status(400).send({
@@ -933,7 +948,10 @@ export const deleteWorkspaceTrustedIp = async (req: Request, res: Response) => {
ProjectPermissionSub.IpAllowList ProjectPermissionSub.IpAllowList
); );
const plan = await EELicenseService.getPlan(req.workspace.organization); const workspace = await Workspace.findById(workspaceId);
if (!workspace) throw BadRequestError({ message: "Workspace not found" });
const plan = await EELicenseService.getPlan(workspace.organization);
if (!plan.ipAllowlisting) if (!plan.ipAllowlisting)
return res.status(400).send({ return res.status(400).send({