From 1213788f9c7694f093cfbe63735461eae5af411e Mon Sep 17 00:00:00 2001 From: Armando Trejo Oliver Date: Thu, 20 Oct 2022 10:58:37 -0700 Subject: [PATCH] Remove share-link feature (#1345) * Remove share-link feature Cosmos DB supports sharing access to an account data using AAD/RBAC now so this feature is unnecessary. * Fix format issues * Fix unit tests * undo package changes --- src/Explorer/OpenFullScreen.test.tsx | 10 +--- src/Explorer/OpenFullScreen.tsx | 74 +++++++--------------------- src/Platform/Hosted/Authorization.ts | 31 ------------ src/hooks/useFullScreenURLs.tsx | 18 ------- tsconfig.strict.json | 4 +- 5 files changed, 19 insertions(+), 118 deletions(-) delete mode 100644 src/Platform/Hosted/Authorization.ts delete mode 100644 src/hooks/useFullScreenURLs.tsx diff --git a/src/Explorer/OpenFullScreen.test.tsx b/src/Explorer/OpenFullScreen.test.tsx index f2473cf2b..39a655b4a 100644 --- a/src/Explorer/OpenFullScreen.test.tsx +++ b/src/Explorer/OpenFullScreen.test.tsx @@ -1,17 +1,9 @@ -jest.mock("../hooks/useFullScreenURLs"); import "@testing-library/jest-dom"; import { render, screen } from "@testing-library/react"; import React from "react"; -import { useFullScreenURLs } from "../hooks/useFullScreenURLs"; import { OpenFullScreen } from "./OpenFullScreen"; it("renders the correct URLs", () => { - (useFullScreenURLs as jest.Mock).mockReturnValue({ - readWrite: "read and write url", - read: "read only url", - }); - render(); - expect(screen.getByLabelText("Read and Write")).toHaveValue("https://cosmos.azure.com/?key=read and write url"); - expect(screen.getByLabelText("Read Only")).toHaveValue("https://cosmos.azure.com/?key=read only url"); + expect(screen.getByText("Open")).toBeDefined(); }); diff --git a/src/Explorer/OpenFullScreen.tsx b/src/Explorer/OpenFullScreen.tsx index d9f4f9508..5474161cd 100644 --- a/src/Explorer/OpenFullScreen.tsx +++ b/src/Explorer/OpenFullScreen.tsx @@ -1,66 +1,26 @@ -import { DefaultButton, PrimaryButton, Spinner, Stack, Text, TextField } from "@fluentui/react"; -import copyToClipboard from "clipboard-copy"; +import { PrimaryButton, Stack, Text } from "@fluentui/react"; import * as React from "react"; -import { useFullScreenURLs } from "../hooks/useFullScreenURLs"; export const OpenFullScreen: React.FunctionComponent = () => { - const [isReadUrlCopy, setIsReadUrlCopy] = React.useState(false); - const [isReadWriteUrlCopy, setIsReadWriteUrlCopy] = React.useState(false); - const result = useFullScreenURLs(); - if (!result) { - return ; - } - - const readWriteUrl = `https://cosmos.azure.com/?key=${result.readWrite}`; - const readUrl = `https://cosmos.azure.com/?key=${result.read}`; - return ( <> - - - Open this database account in a new browser tab with Cosmos DB Explorer. Or copy the read-write or read only - access urls below to share with others. For security purposes, the URLs grant time-bound access to the - account. When access expires, you can reconnect, using a valid connection string for the account. - - - - { - copyToClipboard(readWriteUrl); - setIsReadWriteUrlCopy(true); - }} - text={isReadWriteUrlCopy ? "Copied" : "Copy"} - iconProps={{ iconName: "Copy" }} - /> - { - window.open(readWriteUrl, "_blank"); - }} - text="Open" - iconProps={{ iconName: "OpenInNewWindow" }} - /> +
+ + + Open this database account in a new browser tab with Cosmos DB Explorer. You can connect using your + Microsoft account or a connection string. + + + { + window.open("https://cosmos.azure.com/", "_blank"); + }} + text="Open" + iconProps={{ iconName: "OpenInNewWindow" }} + /> + - - - { - setIsReadUrlCopy(true); - copyToClipboard(readUrl); - }} - text={isReadUrlCopy ? "Copied" : "Copy"} - iconProps={{ iconName: "Copy" }} - /> - { - window.open(readUrl, "_blank"); - }} - text="Open" - iconProps={{ iconName: "OpenInNewWindow" }} - /> - - +
); }; diff --git a/src/Platform/Hosted/Authorization.ts b/src/Platform/Hosted/Authorization.ts deleted file mode 100644 index bebe9ddf4..000000000 --- a/src/Platform/Hosted/Authorization.ts +++ /dev/null @@ -1,31 +0,0 @@ -import * as Constants from "../../Common/Constants"; -import { configContext } from "../../ConfigContext"; -import * as DataModels from "../../Contracts/DataModels"; -import { DefaultExperienceUtility } from "../../Shared/DefaultExperienceUtility"; -import { userContext } from "../../UserContext"; - -export default class AuthHeadersUtil { - public static async generateEncryptedToken(readOnly: boolean = false): Promise { - const url = configContext.BACKEND_ENDPOINT + "/api/tokens/generateToken" + AuthHeadersUtil._generateResourceUrl(); - const headers: any = { authorization: userContext.authorizationToken }; - headers[Constants.HttpHeaders.getReadOnlyKey] = readOnly; - - const response = await fetch(url, { method: "POST", headers }); - const result = await response.json(); - // This API has a quirk where the response must be parsed to JSON twice - return JSON.parse(result); - } - - private static _generateResourceUrl(): string { - const { databaseAccount, resourceGroup, subscriptionId } = userContext; - const apiKind: DataModels.ApiKind = DefaultExperienceUtility.getApiKindFromDefaultExperience(userContext.apiType); - const accountEndpoint = databaseAccount?.properties?.documentEndpoint || ""; - const sid = subscriptionId || ""; - const rg = resourceGroup || ""; - const dba = databaseAccount?.name || ""; - const resourceUrl = encodeURIComponent(accountEndpoint); - const rid = ""; - const rtype = ""; - return `?resourceUrl=${resourceUrl}&rid=${rid}&rtype=${rtype}&sid=${sid}&rg=${rg}&dba=${dba}&api=${apiKind}`; - } -} diff --git a/src/hooks/useFullScreenURLs.tsx b/src/hooks/useFullScreenURLs.tsx deleted file mode 100644 index a83cd859a..000000000 --- a/src/hooks/useFullScreenURLs.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import { useEffect, useState } from "react"; -import { GenerateTokenResponse } from "../Contracts/DataModels"; -import AuthHeadersUtil from "../Platform/Hosted/Authorization"; - -export function useFullScreenURLs(): GenerateTokenResponse | undefined { - const [state, setState] = useState(); - - useEffect(() => { - Promise.all([AuthHeadersUtil.generateEncryptedToken(), AuthHeadersUtil.generateEncryptedToken(true)]).then( - ([readWriteResponse, readOnlyResponse]) => - setState({ - readWrite: readWriteResponse.readWrite, - read: readOnlyResponse.read, - }) - ); - }, []); - return state; -} diff --git a/tsconfig.strict.json b/tsconfig.strict.json index ee037db87..9fbdd6616 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -82,7 +82,6 @@ "./src/Explorer/Tree/AccessibleVerticalList.ts", "./src/GitHub/GitHubConnector.ts", "./src/HostedExplorerChildFrame.ts", - "./src/Platform/Hosted/Authorization.ts", "./src/Platform/Hosted/Components/MeControl.test.tsx", "./src/Platform/Hosted/Components/MeControl.tsx", "./src/Platform/Hosted/Components/SignInButton.tsx", @@ -126,7 +125,6 @@ "./src/Utils/WindowUtils.ts", "./src/hooks/useConfig.ts", "./src/hooks/useDirectories.tsx", - "./src/hooks/useFullScreenURLs.tsx", "./src/hooks/useGraphPhoto.tsx", "./src/hooks/useNotebookSnapshotStore.ts", "./src/hooks/usePortalAccessToken.tsx", @@ -165,4 +163,4 @@ "src/Terminal/**/*", "src/Utils/arm/**/*" ] -} +} \ No newline at end of file