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);
31 if (startUuid === endUuid) {
35 ...await this._ancestors(resource.ownerUuid, endUuid, startUuid),
47 private getService = (objectType?: string) => {
49 case ResourceObjectType.GROUP:
50 return this.groupsService;
51 case ResourceObjectType.USER:
52 return this.userService;