Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions app/apis/azul/anvil-cmg/common/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand All @@ -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 (
<Stack gap={1}>
<Typography
Expand Down
10 changes: 10 additions & 0 deletions app/config/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { SelectCategoryValue } from "@databiosphere/findable-ui/lib/common/entities";

/**
* Returns true if the current environment is production.
* Determined by checking if NEXT_PUBLIC_SITE_CONFIG ends with "-prod".
* @returns true if production environment.
*/
export function isProductionEnvironment(): boolean {
const config = process.env.NEXT_PUBLIC_SITE_CONFIG ?? "";
return config.endsWith("-prod");
}

/**
* Returns select category value with formatted label.
* @param formatLabel - Function to format label.
Expand Down
33 changes: 20 additions & 13 deletions app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
getBioSampleId,
getBioSampleType,
getConsentGroup,
isNRESOrUnrestrictedAccess,
getDatasetDetails,
getDatasetEntryId,
getDocumentId,
Expand Down Expand Up @@ -109,6 +110,7 @@ import { METADATA_KEY } from "../../../../components/Index/common/entities";
import { getPluralizedMetadataLabel } from "../../../../components/Index/common/indexTransformer";
import { SUMMARY_DISPLAY_TEXT } from "./summaryMapper/constants";
import { mapExportSummary } from "./summaryMapper/summaryMapper";
import { isProductionEnvironment } from "../../../../config/utils";

/**
* Build props for activity type BasicCell component from the given activities response.
Expand Down Expand Up @@ -1790,25 +1792,23 @@ function isFileManifestSummaryFileCountValid(
}

/**
* Returns true if the dataset has NRES or Unrestricted access consent group.
* @param viewContext - View context.
* @returns true if the dataset has NRES or Unrestricted access consent group.
* Returns true if the file manifest state includes NRES or Unrestricted access consent group.
* @param fileManifestState - File manifest state.
* @returns true if NRES or Unrestricted access consent group is present.
*/
export function isNRESConsentGroup(
viewContext: ViewContext<DatasetsResponse>
export function hasNRESConsentGroup(
fileManifestState: FileManifestState
): boolean {
const { fileManifestState } = viewContext;

const facet = findFacet(
fileManifestState.filesFacets,
ANVIL_CMG_CATEGORY_KEY.DATASET_CONSENT_GROUP
);

if (!facet) return false;

const termsByName = facet.termsByName;
const consentGroups = [...facet.termsByName.keys()];

return termsByName.has("NRES") || termsByName.has("Unrestricted access");
return isNRESOrUnrestrictedAccess(consentGroups);
}

/**
Expand Down Expand Up @@ -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.
Expand All @@ -1891,19 +1892,25 @@ export const renderCohortCurlDownload = (
_: unknown,
viewContext: ViewContext<DatasetsResponse>
): ComponentProps<typeof C.ConditionalComponent> => {
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.
*/
export const renderDatasetCurlDownload = (
datasetsResponse: DatasetsResponse
): React.ComponentProps<typeof C.ConditionalComponent> => {
return {
isIn: isDatasetNRESConsentGroup(datasetsResponse),
isIn:
!isProductionEnvironment() || isDatasetNRESConsentGroup(datasetsResponse),
};
};

Expand Down
21 changes: 15 additions & 6 deletions pages/[entityListType]/[...params].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();

Expand Down Expand Up @@ -66,8 +70,13 @@ const EntityDetailPage = (props: EntityDetailPageProps): JSX.Element => {
const { query } = useRouter();
if (!props.entityListType) return <></>;
if (props.override) return <EntityGuard override={props.override} />;
// 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 <NextError statusCode={404} />;
}
if (isChooseExportView(query)) return <EntityExportView {...props} />;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions pages/export/get-curl-command.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 <NextError statusCode={404} />;
}

return <ExportMethodView />;
};

Expand Down
Loading