diff --git a/web_ui/frontend/app/registry/components/PutPage.tsx b/web_ui/frontend/app/registry/components/PutPage.tsx index ee2e1b850..b8236e9d6 100644 --- a/web_ui/frontend/app/registry/components/PutPage.tsx +++ b/web_ui/frontend/app/registry/components/PutPage.tsx @@ -55,6 +55,7 @@ const PutPage = ({ update }: NamespaceFormPage) => { const urlParams = new URLSearchParams(window.location.search); const id = urlParams.get('id'); const fromUrl = urlParams.get('fromUrl'); + const accessToken = urlParams.get('access_token'); if (id === null) { dispatch({ @@ -105,13 +106,11 @@ const PutPage = ({ update }: NamespaceFormPage) => { }, }); } - }, []); - useEffect(() => { (async () => { if (id !== undefined) { const response = await alertOnError( - async () => await getNamespace(id), + async () => await getNamespace(id, accessToken || undefined), "Couldn't get namespace", dispatch ); @@ -120,7 +119,7 @@ const PutPage = ({ update }: NamespaceFormPage) => { } } })(); - }, [id]); + }, []); return ( diff --git a/web_ui/frontend/app/registry/components/util.tsx b/web_ui/frontend/app/registry/components/util.tsx index 6ddbc0cbf..718d0202b 100644 --- a/web_ui/frontend/app/registry/components/util.tsx +++ b/web_ui/frontend/app/registry/components/util.tsx @@ -57,30 +57,6 @@ export const deleteKey = (o: any, key: string[]) => { return o; }; -const handleRequestAlert = async ( - url: string, - options: any -): Promise => { - try { - const response = await secureFetch(url, options); - - if (!response.ok) { - let errorMessage = await getErrorMessage(response); - return { severity: 'error', message: errorMessage }; - } - } catch (e) { - return { severity: 'error', message: `Fetch error: ${e}` }; - } -}; - -const namespaceFormNodeToJSON = (formData: FormData) => { - let data: any = {}; - formData.forEach((value: any, name: any) => { - populateKey(data, calculateKeys(name), value); - }); - return data; -}; - export const namespaceToCache = (data: Namespace) => { // Build the cache prefix if (data.prefix.startsWith('/caches/')) { diff --git a/web_ui/frontend/components/layout/AuthenticatedContent.tsx b/web_ui/frontend/components/layout/AuthenticatedContent.tsx index 966a98ab8..f1382b828 100644 --- a/web_ui/frontend/components/layout/AuthenticatedContent.tsx +++ b/web_ui/frontend/components/layout/AuthenticatedContent.tsx @@ -69,7 +69,7 @@ const AuthenticatedContent = ({ if (data && checkAuthentication) { return checkAuthentication(data); } else { - return data?.authenticated === undefined ? false : data.authenticated; + return !!data?.authenticated; } }, [data, checkAuthentication]); diff --git a/web_ui/frontend/helpers/api.ts b/web_ui/frontend/helpers/api.ts index 9c083e351..24b5903e4 100644 --- a/web_ui/frontend/helpers/api.ts +++ b/web_ui/frontend/helpers/api.ts @@ -126,12 +126,19 @@ export const getNamespaces = async (): Promise => { /** * Gets a namespace by ID * @param id Namespace ID + * @param accessToken Access token */ -export const getNamespace = async (id: string | number): Promise => { +export const getNamespace = async ( + id: string | number, + accessToken?: string +): Promise => { const url = new URL( `/api/v1.0/registry_ui/namespaces/${id}`, window.location.origin ); + if (accessToken) { + url.searchParams.append('access_token', accessToken); + } return await fetchApi(async () => await fetch(url)); }; @@ -154,8 +161,20 @@ export const postGeneralNamespace = async ( export const putGeneralNamespace = async ( data: Namespace ): Promise => { + // If an access_token is in the URL, add it to the request + const url = new URL( + `/api/v1.0/registry_ui/namespaces/${data.id}`, + window.location.origin + ); + const accessToken = new URLSearchParams(window.location.search).get( + 'access_token' + ); + if (accessToken) { + url.searchParams.append('access_token', accessToken); + } + return await fetchApi(async () => { - return secureFetch(`/api/v1.0/registry_ui/namespaces/${data.id}`, { + return secureFetch(url.toString(), { body: JSON.stringify(data), method: 'PUT', headers: {