Merge branch '16647-Responsible-person'
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Fri, 21 May 2021 22:06:39 +0000 (00:06 +0200)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Fri, 21 May 2021 22:06:51 +0000 (00:06 +0200)
closes #16647

Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

cypress/integration/collection.spec.js
src/common/config.ts
src/views-components/data-explorer/renderers.tsx
src/views/collection-panel/collection-panel.tsx
tools/arvados_config.yml

index c6d29b2c06c8183a651380dc20168e739b940826..797a9d49fedf4838a8dfdc2619600a644dcbbe40 100644 (file)
@@ -103,8 +103,7 @@ describe('Collection panel tests', function () {
                 cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
                     .its('body').as('collection')
                     .then(function () {
-                        expect(this.collection.properties).to.deep.equal(
-                            { IDTAGCOLORS: 'IDVALCOLORS3' });
+                        expect(this.collection.properties.IDTAGCOLORS).to.equal('IDVALCOLORS3');
                     });
             });
     });
@@ -586,4 +585,35 @@ describe('Collection panel tests', function () {
         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
         cy.get('[data-cy=breadcrumb-last]').should('contain', collName);
     });
+
+    it.only('shows responsible person for collection if available', () => {
+        cy.createCollection(adminUser.token, {
+            name: `Test collection ${Math.floor(Math.random() * 999999)}`,
+            owner_uuid: activeUser.user.uuid,
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+        })
+            .as('testCollection1');
+
+        cy.createCollection(adminUser.token, {
+            name: `Test collection ${Math.floor(Math.random() * 999999)}`,
+            owner_uuid: adminUser.user.uuid,
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+        })
+            .as('testCollection2').then(function (testCollection2) {
+                cy.shareWith(adminUser.token, activeUser.user.uuid, testCollection2.uuid, 'can_write');
+            });
+
+        cy.getAll('@testCollection1', '@testCollection2')
+            .then(function ([testCollection1, testCollection2]) {
+                cy.loginAs(activeUser);
+
+                cy.goToPath(`/collections/${testCollection1.uuid}`);
+                cy.get('[data-cy=responsible-person-wrapper]')
+                    .contains(activeUser.user.uuid);
+
+                cy.goToPath(`/collections/${testCollection2.uuid}`);
+                cy.get('[data-cy=responsible-person-wrapper]')
+                    .contains(adminUser.user.uuid);
+            });
+    });
 })
index 146ca90acf62de05f7c4a0214f74701eb6c97f0f..5d9435953fa819f166dcac4c3f015ff07d42c97a 100644 (file)
@@ -83,6 +83,13 @@ export interface ClusterConfigJSON {
     };
     Collections: {
         ForwardSlashNameSubstitution: string;
+        ManagedProperties?: {
+            [key: string]: {
+                Function: string,
+                Value: string,
+                Protected?: boolean,
+            }
+        }
     };
 }
 
index 93abb15e237ddc73424271f26762cbab3d6471bb..ee40dd3988a2c4b028863903c5c533a045c1c147 100644 (file)
@@ -5,7 +5,7 @@
 import * as React from 'react';
 import { Grid, Typography, withStyles, Tooltip, IconButton, Checkbox } from '@material-ui/core';
 import { FavoriteStar, PublicFavoriteStar } from '../favorite-star/favorite-star';
-import { ResourceKind, TrashableResource } from '~/models/resource';
+import { Resource, ResourceKind, TrashableResource } from '~/models/resource';
 import { ProjectIcon, FilterGroupIcon, CollectionIcon, ProcessIcon, DefaultIcon, ShareIcon, CollectionOldVersionIcon, WorkflowIcon } from '~/components/icon/icon';
 import { formatDate, formatFileSize, formatTime } from '~/common/formatters';
 import { resourceLabel } from '~/common/labels';
@@ -468,6 +468,62 @@ export const ResourceOwnerWithName =
             </Typography>;
         });
 
