updated routing for new device verification notice to show before vault based on flags, and can navigate back to vault after submission
This commit is contained in:
parent
11396b0cd9
commit
954cfe9579
|
@ -5,6 +5,7 @@ import { unauthUiRefreshSwap } from "@bitwarden/angular/auth/functions/unauth-ui
|
|||
import {
|
||||
authGuard,
|
||||
lockGuard,
|
||||
NewDeviceVerificationNoticeGuard,
|
||||
redirectGuard,
|
||||
tdeDecryptionRequiredGuard,
|
||||
unauthGuardFn,
|
||||
|
@ -646,7 +647,7 @@ const routes: Routes = [
|
|||
],
|
||||
},
|
||||
{
|
||||
path: "blah",
|
||||
path: "new-device-notice",
|
||||
component: AnonLayoutWrapperComponent,
|
||||
canActivate: [],
|
||||
children: [
|
||||
|
@ -675,7 +676,7 @@ const routes: Routes = [
|
|||
{
|
||||
path: "",
|
||||
component: UserLayoutComponent,
|
||||
canActivate: [deepLinkGuard(), authGuard],
|
||||
canActivate: [deepLinkGuard(), authGuard, NewDeviceVerificationNoticeGuard],
|
||||
children: [
|
||||
{
|
||||
path: "vault",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
export * from "./auth.guard";
|
||||
export * from "./lock.guard";
|
||||
export * from "./new-device-verification-notice.guard";
|
||||
export * from "./redirect.guard";
|
||||
export * from "./tde-decryption-required.guard";
|
||||
export * from "./unauth.guard";
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
import { inject } from "@angular/core";
|
||||
import { CanActivateFn, Router } from "@angular/router";
|
||||
import { firstValueFrom, map } from "rxjs";
|
||||
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
|
||||
import { NewDeviceVerificationNoticeService } from "../../../../vault/src/services/new-device-verification-notice.service";
|
||||
|
||||
export const NewDeviceVerificationNoticeGuard: CanActivateFn = async (override?) => {
|
||||
const router = inject(Router);
|
||||
const configService = inject(ConfigService);
|
||||
const newDeviceVerificationNoticeService = inject(NewDeviceVerificationNoticeService);
|
||||
const accountService = inject(AccountService);
|
||||
|
||||
const tempNoticeFlag = await configService.getFeatureFlag(
|
||||
FeatureFlag.NewDeviceVerificationTemporaryDismiss,
|
||||
);
|
||||
const permNoticeFlag = await configService.getFeatureFlag(
|
||||
FeatureFlag.NewDeviceVerificationPermanentDismiss,
|
||||
);
|
||||
|
||||
const currentAcctId = await firstValueFrom(
|
||||
accountService.activeAccount$.pipe(map((acct) => acct.id)),
|
||||
);
|
||||
const userItems$ = newDeviceVerificationNoticeService.noticeState$(currentAcctId);
|
||||
const userItems = await firstValueFrom(userItems$);
|
||||
|
||||
if (
|
||||
userItems?.last_dismissal == null &&
|
||||
userItems?.permanent_dismissal == null &&
|
||||
(tempNoticeFlag || permNoticeFlag)
|
||||
) {
|
||||
return router.createUrlTree(["/new-device-notice"]);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
|
@ -290,6 +290,7 @@ import {
|
|||
IndividualVaultExportServiceAbstraction,
|
||||
} from "@bitwarden/vault-export-core";
|
||||
|
||||
import { NewDeviceVerificationNoticeService } from "../../../vault/src/services/new-device-verification-notice.service";
|
||||
import { FormValidationErrorsService as FormValidationErrorsServiceAbstraction } from "../platform/abstractions/form-validation-errors.service";
|
||||
import { ViewCacheService } from "../platform/abstractions/view-cache.service";
|
||||
import { FormValidationErrorsService } from "../platform/services/form-validation-errors.service";
|
||||
|
@ -1393,6 +1394,7 @@ const safeProviders: SafeProvider[] = [
|
|||
useClass: DefaultLoginDecryptionOptionsService,
|
||||
deps: [MessagingServiceAbstraction],
|
||||
}),
|
||||
safeProvider(NewDeviceVerificationNoticeService),
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
|
|
@ -7,6 +7,7 @@ import { firstValueFrom, map } from "rxjs";
|
|||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import {
|
||||
AsyncActionsModule,
|
||||
ButtonModule,
|
||||
|
@ -15,6 +16,8 @@ import {
|
|||
TypographyModule,
|
||||
} from "@bitwarden/components";
|
||||
|
||||
import { NewDeviceVerificationNoticeService } from "./../../services/new-device-verification-notice.service";
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
selector: "app-new-device-verification-notice-page-one",
|
||||
|
@ -35,28 +38,40 @@ export class NewDeviceVerificationNoticePageOneComponent implements OnInit {
|
|||
protected formGroup = this.formBuilder.group({
|
||||
hasEmailAccess: new FormControl(0),
|
||||
});
|
||||
readonly currentAcct$ = this.accountService.activeAccount$.pipe(map((acct) => acct?.email));
|
||||
readonly currentAcct$ = this.accountService.activeAccount$.pipe(map((acct) => acct));
|
||||
private currentEmail: string;
|
||||
private currentUserId: UserId;
|
||||
|
||||
constructor(
|
||||
private i18nService: I18nService,
|
||||
private formBuilder: FormBuilder,
|
||||
private router: Router,
|
||||
private accountService: AccountService,
|
||||
private newDeviceVerificationNoticeService: NewDeviceVerificationNoticeService,
|
||||
) {}
|
||||
|
||||
async ngOnInit() {
|
||||
const currentEmail = await firstValueFrom(this.currentAcct$);
|
||||
this.currentEmail = (await firstValueFrom(this.currentAcct$)).email;
|
||||
this.currentUserId = (await firstValueFrom(this.currentAcct$)).id;
|
||||
this.formMessage = this.i18nService.t(
|
||||
"newDeviceVerificationNoticePageOneFormContent",
|
||||
currentEmail,
|
||||
this.currentEmail,
|
||||
);
|
||||
}
|
||||
|
||||
submit = () => {
|
||||
if (this.formGroup.controls.hasEmailAccess.value === 0) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
this.router.navigate(["blah/setup"]);
|
||||
this.router.navigate(["new-device-notice/setup"]);
|
||||
} else if (this.formGroup.controls.hasEmailAccess.value === 1) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
this.newDeviceVerificationNoticeService.updateNewDeviceVerificationNoticeState(
|
||||
this.currentUserId,
|
||||
{
|
||||
last_dismissal: new Date(),
|
||||
permanent_dismissal: null,
|
||||
},
|
||||
);
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
this.router.navigate(["/vault"]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue