[ARVADOS-WORKBENCH2] created: 2.1.0-156-g57fed302

Git user git at public.arvados.org
Tue Jan 12 22:42:20 UTC 2021


        at  57fed3027c22764b74b144b5755c2ba1aca4f3cb (commit)


commit 57fed3027c22764b74b144b5755c2ba1aca4f3cb
Author: Lucas Di Pentima <lucas at di-pentima.com.ar>
Date:   Tue Jan 12 19:12:25 2021 -0300

    17109: Fixes related unit test.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas at di-pentima.com.ar>

diff --git a/src/components/file-tree/file-thumbnail.test.tsx b/src/components/file-tree/file-thumbnail.test.tsx
index e0d5d255..a23bbcf9 100644
--- a/src/components/file-tree/file-thumbnail.test.tsx
+++ b/src/components/file-tree/file-thumbnail.test.tsx
@@ -3,10 +3,12 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
-import { shallow, configure } from "enzyme";
+import { configure, mount } from "enzyme";
 import { FileThumbnail } from "./file-thumbnail";
 import { CollectionFileType } from '../../models/collection-file';
 import * as Adapter from 'enzyme-adapter-react-16';
+import { Provider } from "react-redux";
+import { combineReducers, createStore } from "redux";
 
 configure({ adapter: new Adapter() });
 
@@ -14,10 +16,22 @@ jest.mock('is-image', () => ({
     'default': () => true,
 }));
 
