mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 22:03:36 +00:00
[PM-11405] Account Management: Prevent a verified user from changing their email address (#11486)
* Update AccountService to include a method for setting the managedByOrganizationId * Update AccountComponent to conditionally show the purgeVault button based on a feature flag and if the user is managed by an organization * Add missing method to FakeAccountService * Remove the setAccountManagedByOrganizationId method from the AccountService abstract class. * Refactor AccountComponent to use OrganizationService to check for managing organization * Rename managesActiveUser to userIsManagedByOrganization * Hide the change email section if the user is managed by an organization * Refactor userIsManagedByOrganization property to be non-nullable in organization data and response models * Refactor organization.data.spec.ts to include non-nullable userIsManagedByOrganization property * Refactor account component initialization logic * Remove opening modal that was added by mistake
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<bit-container>
|
<bit-container>
|
||||||
<app-profile></app-profile>
|
<app-profile></app-profile>
|
||||||
|
|
||||||
<div *ngIf="showChangeEmail" class="tw-mt-16">
|
<div *ngIf="showChangeEmail$ | async" class="tw-mt-16">
|
||||||
<h1 bitTypography="h1">{{ "changeEmail" | i18n }}</h1>
|
<h1 bitTypography="h1">{{ "changeEmail" | i18n }}</h1>
|
||||||
<app-change-email></app-change-email>
|
<app-change-email></app-change-email>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Component, OnInit, ViewChild, ViewContainerRef } from "@angular/core";
|
import { Component, OnInit, ViewChild, ViewContainerRef } from "@angular/core";
|
||||||
import { lastValueFrom, map, Observable, of, switchMap } from "rxjs";
|
import { combineLatest, from, lastValueFrom, map, Observable } from "rxjs";
|
||||||
|
|
||||||
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
||||||
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||||
@@ -21,7 +21,7 @@ export class AccountComponent implements OnInit {
|
|||||||
@ViewChild("deauthorizeSessionsTemplate", { read: ViewContainerRef, static: true })
|
@ViewChild("deauthorizeSessionsTemplate", { read: ViewContainerRef, static: true })
|
||||||
deauthModalRef: ViewContainerRef;
|
deauthModalRef: ViewContainerRef;
|
||||||
|
|
||||||
showChangeEmail = true;
|
showChangeEmail$: Observable<boolean>;
|
||||||
showPurgeVault$: Observable<boolean>;
|
showPurgeVault$: Observable<boolean>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -33,21 +33,36 @@ export class AccountComponent implements OnInit {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
this.showChangeEmail = await this.userVerificationService.hasMasterPassword();
|
const isAccountDeprovisioningEnabled$ = this.configService.getFeatureFlag$(
|
||||||
this.showPurgeVault$ = this.configService
|
FeatureFlag.AccountDeprovisioning,
|
||||||
.getFeatureFlag$(FeatureFlag.AccountDeprovisioning)
|
);
|
||||||
.pipe(
|
|
||||||
switchMap((isAccountDeprovisioningEnabled) =>
|
const userIsManagedByOrganization$ = this.organizationService.organizations$.pipe(
|
||||||
isAccountDeprovisioningEnabled
|
map((organizations) => organizations.some((o) => o.userIsManagedByOrganization === true)),
|
||||||
? this.organizationService.organizations$.pipe(
|
);
|
||||||
map(
|
|
||||||
(organizations) =>
|
const hasMasterPassword$ = from(this.userVerificationService.hasMasterPassword());
|
||||||
!organizations.some((o) => o.userIsManagedByOrganization === true),
|
|
||||||
),
|
this.showChangeEmail$ = combineLatest([
|
||||||
)
|
hasMasterPassword$,
|
||||||
: of(true),
|
isAccountDeprovisioningEnabled$,
|
||||||
),
|
userIsManagedByOrganization$,
|
||||||
);
|
]).pipe(
|
||||||
|
map(
|
||||||
|
([hasMasterPassword, isAccountDeprovisioningEnabled, userIsManagedByOrganization]) =>
|
||||||
|
hasMasterPassword && (!isAccountDeprovisioningEnabled || !userIsManagedByOrganization),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
this.showPurgeVault$ = combineLatest([
|
||||||
|
isAccountDeprovisioningEnabled$,
|
||||||
|
userIsManagedByOrganization$,
|
||||||
|
]).pipe(
|
||||||
|
map(
|
||||||
|
([isAccountDeprovisioningEnabled, userIsManagedByOrganization]) =>
|
||||||
|
!isAccountDeprovisioningEnabled || !userIsManagedByOrganization,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deauthorizeSessions() {
|
async deauthorizeSessions() {
|
||||||
|
|||||||
Reference in New Issue
Block a user