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

272 move filepreview permissions #290

Merged
merged 28 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
860027c
add FilePermissions to FilePreview.ts
ekraffmiller Jan 25, 2024
b1f5213
remove useFileDownloadPermission from components
ekraffmiller Jan 26, 2024
ba5c0cf
lint fix: remove imports
ekraffmiller Jan 26, 2024
81fb11e
fix: remove console.log() statements
ekraffmiller Jan 26, 2024
d6b734a
fix: filePreview expected data
ekraffmiller Jan 26, 2024
481a89a
remove useFilePermissions from useFiles.tsx
ekraffmiller Jan 26, 2024
26be216
remove unneeded files, update tests
ekraffmiller Jan 26, 2024
497f8a6
remove unneeded imports, update tests
ekraffmiller Jan 26, 2024
31bae0a
fix: Dataset.stories.tsx
ekraffmiller Jan 26, 2024
3e0482c
fix: Remove unused files
ekraffmiller Jan 26, 2024
a3e5fbd
fix: Remove decorators
ekraffmiller Jan 26, 2024
590a053
fix: wait for accessButton to be visible.
ekraffmiller Jan 26, 2024
f1288ec
fix: add cy.wait() after button click
ekraffmiller Jan 26, 2024
3df18fa
fix: comment out unused code
ekraffmiller Jan 26, 2024
a382627
fix: remove pipe(), add cypress-grep
ekraffmiller Jan 28, 2024
3ada17f
fix: specify specific version of cypress-grep library
ekraffmiller Jan 30, 2024
c18e6ec
remove getUserPermissionsById() use case, remove FilePermissions from…
ekraffmiller Jan 30, 2024
f27fde0
fix: remove it.only and console.log()
ekraffmiller Jan 30, 2024
3c2c487
remove unused boolean and enum from FilePermissions.ts
ekraffmiller Jan 30, 2024
d084add
rename FileUserPermissionsMother.ts -> FilePermissionsMother.ts
ekraffmiller Jan 30, 2024
3fcc298
Add documentation for @cyprees/grep
ekraffmiller Jan 31, 2024
f62ae74
Remove unneeded mock FileRepository classes
ekraffmiller Jan 31, 2024
3742642
Remove unneeded FilePermissionsMother definition
ekraffmiller Jan 31, 2024
6ba7301
reformat with prettier
ekraffmiller Jan 31, 2024
4b25793
fix: fix FilePermissionsMother import
ekraffmiller Jan 31, 2024
8814cb6
Merge branch 'develop' of https://github.com/IQSS/dataverse-frontend …
MellyGray Feb 9, 2024
a5a8509
fix: tests failing
MellyGray Feb 9, 2024
460304c
fix: coverage
MellyGray Feb 9, 2024
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
52 changes: 52 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"@auto-it/released": "10.46.0",
"@csstools/postcss-cascade-layers": "3.0.1",
"@cypress/code-coverage": "3.10.7",
"@cypress/grep": "^4.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the ^ symbol to avoid unexpected upgrades?

"@storybook/addon-a11y": "7.0.2",
"@storybook/addon-essentials": "7.0.2",
"@storybook/addon-interactions": "7.0.2",
Expand Down
2 changes: 2 additions & 0 deletions src/files/domain/models/FilePreview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FileTypeToFriendlyTypeMap from './FileTypeToFriendlyTypeMap'
import { FilePermissions } from './File'
MellyGray marked this conversation as resolved.
Show resolved Hide resolved

