bitwarden-estensione-browser/src/app/organizations/vault/ciphers.component.ts

80 lines
2.8 KiB
TypeScript
Raw Normal View History

import {
Component,
EventEmitter,
Output,
} from '@angular/core';
2018-07-04 05:33:12 +02:00
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { ApiService } from 'jslib/abstractions/api.service';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { CipherData } from 'jslib/models/data/cipherData';
import { Cipher } from 'jslib/models/domain/cipher';
import { Organization } from 'jslib/models/domain/organization';
import { CipherView } from 'jslib/models/view/cipherView';
2018-07-05 19:14:33 +02:00
import { CiphersComponent as BaseCiphersComponent } from '../../vault/ciphers.component';
2018-07-04 05:33:12 +02:00
@Component({
selector: 'app-org-vault-ciphers',
2018-07-05 19:14:33 +02:00
templateUrl: '../../vault/ciphers.component.html',
2018-07-04 05:33:12 +02:00
})
export class CiphersComponent extends BaseCiphersComponent {
@Output() onEventsClicked = new EventEmitter<CipherView>();
2018-07-04 05:33:12 +02:00
organization: Organization;
accessEvents = false;
2018-07-04 05:33:12 +02:00
constructor(cipherService: CipherService, analytics: Angulartics2,
toasterService: ToasterService, i18nService: I18nService,
platformUtilsService: PlatformUtilsService, private apiService: ApiService) {
super(cipherService, analytics, toasterService, i18nService, platformUtilsService);
2018-07-04 05:33:12 +02:00
}
async load(filter: (cipher: CipherView) => boolean = null) {
2018-07-05 16:48:51 +02:00
if (!this.organization.isAdmin) {
await super.load();
2018-07-05 16:48:51 +02:00
return;
}
this.accessEvents = this.organization.useEvents;
2018-07-05 16:48:51 +02:00
const ciphers = await this.apiService.getCiphersOrganization(this.organization.id);
if (ciphers != null && ciphers.data != null && ciphers.data.length) {
const decCiphers: CipherView[] = [];
const promises: any[] = [];
ciphers.data.forEach((r) => {
const data = new CipherData(r);
const cipher = new Cipher(data);
promises.push(cipher.decrypt().then((c) => decCiphers.push(c)));
});
await Promise.all(promises);
decCiphers.sort(this.cipherService.getLocaleSortingFunction());
this.allCiphers = decCiphers;
} else {
this.allCiphers = [];
}
2018-07-05 16:48:51 +02:00
this.applyFilter(filter);
this.loaded = true;
}
applyFilter(filter: (cipher: CipherView) => boolean = null) {
if (this.organization.isAdmin) {
super.applyFilter(filter);
} else {
const f = (c: CipherView) => c.organizationId === this.organization.id && (filter == null || filter(c));
super.applyFilter(f);
2018-07-04 05:33:12 +02:00
}
}
checkCipher(c: CipherView) {
// do nothing
}
events(c: CipherView) {
this.onEventsClicked.emit(c);
}
2018-07-04 05:33:12 +02:00
}