Skip to content

Commit

Permalink
feat(IngestInfoMessage): add dataset permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Sep 26, 2023
1 parent f41efad commit 99b2159
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { FileIngest, FileIngestStatus } from '../../../../../../../files/domain/
import { QuestionMarkTooltip } from '@iqss/dataverse-design-system'
import { InfoMessageBox } from './FileInfoMessages'
import { useTranslation } from 'react-i18next'
import { useDataset } from '../../../../../DatasetContext'

interface IngestInfoMessageProps {
ingest: FileIngest
}
export function IngestInfoMessage({ ingest }: IngestInfoMessageProps) {
const { t } = useTranslation('files')
const userHasDatasetUpdatePermissions = true // TODO - Implement dataset permissions
const { dataset } = useDataset()

if (ingest.status === FileIngestStatus.IN_PROGRESS) {
return (
Expand All @@ -18,7 +19,7 @@ export function IngestInfoMessage({ ingest }: IngestInfoMessageProps) {
)
}

if (ingest.status === FileIngestStatus.ERROR && userHasDatasetUpdatePermissions) {
if (ingest.status === FileIngestStatus.ERROR && dataset?.permissions.canUpdateDataset) {
return (
<InfoMessageBox>
<span>
Expand All @@ -43,5 +44,5 @@ export function IngestInfoMessage({ ingest }: IngestInfoMessageProps) {
)
}

return null
return <></>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { WithI18next } from '../../../../../WithI18next'
import { WithSettings } from '../../../../../WithSettings'
import { FileInfoMessages } from '../../../../../../sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/FileInfoMessages'
import { FileMother } from '../../../../../../../tests/component/files/domain/models/FileMother'
import { WithDatasetAllPermissionsGranted } from '../../../../WithDatasetAllPermissionsGranted'

const meta: Meta<typeof FileInfoMessages> = {
title:
'Sections/Dataset Page/DatasetFiles/FilesTable/FileActionsCell/FileInfoMessages/FileInfoMessages',
component: FileInfoMessages,
decorators: [WithI18next, WithSettings]
decorators: [WithI18next, WithSettings, WithDatasetAllPermissionsGranted]
}

export default meta
Expand Down
4 changes: 4 additions & 0 deletions tests/component/files/domain/models/FileMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class FileIngestMother {
reportMessage: reportMessage
})
}

static createIngestNone(): FileIngest {
return this.create({ status: FileIngestStatus.NONE })
}
}

export class FileChecksumMother {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
import { IngestInfoMessage } from '../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-info-messages/IngestInfoMessage'
import { FileIngestMother } from '../../../../../../../files/domain/models/FileMother'
import { ReactNode } from 'react'
import { Dataset as DatasetModel } from '../../../../../../../../../src/dataset/domain/models/Dataset'
import { DatasetProvider } from '../../../../../../../../../src/sections/dataset/DatasetProvider'
import { DatasetRepository } from '../../../../../../../../../src/dataset/domain/repositories/DatasetRepository'
import {
DatasetMother,
DatasetPermissionsMother
} from '../../../../../../../dataset/domain/models/DatasetMother'

const datasetRepository: DatasetRepository = {} as DatasetRepository
const datasetWithUpdatePermissions = DatasetMother.create({
permissions: DatasetPermissionsMother.createWithUpdateDatasetAllowed()
})
describe('IngestInfoMessage', () => {
const withDataset = (component: ReactNode, dataset: DatasetModel | undefined) => {
datasetRepository.getByPersistentId = cy.stub().resolves(dataset)
datasetRepository.getByPrivateUrlToken = cy.stub().resolves(dataset)

return (
<DatasetProvider
repository={datasetRepository}
searchParams={{ persistentId: 'some-persistent-id', version: 'some-version' }}>
{component}
</DatasetProvider>
)
}

it('renders the ingest in progress message', () => {
cy.customMount(<IngestInfoMessage ingest={FileIngestMother.createInProgress()} />)

Expand All @@ -11,9 +36,12 @@ describe('IngestInfoMessage', () => {

it('renders the ingest problem when there is an error and the user has update dataset permissions with no report message ', () => {
cy.customMount(
<div style={{ height: 300, alignItems: 'center', display: 'flex' }}>
<IngestInfoMessage ingest={FileIngestMother.createIngestProblem()} />
</div>
withDataset(
<div style={{ height: 300, alignItems: 'center', display: 'flex' }}>
<IngestInfoMessage ingest={FileIngestMother.createIngestProblem()} />
</div>,
datasetWithUpdatePermissions
)
)

cy.findByText('Ingest in progress...').should('not.exist')
Expand All @@ -29,9 +57,12 @@ describe('IngestInfoMessage', () => {

it('renders the ingest problem when there is an error and the user has update dataset permissions with a report message', () => {
cy.customMount(
<div style={{ height: 300, alignItems: 'center', display: 'flex' }}>
<IngestInfoMessage ingest={FileIngestMother.createIngestProblem('Some message.')} />
</div>
withDataset(
<div style={{ height: 300, alignItems: 'center', display: 'flex' }}>
<IngestInfoMessage ingest={FileIngestMother.createIngestProblem('Some message.')} />
</div>,
datasetWithUpdatePermissions
)
)

cy.findByText('Ingest in progress...').should('not.exist')
Expand All @@ -42,4 +73,35 @@ describe('IngestInfoMessage', () => {
cy.findByRole('link', { name: 'Tabular ingest' }).should('exist')
cy.findByText(/was unsuccessful. Some message./).should('exist')
})

it('does not render the ingest problem when there is an error and the user does not have update dataset permissions', () => {
const datasetWithoutUpdatePermissions = DatasetMother.create({
permissions: DatasetPermissionsMother.createWithUpdateDatasetNotAllowed()
})
cy.customMount(
withDataset(
<div style={{ height: 300, alignItems: 'center', display: 'flex' }}>
<IngestInfoMessage ingest={FileIngestMother.createIngestProblem()} />
</div>,
datasetWithoutUpdatePermissions
)
)

cy.findByText('Ingest in progress...').should('not.exist')
cy.findByText('File available in original format only').should('not.exist')
})

it('does not render any message when there is no ingest status', () => {
cy.customMount(
withDataset(
<div style={{ height: 300, alignItems: 'center', display: 'flex' }}>
<IngestInfoMessage ingest={FileIngestMother.createIngestNone()} />
</div>,
datasetWithUpdatePermissions
)
)

cy.findByText('Ingest in progress...').should('not.exist')
cy.findByText('File available in original format only').should('not.exist')
})
})

0 comments on commit 99b2159

Please sign in to comment.