1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { CancelToken } from 'axios';
6 import { snakeCase, camelCase } from "lodash";
7 import { CommonResourceService } from 'services/common-service/common-resource-service';
11 } from 'services/common-service/common-service';
12 import { AxiosInstance, AxiosRequestConfig } from 'axios';
13 import { CollectionResource } from 'models/collection';
14 import { ProjectResource } from 'models/project';
15 import { ProcessResource } from 'models/process';
16 import { WorkflowResource } from 'models/workflow';
17 import { TrashableResourceService } from 'services/common-service/trashable-resource-service';
18 import { ApiActions } from 'services/api/api-actions';
19 import { GroupResource } from 'models/group';
20 import { Session } from 'models/session';
22 export interface ContentsArguments {
28 includeTrash?: boolean;
29 excludeHomeProject?: boolean;
33 export interface SharedArguments extends ListArguments {
37 export type GroupContentsResource =
43 export class GroupsService<
44 T extends GroupResource = GroupResource
45 > extends TrashableResourceService<T> {
46 constructor(serverApi: AxiosInstance, actions: ApiActions) {
47 super(serverApi, 'groups', actions);
50 async contents(uuid: string, args: ContentsArguments = {}, session?: Session, cancelToken?: CancelToken): Promise<ListResults<GroupContentsResource>> {
51 const { filters, order, select, ...other } = args;
54 filters: filters ? `[${filters}]` : undefined,
55 order: order ? order : undefined,
57 ? JSON.stringify(select.map(sel => {
58 const sp = sel.split(".");
59 return sp.length === 2 ? (sp[0] + "." + snakeCase(sp[1])) : snakeCase(sel);
63 const pathUrl = (uuid !== '') ? `/${uuid}/contents` : '/contents';
64 const cfg: AxiosRequestConfig = {
65 params: CommonResourceService.mapKeys(snakeCase)(params),
69 cfg.baseURL = session.baseUrl;
70 cfg.headers = { Authorization: 'Bearer ' + session.token };
74 cfg.cancelToken = cancelToken;
77 const response = await CommonResourceService.defaultResponse(
78 this.serverApi.get(this.resourceType + pathUrl, cfg),
84 ...TrashableResourceService.mapKeys(camelCase)(response),
85 clusterId: session && session.clusterId,
90 params: SharedArguments = {}
91 ): Promise<ListResults<GroupContentsResource>> {
92 return CommonResourceService.defaultResponse(
93 this.serverApi.get(this.resourceType + '/shared', { params }),
99 export enum GroupContentsResourcePrefix {
100 COLLECTION = 'collections',
102 PROCESS = 'container_requests',
103 WORKFLOW = 'workflows',