17152: Adjusts the collection service methods to preserve versions.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 3 Dec 2020 21:58:22 +0000 (18:58 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Sat, 5 Dec 2020 02:58:34 +0000 (23:58 -0300)
As the create() method sets preserve_version to true, it's better
to re-set it to true after each update, so that the modified_at timestamp
of the previous version doesn't change.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

src/services/collection-service/collection-service.ts

index 0aa0aa84de4f476866c60cccb68b5dc2acc9bcb9..3280d05e82f65207c1dd1f9f2dbdcd66ec6ea361 100644 (file)
@@ -27,6 +27,18 @@ export class CollectionService extends TrashableResourceService<CollectionResour
         ]);
     }
 
+    create(data?: Partial<CollectionResource>) {
+        return super.create({ ...data, preserveVersion: true });
+    }
+
+    async update(uuid: string, data: Partial<CollectionResource>) {
+        // First make the changes
+        const collection = await super.update(uuid, data);
+        if (data === { preserveVersion: true }) { return collection; }
+        // Then set the head version to be preserved
+        return await super.update(uuid, { preserveVersion: true });
+    }
+
     async files(uuid: string) {
         const request = await this.webdavClient.propfind(`c=${uuid}`);
         if (request.responseXML != null) {
@@ -36,6 +48,7 @@ export class CollectionService extends TrashableResourceService<CollectionResour
     }
 
     async deleteFiles(collectionUuid: string, filePaths: string[]) {
+        if (collectionUuid === "" || filePaths.length === 0) { return; }
         for (const path of filePaths) {
             const splittedPath = path.split('/');
             if (collectionUuid) {
@@ -44,20 +57,24 @@ export class CollectionService extends TrashableResourceService<CollectionResour
                 await this.webdavClient.delete(`c=${collectionUuid}${path}`);
             }
         }
+        await this.update(collectionUuid, { preserveVersion: true });
     }
 
     async uploadFiles(collectionUuid: string, files: File[], onProgress?: UploadProgress) {
+        if (collectionUuid === "" || files.length === 0) { return; }
         // files have to be uploaded sequentially
         for (let idx = 0; idx < files.length; idx++) {
             await this.uploadFile(collectionUuid, files[idx], idx, onProgress);
         }
+        await this.update(collectionUuid, { preserveVersion: true });
     }
 
-    moveFile(collectionUuid: string, oldPath: string, newPath: string) {
-        return this.webdavClient.move(
+    async moveFile(collectionUuid: string, oldPath: string, newPath: string) {
+        await this.webdavClient.move(
             `c=${collectionUuid}${oldPath}`,
             `c=${collectionUuid}${encodeURI(newPath)}`
         );
+        return await this.update(collectionUuid, { preserveVersion: true });
     }
 
     extendFileURL = (file: CollectionDirectory | CollectionFile) => {