Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
init functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kspearrin committed Mar 6, 2019
1 parent 965e356 commit 199884e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 35 deletions.
48 changes: 26 additions & 22 deletions src/angular/components/attachments.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,7 @@ export class AttachmentsComponent implements OnInit {
protected platformUtilsService: PlatformUtilsService, protected win: Window) { }

async ngOnInit() {
this.cipherDomain = await this.loadCipher();
this.cipher = await this.cipherDomain.decrypt();

this.hasUpdatedKey = await this.cryptoService.hasEncKey();
const canAccessPremium = await this.userService.canAccessPremium();
this.canAccessAttachments = canAccessPremium || this.cipher.organizationId != null;

if (!this.canAccessAttachments) {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t('premiumRequiredDesc'), this.i18nService.t('premiumRequired'),
this.i18nService.t('learnMore'), this.i18nService.t('cancel'));
if (confirmed) {
this.platformUtilsService.launchUri('https://vault.bitwarden.com/#/?premium=purchase');
}
} else if (!this.hasUpdatedKey) {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t('updateKey'), this.i18nService.t('featureUnavailable'),
this.i18nService.t('learnMore'), this.i18nService.t('cancel'), 'warning');
if (confirmed) {
this.platformUtilsService.launchUri('https://help.bitwarden.com/article/update-encryption-key/');
}
}
await this.init();
}

async submit() {
Expand Down Expand Up @@ -156,6 +135,31 @@ export class AttachmentsComponent implements OnInit {
a.downloading = false;
}

protected async init() {
this.cipherDomain = await this.loadCipher();
this.cipher = await this.cipherDomain.decrypt();

this.hasUpdatedKey = await this.cryptoService.hasEncKey();
const canAccessPremium = await this.userService.canAccessPremium();
this.canAccessAttachments = canAccessPremium || this.cipher.organizationId != null;

if (!this.canAccessAttachments) {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t('premiumRequiredDesc'), this.i18nService.t('premiumRequired'),
this.i18nService.t('learnMore'), this.i18nService.t('cancel'));
if (confirmed) {
this.platformUtilsService.launchUri('https://vault.bitwarden.com/#/?premium=purchase');
}
} else if (!this.hasUpdatedKey) {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t('updateKey'), this.i18nService.t('featureUnavailable'),
this.i18nService.t('learnMore'), this.i18nService.t('cancel'), 'warning');
if (confirmed) {
this.platformUtilsService.launchUri('https://help.bitwarden.com/article/update-encryption-key/');
}
}
}

protected async reuploadCipherAttachment(attachment: AttachmentView, admin: boolean) {
const a = (attachment as any);
if (attachment.key != null || a.downloading || this.reuploadPromises[attachment.id] != null) {
Expand Down
24 changes: 14 additions & 10 deletions src/angular/components/folder-add-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,7 @@ export class FolderAddEditComponent implements OnInit {
protected platformUtilsService: PlatformUtilsService) { }

async ngOnInit() {
this.editMode = this.folderId != null;

if (this.editMode) {
this.editMode = true;
this.title = this.i18nService.t('editFolder');
const folder = await this.folderService.get(this.folderId);
this.folder = await folder.decrypt();
} else {
this.title = this.i18nService.t('addFolder');
}
await this.init();
}

async submit(): Promise<boolean> {
Expand Down Expand Up @@ -77,4 +68,17 @@ export class FolderAddEditComponent implements OnInit {

return true;
}

protected async init() {
this.editMode = this.folderId != null;

if (this.editMode) {
this.editMode = true;
this.title = this.i18nService.t('editFolder');
const folder = await this.folderService.get(this.folderId);
this.folder = await folder.decrypt();
} else {
this.title = this.i18nService.t('addFolder');
}
}
}
10 changes: 7 additions & 3 deletions src/angular/components/password-history.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export class PasswordHistoryComponent implements OnInit {
protected i18nService: I18nService, private win: Window) { }

async ngOnInit() {
const cipher = await this.cipherService.get(this.cipherId);
const decCipher = await cipher.decrypt();
this.history = decCipher.passwordHistory == null ? [] : decCipher.passwordHistory;
await this.init();
}

copy(password: string) {
Expand All @@ -26,4 +24,10 @@ export class PasswordHistoryComponent implements OnInit {
this.platformUtilsService.showToast('info', null,
this.i18nService.t('valueCopied', this.i18nService.t('password')));
}

protected async init() {
const cipher = await this.cipherService.get(this.cipherId);
const decCipher = await cipher.decrypt();
this.history = decCipher.passwordHistory == null ? [] : decCipher.passwordHistory;
}
}

0 comments on commit 199884e

Please sign in to comment.