Merge branch '18559-user-profile' into main. Closes #18559
[arvados-workbench2.git] / src / services / common-service / common-service.ts
index b5dd1a08b2d726d3c294c7f6077e38f1443ffe86..ddaf2ab02fa5ee4e18d544158e42f7606339983c 100644 (file)
@@ -3,10 +3,11 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { camelCase, isPlainObject, isArray, snakeCase } from "lodash";
-import { AxiosInstance, AxiosPromise } from "axios";
+import { AxiosInstance, AxiosPromise, AxiosRequestConfig } from "axios";
 import uuid from "uuid/v4";
 import { ApiActions } from "services/api/api-actions";
 import QueryString from "query-string";
+import { Session } from "models/session";
 
 interface Errors {
     status: number;
@@ -113,11 +114,18 @@ export class CommonService<T> {
         );
     }
 
-    get(uuid: string, showErrors?: boolean) {
+    get(uuid: string, showErrors?: boolean, select?: string[], session?: Session) {
         this.validateUuid(uuid);
+
+        const cfg: AxiosRequestConfig = {};
+        if (session) {
+            cfg.baseURL = session.baseUrl;
+            cfg.headers = { 'Authorization': 'Bearer ' + session.token };
+        }
+
         return CommonService.defaultResponse(
             this.serverApi
-                .get<T>(`/${this.resourceType}/${uuid}`),
+                .get<T>(`/${this.resourceType}/${uuid}`, session ? cfg : undefined),
             this.actions,
             true, // mapKeys
             showErrors
@@ -125,11 +133,13 @@ export class CommonService<T> {
     }
 
     list(args: ListArguments = {}, showErrors?: boolean): Promise<ListResults<T>> {
-        const { filters, order, ...other } = args;
+        const { filters, select, ...other } = args;
         const params = {
             ...CommonService.mapKeys(snakeCase)(other),
             filters: filters ? `[${filters}]` : undefined,
-            order: order ? order : undefined
+            select: select
+                ? `[${select.map(snakeCase).map(s => `"${s}"`).join(', ')}]`
+                : undefined
         };
 
         if (QueryString.stringify(params).length <= 1500) {