1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { GroupsService } from "services/groups-service/groups-service";
6 import { UserService } from '../user-service/user-service';
7 import { GroupResource } from 'models/group';
8 import { UserResource } from 'models/user';
9 import { extractUuidObjectType, ResourceObjectType } from "models/resource";
10 import { CollectionService } from "services/collection-service/collection-service";
11 import { CollectionResource } from "models/collection";
13 export class AncestorService {
15 private groupsService: GroupsService,
16 private userService: UserService,
17 private collectionService: CollectionService,
20 async ancestors(startUuid: string, endUuid: string): Promise<Array<UserResource | GroupResource | CollectionResource>> {
21 return this._ancestors(startUuid, endUuid);
24 private async _ancestors(startUuid: string, endUuid: string, previousUuid = ''): Promise<Array<UserResource | GroupResource | CollectionResource>> {
26 if (startUuid === previousUuid) {
30 const service = this.getService(extractUuidObjectType(startUuid));
33 const resource = await service.get(startUuid, false);
34 if (startUuid === endUuid) {
38 ...await this._ancestors(resource.ownerUuid, endUuid, startUuid),
49 private getService = (objectType?: string) => {
51 case ResourceObjectType.GROUP:
52 return this.groupsService;
53 case ResourceObjectType.USER:
54 return this.userService;
55 case ResourceObjectType.COLLECTION:
56 return this.collectionService;