mirror of
https://github.com/bitwarden/browser
synced 2026-02-28 10:33:31 +00:00
fix(browser-approval): [PM-23620] Auth Request Answering Service - Work in progress.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { SystemNotificationEvent } from "@bitwarden/common/platform/notifications/system-notifications-service";
|
||||
import { UserId } from "@bitwarden/user-core";
|
||||
|
||||
export abstract class AuthRequestAnsweringServiceAbstraction {
|
||||
abstract receivedPendingAuthRequest(userId: UserId, notificationId: string): Promise<void>;
|
||||
|
||||
abstract handleAuthRequestNotificationClicked(event: SystemNotificationEvent): Promise<void>;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { filter, mergeMap } from "rxjs";
|
||||
|
||||
import { ActionsService } from "@bitwarden/common/platform/actions";
|
||||
import {
|
||||
ButtonActions,
|
||||
ButtonLocation,
|
||||
SystemNotificationEvent,
|
||||
SystemNotificationsService,
|
||||
} from "@bitwarden/common/platform/notifications/system-notifications-service";
|
||||
import { UserId } from "@bitwarden/user-core";
|
||||
|
||||
import { AuthRequestAnsweringServiceAbstraction } from "../../abstractions/auth-request-answering/auth-request-answering.service.abstraction";
|
||||
|
||||
export class AuthRequestAnsweringService implements AuthRequestAnsweringServiceAbstraction {
|
||||
constructor(
|
||||
private readonly systemNotificationsService: SystemNotificationsService,
|
||||
private readonly actionService: ActionsService,
|
||||
) {
|
||||
this.systemNotificationsService.notificationClicked$
|
||||
.pipe(
|
||||
filter(
|
||||
(event: SystemNotificationEvent) => event.type === ButtonActions.AuthRequestNotification,
|
||||
),
|
||||
mergeMap((event: SystemNotificationEvent) =>
|
||||
this.handleAuthRequestNotificationClicked(event),
|
||||
),
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
async handleAuthRequestNotificationClicked(event: SystemNotificationEvent): Promise<void> {
|
||||
if (event.buttonIdentifier === ButtonLocation.NotificationButton) {
|
||||
// TODO: Uncomment this before going into review
|
||||
// await this.systemNotificationService.clear({
|
||||
// id: event.id,
|
||||
// })
|
||||
await this.actionService.openPopup();
|
||||
}
|
||||
}
|
||||
|
||||
async receivedPendingAuthRequest(userId: UserId, notificationId: string): Promise<void> {
|
||||
await this.systemNotificationsService.create({
|
||||
id: notificationId,
|
||||
type: ButtonActions.AuthRequestNotification,
|
||||
title: "Test (i18n)",
|
||||
body: "Pending Auth Request to Approve (i18n)",
|
||||
buttons: [],
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { SystemNotificationEvent } from "@bitwarden/common/platform/notifications/system-notifications-service";
|
||||
import { UserId } from "@bitwarden/user-core";
|
||||
|
||||
import { AuthRequestAnsweringServiceAbstraction } from "../../abstractions/auth-request-answering/auth-request-answering.service.abstraction";
|
||||
|
||||
export class UnsupportedAuthRequestAnsweringService
|
||||
implements AuthRequestAnsweringServiceAbstraction
|
||||
{
|
||||
constructor() {}
|
||||
async handleAuthRequestNotificationClicked(event: SystemNotificationEvent): Promise<void> {
|
||||
throw new Error("Received pending auth request not supported.");
|
||||
}
|
||||
|
||||
async receivedPendingAuthRequest(userId: UserId, notificationId: string): Promise<void> {
|
||||
throw new Error("Received pending auth request not supported.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user