export enum FileSizeUnit {
BYTES = 'B',
Expand Down Expand Up @@ -182,6 +183,7 @@ export class FilePreview {
public readonly isDeleted: boolean,
public readonly ingest: FileIngest,
public readonly downloadUrls: FileDownloadUrls,
public readonly permissions: FilePermissions,
public thumbnail?: string,
readonly directory?: string,
readonly embargo?: FileEmbargo,
Expand Down
13 changes: 12 additions & 1 deletion src/files/infrastructure/FileJSDataverseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
File as JSFile,
FileDataTable as JSFileTabularData,
FileDownloadSizeMode,
FileUserPermissions as JSFileUserPermissions,
getDatasetFileCounts,
getDatasetFiles,
getDatasetFilesTotalDownloadSize,
Expand Down Expand Up @@ -49,15 +50,17 @@ export class FileJSDataverseRepository implements FileRepository {
jsFiles,
FileJSDataverseRepository.getAllDownloadCount(jsFiles),
FileJSDataverseRepository.getAllThumbnails(jsFiles),
FileJSDataverseRepository.getAllWithPermissions(jsFiles),
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
FileJSDataverseRepository.getAllTabularData(jsFiles)
])
)
.then(([jsFiles, downloadCounts, thumbnails, jsTabularData]) =>
.then(([jsFiles, downloadCounts, thumbnails, jsFileUserPermissions, jsTabularData]) =>
jsFiles.map((jsFile, index) =>
JSFileMapper.toFile(
jsFile,
datasetVersion,
downloadCounts[index],
jsFileUserPermissions[index],
thumbnails[index],
jsTabularData[index]
)
Expand Down Expand Up @@ -87,7 +90,15 @@ export class FileJSDataverseRepository implements FileRepository {
)
)
}
private static getAllWithPermissions(files: JSFile[]): Promise<JSFileUserPermissions[]> {
return Promise.all(files.map((jsFile) => this.getFileUserPermissionById(jsFile.id)))
}

private static getFileUserPermissionById(id: number): Promise<JSFileUserPermissions> {
return getFileUserPermissions.execute(id).then((jsFileUserPermissions) => {
return jsFileUserPermissions
})
}
private static getAllThumbnails(jsFiles: JSFile[]): Promise<(string | undefined)[]> {
return Promise.all(jsFiles.map((jsFile) => this.getThumbnailById(jsFile.id)))
}
Expand Down
13 changes: 12 additions & 1 deletion src/files/infrastructure/mappers/JSFileMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
FileEmbargo as JSFileEmbargo,
FileChecksum as JSFileChecksum,
FileCounts as JSFilesCountInfo,
FileUserPermissions as JSFileUserPermissions,
FileContentTypeCount as JSFileContentTypeCount,
FileCategoryNameCount as JSFileCategoryNameCount,
FileAccessStatusCount as JSFileAccessStatusCount,
Expand All @@ -36,12 +37,14 @@ import {
FileTypeCount
} from '../../domain/models/FilesCountInfo'
import { FileAccessOption, FileTag } from '../../domain/models/FileCriteria'
import { FilePermissions } from '../../domain/models/File'

export class JSFileMapper {
static toFile(
jsFile: JSFile,
datasetVersion: DatasetVersion,
downloadsCount: number,
fileUserPermissions: JSFileUserPermissions,
thumbnail?: string,
jsTabularData?: JSFileTabularData[]
): FilePreview {
Expand All @@ -58,6 +61,7 @@ export class JSFileMapper {
this.toFileIsDeleted(jsFile.deleted),
{ status: FileIngestStatus.NONE }, // TODO - Implement this when it is added to js-dataverse
this.toFileOriginalFileDownloadUrl(jsFile.id),
this.toFilePermissions(fileUserPermissions),
this.toFileThumbnail(thumbnail),
this.toFileDirectory(jsFile.directoryLabel),
this.toFileEmbargo(jsFile.embargo),
Expand All @@ -66,7 +70,14 @@ export class JSFileMapper {
this.toFileChecksum(jsFile.checksum)
)
}

static toFilePermissions(jsFileUserPermissions: {
canDownloadFile: boolean
canEditOwnerDataset: boolean
}): FilePermissions {
return {
canDownloadFile: jsFileUserPermissions.canDownloadFile
}
}
static toFileUserPermissions(
jsFileId: number,
jsFileUserPermissions: {
Expand Down
25 changes: 11 additions & 14 deletions src/sections/dataset/DatasetFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { FileJSDataverseRepository } from '../../files/infrastructure/FileJSData
import { MetadataBlockInfoProvider } from './metadata-block-info/MetadataBlockProvider'
import { MetadataBlockInfoJSDataverseRepository } from '../../metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository'
import { SettingJSDataverseRepository } from '../../settings/infrastructure/SettingJSDataverseRepository'
import { FilePermissionsProvider } from '../file/file-permissions/FilePermissionsProvider'
import { SettingsProvider } from '../settings/SettingsProvider'
import { DatasetProvider } from './DatasetProvider'
import { MultipleFileDownloadProvider } from '../file/multiple-file-download/MultipleFileDownloadProvider'
Expand All @@ -24,19 +23,17 @@ export class DatasetFactory {
static create(): ReactElement {
return (
<MultipleFileDownloadProvider repository={fileRepository}>
<FilePermissionsProvider repository={fileRepository}>
<SettingsProvider repository={settingRepository}>
<NotImplementedModalProvider>
<MetadataBlockInfoProvider repository={metadataBlockInfoRepository}>
<AnonymizedProvider>
<AlertProvider>
<DatasetWithSearchParams />
</AlertProvider>
</AnonymizedProvider>
</MetadataBlockInfoProvider>
</NotImplementedModalProvider>
</SettingsProvider>
</FilePermissionsProvider>
<SettingsProvider repository={settingRepository}>
<NotImplementedModalProvider>
<MetadataBlockInfoProvider repository={metadataBlockInfoRepository}>
<AnonymizedProvider>
<AlertProvider>
<DatasetWithSearchParams />
</AlertProvider>
</AnonymizedProvider>
</MetadataBlockInfoProvider>
</NotImplementedModalProvider>
</SettingsProvider>
</MultipleFileDownloadProvider>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ import { Globe, LockFill, UnlockFill } from 'react-bootstrap-icons'
import { useTranslation } from 'react-i18next'
import styles from './AccessFileMenu.module.scss'
import { DropdownButtonItem } from '@iqss/dataverse-design-system'
import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission'

interface AccessStatusProps {
file: FilePreview
}

export function AccessStatus({ file }: AccessStatusProps) {
const { sessionUserHasFileDownloadPermission } = useFileDownloadPermission(file)

return (
<DropdownButtonItem disabled>
<span>
<AccessStatusIcon
sessionUserHasFileDownloadPermission={sessionUserHasFileDownloadPermission}
sessionUserHasFileDownloadPermission={file.permissions.canDownloadFile}
restricted={file.access.restricted}
/>{' '}
<AccessStatusText
file={file}
sessionUserHasFileDownloadPermission={sessionUserHasFileDownloadPermission}
sessionUserHasFileDownloadPermission={file.permissions.canDownloadFile}
/>
</span>
</DropdownButtonItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import { FilePreview } from '../../../../../../../../files/domain/models/FilePre
import { FileTabularDownloadOptions } from './FileTabularDownloadOptions'
import { FileNonTabularDownloadOptions } from './FileNonTabularDownloadOptions'
import { useTranslation } from 'react-i18next'
import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission'

interface FileDownloadOptionsProps {
file: FilePreview
}

export function FileDownloadOptions({ file }: FileDownloadOptionsProps) {
const { t } = useTranslation('files')
const { sessionUserHasFileDownloadPermission } = useFileDownloadPermission(file)

if (!sessionUserHasFileDownloadPermission) {
if (!file.permissions.canDownloadFile) {
return <></>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ import {
FilePublishingStatus
} from '../../../../../../../../files/domain/models/FilePreview'
import { useTranslation } from 'react-i18next'
import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission'

interface RequestAccessButtonProps {
file: FilePreview
}
export function RequestAccessOption({ file }: RequestAccessButtonProps) {
const { t } = useTranslation('files')
const { sessionUserHasFileDownloadPermission } = useFileDownloadPermission(file)

if (
file.version.publishingStatus === FilePublishingStatus.DEACCESSIONED ||
sessionUserHasFileDownloadPermission
file.permissions.canDownloadFile
) {
return <></>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,28 @@ import { FileThumbnailPreviewImage } from './FileThumbnailPreviewImage'
import { FilePreview } from '../../../../../../../../files/domain/models/FilePreview'
import { FileAccessRestrictedIcon } from '../../../../../../../file/file-access/FileAccessRestrictedIcon'
import styles from './FileThumbnail.module.scss'
import { useFileDownloadPermission } from '../../../../../../../file/file-permissions/useFileDownloadPermission'

interface FileThumbnailProps {
file: FilePreview
}

export function FileThumbnail({ file }: FileThumbnailProps) {
const { sessionUserHasFileDownloadPermission } = useFileDownloadPermission(file)

return (
<div
className={`${
file.thumbnail && sessionUserHasFileDownloadPermission
file.thumbnail && file.permissions.canDownloadFile
? styles['container-preview-image']
: styles['container-icon']
}`}>
{file.thumbnail && sessionUserHasFileDownloadPermission ? (
{file.thumbnail && file.permissions.canDownloadFile ? (
<FileThumbnailPreviewImage thumbnail={file.thumbnail} name={file.name} />
) : (
<FileThumbnailIcon type={file.type} />
)}
<div className={styles['restricted-icon']}>
<FileAccessRestrictedIcon
restricted={file.access.restricted}
canDownloadFile={sessionUserHasFileDownloadPermission}
canDownloadFile={file.permissions.canDownloadFile}
/>
</div>
</div>
Expand Down
8 changes: 1 addition & 7 deletions src/sections/dataset/dataset-files/useFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { getFilesByDatasetPersistentId } from '../../../files/domain/useCases/ge
import { FileCriteria } from '../../../files/domain/models/FileCriteria'
import { FilesCountInfo } from '../../../files/domain/models/FilesCountInfo'
import { getFilesCountInfoByDatasetPersistentId } from '../../../files/domain/useCases/getFilesCountInfoByDatasetPersistentId'
import { useFilePermissions } from '../../file/file-permissions/FilePermissionsContext'
import { FilePermission } from '../../../files/domain/models/FileUserPermissions'
import { DatasetVersion } from '../../../dataset/domain/models/Dataset'
import { getFilesTotalDownloadSize } from '../../../files/domain/useCases/getFilesTotalDownloadSize'
import { FilePaginationInfo } from '../../../files/domain/models/FilePaginationInfo'
Expand All @@ -19,7 +17,6 @@ export function useFiles(
paginationInfo: FilePaginationInfo,
criteria?: FileCriteria
) {
const { fetchFilesPermission } = useFilePermissions()
const [files, setFiles] = useState<FilePreview[]>([])
const [isLoading, setIsLoading] = useState<boolean>(true)
const [filesCountInfo, setFilesCountInfo] = useState<FilesCountInfo>()
Expand Down Expand Up @@ -58,11 +55,8 @@ export function useFiles(
)
.then((files: FilePreview[]) => {
setFiles(files)
return files
setIsLoading(false)
})
.then((files: FilePreview[]) =>
fetchFilesPermission(FilePermission.DOWNLOAD_FILE, files).then(() => setIsLoading(false))
)
.catch(() => {
throw new Error('There was an error getting the files')
})
Expand Down
18 changes: 0 additions & 18 deletions src/sections/file/file-permissions/FilePermissionsContext.ts

This file was deleted.

Loading
Loading