From 7ae6d1610fddf140fa32104837961135994423d2 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Wed, 26 Jul 2023 17:46:33 +0700 Subject: [PATCH] Fix IP whitelist PATCH endpoint, update localStorage project id to reflect navigated to project --- .../ee/controllers/v1/workspaceController.ts | 30 ++++++++++++++----- frontend/src/layouts/AppLayout/AppLayout.tsx | 1 + .../src/pages/org/[id]/overview/index.tsx | 10 ++++--- .../IntegrationPage.utils.tsx | 2 +- .../CloudIntegrationSection.tsx | 2 +- .../components/IPAllowlistModal.tsx | 12 ++++++-- .../components/IPAllowlistTable.tsx | 2 ++ 7 files changed, 43 insertions(+), 16 deletions(-) diff --git a/backend/src/ee/controllers/v1/workspaceController.ts b/backend/src/ee/controllers/v1/workspaceController.ts index 64b6980f8..d4f097ea2 100644 --- a/backend/src/ee/controllers/v1/workspaceController.ts +++ b/backend/src/ee/controllers/v1/workspaceController.ts @@ -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 }); diff --git a/frontend/src/layouts/AppLayout/AppLayout.tsx b/frontend/src/layouts/AppLayout/AppLayout.tsx index f25c2d05a..6c9e04f55 100644 --- a/frontend/src/layouts/AppLayout/AppLayout.tsx +++ b/frontend/src/layouts/AppLayout/AppLayout.tsx @@ -330,6 +330,7 @@ export const AppLayout = ({ children }: LayoutProps) => { className="w-full truncate bg-mineshaft-600 py-2.5 font-medium" onValueChange={(value) => { router.push(`/project/${value}/secrets`); + localStorage.setItem("projectData.id", value); }} position="popper" dropdownContainerClassName="text-bunker-200 bg-mineshaft-800 border border-mineshaft-600 z-50 max-h-96 border-gray-700" diff --git a/frontend/src/pages/org/[id]/overview/index.tsx b/frontend/src/pages/org/[id]/overview/index.tsx index 45b9a1743..693af4d6f 100644 --- a/frontend/src/pages/org/[id]/overview/index.tsx +++ b/frontend/src/pages/org/[id]/overview/index.tsx @@ -5,7 +5,6 @@ import { useEffect, useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import Head from "next/head"; -import Link from "next/link"; import { useRouter } from "next/router"; import { IconProp } from "@fortawesome/fontawesome-svg-core"; import { faSlack } from "@fortawesome/free-brands-svg-icons"; @@ -325,9 +324,12 @@ export default function Organization() { {orgWorkspaces.filter(ws => ws?.name?.toLowerCase().includes(searchFilter.toLowerCase())).map(workspace =>
{workspace.name}
{(workspace.environments?.length || 0)} environments
- -
Explore
- +
)} {orgWorkspaces.length === 0 && ( diff --git a/frontend/src/views/IntegrationsPage/IntegrationPage.utils.tsx b/frontend/src/views/IntegrationsPage/IntegrationPage.utils.tsx index 7ec4a15a8..1beb4038e 100644 --- a/frontend/src/views/IntegrationsPage/IntegrationPage.utils.tsx +++ b/frontend/src/views/IntegrationsPage/IntegrationPage.utils.tsx @@ -35,7 +35,7 @@ export const redirectForProviderAuth = (integrationOption: TCloudIntegration) => // generate CSRF token for OAuth2 code-token exchange integrations const state = crypto.randomBytes(16).toString("hex"); localStorage.setItem("latestCSRFToken", state); - + let link = ""; switch (integrationOption.slug) { case "azure-key-vault": diff --git a/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx b/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx index e8e761a0f..7f458d5e5 100644 --- a/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx +++ b/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx @@ -32,7 +32,7 @@ export const CloudIntegrationSection = ({ const isEmpty = !isLoading && !cloudIntegrations?.length; const sortedCloudIntegrations = cloudIntegrations.sort((a, b) => a.name.localeCompare(b.name)); - + return (
diff --git a/frontend/src/views/Project/IPAllowListPage/components/IPAllowlistModal.tsx b/frontend/src/views/Project/IPAllowListPage/components/IPAllowlistModal.tsx index 07de4425e..d6e746d1a 100644 --- a/frontend/src/views/Project/IPAllowListPage/components/IPAllowlistModal.tsx +++ b/frontend/src/views/Project/IPAllowListPage/components/IPAllowlistModal.tsx @@ -55,10 +55,16 @@ export const IPAllowlistModal = ({ }); useEffect(() => { + const trustedIpData = popUp?.trustedIp?.data as { + ipAddress: string; + comment: string; + prefix: number; + }; + if (popUp?.trustedIp?.data) { - reset(popUp?.trustedIp?.data as { - ipAddress: string; - comment: string; + reset({ + ipAddress: `${trustedIpData.ipAddress}${trustedIpData.prefix !== undefined ? `/${trustedIpData.prefix}` : ""}`, + comment: trustedIpData.comment }); } else { reset({ diff --git a/frontend/src/views/Project/IPAllowListPage/components/IPAllowlistTable.tsx b/frontend/src/views/Project/IPAllowListPage/components/IPAllowlistTable.tsx index cd93d7c1b..d160f15db 100644 --- a/frontend/src/views/Project/IPAllowListPage/components/IPAllowlistTable.tsx +++ b/frontend/src/views/Project/IPAllowListPage/components/IPAllowlistTable.tsx @@ -29,6 +29,7 @@ type Props = { ipAddress?: string; comment?: string; isActive?: boolean; + prefix?: number; }, ) => void; handlePopUpToggle: (popUpName: keyof UsePopUpState<["upgradePlan"]>, state?: boolean) => void; @@ -103,6 +104,7 @@ export const IPAllowlistTable = ({ trustedIpId: _id, ipAddress, comment, + prefix, isActive }); } else {