1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 02:03:39 +00:00
Files
browser/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/access/access-tokens.component.ts
Oscar Hinton 4e1867682f [PM-1504] Migrate Dialogs to DialogService (#5013)
This PR introduces a generic `DialogService` which can be used by all the clients. This allows us to decouple dialogs from the `PlatformUtilsHelper`.

The `DialogService` provides a new method, `openSimpleDialog` which is the new interface for that type of dialogs.

This gives us 3 different implementations: 
- Web: DialogService modern dialogs
- Browser: SweetAlert
- Desktop: Native electron based
2023-05-02 18:46:03 +02:00

87 lines
2.7 KiB
TypeScript

import { Component, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { combineLatestWith, Observable, startWith, switchMap } from "rxjs";
import { DialogServiceAbstraction } from "@bitwarden/angular/services/dialog";
import { ModalService } from "@bitwarden/angular/services/modal.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { UserVerificationPromptComponent } from "@bitwarden/web-vault/app/components/user-verification-prompt.component";
import { AccessTokenView } from "../models/view/access-token.view";
import { AccessService } from "./access.service";
import { AccessTokenCreateDialogComponent } from "./dialogs/access-token-create-dialog.component";
@Component({
selector: "sm-access-tokens",
templateUrl: "./access-tokens.component.html",
})
export class AccessTokenComponent implements OnInit {
accessTokens$: Observable<AccessTokenView[]>;
private serviceAccountId: string;
private organizationId: string;
constructor(
private route: ActivatedRoute,
private accessService: AccessService,
private dialogService: DialogServiceAbstraction,
private modalService: ModalService,
private platformUtilsService: PlatformUtilsService
) {}
ngOnInit() {
this.accessTokens$ = this.accessService.accessToken$.pipe(
startWith(null),
combineLatestWith(this.route.params),
switchMap(async ([_, params]) => {
this.organizationId = params.organizationId;
this.serviceAccountId = params.serviceAccountId;
return await this.getAccessTokens();
})
);
}
protected async revoke(tokens: AccessTokenView[]) {
if (!(await this.verifyUser())) {
return;
}
await this.accessService.revokeAccessTokens(
this.serviceAccountId,
tokens.map((t) => t.id)
);
this.platformUtilsService.showToast("success", null, "Access tokens revoked.");
}
protected openNewAccessTokenDialog() {
AccessTokenCreateDialogComponent.openNewAccessTokenDialog(
this.dialogService,
this.serviceAccountId,
this.organizationId
);
}
private verifyUser() {
const ref = this.modalService.open(UserVerificationPromptComponent, {
allowMultipleModals: true,
data: {
confirmDescription: "revokeAccessTokenDesc",
confirmButtonText: "revokeAccessToken",
modalTitle: "revokeAccessToken",
},
});
if (ref == null) {
return;
}
return ref.onClosedPromise();
}
private async getAccessTokens(): Promise<AccessTokenView[]> {
return await this.accessService.getAccessTokens(this.organizationId, this.serviceAccountId);
}
}