From 25dc48d4655faf7a6eebdb717e225b77d8ff5c3f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kuty=C5=82a?= Date: Fri, 21 May 2021 01:39:37 +0200 Subject: [PATCH] 16647: Added key search from config and tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- cypress/integration/collection.spec.js | 34 +++++++++++++++++-- src/common/config.ts | 4 ++- .../data-explorer/renderers.tsx | 15 +++++--- .../collection-panel/collection-panel.tsx | 2 +- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/cypress/integration/collection.spec.js b/cypress/integration/collection.spec.js index 15170076..75be94f9 100644 --- a/cypress/integration/collection.spec.js +++ b/cypress/integration/collection.spec.js @@ -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); + }); + }); }) diff --git a/src/common/config.ts b/src/common/config.ts index 2a02f8c2..5d943595 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -84,8 +84,10 @@ export interface ClusterConfigJSON { Collections: { ForwardSlashNameSubstitution: string; ManagedProperties?: { - responsible_person_uuid?: { + [key: string]: { Function: string, + Value: string, + Protected?: boolean, } } }; diff --git a/src/views-components/data-explorer/renderers.tsx b/src/views-components/data-explorer/renderers.tsx index ed8e393f..ee40dd39 100644 --- a/src/views-components/data-explorer/renderers.tsx +++ b/src/views-components/data-explorer/renderers.tsx @@ -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(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(responsiblePersonUUID)(state.resources); } @@ -506,7 +513,7 @@ export const ResponsiblePerson = parentRef.style.display = 'block'; } - if (responsiblePersonName === '') { + if (!responsiblePersonName) { return {uuid} ; diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx index d57afd47..81bd1ebc 100644 --- a/src/views/collection-panel/collection-panel.tsx +++ b/src/views/collection-panel/collection-panel.tsx @@ -302,7 +302,7 @@ export const CollectionDetailsAttributes = (props: { item: CollectionResource, t label='Owner' linkToUuid={item.ownerUuid} uuidEnhancer={(uuid: string) => } /> -
+