Fix IP whitelist PATCH endpoint, update localStorage project id to reflect navigated to project

This commit is contained in:
Tuan Dang
2023-07-26 17:46:33 +07:00
parent 7da6d72f13
commit 7ae6d1610f
7 changed files with 43 additions and 16 deletions
@@ -3,6 +3,7 @@ import { PipelineStage, Types } from "mongoose";
import { Secret } from "../../../models";
import {
FolderVersion,
IPType,
ISecretVersion,
Log,
SecretSnapshot,
@@ -675,23 +676,38 @@ export const updateWorkspaceTrustedIp = async (req: Request, res: Response) => {
});
const { ipAddress, type, prefix } = extractIPDetails(ip);
const updateObject: {
ipAddress: string;
type: IPType;
comment: string;
prefix?: number;
$unset?: {
prefix: number;
}
} = {
ipAddress,
type,
comment
};
if (prefix !== undefined) {
updateObject.prefix = prefix;
} else {
updateObject.$unset = { prefix: 1 };
}
const trustedIp = await TrustedIP.findOneAndUpdate(
{
_id: new Types.ObjectId(trustedIpId),
workspace: new Types.ObjectId(workspaceId),
},
{
ipAddress,
type,
prefix,
comment
},
updateObject,
{
new: true
}
);
return res.status(200).send({
trustedIp
});