-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove use of eda_study_id and url-based cache for permissions (#302)
* Remove use of eda_study_id and url-based cache for permissions * Request data in parallel, when possible * Add a non-hook way to get WDK datasets for use in EDA * Use AllDatasets to populate map, for now
- Loading branch information
Showing
13 changed files
with
261 additions
and
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// utils for getting study records | ||
|
||
import { cachedPermissionCheck } from '@veupathdb/study-data-access/lib/data-restriction/permissionsHooks'; | ||
import { getStudyId } from '@veupathdb/study-data-access/lib/shared/studies'; | ||
import { StudyAccessApi } from '@veupathdb/study-data-access/lib/study-access/api'; | ||
import { WdkService } from '@veupathdb/wdk-client/lib/Core'; | ||
import { AnswerJsonFormatConfig } from '@veupathdb/wdk-client/lib/Utils/WdkModel'; | ||
import { SubsettingClient } from '../api'; | ||
import { StudyRecord } from '../types/study'; | ||
|
||
interface WdkStudyRecordsDeps { | ||
wdkService: WdkService; | ||
subsettingClient: SubsettingClient; | ||
studyAccessApi: StudyAccessApi; | ||
} | ||
|
||
interface WdkStudyRecordsOptions { | ||
attributes?: AnswerJsonFormatConfig['attributes']; | ||
tables?: AnswerJsonFormatConfig['tables']; | ||
searchName?: string; | ||
} | ||
|
||
const DEFAULT_STUDY_ATTRIBUTES = ['dataset_id']; | ||
const DEFAULT_STUDY_TABLES: string[] = []; | ||
const EMPTY_ARRAY: string[] = []; | ||
|
||
export async function getWdkStudyRecords( | ||
deps: WdkStudyRecordsDeps, | ||
options?: WdkStudyRecordsOptions | ||
): Promise<StudyRecord[]> { | ||
const { wdkService, subsettingClient, studyAccessApi } = deps; | ||
const attributes = options?.attributes ?? EMPTY_ARRAY; | ||
const tables = options?.tables ?? EMPTY_ARRAY; | ||
const searchName = options?.searchName ?? 'Studies'; | ||
|
||
const [permissions, recordClass] = await Promise.all([ | ||
cachedPermissionCheck(await wdkService.getCurrentUser(), studyAccessApi), | ||
wdkService.findRecordClass('dataset'), | ||
]); | ||
const finalAttributes = DEFAULT_STUDY_ATTRIBUTES.concat(attributes).filter( | ||
(attribute) => attribute in recordClass.attributesMap | ||
); | ||
const finalTables = DEFAULT_STUDY_TABLES.concat(tables).filter( | ||
(table) => table in recordClass.tablesMap | ||
); | ||
const [edaStudies, answer] = await Promise.all([ | ||
subsettingClient.getStudies(), | ||
wdkService.getAnswerJson( | ||
{ | ||
searchName, | ||
searchConfig: { | ||
parameters: {}, | ||
}, | ||
}, | ||
{ | ||
attributes: finalAttributes, | ||
tables: finalTables, | ||
sorting: [ | ||
{ | ||
attributeName: 'display_name', | ||
direction: 'ASC', | ||
}, | ||
], | ||
} | ||
), | ||
]); | ||
const studyIds = new Set(edaStudies.map((s) => s.id)); | ||
return answer.records.filter((record) => { | ||
const datasetId = getStudyId(record); | ||
if (datasetId == null) { | ||
return false; | ||
} | ||
const studyId = permissions.perDataset[datasetId]?.studyId; | ||
return studyId && studyIds.has(studyId); | ||
}); | ||
} |
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
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
Oops, something went wrong.