-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from IQSS/feature/159-manage-user-permissions…
…-files 159 - Manage File User Permissions for the Files Tab
- Loading branch information
Showing
52 changed files
with
1,440 additions
and
491 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface FileUserPermissions { | ||
fileId: string | ||
canDownloadFile: boolean | ||
canEditDataset: boolean | ||
} | ||
|
||
export enum FilePermission { | ||
DOWNLOAD_FILE = 'downloadFile', | ||
EDIT_DATASET = 'editDataset' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { FileRepository } from '../repositories/FileRepository' | ||
import { File, FileStatus } from '../models/File' | ||
|
||
export async function checkFileDownloadPermission( | ||
fileRepository: FileRepository, | ||
file: File | ||
): Promise<boolean> { | ||
if (file.version.status === FileStatus.DEACCESSIONED) { | ||
return fileRepository.getFileUserPermissionsById(file.id).then((permissions) => { | ||
return permissions.canEditDataset | ||
}) | ||
} | ||
|
||
const isRestricted = file.access.restricted || file.access.latestVersionRestricted | ||
if (!isRestricted && !file.isActivelyEmbargoed) { | ||
return true | ||
} | ||
|
||
return fileRepository.getFileUserPermissionsById(file.id).then((permissions) => { | ||
return permissions.canDownloadFile | ||
}) | ||
} |
11 changes: 11 additions & 0 deletions
11
src/files/domain/useCases/checkFileEditDatasetPermission.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { FileRepository } from '../repositories/FileRepository' | ||
import { File } from '../models/File' | ||
|
||
export async function checkFileEditDatasetPermission( | ||
fileRepository: FileRepository, | ||
file: File | ||
): Promise<boolean> { | ||
return fileRepository.getFileUserPermissionsById(file.id).then((permissions) => { | ||
return permissions.canEditDataset | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...able/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { File } from '../../../../../../../../files/domain/models/File' | ||
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: File | ||
} | ||
|
||
export function AccessStatus({ file }: AccessStatusProps) { | ||
const { sessionUserHasFileDownloadPermission } = useFileDownloadPermission(file) | ||
|
||
return ( | ||
<DropdownButtonItem disabled> | ||
<span> | ||
<AccessStatusIcon | ||
sessionUserHasFileDownloadPermission={sessionUserHasFileDownloadPermission} | ||
restricted={file.access.restricted} | ||
/>{' '} | ||
<AccessStatusText | ||
file={file} | ||
sessionUserHasFileDownloadPermission={sessionUserHasFileDownloadPermission} | ||
/> | ||
</span> | ||
</DropdownButtonItem> | ||
) | ||
} | ||
|
||
function AccessStatusIcon({ | ||
sessionUserHasFileDownloadPermission, | ||
restricted | ||
}: { | ||
sessionUserHasFileDownloadPermission: boolean | ||
restricted: boolean | ||
}) { | ||
const { t } = useTranslation('files') | ||
if (restricted) { | ||
if (sessionUserHasFileDownloadPermission) { | ||
return ( | ||
<UnlockFill | ||
title={t('table.fileAccess.restrictedWithAccess.icon')} | ||
className={styles.success} | ||
/> | ||
) | ||
} | ||
return ( | ||
<LockFill | ||
role="img" | ||
title={t('table.fileAccess.restricted.icon')} | ||
className={styles.danger} | ||
/> | ||
) | ||
} | ||
return <Globe role="img" title={t('table.fileAccess.public.icon')} className={styles.success} /> | ||
} | ||
|
||
function AccessStatusText({ | ||
file, | ||
sessionUserHasFileDownloadPermission | ||
}: { | ||
file: File | ||
sessionUserHasFileDownloadPermission: boolean | ||
}) { | ||
const { t } = useTranslation('files') | ||
const getAccessStatus = () => { | ||
if (file.isActivelyEmbargoed) { | ||
return 'embargoed' | ||
} | ||
|
||
if (file.access.restricted) { | ||
if (!sessionUserHasFileDownloadPermission) { | ||
return 'restricted' | ||
} | ||
|
||
return 'restrictedWithAccess' | ||
} | ||
|
||
return 'public' | ||
} | ||
|
||
return ( | ||
<span | ||
className={ | ||
styles[ | ||
getAccessStatus() === 'public' || sessionUserHasFileDownloadPermission | ||
? 'success' | ||
: 'danger' | ||
] | ||
}> | ||
{t(`table.fileAccess.${getAccessStatus()}.name`)} | ||
</span> | ||
) | ||
} |
39 changes: 0 additions & 39 deletions
39
.../file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessStatusText.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.