16647: Added key search from config and tests
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 20 May 2021 23:39:37 +0000 (01:39 +0200)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 20 May 2021 23:39:37 +0000 (01:39 +0200)
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

index 151700768fcdae0eaa0eb2269341fd3eaf031ad3..75be94f9ad2102d9ba1aa92e6573fe1ad09cbb88 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');
                     });
             });
     });
@@ -583,4 +582,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 2a02f8c20455f0324c0f69f73c377a14d6d103c7..5d9435953fa819f166dcac4c3f015ff07d42c97a 100644 (file)
@@ -84,8 +84,10 @@ export interface ClusterConfigJSON {
     Collections: {
         ForwardSlashNameSubstitution: string;
         ManagedProperties?: {
-            responsible_person_uuid?: {
+            [key: string]: {
                 Function: string,
+                Value: string,
+                Protected?: boolean,
             }
         }
     };
index ed8e393f5f28a9ef5a30c31647fd26075ffe04fe..ee40dd3988a2c4b028863903c5c533a045c1c147 100644 (file)
@@ -477,14 +477,21 @@ export const ResponsiblePerson =
                 let responsiblePersonProperty = null;
 
                 if (state.auth.config.clusterConfig.Collections.ManagedProperties) {
-                    if (state.auth.config.clusterConfig.Collections.ManagedProperties.responsible_person_uuid) {
-                        responsiblePersonProperty = state.auth.config.clusterConfig.Collections.ManagedProperties.responsible_person_uuid.Function;
+                    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 && resource.kind === ResourceKind.COLLECTION && responsiblePersonProperty) {
+                while (resource && resource.kind !== ResourceKind.USER && responsiblePersonProperty) {
                     responsiblePersonUUID = (resource as CollectionResource).properties[responsiblePersonProperty];
                     resource = getResource<GroupContentsResource & UserResource>(responsiblePersonUUID)(state.resources);
                 }
@@ -506,7 +513,7 @@ export const ResponsiblePerson =
                 parentRef.style.display = 'block';
             }
 
-            if (responsiblePersonName === '') {
+            if (!responsiblePersonName) {
                 return <Typography style={{ color: theme.palette.primary.main }} inline noWrap>
                     {uuid}
                 </Typography>;
index d57afd47ba69222a9c66a2228fda711a598c393b..81bd1ebc15d2da8a66ef7d777b5bdbd391d4a490 100644 (file)
@@ -302,7 +302,7 @@ export const CollectionDetailsAttributes = (props: { item: CollectionResource, t
                 label='Owner' linkToUuid={item.ownerUuid}
                 uuidEnhancer={(uuid: string) => <ResourceOwnerWithName uuid={uuid} />} />
         </Grid>
-        <div ref={responsiblePersonRef}>
+        <div data-cy="responsible-person-wrapper" ref={responsiblePersonRef}>
             <Grid item xs={12} md={mdSize}>
                 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
                     label='Responsible person' linkToUuid={item.ownerUuid}