mirror of
https://github.com/bitwarden/browser
synced 2026-02-18 18:33:50 +00:00
added another route guard so when user clears all at risk items they are directed back to the vault page
This commit is contained in:
@@ -74,7 +74,10 @@ import { IntroCarouselComponent } from "../vault/popup/components/vault-v2/intro
|
||||
import { PasswordHistoryV2Component } from "../vault/popup/components/vault-v2/vault-password-history-v2/vault-password-history-v2.component";
|
||||
import { VaultV2Component } from "../vault/popup/components/vault-v2/vault-v2.component";
|
||||
import { ViewV2Component } from "../vault/popup/components/vault-v2/view-v2/view-v2.component";
|
||||
import { canAccessAtRiskPasswords } from "../vault/popup/guards/at-risk-passwords.guard";
|
||||
import {
|
||||
canAccessAtRiskPasswords,
|
||||
hasAtRiskPasswords,
|
||||
} from "../vault/popup/guards/at-risk-passwords.guard";
|
||||
import { clearVaultStateGuard } from "../vault/popup/guards/clear-vault-state.guard";
|
||||
import { IntroCarouselGuard } from "../vault/popup/guards/intro-carousel.guard";
|
||||
import { AppearanceV2Component } from "../vault/popup/settings/appearance-v2.component";
|
||||
@@ -660,7 +663,7 @@ const routes: Routes = [
|
||||
{
|
||||
path: "at-risk-passwords",
|
||||
component: AtRiskPasswordsComponent,
|
||||
canActivate: [authGuard, canAccessAtRiskPasswords],
|
||||
canActivate: [authGuard, canAccessAtRiskPasswords, hasAtRiskPasswords],
|
||||
},
|
||||
{
|
||||
path: "account-switcher",
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { inject } from "@angular/core";
|
||||
import { CanActivateFn, Router } from "@angular/router";
|
||||
import { map, switchMap } from "rxjs";
|
||||
import { combineLatest, map, switchMap } from "rxjs";
|
||||
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { TaskService } from "@bitwarden/common/vault/tasks";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { SecurityTaskType, TaskService } from "@bitwarden/common/vault/tasks";
|
||||
import { filterOutNullish } from "@bitwarden/common/vault/utils/observable-utilities";
|
||||
import { ToastService } from "@bitwarden/components";
|
||||
|
||||
@@ -32,3 +33,40 @@ export const canAccessAtRiskPasswords: CanActivateFn = () => {
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
export const hasAtRiskPasswords: CanActivateFn = () => {
|
||||
const accountService = inject(AccountService);
|
||||
const taskService = inject(TaskService);
|
||||
const cipherService = inject(CipherService);
|
||||
const router = inject(Router);
|
||||
|
||||
return accountService.activeAccount$.pipe(
|
||||
filterOutNullish(),
|
||||
switchMap((user) =>
|
||||
combineLatest([
|
||||
taskService.pendingTasks$(user.id),
|
||||
cipherService.cipherViews$(user.id).pipe(
|
||||
filterOutNullish(),
|
||||
map((ciphers) => Object.fromEntries(ciphers.map((c) => [c.id, c]))),
|
||||
),
|
||||
]).pipe(
|
||||
map(([tasks, ciphers]) => {
|
||||
const atRiskCiphers = tasks
|
||||
.filter(
|
||||
(t) =>
|
||||
t.type === SecurityTaskType.UpdateAtRiskCredential &&
|
||||
t.cipherId != null &&
|
||||
ciphers[t.cipherId] != null &&
|
||||
!ciphers[t.cipherId].isDeleted,
|
||||
)
|
||||
.map((t) => ciphers[t.cipherId!]);
|
||||
|
||||
if (atRiskCiphers.length === 0) {
|
||||
return router.createUrlTree(["/tabs/vault"]);
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user