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

fix: handle obsolete where filter fields mapping to current schema #1521

Merged
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
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ OIDC_USERQUERY_OPERATOR=<"or"|"and">
OIDC_USERQUERY_FILTER="username:username, email:email"

ELASTICSEARCH_ENABLED=<"yes"|"no">
APP_PORT=3003
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unrelated?

Copy link
Member Author

Choose a reason for hiding this comment

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

This ENV variable is not used anywhere and I felt the change was too small to open a PR.. As it's an unused variable in an example file

STACK_VERSION="8.8.2"
CLUSTER_NAME="es-cluster"
MEM_LIMIT="4G"
Expand Down
32 changes: 29 additions & 3 deletions src/datasets/datasets.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ export class DatasetsController {
DatasetClass,
);

if (!mergedFilters.where) {
mergedFilters.where = {};
}

if (!canViewAny) {
if (!mergedFilters.where) {
mergedFilters.where = {};
}
if (canViewAccess) {
mergedFilters.where["$or"] = [
{ ownerGroup: { $in: user.currentGroups } },
Expand All @@ -196,6 +197,10 @@ export class DatasetsController {
}
}

mergedFilters.where = this.convertObsoleteWhereFilterToCurrentSchema(
mergedFilters.where,
);

return mergedFilters;
}

Expand Down Expand Up @@ -396,6 +401,27 @@ export class DatasetsController {
return dataset;
}

convertObsoleteWhereFilterToCurrentSchema(
whereFilter: Record<string, unknown>,
): IFilters<DatasetDocument, IDatasetFields> {
if ("proposalId" in whereFilter) {
whereFilter.proposalIds = whereFilter.proposalId;
delete whereFilter.proposalId;
}
if ("sampleId" in whereFilter) {
whereFilter.sampleIds = whereFilter.sampleId;
delete whereFilter.sampleId;
}
if ("instrumentId" in whereFilter) {
whereFilter.instrumentIds = whereFilter.instrumentId;
delete whereFilter.instrumentId;
}
if ("principalInvestigator" in whereFilter) {
whereFilter.investigator = whereFilter.principalInvestigator;
delete whereFilter.principalInvestigator;
}
return whereFilter;
}
convertObsoleteToCurrentSchema(
inputObsoleteDataset:
| CreateRawDatasetObsoleteDto
Expand Down
Loading