+let store;
+
 describe("<FileThumbnail />", () => {
     let file;
 
     beforeEach(() => {
+        const initialAuthState = {
+            config: {
+                keepWebServiceUrl: 'http://example.com/',
+                keepWebInlineServiceUrl: 'http://*.collections.example.com/',
+            }
+        }
+        store = createStore(combineReducers({
+            auth: (state: any = initialAuthState, action: any) => state,
+        }));
+
         file = {
             name: 'test-image',
             type: CollectionFileType.FILE,
@@ -27,7 +41,7 @@ describe("<FileThumbnail />", () => {
     });
 
     it("renders file thumbnail with proper src", () => {
-        const fileThumbnail = shallow(<FileThumbnail file={file} />);
-        expect(fileThumbnail.html()).toBe('<img class="Component-thumbnail-1" alt="test-image" src="http://example.com/c=zzzzz-4zz18-0123456789abcde/test-image.jpg?api_token=v2/zzzzz-gj3su-0123456789abcde/xxxxxxtokenxxxxx"/>');
+        const fileThumbnail = mount(<Provider store={store}><FileThumbnail file={file} /></Provider>);
+        expect(fileThumbnail.html()).toBe('<img class="Component-thumbnail-1" alt="test-image" src="http://zzzzz-4zz18-0123456789abcde.collections.example.com/test-image.jpg?api_token=v2/zzzzz-gj3su-0123456789abcde/xxxxxxtokenxxxxx">');
     });
 });

commit 0afc40ccf18f9909ef1bab6cd8a41350a9789610
Merge: f470b415 2885e25d
Author: Lucas Di Pentima <lucas at di-pentima.com.ar>
Date:   Tue Jan 12 18:38:01 2021 -0300

    17109: Merge branch 'master' into 17109-keepweb-webdav-urls
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas at di-pentima.com.ar>


commit f470b41502497ccc4b37872cc921d71e57a37986
Author: Lucas Di Pentima <lucas at di-pentima.com.ar>
Date:   Tue Jan 12 18:33:50 2021 -0300

    17109: Handles keep-web's inline wildcard urls correctly.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas at di-pentima.com.ar>

diff --git a/src/components/file-tree/file-thumbnail.tsx b/src/components/file-tree/file-thumbnail.tsx
index 40631961..a56dcf2f 100644
--- a/src/components/file-tree/file-thumbnail.tsx
+++ b/src/components/file-tree/file-thumbnail.tsx
@@ -7,7 +7,9 @@ import isImage from 'is-image';
 import { withStyles, WithStyles } from '@material-ui/core';
 import { FileTreeData } from '~/components/file-tree/file-tree-data';
 import { CollectionFileType } from '~/models/collection-file';
-import { sanitizeToken } from "~/views-components/context-menu/actions/helpers";
+import { getInlineFileUrl, sanitizeToken } from "~/views-components/context-menu/actions/helpers";
+import { connect } from "react-redux";
+import { RootState } from "~/store/store";
 
 export interface FileThumbnailProps {
     file: FileTreeData;
@@ -28,10 +30,20 @@ const imageFileThumbnailStyle = withStyles<ImageFileThumbnailCssRules>(theme =>
     }
 }));
 
-const ImageFileThumbnail = imageFileThumbnailStyle(
-    ({ classes, file }: WithStyles<ImageFileThumbnailCssRules> & FileThumbnailProps) =>
+interface ImageFileThumbnailProps {
+    keepWebServiceUrl: string;
+    keepWebInlineServiceUrl: string;
+}
+
+const mapStateToProps = ({ auth }: RootState): ImageFileThumbnailProps => ({
+    keepWebServiceUrl: auth.config.keepWebServiceUrl,
+    keepWebInlineServiceUrl: auth.config.keepWebInlineServiceUrl,
+});
+
+const ImageFileThumbnail = connect(mapStateToProps)(imageFileThumbnailStyle(
+    ({ classes, file, keepWebServiceUrl, keepWebInlineServiceUrl }: WithStyles<ImageFileThumbnailCssRules> & FileThumbnailProps & ImageFileThumbnailProps) =>
         <img
             className={classes.thumbnail}
             alt={file.name}
-            src={sanitizeToken(file.url)} />
-);
+            src={sanitizeToken(getInlineFileUrl(file.url, keepWebServiceUrl, keepWebInlineServiceUrl))} />
+));
diff --git a/src/views-components/context-menu/actions/collection-file-viewer-action.tsx b/src/views-components/context-menu/actions/collection-file-viewer-action.tsx
index dfc9d14a..aba35534 100644
--- a/src/views-components/context-menu/actions/collection-file-viewer-action.tsx
+++ b/src/views-components/context-menu/actions/collection-file-viewer-action.tsx
@@ -7,6 +7,7 @@ import { RootState } from "../../../store/store";
 import { FileViewerAction } from '~/views-components/context-menu/actions/file-viewer-action';
 import { getNodeValue } from "~/models/tree";
 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
+import { getInlineFileUrl, sanitizeToken } from "./helpers";
 
 const mapStateToProps = (state: RootState) => {
     const { resource } = state.contextMenu;
@@ -16,8 +17,12 @@ const mapStateToProps = (state: RootState) => {
         resource.menuKind === ContextMenuKind.READONLY_COLLECTION_FILES_ITEM)) {
         const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
         if (file) {
+            const fileUrl = sanitizeToken(getInlineFileUrl(
+                file.url,
+                state.auth.config.keepWebServiceUrl,
+                state.auth.config.keepWebInlineServiceUrl), true);
             return {
-                href: file.url.replace(state.auth.config.keepWebServiceUrl, state.auth.config.keepWebInlineServiceUrl),
+                href: fileUrl,
                 kind: 'file',
                 currentCollectionUuid
             };
diff --git a/src/views-components/context-menu/actions/file-viewer-action.tsx b/src/views-components/context-menu/actions/file-viewer-action.tsx
index a631424e..e31bb10d 100644
--- a/src/views-components/context-menu/actions/file-viewer-action.tsx
+++ b/src/views-components/context-menu/actions/file-viewer-action.tsx
@@ -3,22 +3,14 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
-import { connect } from 'react-redux';
 import { ListItemIcon, ListItemText, ListItem } from "@material-ui/core";
 import { OpenIcon } from "~/components/icon/icon";
-import { sanitizeToken } from "./helpers";
-import { RootState } from "~/store/store";
 
 export const FileViewerAction = (props: any) => {
-    const {
-        keepWebServiceUrl,
-        keepWebInlineServiceUrl,
-    } = props;
-
     return props.href
         ? <a
             style={{ textDecoration: 'none' }}
-            href={sanitizeToken(props.href.replace(keepWebServiceUrl, keepWebInlineServiceUrl), true)}
+            href={props.href}
             target="_blank"
             onClick={props.onClick}>
             <ListItem button>
@@ -32,11 +24,3 @@ export const FileViewerAction = (props: any) => {
         </a>
         : null;
 };
-
-const mapStateToProps = ({ auth }: RootState): any => ({
-    keepWebServiceUrl: auth.config.keepWebServiceUrl,
-    keepWebInlineServiceUrl: auth.config.keepWebInlineServiceUrl,
-});
-
-
-export default connect(mapStateToProps, null)(FileViewerAction);
diff --git a/src/views-components/context-menu/actions/helpers.test.ts b/src/views-components/context-menu/actions/helpers.test.ts
index 4234a8cc..c3a31691 100644
--- a/src/views-components/context-menu/actions/helpers.test.ts
+++ b/src/views-components/context-menu/actions/helpers.test.ts
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { sanitizeToken, getClipboardUrl } from "./helpers";
+import { sanitizeToken, getClipboardUrl, getInlineFileUrl } from "./helpers";
 
 describe('helpers', () => {
     // given
@@ -27,4 +27,39 @@ describe('helpers', () => {
             expect(result).toBe('http://localhost?redirectTo=https://example.com/c=zzzzz/LIMS/1.html');
         });
     });
+
+    describe('getInlineFileUrl', () => {
+        it('should add the collection\'s uuid to the hostname', () => {
+            // when
+            const webDavUrlA = 'https://*.collections.example.com/';
+            const webDavUrlB = 'https://*--collections.example.com/';
+            const webDavDownloadUrl = 'https://example.com/';
+
+            // then
+            expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlA))
+                .toBe('https://zzzzz.collections.example.com/t=v2/a/b/LIMS/1.html');
+            expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlB))
+                .toBe('https://zzzzz--collections.example.com/t=v2/a/b/LIMS/1.html');
+        });
+
+        it('should keep the url the same when no inline url available', () => {
+            // when
+            const webDavUrl = '';
+            const webDavDownloadUrl = 'https://example.com/';
+            const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
+
+            // then
+            expect(result).toBe('https://example.com/c=zzzzz/t=v2/a/b/LIMS/1.html');
+        });
+
+        it('should replace the url when available', () => {
+            // when
+            const webDavUrl = 'https://download.example.com/';
+            const webDavDownloadUrl = 'https://example.com/';
+            const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
+
+            // then
+            expect(result).toBe('https://download.example.com/c=zzzzz/t=v2/a/b/LIMS/1.html');
+        });
+    });
 });
