1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-23 19:53:43 +00:00

exposed passwords report for orgs

This commit is contained in:
Kyle Spearrin
2018-12-14 13:56:01 -05:00
parent 7a58f6d967
commit 392a90c02c
13 changed files with 139 additions and 35 deletions

View File

@@ -6,7 +6,10 @@ import {
import { CipherView } from 'jslib/models/view/cipherView';
import { Organization } from 'jslib/models/domain/organization';
import { ModalComponent } from '../modal.component';
import { AddEditComponent as OrgAddEditComponent } from '../organizations/vault/add-edit.component';
import { AddEditComponent } from '../vault/add-edit.component';
import { MessagingService } from 'jslib/abstractions/messaging.service';
@@ -18,11 +21,12 @@ export class CipherReportComponent {
loading = false;
hasLoaded = false;
ciphers: CipherView[] = [];
organization: Organization;
private modal: ModalComponent = null;
constructor(private componentFactoryResolver: ComponentFactoryResolver, protected userService: UserService,
protected messagingService: MessagingService, public requiresPremium: boolean) { }
protected messagingService: MessagingService, public requiresPaid: boolean) { }
async load() {
this.loading = true;
@@ -38,10 +42,18 @@ export class CipherReportComponent {
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.modal = this.cipherAddEditModalRef.createComponent(factory).instance;
const childComponent = this.modal.show<AddEditComponent>(
AddEditComponent, this.cipherAddEditModalRef);
let childComponent: OrgAddEditComponent | AddEditComponent;
if (this.organization != null) {
childComponent = this.modal.show<OrgAddEditComponent>(OrgAddEditComponent, this.cipherAddEditModalRef);
(childComponent as OrgAddEditComponent).organization = this.organization;
} else {
childComponent = this.modal.show<AddEditComponent>(AddEditComponent, this.cipherAddEditModalRef);
}
childComponent.cipherId = cipher == null ? null : cipher.id;
if (this.organization != null) {
childComponent.organizationId = this.organization.id;
}
childComponent.onSavedCipher.subscribe(async (c: CipherView) => {
this.modal.close();
await this.load();
@@ -58,12 +70,21 @@ export class CipherReportComponent {
return childComponent;
}
protected async checkPremium(): Promise<boolean> {
const accessPremium = await this.userService.canAccessPremium();
if (this.requiresPremium && !accessPremium) {
this.messagingService.send('premiumRequired');
this.loading = false;
return false;
protected async checkAccess(): Promise<boolean> {
if (this.organization != null) {
// TODO: Maybe we want to just make sure they are not on a free plan? Just compare use2fa for now
// since all paid plans include use2fa
if (this.requiresPaid && !this.organization.use2fa) {
this.messagingService.send('upgradeOrganization', { organizationId: this.organization.id });
return false;
}
} else {
const accessPremium = await this.userService.canAccessPremium();
if (this.requiresPaid && !accessPremium) {
this.messagingService.send('premiumRequired');
this.loading = false;
return false;
}
}
return true;
}

View File

@@ -22,24 +22,24 @@ import { CipherReportComponent } from './cipher-report.component';
export class ExposedPasswordsReportComponent extends CipherReportComponent implements OnInit {
exposedPasswordMap = new Map<string, number>();
constructor(private ciphersService: CipherService, private auditService: AuditService,
constructor(protected cipherService: CipherService, protected auditService: AuditService,
componentFactoryResolver: ComponentFactoryResolver, messagingService: MessagingService,
userService: UserService) {
super(componentFactoryResolver, userService, messagingService, true);
}
ngOnInit() {
this.checkPremium();
this.checkAccess();
}
async load() {
if (await this.checkPremium()) {
if (await this.checkAccess()) {
super.load();
}
}
async setCiphers() {
const allCiphers = await this.ciphersService.getAllDecrypted();
const allCiphers = await this.getAllCiphers();
const exposedPasswordCiphers: CipherView[] = [];
const promises: Array<Promise<void>> = [];
allCiphers.forEach((c) => {
@@ -57,4 +57,8 @@ export class ExposedPasswordsReportComponent extends CipherReportComponent imple
await Promise.all(promises);
this.ciphers = exposedPasswordCiphers;
}
protected getAllCiphers(): Promise<CipherView[]> {
return this.cipherService.getAllDecrypted();
}
}

View File

@@ -30,7 +30,7 @@ export class InactiveTwoFactorReportComponent extends CipherReportComponent impl
}
async ngOnInit() {
if (await this.checkPremium()) {
if (await this.checkAccess()) {
await super.load();
}
}

View File

@@ -27,7 +27,7 @@ export class ReusedPasswordsReportComponent extends CipherReportComponent implem
}
async ngOnInit() {
if (await this.checkPremium()) {
if (await this.checkAccess()) {
await super.load();
}
}

View File

@@ -23,7 +23,7 @@ export class UnsecuredWebsitesReportComponent extends CipherReportComponent impl
}
async ngOnInit() {
if (await this.checkPremium()) {
if (await this.checkAccess()) {
await super.load();
}
}

View File

@@ -31,7 +31,7 @@ export class WeakPasswordsReportComponent extends CipherReportComponent implemen
}
async ngOnInit() {
if (await this.checkPremium()) {
if (await this.checkAccess()) {
await super.load();
}
}