18966: Changes back collectionService.get() to use the GET HTTP method.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Mon, 4 Apr 2022 20:03:05 +0000 (17:03 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Mon, 4 Apr 2022 20:03:05 +0000 (17:03 -0300)
To avoid getting the manifest text, we hardcode the default list of selected
fields instead of using the LIST request. This makes the code detect 404s
correctly.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

src/models/collection.ts
src/services/collection-service/collection-service.test.ts
src/services/collection-service/collection-service.ts
src/services/common-service/common-service.ts

index 3effe6724847485185fb6d15c8043fe90baac69c..9a5d2ee2d86d6e34ef71c77af3fab222b3538d9c 100644 (file)
@@ -28,6 +28,40 @@ export interface CollectionResource extends TrashableResource, ResourceWithPrope
     fileSizeTotal: number;
 }
 
     fileSizeTotal: number;
 }
 
+// We exclude 'manifestText' and 'unsignedManifestText' from the default
+export const defaultCollectionSelectedFields = [
+    'name',
+    'description',
+    'portableDataHash',
+    'replicationDesired',
+    'replicationConfirmed',
+    'replicationConfirmedAt',
+    'storageClassesDesired',
+    'storageClassesConfirmed',
+    'storageClassesConfirmedAt',
+    'currentVersionUuid',
+    'version',
+    'preserveVersion',
+    'fileCount',
+    'fileSizeTotal',
+    // ResourceWithProperties field
+    'properties',
+    // TrashableResource fields
+    'trashAt',
+    'deleteAt',
+    'isTrashed',
+    // Resource fields
+    'uuid',
+    'ownerUuid',
+    'createdAt',
+    'modifiedByClientUuid',
+    'modifiedByUserUuid',
+    'modifiedAt',
+    'href',
+    'kind',
+    'etag',
+];
+
 export const getCollectionUrl = (uuid: string) => {
     return `/collections/${uuid}`;
 };
 export const getCollectionUrl = (uuid: string) => {
     return `/collections/${uuid}`;
 };
index b759fd1a46d9cb622e9567196887667d71e6a9ab..610683694f626c7bd9157fabec99240f9f922835 100644 (file)
@@ -4,7 +4,8 @@
 
 import axios, { AxiosInstance } from 'axios';
 import MockAdapter from 'axios-mock-adapter';
 
 import axios, { AxiosInstance } from 'axios';
 import MockAdapter from 'axios-mock-adapter';
-import { CollectionResource } from 'models/collection';
+import { snakeCase } from 'lodash';
+import { CollectionResource, defaultCollectionSelectedFields } from 'models/collection';
 import { AuthService } from '../auth-service/auth-service';
 import { CollectionService } from './collection-service';
 
 import { AuthService } from '../auth-service/auth-service';
 import { CollectionService } from './collection-service';
 
