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";
11 export class AncestorService {
13 private groupsService: GroupsService,
14 private userService: UserService
17 async ancestors(startUuid: string, endUuid: string): Promise<Array<UserResource | GroupResource>> {
18 return this._ancestors(startUuid, endUuid);
21 private async _ancestors(startUuid: string, endUuid: string, previousUuid = ''): Promise<Array<UserResource | GroupResource>> {
23 if (startUuid === previousUuid) {
27 const service = this.getService(extractUuidObjectType(startUuid));
30 const resource = await service.get(startUuid, false);
31 if (startUuid === endUuid) {
35 ...await this._ancestors(resource.ownerUuid, endUuid, startUuid),
46 private getService = (objectType?: string) => {
48 case ResourceObjectType.GROUP:
49 return this.groupsService;
50 case ResourceObjectType.USER:
51 return this.userService;