2018-07-11 21:22:55 +02:00
|
|
|
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';
|
2018-08-13 22:27:17 +02:00
|
|
|
import { SearchService } from 'jslib/abstractions/search.service';
|
2018-07-04 05:33:12 +02:00
|
|
|
|
|
|
|
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-05 15:58:15 +02:00
|
|
|
|
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 {
|
2018-07-11 21:22:55 +02:00
|
|
|
@Output() onEventsClicked = new EventEmitter<CipherView>();
|
|
|
|
|
2018-07-04 05:33:12 +02:00
|
|
|
organization: Organization;
|
2018-07-11 21:22:55 +02:00
|
|
|
accessEvents = false;
|
2018-07-04 05:33:12 +02:00
|
|
|
|
2018-08-13 22:27:17 +02:00
|
|
|
protected allCiphers: CipherView[] = [];
|
|
|
|
|
|
|
|
constructor(searchService: SearchService, analytics: Angulartics2,
|
2018-07-05 15:58:15 +02:00
|
|
|
toasterService: ToasterService, i18nService: I18nService,
|
2018-08-13 22:27:17 +02:00
|
|
|
platformUtilsService: PlatformUtilsService, cipherService: CipherService,
|
|
|
|
private apiService: ApiService) {
|
|
|
|
super(searchService, analytics, toasterService, i18nService, platformUtilsService, cipherService);
|
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) {
|
2018-10-17 22:09:09 +02:00
|
|
|
await super.load(filter);
|
2018-07-05 16:48:51 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-07-11 21:22:55 +02:00
|
|
|
this.accessEvents = this.organization.useEvents;
|
2018-12-14 19:56:01 +01:00
|
|
|
this.allCiphers = await this.cipherService.getAllFromApiForOrganization(this.organization.id);
|
2018-07-05 16:48:51 +02:00
|
|
|
this.applyFilter(filter);
|
|
|
|
this.loaded = true;
|
2018-07-04 15:55:52 +02:00
|
|
|
}
|
|
|
|
|
2018-08-13 22:27:17 +02:00
|
|
|
async applyFilter(filter: (cipher: CipherView) => boolean = null) {
|
2018-07-04 15:55:52 +02:00
|
|
|
if (this.organization.isAdmin) {
|
2018-08-13 22:27:17 +02:00
|
|
|
await super.applyFilter(filter);
|
2018-07-04 15:55:52 +02:00
|
|
|
} else {
|
|
|
|
const f = (c: CipherView) => c.organizationId === this.organization.id && (filter == null || filter(c));
|
2018-08-13 22:27:17 +02:00
|
|
|
await super.applyFilter(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-19 17:44:22 +01:00
|
|
|
async search(timeout: number = null) {
|
2018-08-13 22:27:17 +02:00
|
|
|
if (!this.organization.isAdmin) {
|
|
|
|
return super.search(timeout);
|
|
|
|
}
|
|
|
|
this.searchPending = false;
|
2018-08-13 22:38:21 +02:00
|
|
|
let filteredCiphers = this.allCiphers;
|
|
|
|
if (this.filter != null) {
|
|
|
|
filteredCiphers = filteredCiphers.filter(this.filter);
|
|
|
|
}
|
2018-08-13 22:27:17 +02:00
|
|
|
if (this.searchText == null || this.searchText.trim().length < 2) {
|
2018-08-13 22:38:21 +02:00
|
|
|
this.ciphers = filteredCiphers;
|
2018-08-13 22:27:17 +02:00
|
|
|
} else {
|
2018-08-13 22:38:21 +02:00
|
|
|
this.ciphers = this.searchService.searchCiphersBasic(filteredCiphers, this.searchText);
|
2018-07-04 05:33:12 +02:00
|
|
|
}
|
2019-03-19 17:44:22 +01:00
|
|
|
await this.resetPaging();
|
2018-07-04 05:33:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
checkCipher(c: CipherView) {
|
|
|
|
// do nothing
|
|
|
|
}
|
2018-07-11 21:22:55 +02:00
|
|
|
|
|
|
|
events(c: CipherView) {
|
|
|
|
this.onEventsClicked.emit(c);
|
|
|
|
}
|
2018-07-28 04:36:25 +02:00
|
|
|
|
|
|
|
protected deleteCipher(id: string) {
|
|
|
|
if (!this.organization.isAdmin) {
|
|
|
|
return super.deleteCipher(id);
|
|
|
|
}
|
|
|
|
return this.apiService.deleteCipherAdmin(id);
|
|
|
|
}
|
2018-11-14 21:20:17 +01:00
|
|
|
|
|
|
|
protected showFixOldAttachments(c: CipherView) {
|
|
|
|
return this.organization.isAdmin && c.hasOldAttachments;
|
|
|
|
}
|
2018-07-04 05:33:12 +02:00
|
|
|
}
|