\ No newline at end of file
diff --git a/src/views-components/context-menu/actions/helpers.ts b/src/views-components/context-menu/actions/helpers.ts
index 0ad2dc3c..ce5dd8b1 100644
--- a/src/views-components/context-menu/actions/helpers.ts
+++ b/src/views-components/context-menu/actions/helpers.ts
@@ -17,3 +17,27 @@ export const getClipboardUrl = (href: string, shouldSanitizeToken = true): strin
 
     return shouldSanitizeToken ? `${origin}?redirectTo=${url}` : `${origin}${url}`;
 };
+
+export const getInlineFileUrl = (url: string, keepWebSvcUrl: string, keepWebInlineSvcUrl: string): string => {
+    const collUuidMatch = url.match(/\/c=([a-z0-9-]+)\//);
+    if (collUuidMatch === null) { return ''; }
+    const collUuid = collUuidMatch[1];
+    let inlineUrl = keepWebInlineSvcUrl !== ""
+        ? url.replace(keepWebSvcUrl, keepWebInlineSvcUrl)
+        : url;
+    let uuidOnHostname = false;
+    // Inline URLs as 'https://*.collections.example.com' or
+    // 'https://*--collections.example.com' should get the uuid on their hostnames
+    // See: https://doc.arvados.org/v2.1/api/keep-web-urls.html
+    if (inlineUrl.indexOf('*.') > -1) {
+        inlineUrl = inlineUrl.replace('*.', `${collUuid}.`);
+        uuidOnHostname = true;
+    } else if (inlineUrl.indexOf('*--') > -1) {
+        inlineUrl = inlineUrl.replace('*--', `${collUuid}--`);
+        uuidOnHostname = true;
+    }
+    if (uuidOnHostname) {
+        inlineUrl = inlineUrl.replace(`/c=${collUuid}`, '');
+    }
+    return inlineUrl;
+};
\ No newline at end of file

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list