+export const ResponsiblePerson =
+    compose(
+        connect(
+            (state: RootState, props: { uuid: string, parentRef: HTMLElement | null }) => {
+                let responsiblePersonName = null;
+                let responsiblePersonUUID = null;
+                let responsiblePersonProperty = null;
+
+                if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
+                    let index = 0;
+                    const keys = Object.keys(state.auth.config.clusterConfig.Collections.ManagedProperties);
+
+                    while (!responsiblePersonProperty && keys[index]) {
+                        const key = keys[index];
+                        if (state.auth.config.clusterConfig.Collections.ManagedProperties[key].Function === 'original_owner') {
+                            responsiblePersonProperty = key;
+                        }
+                        index++;
+                    }
+                }
+
+                let resource: Resource | undefined = getResource<GroupContentsResource & UserResource>(props.uuid)(state.resources);
+
+                while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
+                    responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
+                    resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
+                }
+
+                if (resource && resource.kind === ResourceKind.USER) {
+                    responsiblePersonName = getUserFullname(resource as UserResource) || (resource as GroupContentsResource).name;
+                }
+
+                return { uuid: responsiblePersonUUID, responsiblePersonName, parentRef: props.parentRef };
+            }),
+        withStyles({}, { withTheme: true }))
+        ((props: { uuid: string | null, responsiblePersonName: string, parentRef: HTMLElement | null, theme: ArvadosTheme }) => {
+            const { uuid, responsiblePersonName, parentRef, theme } = props;
+
+            if (!uuid && parentRef) {
+                parentRef.style.display = 'none';
+                return null;
+            } else if (parentRef) {
+                parentRef.style.display = 'block';
+            }
+
+            if (!responsiblePersonName) {
+                return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
+                    {uuid}
+                </Typography>;
+            }
+
+            return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
+                {responsiblePersonName} ({uuid})
+                </Typography>;
+        });
+
 const renderType = (type: string, subtype: string) =>
     <Typography noWrap>
         {resourceLabel(type, subtype)}
index 7d54992ebd222eca77df3bfea7f877f258de5e1f..8d08f28eb4163d4eb2decf05bfd7d2029c869319 100644 (file)
@@ -32,7 +32,7 @@ import { getProgressIndicator } from '~/store/progress-indicator/progress-indica
 import { COLLECTION_PANEL_LOAD_FILES, loadCollectionFiles, COLLECTION_PANEL_LOAD_FILES_THRESHOLD } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
 import { Link } from 'react-router-dom';
 import { Link as ButtonLink } from '@material-ui/core';
-import { ResourceOwnerWithName } from '~/views-components/data-explorer/renderers';
+import { ResourceOwnerWithName, ResponsiblePerson } from '~/views-components/data-explorer/renderers';
 
 type CssRules = 'root'
     | 'button'
@@ -285,6 +285,7 @@ export const CollectionDetailsAttributes = (props: { item: CollectionResource, t
     const isOldVersion = item && item.currentVersionUuid !== item.uuid;
     const mdSize = props.twoCol ? 6 : 12;
     const showVersionBrowser = props.showVersionBrowser;
+    const responsiblePersonRef = React.useRef(null);
     return <Grid container>
         <Grid item xs={12} md={mdSize}>
             <DetailsAttribute classLabel={classes.label} classValue={classes.value}
@@ -301,6 +302,13 @@ export const CollectionDetailsAttributes = (props: { item: CollectionResource, t
                 label='Owner' linkToUuid={item.ownerUuid}
                 uuidEnhancer={(uuid: string) => <ResourceOwnerWithName uuid={uuid} />} />
         </Grid>
+        <div data-cy="responsible-person-wrapper" ref={responsiblePersonRef}>
+            <Grid item xs={12} md={12}>
+                <DetailsAttribute classLabel={classes.label} classValue={classes.value}
+                    label='Responsible person' linkToUuid={item.ownerUuid}
+                    uuidEnhancer={(uuid: string) => <ResponsiblePerson uuid={item.uuid} parentRef={responsiblePersonRef.current} />} />
+            </Grid>
+        </div>
         <Grid item xs={12} md={mdSize}>
             <DetailsAttribute classLabel={classes.label} classValue={classes.value}
                 label='Head version'
index d93ec7ae5971cb3e6b529b561f5102690e4daae9..a287fed4bddb8d0f6d2e76b4fcd8e8ba1d0de267 100644 (file)
@@ -12,6 +12,8 @@ Clusters:
       BlobSigningKey: zfhgfenhffzltr9dixws36j1yhksjoll2grmku38mi7yxd66h5j4q9w4jzanezacp8s6q0ro3hxakfye02152hncy6zml2ed0uc
       TrustAllContent: true
       ForwardSlashNameSubstitution: /
+      ManagedProperties:
+        original_owner_uuid: {Function: original_owner, Protected: true}
     Login:
       PAM:
         Enable: true