Skip to content

Commit

Permalink
feat(IntegrationDatasetPermissions): integrate canEditDataset permission
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Nov 2, 2023
1 parent d3eb838 commit 7b14fa0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dev-env/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
POSTGRES_VERSION=13
DATAVERSE_DB_USER=dataverse
SOLR_VERSION=9.3.0
REGISTRY=ghcr.io
REGISTRY=docker.io
33 changes: 22 additions & 11 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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) {
Expand All @@ -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)
Expand Down
25 changes: 24 additions & 1 deletion tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand All @@ -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) => {
Expand Down

0 comments on commit 7b14fa0

Please sign in to comment.