From 35bb3e9024bb32a623e0ec6fb6a8d2c7782447a7 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Fri, 1 Oct 2021 11:29:44 -0600 Subject: [PATCH] add readtoken when in readonly mode (#1382) --- webapp/src/app.tsx | 4 ++-- webapp/src/components/viewMenu.tsx | 5 ++++- webapp/src/components/workspace.tsx | 6 +++++- webapp/src/octoClient.ts | 10 ++-------- webapp/src/utils.ts | 6 ++++++ 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/webapp/src/app.tsx b/webapp/src/app.tsx index bac75828e..175ad6811 100644 --- a/webapp/src/app.tsx +++ b/webapp/src/app.tsx @@ -158,7 +158,7 @@ const App = React.memo((): JSX.Element => { - + { return null }} /> - + { const match = useRouteMatch() const showView = useCallback((viewId) => { - const newPath = generatePath(match.path, {...match.params, viewId: viewId || ''}) + let newPath = generatePath(match.path, {...match.params, viewId: viewId || ''}) + if (props.readonly) { + newPath += `?r=${Utils.getReadToken()}` + } history.push(newPath) }, [match, history]) diff --git a/webapp/src/components/workspace.tsx b/webapp/src/components/workspace.tsx index e63307671..710533846 100644 --- a/webapp/src/components/workspace.tsx +++ b/webapp/src/components/workspace.tsx @@ -13,6 +13,7 @@ import {getClientConfig, setClientConfig} from '../store/clientConfig' import wsClient, {WSClient} from '../wsclient' import {ClientConfig} from '../config/clientConfig' +import {Utils} from '../utils' import CenterPanel from './centerPanel' import EmptyCenterPanel from './emptyCenterPanel' @@ -37,7 +38,10 @@ function CenterContent(props: Props) { const showCard = useCallback((cardId?: string) => { const params = {...match.params, cardId} - const newPath = generatePath(match.path, params) + let newPath = generatePath(match.path, params) + if (props.readonly) { + newPath += `?r=${Utils.getReadToken()}` + } history.push(newPath) }, [match, history]) diff --git a/webapp/src/octoClient.ts b/webapp/src/octoClient.ts index d979a8b58..c5424427b 100644 --- a/webapp/src/octoClient.ts +++ b/webapp/src/octoClient.ts @@ -41,12 +41,6 @@ class OctoClient { localStorage.setItem('focalboardSessionId', value) } - private readToken(): string { - const queryString = new URLSearchParams(window.location.search) - const readToken = queryString.get('r') || '' - return readToken - } - constructor(serverUrl?: string, public workspaceId = '0') { this.serverUrl = serverUrl } @@ -168,7 +162,7 @@ class OctoClient { async getSubtree(rootId?: string, levels = 2, workspaceID?: string): Promise { let path = this.workspacePath(workspaceID) + `/blocks/${encodeURIComponent(rootId || '')}/subtree?l=${levels}` - const readToken = this.readToken() + const readToken = Utils.getReadToken() if (readToken) { path += `&read_token=${readToken}` } @@ -406,7 +400,7 @@ class OctoClient { async getFileAsDataUrl(rootId: string, fileId: string): Promise { let path = '/files/workspaces/' + this.workspaceId + '/' + rootId + '/' + fileId - const readToken = this.readToken() + const readToken = Utils.getReadToken() if (readToken) { path += `?read_token=${readToken}` } diff --git a/webapp/src/utils.ts b/webapp/src/utils.ts index de7f0290d..ad9907161 100644 --- a/webapp/src/utils.ts +++ b/webapp/src/utils.ts @@ -504,6 +504,12 @@ class Utils { static isDesktop(): boolean { return Utils.isDesktopApp() && Utils.isVersionGreaterThanOrEqualTo(Utils.getDesktopVersion(), '5.0.0') } + + static getReadToken(): string { + const queryString = new URLSearchParams(window.location.search) + const readToken = queryString.get('r') || '' + return readToken + } } export {Utils}