diff --git a/app/apis/azul/anvil-cmg/common/transformers.ts b/app/apis/azul/anvil-cmg/common/transformers.ts index 780560f45..cd013f375 100644 --- a/app/apis/azul/anvil-cmg/common/transformers.ts +++ b/app/apis/azul/anvil-cmg/common/transformers.ts @@ -71,6 +71,18 @@ export function getConsentGroup(response: DatasetsResponse): string[] { return processAggregatedOrArrayValue(response.datasets, "consent_group"); } +/** + * Returns true if consent groups include NRES or Unrestricted access. + * @param consentGroups - Array of consent group strings. + * @returns true if NRES or Unrestricted access is present. + */ +export function isNRESOrUnrestrictedAccess(consentGroups: string[]): boolean { + return ( + consentGroups.includes("NRES") || + consentGroups.includes("Unrestricted access") + ); +} + /** * Maps biosample type from an aggregated biosamples value returned from endpoints other than index/biosamples. * @param response - Response model return from Azul that includes aggregated biosamples. diff --git a/app/components/Export/components/AnVILExplorer/components/ExportCohort/components/DownloadSection/downloadSection.tsx b/app/components/Export/components/AnVILExplorer/components/ExportCohort/components/DownloadSection/downloadSection.tsx index 5890a101a..beb0d2392 100644 --- a/app/components/Export/components/AnVILExplorer/components/ExportCohort/components/DownloadSection/downloadSection.tsx +++ b/app/components/Export/components/AnVILExplorer/components/ExportCohort/components/DownloadSection/downloadSection.tsx @@ -1,7 +1,7 @@ import { TYPOGRAPHY_PROPS } from "@databiosphere/findable-ui/lib/styles/common/mui/typography"; import { Stack, Typography } from "@mui/material"; import type { JSX } from "react"; -import { isNRESConsentGroup } from "../../../../../../../../viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders"; +import { hasNRESConsentGroup } from "../../../../../../../../viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders"; import { Props } from "./types"; /** @@ -11,7 +11,7 @@ import { Props } from "./types"; * @returns Download section title and description. */ export const DownloadSection = ({ viewContext }: Props): JSX.Element => { - const isNRES = isNRESConsentGroup(viewContext); + const isNRES = hasNRESConsentGroup(viewContext.fileManifestState); return ( +export function hasNRESConsentGroup( + fileManifestState: FileManifestState ): boolean { - const { fileManifestState } = viewContext; - const facet = findFacet( fileManifestState.filesFacets, ANVIL_CMG_CATEGORY_KEY.DATASET_CONSENT_GROUP @@ -1806,9 +1806,9 @@ export function isNRESConsentGroup( if (!facet) return false; - const termsByName = facet.termsByName; + const consentGroups = [...facet.termsByName.keys()]; - return termsByName.has("NRES") || termsByName.has("Unrestricted access"); + return isNRESOrUnrestrictedAccess(consentGroups); } /** @@ -1882,7 +1882,8 @@ export const renderWhenUnAuthenticated = ( }; /** - * Renders cohort curl download component when the current query includes NRES or Unrestricted access consent groups. + * Renders cohort curl download component when the current query includes NRES or Unrestricted access consent groups, + * or when the environment is non-production. * @param _ - Unused. * @param viewContext - View context. * @returns model to be used as props for the ConditionalComponent component. @@ -1891,11 +1892,16 @@ export const renderCohortCurlDownload = ( _: unknown, viewContext: ViewContext ): ComponentProps => { - return { isIn: isNRESConsentGroup(viewContext) }; + return { + isIn: + !isProductionEnvironment() || + hasNRESConsentGroup(viewContext.fileManifestState), + }; }; /** - * Renders dataset curl download components when the given dataset has NRES consent group. + * Renders dataset curl download components when the given dataset has NRES consent group, + * or when the environment is non-production. * @param datasetsResponse - Response model return from datasets API. * @returns model to be used as props for the ConditionalComponent component. */ @@ -1903,7 +1909,8 @@ export const renderDatasetCurlDownload = ( datasetsResponse: DatasetsResponse ): React.ComponentProps => { return { - isIn: isDatasetNRESConsentGroup(datasetsResponse), + isIn: + !isProductionEnvironment() || isDatasetNRESConsentGroup(datasetsResponse), }; }; diff --git a/pages/[entityListType]/[...params].tsx b/pages/[entityListType]/[...params].tsx index 804919442..07250b4be 100644 --- a/pages/[entityListType]/[...params].tsx +++ b/pages/[entityListType]/[...params].tsx @@ -33,8 +33,12 @@ import { useConfig } from "@databiosphere/findable-ui/lib/hooks/useConfig"; import NextError from "next/error"; import { ROUTES } from "../../site-config/anvil-cmg/dev/export/routes"; -import { getConsentGroup } from "../../app/apis/azul/anvil-cmg/common/transformers"; +import { + getConsentGroup, + isNRESOrUnrestrictedAccess, +} from "../../app/apis/azul/anvil-cmg/common/transformers"; import { DatasetsResponse } from "../../app/apis/azul/anvil-cmg/common/responses"; +import { isProductionEnvironment } from "../../app/config/utils"; const setOfProcessedIds = new Set(); @@ -66,8 +70,13 @@ const EntityDetailPage = (props: EntityDetailPageProps): JSX.Element => { const { query } = useRouter(); if (!props.entityListType) return <>; if (props.override) return ; - // Curl download requires NRES consent group (AnVIL only) - if (isAnVIL && isCurlDownloadRoute(query) && !isNRESDataset(props.data)) { + // Curl download requires NRES consent group (AnVIL production only) + if ( + isAnVIL && + isProductionEnvironment() && + isCurlDownloadRoute(query) && + !isNRESDataset(props.data) + ) { return ; } if (isChooseExportView(query)) return ; @@ -103,14 +112,14 @@ function isCurlDownloadRoute(query: ParsedUrlQuery): boolean { } /** - * Returns true if the dataset has NRES consent group. + * Returns true if the dataset has NRES or Unrestricted access consent group. * @param data - Entity response data. - * @returns True if the dataset has NRES consent group. + * @returns True if the dataset has NRES or Unrestricted access consent group. */ function isNRESDataset(data: AzulEntityStaticResponse | undefined): boolean { if (!data) return false; const consentGroups = getConsentGroup(data as DatasetsResponse); - return consentGroups.includes("NRES"); + return isNRESOrUnrestrictedAccess(consentGroups); } /** diff --git a/pages/export/get-curl-command.tsx b/pages/export/get-curl-command.tsx index f9d520594..6314aba17 100644 --- a/pages/export/get-curl-command.tsx +++ b/pages/export/get-curl-command.tsx @@ -1,6 +1,11 @@ import { JSX } from "react"; import { ExportMethodView } from "@databiosphere/findable-ui/lib/views/ExportMethodView/exportMethodView"; import { GetStaticProps } from "next"; +import { useFileManifestState } from "@databiosphere/findable-ui/lib/hooks/useFileManifestState"; +import { useConfig } from "@databiosphere/findable-ui/lib/hooks/useConfig"; +import NextError from "next/error"; +import { isProductionEnvironment } from "../../app/config/utils"; +import { hasNRESConsentGroup } from "../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders"; export const getStaticProps: GetStaticProps = async () => { return { @@ -15,6 +20,19 @@ export const getStaticProps: GetStaticProps = async () => { * @returns download curl command view component. */ const GetCurlCommandPage = (): JSX.Element => { + const { config } = useConfig(); + const { fileManifestState } = useFileManifestState(); + const isAnVIL = config.appTitle?.includes("AnVIL"); + + // Curl download requires NRES consent group (AnVIL production only) + if ( + isAnVIL && + isProductionEnvironment() && + !hasNRESConsentGroup(fileManifestState) + ) { + return ; + } + return ; };