-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
service-accounts.component.ts
93 lines (81 loc) · 2.87 KB
/
service-accounts.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { combineLatest, Observable, startWith, switchMap } from "rxjs";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { DialogService } from "@bitwarden/components";
import {
ServiceAccountSecretsDetailsView,
ServiceAccountView,
} from "../models/view/service-account.view";
import {
ServiceAccountDeleteDialogComponent,
ServiceAccountDeleteOperation,
} from "./dialog/service-account-delete-dialog.component";
import {
OperationType,
ServiceAccountDialogComponent,
ServiceAccountOperation,
} from "./dialog/service-account-dialog.component";
import { ServiceAccountService } from "./service-account.service";
@Component({
selector: "sm-service-accounts",
templateUrl: "./service-accounts.component.html",
})
export class ServiceAccountsComponent implements OnInit {
protected serviceAccounts$: Observable<ServiceAccountSecretsDetailsView[]>;
protected search: string;
private organizationId: string;
private organizationEnabled: boolean;
constructor(
private route: ActivatedRoute,
private dialogService: DialogService,
private serviceAccountService: ServiceAccountService,
private organizationService: OrganizationService,
) {}
ngOnInit() {
this.serviceAccounts$ = combineLatest([
this.route.params,
this.serviceAccountService.serviceAccount$.pipe(startWith(null)),
]).pipe(
switchMap(async ([params]) => {
this.organizationId = params.organizationId;
this.organizationEnabled = (
await this.organizationService.get(params.organizationId)
)?.enabled;
return await this.getServiceAccounts();
}),
);
}
openNewServiceAccountDialog() {
this.dialogService.open<unknown, ServiceAccountOperation>(ServiceAccountDialogComponent, {
data: {
organizationId: this.organizationId,
operation: OperationType.Add,
organizationEnabled: this.organizationEnabled,
},
});
}
openEditServiceAccountDialog(serviceAccountId: string) {
this.dialogService.open<unknown, ServiceAccountOperation>(ServiceAccountDialogComponent, {
data: {
organizationId: this.organizationId,
serviceAccountId: serviceAccountId,
operation: OperationType.Edit,
organizationEnabled: this.organizationEnabled,
},
});
}
openDeleteDialog(event: ServiceAccountView[]) {
this.dialogService.open<unknown, ServiceAccountDeleteOperation>(
ServiceAccountDeleteDialogComponent,
{
data: {
serviceAccounts: event,
},
},
);
}
private async getServiceAccounts(): Promise<ServiceAccountSecretsDetailsView[]> {
return await this.serviceAccountService.getServiceAccounts(this.organizationId, true);
}
}