@@ -31,17 +32,16 @@ describe('collection-service', () => {
     });
 
     describe('get', () => {
     });
 
     describe('get', () => {
-        it('should make a list request with uuid filtering', async () => {
+        it('should make a request with default selected fields', async () => {
             serverApi.get = jest.fn(() => Promise.resolve(
                 { data: { items: [{}] } }
             ));
             const uuid = 'zzzzz-4zz18-0123456789abcde'
             await collectionService.get(uuid);
             expect(serverApi.get).toHaveBeenCalledWith(
             serverApi.get = jest.fn(() => Promise.resolve(
                 { data: { items: [{}] } }
             ));
             const uuid = 'zzzzz-4zz18-0123456789abcde'
             await collectionService.get(uuid);
             expect(serverApi.get).toHaveBeenCalledWith(
-                '/collections', {
+                `/collections/${uuid}`, {
                     params: {
                     params: {
-                        filters: `[["uuid","=","zzzzz-4zz18-0123456789abcde"]]`,
-                        include_old_versions: true,
+                        select: JSON.stringify(defaultCollectionSelectedFields.map(snakeCase)),
                     },
                 }
             );
                     },
                 }
             );
@@ -54,10 +54,8 @@ describe('collection-service', () => {
             const uuid = 'zzzzz-4zz18-0123456789abcde'
             await collectionService.get(uuid, undefined, ['manifestText']);
             expect(serverApi.get).toHaveBeenCalledWith(
             const uuid = 'zzzzz-4zz18-0123456789abcde'
             await collectionService.get(uuid, undefined, ['manifestText']);
             expect(serverApi.get).toHaveBeenCalledWith(
-                '/collections', {
+                `/collections/${uuid}`, {
                     params: {
                     params: {
-                        filters: `[["uuid","=","zzzzz-4zz18-0123456789abcde"]]`,
-                        include_old_versions: true,
                         select: `["manifest_text"]`
                     },
                 }
                         select: `["manifest_text"]`
                     },
                 }
index 0bddc82b56f41d090ce74f8d4626bf1849c9a404..857828c255ed2d5df521a39b078cb5ae973bc129 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { CollectionResource } from "models/collection";
+import { CollectionResource, defaultCollectionSelectedFields } from "models/collection";
 import { AxiosInstance } from "axios";
 import { CollectionFile, CollectionDirectory } from "models/collection-file";
 import { WebDAV } from "common/webdav";
 import { AxiosInstance } from "axios";
 import { CollectionFile, CollectionDirectory } from "models/collection-file";
 import { WebDAV } from "common/webdav";
@@ -11,8 +11,6 @@ import { extractFilesData } from "./collection-service-files-response";
 import { TrashableResourceService } from "services/common-service/trashable-resource-service";
 import { ApiActions } from "services/api/api-actions";
 import { customEncodeURI } from "common/url";
 import { TrashableResourceService } from "services/common-service/trashable-resource-service";
 import { ApiActions } from "services/api/api-actions";
 import { customEncodeURI } from "common/url";
-import { FilterBuilder } from "services/api/filter-builder";
-import { ListArguments } from "services/common-service/common-service";
 import { Session } from "models/session";
 
 export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void;
 import { Session } from "models/session";
 
 export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void;
@@ -33,19 +31,8 @@ export class CollectionService extends TrashableResourceService<CollectionResour
 
     async get(uuid: string, showErrors?: boolean, select?: string[], session?: Session) {
         super.validateUuid(uuid);
 
     async get(uuid: string, showErrors?: boolean, select?: string[], session?: Session) {
         super.validateUuid(uuid);
-        // We use a filtered list request to avoid getting the manifest text
-        const filters = new FilterBuilder().addEqual('uuid', uuid).getFilters();
-        const listArgs: ListArguments = {filters, includeOldVersions: true};
-        if (select) {
-            listArgs.select = select;
-        }
-
-        if (!session) {
-            const lst = await super.list(listArgs, showErrors);
-            return lst.items[0];
-        } else {
-            return super.get(uuid, showErrors, select, session);
-        }
+        const selectParam = select || defaultCollectionSelectedFields;
+        return super.get(uuid, showErrors, selectParam, session);
     }
 
     create(data?: Partial<CollectionResource>) {
     }
 
     create(data?: Partial<CollectionResource>) {
index ddaf2ab02fa5ee4e18d544158e42f7606339983c..f16a2024ad2c3a1775d4a5fb7e83f784e08554e4 100644 (file)
@@ -117,7 +117,13 @@ export class CommonService<T> {
     get(uuid: string, showErrors?: boolean, select?: string[], session?: Session) {
         this.validateUuid(uuid);
 
     get(uuid: string, showErrors?: boolean, select?: string[], session?: Session) {
         this.validateUuid(uuid);
 
-        const cfg: AxiosRequestConfig = {};
+        const cfg: AxiosRequestConfig = {
+            params: {
+                select: select
+                    ? `[${select.map(snakeCase).map(s => `"${s}"`).join(',')}]`
+                    : undefined
+            }
+        };
         if (session) {
             cfg.baseURL = session.baseUrl;
             cfg.headers = { 'Authorization': 'Bearer ' + session.token };
         if (session) {
             cfg.baseURL = session.baseUrl;
             cfg.headers = { 'Authorization': 'Bearer ' + session.token };
@@ -125,7 +131,7 @@ export class CommonService<T> {
 
         return CommonService.defaultResponse(
             this.serverApi
 
         return CommonService.defaultResponse(
             this.serverApi
-                .get<T>(`/${this.resourceType}/${uuid}`, session ? cfg : undefined),
+                .get<T>(`/${this.resourceType}/${uuid}`, cfg),
             this.actions,
             true, // mapKeys
             showErrors
             this.actions,
             true, // mapKeys
             showErrors