-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restrict/unrestrict file feature
- Loading branch information
1 parent
fa6299a
commit c7b80bd
Showing
20 changed files
with
715 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
POSTGRES_VERSION=13 | ||
DATAVERSE_DB_USER=dataverse | ||
SOLR_VERSION=9.3.0 | ||
SOLR_VERSION=9.8.0 | ||
REGISTRY=docker.io | ||
S3_ACCESS_KEY=<S3_ACCESS_KEY> | ||
S3_SECRET_KEY=<S3_SECRET_KEY> |
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
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,9 @@ | ||
import { FileRepository } from '../repositories/FileRepository' | ||
|
||
export function restrictFile( | ||
fileRepository: FileRepository, | ||
fileId: number | string, | ||
restrict: boolean | ||
): Promise<void> { | ||
return fileRepository.restrict(fileId, restrict) | ||
} |
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
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
69 changes: 69 additions & 0 deletions
69
...tions/file/file-action-buttons/edit-file-menu/restrict-file-button/RestrictFileButton.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,69 @@ | ||
import { useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { useNavigate } from 'react-router-dom' | ||
import { toast } from 'react-toastify' | ||
import { DropdownButtonItem } from '@iqss/dataverse-design-system' | ||
import { FileRepository } from '@/files/domain/repositories/FileRepository' | ||
import { QueryParamKey, Route } from '@/sections/Route.enum' | ||
import { DatasetNonNumericVersionSearchParam } from '@/dataset/domain/models/Dataset' | ||
import { ConfirmRestrictFileModal } from './confirm-restrict-file-modal/ConfirmRestrictFileModal' | ||
import { EditFileMenuDatasetInfo } from '../EditFileMenu' | ||
import { useRestrictFile } from './useRestrictFile' | ||
|
||
interface RestrictFileButtonProps { | ||
fileId: number | ||
isRestricted: boolean | ||
fileRepository: FileRepository | ||
datasetInfo: EditFileMenuDatasetInfo | ||
} | ||
|
||
export const RestrictFileButton = ({ | ||
fileId, | ||
isRestricted, | ||
fileRepository, | ||
datasetInfo | ||
}: RestrictFileButtonProps) => { | ||
const [showConfirmationModal, setShowConfirmationModal] = useState(false) | ||
const navigate = useNavigate() | ||
const { t } = useTranslation('file') | ||
|
||
const { handleRestrictFile, isRestrictingFile, errorRestrictingFile } = useRestrictFile({ | ||
isRestricted, | ||
fileRepository, | ||
onSuccessfulRestrict: closeModalAndNavigateToDataset | ||
}) | ||
const handleOpenModal = () => setShowConfirmationModal(true) | ||
const handleCloseModal = () => setShowConfirmationModal(false) | ||
|
||
function closeModalAndNavigateToDataset() { | ||
setShowConfirmationModal(false) | ||
|
||
const searchParams = new URLSearchParams() | ||
searchParams.set(QueryParamKey.PERSISTENT_ID, datasetInfo.persistentId) | ||
searchParams.set(QueryParamKey.VERSION, DatasetNonNumericVersionSearchParam.DRAFT) | ||
isRestricted | ||
? toast.success(t('restriction.fileUnrestrictedSuccess')) | ||
: toast.success(t('restriction.fileRestrictdSuccess')) | ||
navigate(`${Route.DATASETS}?${searchParams.toString()}`) | ||
} | ||
|
||
return ( | ||
<> | ||
<DropdownButtonItem onClick={handleOpenModal}> | ||
{isRestricted | ||
? t('actionButtons.editFileMenu.options.unrestrict') | ||
: t('actionButtons.editFileMenu.options.restrict')} | ||
</DropdownButtonItem> | ||
<ConfirmRestrictFileModal | ||
show={showConfirmationModal} | ||
handleClose={handleCloseModal} | ||
handleRestrict={() => handleRestrictFile(fileId)} | ||
datasetReleasedVersionExists={datasetInfo.releasedVersionExists} | ||
termsOfAccessForRestrictedFiles={datasetInfo.termsOfAccessForRestrictedFiles} | ||
isRestrictingFile={isRestrictingFile} | ||
errorRestrictingFile={errorRestrictingFile} | ||
isRestricted={isRestricted} | ||
/> | ||
</> | ||
) | ||
} |
24 changes: 24 additions & 0 deletions
24
...enu/restrict-file-button/confirm-restrict-file-modal/ConfirmRestrictFileModal.module.scss
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,24 @@ | ||
@import 'node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module'; | ||
|
||
.message { | ||
color: $dv-warning-color; | ||
|
||
&.error { | ||
color: $dv-danger-color; | ||
} | ||
|
||
svg { | ||
min-width: fit-content; | ||
} | ||
} | ||
|
||
.restriction_form { | ||
padding-top: 0.5em; | ||
padding-bottom: 0.5em; | ||
} | ||
|
||
.restriction_info { | ||
padding-top: 0.5em; | ||
padding-bottom: 0.5em; | ||
color: $dv-subtext-color; | ||
} |
Oops, something went wrong.