mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 02:03:39 +00:00
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
87 lines
2.7 KiB
TypeScript
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);
|
|
}
|
|
}
|