Merge branch 'master' into 16941-inactive-remotes
[arvados.git] / src / services / ancestors-service / ancestors-service.ts
index 1cd42fb523945c3a6a5918b24b0474780dabe908..8f5b9032bd1c6c5d5e390909e79b7c2b14ace3f5 100644 (file)
@@ -14,21 +14,33 @@ export class AncestorService {
         private userService: UserService
     ) { }
 
-    async ancestors(uuid: string, rootUuid: string): Promise<Array<UserResource | GroupResource>> {
-        const service = this.getService(extractUuidObjectType(uuid));
+    async ancestors(startUuid: string, endUuid: string): Promise<Array<UserResource | GroupResource>> {
+        return this._ancestors(startUuid, endUuid);
+    }
+
+    private async _ancestors(startUuid: string, endUuid: string, previousUuid = ''): Promise<Array<UserResource | GroupResource>> {
+
+        if (startUuid === previousUuid) {
+            return [];
+        }
+
+        const service = this.getService(extractUuidObjectType(startUuid));
         if (service) {
-            const resource = await service.get(uuid);
-            if (uuid === rootUuid) {
-                return [resource];
-            } else {
-                return [
-                    ...await this.ancestors(resource.ownerUuid, rootUuid),
-                    resource
-                ];
+            try {
+                const resource = await service.get(startUuid, false);
+                if (startUuid === endUuid) {
+                    return [resource];
+                } else {
+                    return [
+                        ...await this._ancestors(resource.ownerUuid, endUuid, startUuid),
+                        resource
+                    ];
+                }
+            } catch (e) {
+                return [];
             }
-        } else {
-            return [];
         }
+        return [];
     }
 
     private getService = (objectType?: string) => {
@@ -41,4 +53,4 @@ export class AncestorService {
                 return undefined;
         }
     }
-}
\ No newline at end of file
+}