Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

205 - Integration dataset user permissions #218

Merged
merged 11 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN npm run build

WORKDIR /usr/src/app
COPY package.json ./
COPY package-lock.json ./
COPY .npmrc ./
RUN npm install

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"i18next": "22.4.9",
"i18next-browser-languagedetector": "7.0.1",
"i18next-http-backend": "2.1.1",
"moment-timezone": "^0.5.43",
"moment-timezone": "0.5.43",
"react-bootstrap": "2.7.2",
"react-bootstrap-icons": "1.10.3",
"react-i18next": "12.1.5",
Expand Down
36 changes: 24 additions & 12 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DatasetMetadataBlocks as JSDatasetMetadataBlocks,
DatasetMetadataFields as JSDatasetMetadataFields,
DatasetVersionInfo as JSDatasetVersionInfo,
DatasetUserPermissions as JSDatasetPermissions,
DatasetLock as JSDatasetLock
} from '@iqss/dataverse-client-javascript'
import { DatasetVersionState as JSDatasetVersionState } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset'
Expand All @@ -15,16 +16,18 @@ import {
DatasetMetadataFields,
DatasetVersion,
MetadataBlockName,
PrivateUrl,
DatasetPermissions,
DatasetLock,
DatasetLockReason
DatasetLockReason,
PrivateUrl
} from '../../domain/models/Dataset'

export class JSDatasetMapper {
static toDataset(
jsDataset: JSDataset,
citation: string,
summaryFieldsNames: string[],
jsDatasetPermissions: JSDatasetPermissions,
jsDatasetLocks: JSDatasetLock[],
requestedVersion?: string,
privateUrl?: PrivateUrl
Expand All @@ -41,19 +44,11 @@ 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),
JSDatasetMapper.toLocks(jsDatasetLocks),
true, // TODO Connect with dataset hasValidTermsOfAccess
true, // TODO Connect with dataset isValid
jsDataset.versionInfo.releaseTime !== undefined &&
!isNaN(jsDataset.versionInfo.releaseTime.getTime()), // TODO Connect with dataset isReleased,
JSDatasetMapper.toIsReleased(jsDataset.versionInfo),
undefined, // TODO: get dataset thumbnail from Dataverse https://github.com/IQSS/dataverse-frontend/issues/203
privateUrl
).build()
Expand Down Expand Up @@ -190,6 +185,23 @@ export class JSDatasetMapper {
return extraFields
}

static toIsReleased(jsDatasetVersionInfo: JSDatasetVersionInfo): boolean {
return (
jsDatasetVersionInfo.releaseTime !== undefined &&
!isNaN(jsDatasetVersionInfo.releaseTime.getTime())
)
}

static toDatasetPermissions(jsDatasetPermissions: JSDatasetPermissions): DatasetPermissions {
return {
canDownloadFiles: true, // TODO: connect with js-dataverse
canUpdateDataset: jsDatasetPermissions.canEditDataset,
canPublishDataset: jsDatasetPermissions.canPublishDataset,
canManageDatasetPermissions: jsDatasetPermissions.canManageDatasetPermissions,
canManageFilesPermissions: true, // TODO: connect with js-dataverse DatasetPermissions.canManageFilesPermissions
canDeleteDataset: jsDatasetPermissions.canManageDatasetPermissions
}
}
static toLocks(jsDatasetLocks: JSDatasetLock[]): DatasetLock[] {
return jsDatasetLocks.map((jsDatasetLock) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
getDatasetCitation,
getDatasetSummaryFieldNames,
Dataset as JSDataset,
DatasetUserPermissions as JSDatasetPermissions,
getPrivateUrlDataset,
getPrivateUrlDatasetCitation,
getDatasetUserPermissions,
ReadError,
getDatasetLocks,
DatasetLock as JSDatasetLock
Expand All @@ -26,20 +28,23 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
jsDataset,
getDatasetSummaryFieldNames.execute(),
getDatasetCitation.execute(jsDataset.id, this.versionToVersionId(version)),
getDatasetUserPermissions.execute(jsDataset.id),
getDatasetLocks.execute(jsDataset.id)
])
)
.then(
([jsDataset, summaryFieldsNames, citation, jsDatasetLocks]: [
([jsDataset, summaryFieldsNames, citation, jsDatasetPermissions, jsDatasetLocks]: [
JSDataset,
string[],
string,
JSDatasetPermissions,
JSDatasetLock[]
]) =>
JSDatasetMapper.toDataset(
jsDataset,
citation,
summaryFieldsNames,
jsDatasetPermissions,
jsDatasetLocks,
requestedVersion
)
Expand All @@ -57,10 +62,22 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
getPrivateUrlDataset.execute(privateUrlToken),
getDatasetSummaryFieldNames.execute(),
getPrivateUrlDatasetCitation.execute(privateUrlToken)
]) // TODO - Add getDatasetLocks.execute(privateUrlToken) when it is available in js-dataverse
])
.then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) =>
JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames, [])
)
JSDatasetMapper.toDataset(
jsDataset,
citation,
summaryFieldsNames,
{
canEditDataset: true,
canPublishDataset: true,
canManageDatasetPermissions: true,
canDeleteDatasetDraft: true,
canViewUnpublishedDataset: true
},
[]
)
) // TODO Connect with JS dataset permissions and getDatasetLocks.execute(privateUrlToken) when it is available in js-dataverse
.catch((error: ReadError) => {
throw new Error(error.message)
})
Expand Down
30 changes: 26 additions & 4 deletions src/settings/infrastructure/SettingJSDataverseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,33 @@ export class SettingJSDataverseRepository implements SettingRepository {
// TODO - implement using js-dataverse
return new Promise((resolve) => {
setTimeout(() => {
resolve({
name: SettingName.ZIP_DOWNLOAD_LIMIT,
value: new ZipDownloadLimit(1, FileSizeUnit.BYTES)
} as Setting<T>)
resolve(mockedSettingResponse<T>(name))
}, 1000)
})
}
}

