X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/0a97d1cc5eedb11445af4b675c57b8cbdb4f1af3..bdf65674185522fd6202840513574d8e216e6fc5:/src/services/groups-service/groups-service.ts diff --git a/src/services/groups-service/groups-service.ts b/src/services/groups-service/groups-service.ts index 65ae705e..cdbe8bab 100644 --- a/src/services/groups-service/groups-service.ts +++ b/src/services/groups-service/groups-service.ts @@ -2,14 +2,22 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as _ from "lodash"; -import { CommonResourceService, ListResults, ListArguments } from '~/services/common-service/common-resource-service'; -import { AxiosInstance } from "axios"; -import { CollectionResource } from "~/models/collection"; -import { ProjectResource } from "~/models/project"; -import { ProcessResource } from "~/models/process"; -import { TrashableResource } from "~/models/resource"; -import { TrashableResourceService } from "~/services/common-service/trashable-resource-service"; +import { CancelToken } from 'axios'; +import { snakeCase, camelCase } from "lodash"; +import { CommonResourceService } from 'services/common-service/common-resource-service'; +import { + ListResults, + ListArguments, +} from 'services/common-service/common-service'; +import { AxiosInstance, AxiosRequestConfig } from 'axios'; +import { CollectionResource } from 'models/collection'; +import { ProjectResource } from 'models/project'; +import { ProcessResource } from 'models/process'; +import { WorkflowResource } from 'models/workflow'; +import { TrashableResourceService } from 'services/common-service/trashable-resource-service'; +import { ApiActions } from 'services/api/api-actions'; +import { GroupResource } from 'models/group'; +import { Session } from 'models/session'; export interface ContentsArguments { limit?: number; @@ -18,6 +26,8 @@ export interface ContentsArguments { filters?: string; recursive?: boolean; includeTrash?: boolean; + excludeHomeProject?: boolean; + select?: string[]; } export interface SharedArguments extends ListArguments { @@ -25,39 +35,70 @@ export interface SharedArguments extends ListArguments { } export type GroupContentsResource = - CollectionResource | - ProjectResource | - ProcessResource; + | CollectionResource + | ProjectResource + | ProcessResource + | WorkflowResource; -export class GroupsService extends TrashableResourceService { - - constructor(serverApi: AxiosInstance) { - super(serverApi, "groups"); +export class GroupsService< + T extends GroupResource = GroupResource + > extends TrashableResourceService { + constructor(serverApi: AxiosInstance, actions: ApiActions) { + super(serverApi, 'groups', actions); } - contents(uuid: string, args: ContentsArguments = {}): Promise> { - const { filters, order, ...other } = args; + async contents(uuid: string, args: ContentsArguments = {}, session?: Session, cancelToken?: CancelToken): Promise> { + const { filters, order, select, ...other } = args; const params = { ...other, filters: filters ? `[${filters}]` : undefined, - order: order ? order : undefined + order: order ? order : undefined, + select: select + ? JSON.stringify(select.map(sel => { + const sp = sel.split("."); + return sp.length == 2 ? (sp[0] + "." + snakeCase(sp[1])) : snakeCase(sel); + })) + : undefined + }; + const pathUrl = uuid ? `/${uuid}/contents` : '/contents'; + const cfg: AxiosRequestConfig = { + params: CommonResourceService.mapKeys(snakeCase)(params), + }; + + if (session) { + cfg.baseURL = session.baseUrl; + cfg.headers = { Authorization: 'Bearer ' + session.token }; + } + + if (cancelToken) { + cfg.cancelToken = cancelToken; + } + + const response = await CommonResourceService.defaultResponse( + this.serverApi.get(this.resourceType + pathUrl, cfg), + this.actions, + false + ); + + return { + ...TrashableResourceService.mapKeys(camelCase)(response), + clusterId: session && session.clusterId, }; - return this.serverApi - .get(this.resourceType + `${uuid}/contents`, { - params: CommonResourceService.mapKeys(_.snakeCase)(params) - }) - .then(CommonResourceService.mapResponseKeys); } - shared(params: SharedArguments = {}): Promise> { - return this.serverApi - .get(this.resourceType + 'shared', { params }) - .then(CommonResourceService.mapResponseKeys); + shared( + params: SharedArguments = {} + ): Promise> { + return CommonResourceService.defaultResponse( + this.serverApi.get(this.resourceType + '/shared', { params }), + this.actions + ); } } export enum GroupContentsResourcePrefix { - COLLECTION = "collections", - PROJECT = "groups", - PROCESS = "container_requests" + COLLECTION = 'collections', + PROJECT = 'groups', + PROCESS = 'container_requests', + WORKFLOW = 'workflows', }