From 14d76770564a37fede5fabb977087afce5cb16fe Mon Sep 17 00:00:00 2001 From: jawelton74 <103591340+jawelton74@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:18:40 -0700 Subject: [PATCH] Add feature for disabling connection string login and enable this for aad redirect. (#1660) * Add redirect for /aad to /?feature.enableAadDataPlane=true * Add feature to hide the connection string login link. Enable this new feature for the aad redirect. --- .../Components/ConnectExplorer.test.tsx | 23 +++++++++++++++++++ .../Hosted/Components/ConnectExplorer.tsx | 12 ++++++---- src/Platform/Hosted/extractFeatures.ts | 2 ++ web.config | 2 +- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Platform/Hosted/Components/ConnectExplorer.test.tsx b/src/Platform/Hosted/Components/ConnectExplorer.test.tsx index ed342a17b..dc54a5f2a 100644 --- a/src/Platform/Hosted/Components/ConnectExplorer.test.tsx +++ b/src/Platform/Hosted/Components/ConnectExplorer.test.tsx @@ -1,6 +1,8 @@ jest.mock("../../../hooks/useDirectories"); import "@testing-library/jest-dom"; import { fireEvent, render, screen } from "@testing-library/react"; +import { extractFeatures } from "Platform/Hosted/extractFeatures"; +import { updateUserContext, userContext } from "UserContext"; import React from "react"; import { ConnectExplorer } from "./ConnectExplorer"; @@ -16,3 +18,24 @@ it("shows the connect form", () => { fireEvent.click(screen.getByText("Connect to your account with connection string")); expect(screen.queryByPlaceholderText("Please enter a connection string")).toBeDefined(); }); + +it("hides the connection string link when feature.disableConnectionStringLogin is true", () => { + const connectionString = "fakeConnectionString"; + const login = jest.fn(); + const setConnectionString = jest.fn(); + const setEncryptedToken = jest.fn(); + const setAuthType = jest.fn(); + const oldFeatures = userContext.features; + + const params = new URLSearchParams({ + "feature.disableConnectionStringLogin": "true", + }); + + const testFeatures = extractFeatures(params); + updateUserContext({ features: testFeatures }); + + render(); + expect(screen.queryByPlaceholderText("Connect to your account with connection string")).toBeNull(); + + updateUserContext({ features: oldFeatures }); +}); diff --git a/src/Platform/Hosted/Components/ConnectExplorer.tsx b/src/Platform/Hosted/Components/ConnectExplorer.tsx index 575093bc2..3ee72246e 100644 --- a/src/Platform/Hosted/Components/ConnectExplorer.tsx +++ b/src/Platform/Hosted/Components/ConnectExplorer.tsx @@ -1,4 +1,5 @@ import { useBoolean } from "@fluentui/react-hooks"; +import { userContext } from "UserContext"; import * as React from "react"; import ConnectImage from "../../../../images/HdeConnectCosmosDB.svg"; import ErrorImage from "../../../../images/error.svg"; @@ -37,6 +38,7 @@ export const ConnectExplorer: React.FunctionComponent = ({ setConnectionString, }: Props) => { const [isFormVisible, { setTrue: showForm }] = useBoolean(false); + const enableConnectionStringLogin = !userContext.features.disableConnectionStringLogin; return ( @@ -46,7 +48,7 @@ export const ConnectExplorer: React.FunctionComponent = ({ Welcome to Azure Cosmos DB - {isFormVisible ? ( + {isFormVisible && enableConnectionStringLogin ? ( { @@ -89,9 +91,11 @@ export const ConnectExplorer: React.FunctionComponent = ({ ) : ( - - Connect to your account with connection string - + {enableConnectionStringLogin && ( + + Connect to your account with connection string + + )} )} diff --git a/src/Platform/Hosted/extractFeatures.ts b/src/Platform/Hosted/extractFeatures.ts index 3e34ced0b..d6f8c8538 100644 --- a/src/Platform/Hosted/extractFeatures.ts +++ b/src/Platform/Hosted/extractFeatures.ts @@ -41,6 +41,7 @@ export type Features = { readonly enableCopilotFullSchema: boolean; readonly copilotChatFixedMonacoEditorHeight: boolean; readonly enablePriorityBasedExecution: boolean; + readonly disableConnectionStringLogin: boolean; // can be set via both flight and feature flag autoscaleDefault: boolean; @@ -114,6 +115,7 @@ export function extractFeatures(given = new URLSearchParams(window.location.sear enableCopilotFullSchema: "true" === get("enablecopilotfullschema", "true"), copilotChatFixedMonacoEditorHeight: "true" === get("copilotchatfixedmonacoeditorheight"), enablePriorityBasedExecution: "true" === get("enableprioritybasedexecution"), + disableConnectionStringLogin: "true" === get("disableconnectionstringlogin"), }; } diff --git a/web.config b/web.config index 752b01196..9d9ff2619 100644 --- a/web.config +++ b/web.config @@ -12,7 +12,7 @@ - +
Welcome to Azure Cosmos DB
- Connect to your account with connection string -
+ Connect to your account with connection string +