From 67d77b206ebee7c776bd4d7dbc112ebb0c7ba800 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kuty=C5=82a?= Date: Mon, 19 Oct 2020 21:37:24 +0200 Subject: [PATCH] 16812: Cleared token code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- .../collection-service/collection-service.ts | 4 +-- .../open-in-new-tab.actions.ts | 28 +++++++++++++++++++ .../context-menu/actions/download-action.tsx | 2 +- .../download-collection-file-action.tsx | 3 +- .../context-menu/actions/helpers.test.ts | 4 +-- .../context-menu/actions/helpers.ts | 4 +-- 6 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 src/store/open-in-new-tab/open-in-new-tab.actions.ts diff --git a/src/services/collection-service/collection-service.ts b/src/services/collection-service/collection-service.ts index 90441a64..0aa0aa84 100644 --- a/src/services/collection-service/collection-service.ts +++ b/src/services/collection-service/collection-service.ts @@ -65,8 +65,8 @@ export class CollectionService extends TrashableResourceService(), + OPEN_COLLECTION_IN_NEW_TAB: ofType(), + OPEN_PROJECT_IN_NEW_TAB: ofType() +}); + +export const openInNewTabAction = (resource: any) => (dispatch: Dispatch) => { + const { uuid, kind } = resource; + + dispatch(openInNewTabActions.COPY_STORE()); + + if (kind === ResourceKind.COLLECTION) { + dispatch(openInNewTabActions.OPEN_COLLECTION_IN_NEW_TAB(uuid)); + } + if (kind === ResourceKind.PROJECT) { + dispatch(openInNewTabActions.OPEN_PROJECT_IN_NEW_TAB(uuid)); + } + + console.log(uuid); +}; \ No newline at end of file diff --git a/src/views-components/context-menu/actions/download-action.tsx b/src/views-components/context-menu/actions/download-action.tsx index 7468954f..86694c8b 100644 --- a/src/views-components/context-menu/actions/download-action.tsx +++ b/src/views-components/context-menu/actions/download-action.tsx @@ -47,7 +47,7 @@ export const DownloadAction = (props: { href?: any, download?: any, onClick?: () return props.href || props.kind === 'files' ? props.kind === 'files' ? createZip(props.href, props.download) : undefined}> diff --git a/src/views-components/context-menu/actions/download-collection-file-action.tsx b/src/views-components/context-menu/actions/download-collection-file-action.tsx index 7849109d..3e4e4a0b 100644 --- a/src/views-components/context-menu/actions/download-collection-file-action.tsx +++ b/src/views-components/context-menu/actions/download-collection-file-action.tsx @@ -8,6 +8,7 @@ import { DownloadAction } from "./download-action"; import { getNodeValue } from "../../../models/tree"; import { ContextMenuKind } from '../context-menu'; import { filterCollectionFilesBySelection } from "~/store/collection-panel/collection-panel-files/collection-panel-files-state"; +import { sanitizeToken } from "./helpers"; const mapStateToProps = (state: RootState) => { const { resource } = state.contextMenu; @@ -16,7 +17,7 @@ const mapStateToProps = (state: RootState) => { const file = getNodeValue(resource.uuid)(state.collectionPanelFiles); if (file) { return { - href: file.url, + href: sanitizeToken(file.url, true), kind: 'file', currentCollectionUuid }; diff --git a/src/views-components/context-menu/actions/helpers.test.ts b/src/views-components/context-menu/actions/helpers.test.ts index 6aaacc2f..9750a1cc 100644 --- a/src/views-components/context-menu/actions/helpers.test.ts +++ b/src/views-components/context-menu/actions/helpers.test.ts @@ -6,7 +6,7 @@ import { sanitizeToken, getClipboardUrl } from "./helpers"; describe('helpers', () => { // given - const url = 'https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/t=1ha4ykd3w14ed19b2gh3uyjrjup38vsx27x1utwdne0bxcfg5d/LIMS/1.html'; + const url = 'https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/t=v2/arlog-gj3su-stk5unu8570brvs/fryzaq6z1ow1npak5nngldtkoup918isrvlualf134uf1fbtd/LIMS/1.html'; describe('sanitizeToken', () => { it('should sanitize token from the url', () => { @@ -14,7 +14,7 @@ describe('helpers', () => { const result = sanitizeToken(url); // then - expect(result).toBe('https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/LIMS/1.html?api_token=1ha4ykd3w14ed19b2gh3uyjrjup38vsx27x1utwdne0bxcfg5d'); + expect(result).toBe('https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/LIMS/1.html?api_token=v2/arlog-gj3su-stk5unu8570brvs/fryzaq6z1ow1npak5nngldtkoup918isrvlualf134uf1fbtd'); }); }); diff --git a/src/views-components/context-menu/actions/helpers.ts b/src/views-components/context-menu/actions/helpers.ts index 419c796d..8dfcaca0 100644 --- a/src/views-components/context-menu/actions/helpers.ts +++ b/src/views-components/context-menu/actions/helpers.ts @@ -4,8 +4,8 @@ export const sanitizeToken = (href: string, tokenAsQueryParam: boolean = true): string => { const [prefix, suffix] = href.split('/t='); - const [token, ...rest] = suffix.split('/'); - + const [token1, token2, token3, ...rest] = suffix.split('/'); + const token = `${token1}/${token2}/${token3}`; const sep = href.indexOf("?") > -1 ? "&" : "?"; return `${[prefix, ...rest].join('/')}${tokenAsQueryParam ? `${sep}api_token=${token}` : ''}`; -- 2.30.2