From 7b14fa06a3ed70e7195766c6a8fb93e406b0a9c5 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Thu, 2 Nov 2023 12:17:29 +0100 Subject: [PATCH] feat(IntegrationDatasetPermissions): integrate canEditDataset permission --- dev-env/.env | 2 +- .../infrastructure/mappers/JSDatasetMapper.ts | 33 ++++++++++++------- .../DatasetJSDataverseRepository.ts | 28 ++++++++++++---- .../e2e/sections/dataset/Dataset.spec.tsx | 25 +++++++++++++- 4 files changed, 69 insertions(+), 19 deletions(-) diff --git a/dev-env/.env b/dev-env/.env index a7a8a8574..05d4bebe8 100644 --- a/dev-env/.env +++ b/dev-env/.env @@ -1,4 +1,4 @@ POSTGRES_VERSION=13 DATAVERSE_DB_USER=dataverse SOLR_VERSION=9.3.0 -REGISTRY=ghcr.io +REGISTRY=docker.io diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index ce3ade4b9..cef9e67a4 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -3,7 +3,8 @@ import { DatasetMetadataBlock as JSDatasetMetadataBlock, DatasetMetadataBlocks as JSDatasetMetadataBlocks, DatasetMetadataFields as JSDatasetMetadataFields, - DatasetVersionInfo as JSDatasetVersionInfo + DatasetVersionInfo as JSDatasetVersionInfo, + DatasetUserPermissions as JSDatasetPermissions } from '@iqss/dataverse-client-javascript' import { DatasetVersionState as JSDatasetVersionState } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset' import { @@ -13,11 +14,17 @@ import { DatasetMetadataBlocks, DatasetMetadataFields, DatasetVersion, - MetadataBlockName + MetadataBlockName, + DatasetPermissions } from '../../domain/models/Dataset' export class JSDatasetMapper { - static toDataset(jsDataset: JSDataset, citation: string, summaryFieldsNames: string[]): Dataset { + static toDataset( + jsDataset: JSDataset, + citation: string, + summaryFieldsNames: string[], + jsDatasetPermissions: JSDatasetPermissions + ): Dataset { return new Dataset.Builder( jsDataset.persistentId, JSDatasetMapper.toVersion(jsDataset.versionId, jsDataset.versionInfo), @@ -30,14 +37,7 @@ export class JSDatasetMapper { jsDataset.publicationDate, jsDataset.citationDate ), - { - canDownloadFiles: true, - canUpdateDataset: true, - canPublishDataset: true, - canManageDatasetPermissions: true, - canManageFilesPermissions: true, - canDeleteDataset: true - }, // TODO Connect with dataset permissions + JSDatasetMapper.toDatasetPermissions(jsDatasetPermissions), [], // TODO Connect with dataset locks true, // TODO Connect with dataset hasValidTermsOfAccess true, // TODO Connect with dataset isValid @@ -173,4 +173,15 @@ export class JSDatasetMapper { return extraFields } + + static toDatasetPermissions(jsDatasetPermissions: JSDatasetPermissions): DatasetPermissions { + return { + canDownloadFiles: true, + canUpdateDataset: jsDatasetPermissions.canEditDataset, + canPublishDataset: true, + canManageDatasetPermissions: true, + canManageFilesPermissions: true, + canDeleteDataset: true + } + } } diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index ea25c0aa2..0f0dbc28f 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -6,8 +6,10 @@ import { getDatasetSummaryFieldNames, WriteError, Dataset as JSDataset, + DatasetUserPermissions as JSDatasetPermissions, getPrivateUrlDataset, - getPrivateUrlDatasetCitation + getPrivateUrlDatasetCitation, + getDatasetUserPermissions } from '@iqss/dataverse-client-javascript' import { JSDatasetMapper } from '../mappers/JSDatasetMapper' @@ -19,11 +21,18 @@ export class DatasetJSDataverseRepository implements DatasetRepository { Promise.all([ jsDataset, getDatasetSummaryFieldNames.execute(), - getDatasetCitation.execute(jsDataset.id, this.versionToVersionId(version)) + getDatasetCitation.execute(jsDataset.id, this.versionToVersionId(version)), + getDatasetUserPermissions.execute(jsDataset.id) ]) ) - .then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) => - JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames) + .then( + ([jsDataset, summaryFieldsNames, citation, jsDatasetPermissions]: [ + JSDataset, + string[], + string, + JSDatasetPermissions + ]) => + JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames, jsDatasetPermissions) ) .catch((error: WriteError) => { if (!version) { @@ -39,8 +48,15 @@ export class DatasetJSDataverseRepository implements DatasetRepository { getDatasetSummaryFieldNames.execute(), getPrivateUrlDatasetCitation.execute(privateUrlToken) ]) - .then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) => - JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames) + .then( + ([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) => + JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames, { + canEditDataset: true, + canPublishDataset: true, + canManageDatasetPermissions: true, + canDeleteDatasetDraft: true, + canViewUnpublishedDataset: true + }) // TODO Connect with JS dataset permissions ) .catch((error: WriteError) => { throw new Error(error.message) diff --git a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx index 4973b2165..d32ea2ed2 100644 --- a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx +++ b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx @@ -30,6 +30,29 @@ describe('Dataset', () => { cy.findByText(DatasetLabelValue.DRAFT).should('exist') // cy.findByText(DatasetLabelValue.UNPUBLISHED).should('exist') TODO - Implemnent isReleased property in js-dataverse to get the Unpublished label + cy.findByRole('button', { name: 'Edit Dataset' }).should('exist') + cy.findByRole('button', { name: 'Upload Files' }).should('exist') + cy.findByText('Metadata').should('exist') + cy.findByText('Files').should('exist') + }) + }) + }) + + it('successfully loads a published dataset when the user is not authenticated', () => { + cy.wrap(DatasetHelper.create().then((dataset) => DatasetHelper.publish(dataset.persistentId))) + .its('persistentId') + .then((persistentId: string) => { + cy.wrap(TestsUtils.logout()) + cy.wait(1500) // Wait for the dataset to be published + cy.visit(`/spa/datasets?persistentId=${persistentId}`) + + cy.fixture('dataset-finch1.json').then((dataset: Dataset) => { + cy.findByRole('heading', { + name: dataset.datasetVersion.metadataBlocks.citation.fields[0].value + }).should('exist') + + cy.findByRole('button', { name: 'Edit Dataset' }).should('not.exist') + cy.findByRole('button', { name: 'Upload Files' }).should('not.exist') cy.findByText('Metadata').should('exist') cy.findByText('Files').should('exist') }) @@ -51,7 +74,7 @@ describe('Dataset', () => { cy.wrap(DatasetHelper.create().then((dataset) => DatasetHelper.publish(dataset.persistentId))) .its('persistentId') .then((persistentId: string) => { - cy.wait(1500) + cy.wait(1500) // Wait for the dataset to be published cy.visit(`/spa/datasets?persistentId=${persistentId}&version=1.0`) cy.fixture('dataset-finch1.json').then((dataset: Dataset) => {