function mockedSettingResponse<T>(name: SettingName): Setting<T> {
switch (name) {
case SettingName.ZIP_DOWNLOAD_LIMIT:
return {
name: SettingName.ZIP_DOWNLOAD_LIMIT,
value: new ZipDownloadLimit(1, FileSizeUnit.BYTES)
} as Setting<T>
case SettingName.ALLOWED_EXTERNAL_STATUSES:
return {
name: SettingName.ALLOWED_EXTERNAL_STATUSES,
value: [
'Author Contacted',
'Privacy Review',
'Awaiting Paper Publication',
'Final Approval'
]
} as Setting<T>
case SettingName.HAS_PUBLIC_STORE:
return {
name: SettingName.HAS_PUBLIC_STORE,
value: false
} as Setting<T>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ const jsDataset = {
const citation =
'Finch, Fiona, 2023, "Darwin\'s Finches", <a href="https://doi.org/10.5072/FK2/B4B2MJ" target="_blank">https://doi.org/10.5072/FK2/B4B2MJ</a>, Root, DRAFT VERSION'
const datasetSummaryFields = ['dsDescription', 'subject', 'keyword', 'publication', 'notesText']
const jsDatasetPermissions = {
canEditDataset: true,
canPublishDataset: true,
canManageDatasetPermissions: true,
canDeleteDatasetDraft: true,
canViewUnpublishedDataset: true
}
const jsDatasetLocks: JSDatasetLock[] = [
{
lockType: DatasetLockType.IN_REVIEW,
Expand Down Expand Up @@ -234,6 +241,7 @@ describe('JS Dataset Mapper', () => {
jsDataset,
citation,
datasetSummaryFields,
jsDatasetPermissions,
jsDatasetLocks
)
expect(expectedDataset).to.deep.equal(mapped)
Expand All @@ -243,6 +251,7 @@ describe('JS Dataset Mapper', () => {
jsDataset,
citation,
datasetSummaryFields,
jsDatasetPermissions,
jsDatasetLocks,
'4.0'
)
Expand Down Expand Up @@ -284,6 +293,7 @@ describe('JS Dataset Mapper', () => {
jsDatasetWithAlternativePersistentId,
citation,
datasetSummaryFields,
jsDatasetPermissions,
jsDatasetLocks
)
)
Expand Down Expand Up @@ -323,6 +333,7 @@ describe('JS Dataset Mapper', () => {
jsDatasetWithCitationDate,
citation,
datasetSummaryFields,
jsDatasetPermissions,
jsDatasetLocks
)
)
Expand Down Expand Up @@ -361,6 +372,7 @@ describe('JS Dataset Mapper', () => {
jsDatasetWithPublicationDate,
citation,
datasetSummaryFields,
jsDatasetPermissions,
jsDatasetLocks
)
)
Expand Down
38 changes: 33 additions & 5 deletions tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,38 @@ describe('Dataset', () => {
name: dataset.datasetVersion.metadataBlocks.citation.fields[0].value
}).should('exist')
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.findByText(DatasetLabelValue.UNPUBLISHED).should('exist')

cy.findByText('Metadata').should('exist')
cy.findByText('Files').should('exist')

cy.findByRole('button', { name: 'Edit Dataset' }).should('exist').click()
cy.findByRole('button', { name: 'Permissions' }).should('exist').click()
cy.findByRole('button', { name: 'Dataset' }).should('exist')
cy.findByRole('button', { name: 'Delete Dataset' }).should('exist')
cy.findByRole('button', { name: 'Publish Dataset' }).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: 'Publish 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 @@ -52,15 +80,15 @@ 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) => {
cy.findByRole('heading', {
name: dataset.datasetVersion.metadataBlocks.citation.fields[0].value
}).should('exist')
cy.findByText(DatasetLabelValue.DRAFT).should('not.exist')
// cy.findByText(DatasetLabelValue.UNPUBLISHED).should('not.exist') TODO - Implemnent isReleased property in js-dataverse to get the Unpublished label
cy.findByText(DatasetLabelValue.UNPUBLISHED).should('not.exist')
cy.findByText('Version 1.0').should('exist')
})
})
Expand Down Expand Up @@ -100,7 +128,7 @@ describe('Dataset', () => {
name: dataset.datasetVersion.metadataBlocks.citation.fields[0].value
}).should('exist')
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.findByText(DatasetLabelValue.UNPUBLISHED).should('exist')
})
})
})
Expand All @@ -120,7 +148,7 @@ describe('Dataset', () => {
name: dataset.datasetVersion.metadataBlocks.citation.fields[0].value
}).should('exist')
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.findByText(DatasetLabelValue.UNPUBLISHED).should('exist')

cy.findAllByText('withheld').should('exist')
})
Expand Down
Loading