2018-07-03 18:34:20 +02:00
|
|
|
import {
|
2018-08-21 04:21:13 +02:00
|
|
|
ChangeDetectorRef,
|
2018-07-03 21:11:58 +02:00
|
|
|
Component,
|
2018-08-21 04:21:13 +02:00
|
|
|
NgZone,
|
|
|
|
OnDestroy,
|
2018-07-03 21:11:58 +02:00
|
|
|
OnInit,
|
2018-07-04 05:33:12 +02:00
|
|
|
ViewChild,
|
2018-07-05 15:42:50 +02:00
|
|
|
ViewContainerRef,
|
2018-07-03 18:34:20 +02:00
|
|
|
} from "@angular/core";
|
2018-07-04 05:33:12 +02:00
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
|
|
|
|
2021-10-15 00:59:43 +02:00
|
|
|
import { first } from "rxjs/operators";
|
|
|
|
|
2021-12-07 23:16:47 +01:00
|
|
|
import { BroadcasterService } from "jslib-common/abstractions/broadcaster.service";
|
2021-06-07 20:13:58 +02:00
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
|
|
|
import { MessagingService } from "jslib-common/abstractions/messaging.service";
|
2021-12-14 17:10:26 +01:00
|
|
|
import { OrganizationService } from "jslib-common/abstractions/organization.service";
|
2021-06-07 20:13:58 +02:00
|
|
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
|
|
|
import { SyncService } from "jslib-common/abstractions/sync.service";
|
2018-07-04 05:33:12 +02:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
import { ModalService } from "jslib-angular/services/modal.service";
|
2018-08-21 04:21:13 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { Organization } from "jslib-common/models/domain/organization";
|
|
|
|
import { CipherView } from "jslib-common/models/view/cipherView";
|
2018-07-04 05:33:12 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { CipherType } from "jslib-common/enums/cipherType";
|
2018-07-04 05:33:12 +02:00
|
|
|
|
2018-07-11 21:22:55 +02:00
|
|
|
import { EntityEventsComponent } from "../manage/entity-events.component";
|
2018-07-05 15:42:50 +02:00
|
|
|
import { AddEditComponent } from "./add-edit.component";
|
2018-07-05 16:48:51 +02:00
|
|
|
import { AttachmentsComponent } from "./attachments.component";
|
2018-07-04 05:33:12 +02:00
|
|
|
import { CiphersComponent } from "./ciphers.component";
|
2018-07-05 18:56:58 +02:00
|
|
|
import { CollectionsComponent } from "./collections.component";
|
2018-07-04 05:33:12 +02:00
|
|
|
import { GroupingsComponent } from "./groupings.component";
|
2018-07-03 18:34:20 +02:00
|
|
|
|
2018-08-21 04:21:13 +02:00
|
|
|
const BroadcasterSubscriptionId = "OrgVaultComponent";
|
|
|
|
|
2018-07-03 18:34:20 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-org-vault",
|
|
|
|
templateUrl: "vault.component.html",
|
|
|
|
})
|
2018-08-21 04:21:13 +02:00
|
|
|
export class VaultComponent implements OnInit, OnDestroy {
|
2020-08-17 16:04:38 +02:00
|
|
|
@ViewChild(GroupingsComponent, { static: true }) groupingsComponent: GroupingsComponent;
|
|
|
|
@ViewChild(CiphersComponent, { static: true }) ciphersComponent: CiphersComponent;
|
|
|
|
@ViewChild("attachments", { read: ViewContainerRef, static: true })
|
|
|
|
attachmentsModalRef: ViewContainerRef;
|
|
|
|
@ViewChild("cipherAddEdit", { read: ViewContainerRef, static: true })
|
|
|
|
cipherAddEditModalRef: ViewContainerRef;
|
|
|
|
@ViewChild("collections", { read: ViewContainerRef, static: true })
|
|
|
|
collectionsModalRef: ViewContainerRef;
|
|
|
|
@ViewChild("eventsTemplate", { read: ViewContainerRef, static: true })
|
|
|
|
eventsModalRef: ViewContainerRef;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-04 05:33:12 +02:00
|
|
|
organization: Organization;
|
2020-04-08 22:48:30 +02:00
|
|
|
collectionId: string = null;
|
|
|
|
type: CipherType = null;
|
|
|
|
deleted: boolean = false;
|
2021-04-27 18:49:02 +02:00
|
|
|
trashCleanupWarning: string = null;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-12-14 17:10:26 +01:00
|
|
|
constructor(
|
2018-11-30 16:28:46 +01:00
|
|
|
private route: ActivatedRoute,
|
2021-12-14 17:10:26 +01:00
|
|
|
private organizationService: OrganizationService,
|
2021-10-15 00:59:43 +02:00
|
|
|
private router: Router,
|
2021-10-05 18:12:44 +02:00
|
|
|
private changeDetectorRef: ChangeDetectorRef,
|
2018-07-04 05:33:12 +02:00
|
|
|
private syncService: SyncService,
|
2018-07-05 15:42:50 +02:00
|
|
|
private i18nService: I18nService,
|
2018-07-04 05:33:12 +02:00
|
|
|
private modalService: ModalService,
|
2018-08-21 04:21:13 +02:00
|
|
|
private messagingService: MessagingService,
|
|
|
|
private broadcasterService: BroadcasterService,
|
|
|
|
private ngZone: NgZone,
|
2021-04-27 18:49:02 +02:00
|
|
|
private platformUtilsService: PlatformUtilsService
|
2021-12-17 15:57:11 +01:00
|
|
|
) {}
|
|
|
|
|
2018-08-21 04:21:13 +02:00
|
|
|
ngOnInit() {
|
|
|
|
this.trashCleanupWarning = this.i18nService.t(
|
|
|
|
this.platformUtilsService.isSelfHost()
|
|
|
|
? "trashCleanupWarningSelfHosted"
|
|
|
|
: "trashCleanupWarning"
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
2018-08-21 04:21:13 +02:00
|
|
|
this.route.parent.params.pipe(first()).subscribe(async (params) => {
|
2018-07-04 05:33:12 +02:00
|
|
|
this.organization = await this.organizationService.get(params.organizationId);
|
|
|
|
this.groupingsComponent.organization = this.organization;
|
2019-03-19 17:44:22 +01:00
|
|
|
this.ciphersComponent.organization = this.organization;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-11 21:44:40 +02:00
|
|
|
this.route.queryParams.pipe(first()).subscribe(async (qParams) => {
|
|
|
|
this.ciphersComponent.searchText = this.groupingsComponent.searchText = qParams.search;
|
|
|
|
if (!this.organization.canViewAllCollections) {
|
|
|
|
await this.syncService.fullSync(false);
|
|
|
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
|
|
|
this.ngZone.run(async () => {
|
2018-08-21 04:21:13 +02:00
|
|
|
switch (message.command) {
|
2018-07-11 21:44:40 +02:00
|
|
|
case "syncCompleted":
|
|
|
|
if (message.successfully) {
|
|
|
|
await Promise.all([
|
|
|
|
this.groupingsComponent.load(),
|
2019-03-19 17:44:22 +01:00
|
|
|
this.ciphersComponent.refresh(),
|
|
|
|
]);
|
2021-02-03 18:41:33 +01:00
|
|
|
this.changeDetectorRef.detectChanges();
|
2018-07-11 21:44:40 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
break;
|
2018-07-04 05:33:12 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
await this.groupingsComponent.load();
|
|
|
|
|
|
|
|
if (qParams == null) {
|
|
|
|
this.groupingsComponent.selectedAll = true;
|
2019-03-19 17:44:22 +01:00
|
|
|
await this.ciphersComponent.reload();
|
2018-07-04 05:33:12 +02:00
|
|
|
} else {
|
2020-04-08 22:48:30 +02:00
|
|
|
if (qParams.deleted) {
|
|
|
|
this.groupingsComponent.selectedTrash = true;
|
2018-07-04 05:33:12 +02:00
|
|
|
await this.filterDeleted(true);
|
2020-04-08 22:48:30 +02:00
|
|
|
} else if (qParams.type) {
|
2018-07-11 21:44:40 +02:00
|
|
|
const t = parseInt(qParams.type, null);
|
|
|
|
this.groupingsComponent.selectedType = t;
|
2018-07-04 05:33:12 +02:00
|
|
|
await this.filterCipherType(t, true);
|
2018-07-11 21:44:40 +02:00
|
|
|
} else if (qParams.collectionId) {
|
2021-08-27 14:50:58 +02:00
|
|
|
this.groupingsComponent.selectedCollectionId = qParams.collectionId;
|
|
|
|
await this.filterCollection(qParams.collectionId, true);
|
2021-12-17 15:57:11 +01:00
|
|
|
} else {
|
2020-04-08 22:48:30 +02:00
|
|
|
this.groupingsComponent.selectedAll = true;
|
2018-07-04 05:33:12 +02:00
|
|
|
await this.ciphersComponent.reload();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-07-04 05:33:12 +02:00
|
|
|
}
|
|
|
|
|
2020-04-08 22:48:30 +02:00
|
|
|
if (qParams.viewEvents != null) {
|
|
|
|
const cipher = this.ciphersComponent.ciphers.filter((c) => c.id === qParams.viewEvents);
|
2018-07-11 21:44:40 +02:00
|
|
|
if (cipher.length > 0) {
|
|
|
|
this.viewEvents(cipher[0]);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2020-04-08 22:48:30 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-21 04:21:13 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-07-04 05:33:12 +02:00
|
|
|
async clearGroupingFilters() {
|
2018-10-22 22:46:48 +02:00
|
|
|
this.ciphersComponent.showAddNew = true;
|
2020-04-08 22:48:30 +02:00
|
|
|
this.ciphersComponent.deleted = false;
|
2018-07-04 05:33:12 +02:00
|
|
|
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchVault");
|
|
|
|
await this.ciphersComponent.applyFilter();
|
2020-04-08 22:48:30 +02:00
|
|
|
this.clearFilters();
|
2018-07-04 05:33:12 +02:00
|
|
|
this.go();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-07-04 05:33:12 +02:00
|
|
|
async filterCipherType(type: CipherType, load = false) {
|
2020-04-08 22:48:30 +02:00
|
|
|
this.ciphersComponent.showAddNew = true;
|
|
|
|
this.ciphersComponent.deleted = false;
|
|
|
|
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchType");
|
2018-07-04 05:33:12 +02:00
|
|
|
const filter = (c: CipherView) => c.type === type;
|
|
|
|
if (load) {
|
2019-03-19 17:44:22 +01:00
|
|
|
await this.ciphersComponent.reload(filter);
|
2021-12-17 15:57:11 +01:00
|
|
|
} else {
|
2018-07-04 05:33:12 +02:00
|
|
|
await this.ciphersComponent.applyFilter(filter);
|
2020-04-08 22:48:30 +02:00
|
|
|
}
|
2018-07-04 05:33:12 +02:00
|
|
|
this.clearFilters();
|
|
|
|
this.type = type;
|
|
|
|
this.go();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-07-04 05:33:12 +02:00
|
|
|
async filterCollection(collectionId: string, load = false) {
|
|
|
|
this.ciphersComponent.showAddNew = true;
|
|
|
|
this.ciphersComponent.deleted = false;
|
|
|
|
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchCollection");
|
|
|
|
const filter = (c: CipherView) => {
|
2018-07-04 05:43:57 +02:00
|
|
|
if (collectionId === "unassigned") {
|
|
|
|
return c.collectionIds == null || c.collectionIds.length === 0;
|
2021-12-17 15:57:11 +01:00
|
|
|
} else {
|
2018-07-04 05:33:12 +02:00
|
|
|
return c.collectionIds != null && c.collectionIds.indexOf(collectionId) > -1;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
};
|
2020-04-08 22:48:30 +02:00
|
|
|
if (load) {
|
2018-08-13 22:27:17 +02:00
|
|
|
await this.ciphersComponent.reload(filter);
|
|
|
|
} else {
|
2018-07-04 05:33:12 +02:00
|
|
|
await this.ciphersComponent.applyFilter(filter);
|
|
|
|
}
|
2018-07-18 15:21:23 +02:00
|
|
|
this.clearFilters();
|
|
|
|
this.collectionId = collectionId;
|
|
|
|
this.go();
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-18 15:21:23 +02:00
|
|
|
async filterDeleted(load: boolean = false) {
|
|
|
|
this.ciphersComponent.showAddNew = false;
|
|
|
|
this.ciphersComponent.deleted = true;
|
2021-08-27 14:50:58 +02:00
|
|
|
this.groupingsComponent.searchPlaceholder = this.i18nService.t("searchTrash");
|
|
|
|
if (load) {
|
|
|
|
await this.ciphersComponent.reload(null, true);
|
|
|
|
} else {
|
2018-07-05 16:48:51 +02:00
|
|
|
await this.ciphersComponent.applyFilter(null);
|
|
|
|
}
|
2018-07-04 05:33:12 +02:00
|
|
|
this.clearFilters();
|
2021-08-27 14:50:58 +02:00
|
|
|
this.deleted = true;
|
2018-07-04 05:33:12 +02:00
|
|
|
this.go();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-08-16 04:26:39 +02:00
|
|
|
filterSearchText(searchText: string) {
|
2021-08-27 14:50:58 +02:00
|
|
|
this.ciphersComponent.searchText = searchText;
|
2018-08-16 04:26:39 +02:00
|
|
|
this.ciphersComponent.search(200);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async editCipherAttachments(cipher: CipherView) {
|
2021-10-05 18:12:44 +02:00
|
|
|
if (this.organization.maxStorageGb == null || this.organization.maxStorageGb === 0) {
|
2021-08-27 14:50:58 +02:00
|
|
|
this.messagingService.send("upgradeOrganization", { organizationId: cipher.organizationId });
|
|
|
|
return;
|
2018-07-05 18:56:58 +02:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
let madeAttachmentChanges = false;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
const [modal] = await this.modalService.openViewRef(
|
|
|
|
AttachmentsComponent,
|
2018-10-22 22:46:48 +02:00
|
|
|
this.attachmentsModalRef,
|
2021-08-27 14:50:58 +02:00
|
|
|
(comp) => {
|
2018-10-22 22:46:48 +02:00
|
|
|
comp.organization = this.organization;
|
|
|
|
comp.cipherId = cipher.id;
|
2018-07-05 15:42:50 +02:00
|
|
|
comp.onUploadedAttachment.subscribe(() => (madeAttachmentChanges = true));
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onDeletedAttachment.subscribe(() => (madeAttachmentChanges = true));
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
modal.onClosed.subscribe(async () => {
|
2018-07-05 16:48:51 +02:00
|
|
|
if (madeAttachmentChanges) {
|
2018-07-05 15:42:50 +02:00
|
|
|
await this.ciphersComponent.refresh();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-07-05 15:42:50 +02:00
|
|
|
madeAttachmentChanges = false;
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async editCipherCollections(cipher: CipherView) {
|
2018-07-05 15:42:50 +02:00
|
|
|
const [modal] = await this.modalService.openViewRef(
|
2021-08-27 14:50:58 +02:00
|
|
|
CollectionsComponent,
|
|
|
|
this.collectionsModalRef,
|
|
|
|
(comp) => {
|
2021-10-05 18:12:44 +02:00
|
|
|
if (this.organization.canEditAnyCollection) {
|
2021-02-03 18:41:33 +01:00
|
|
|
comp.collectionIds = cipher.collectionIds;
|
|
|
|
comp.collections = this.groupingsComponent.collections.filter((c) => !c.readOnly);
|
2018-10-22 22:46:48 +02:00
|
|
|
}
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.organization = this.organization;
|
|
|
|
comp.cipherId = cipher.id;
|
|
|
|
comp.onSavedCollections.subscribe(async () => {
|
|
|
|
modal.close();
|
|
|
|
await this.ciphersComponent.refresh();
|
2018-07-05 15:42:50 +02:00
|
|
|
});
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-05 15:42:50 +02:00
|
|
|
async addCipher() {
|
2021-08-27 14:50:58 +02:00
|
|
|
const component = await this.editCipher(null);
|
2020-02-10 20:03:36 +01:00
|
|
|
component.organizationId = this.organization.id;
|
2018-07-04 05:33:12 +02:00
|
|
|
component.type = this.type;
|
2021-10-05 18:12:44 +02:00
|
|
|
if (this.organization.canEditAnyCollection) {
|
2018-07-05 15:42:50 +02:00
|
|
|
component.collections = this.groupingsComponent.collections.filter((c) => !c.readOnly);
|
|
|
|
}
|
2021-10-05 18:12:44 +02:00
|
|
|
if (this.collectionId != null) {
|
2020-02-10 20:03:36 +01:00
|
|
|
component.collectionIds = [this.collectionId];
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-07-11 21:22:55 +02:00
|
|
|
async editCipher(cipher: CipherView) {
|
2021-08-27 14:50:58 +02:00
|
|
|
const [modal, childComponent] = await this.modalService.openViewRef(
|
|
|
|
AddEditComponent,
|
|
|
|
this.cipherAddEditModalRef,
|
|
|
|
(comp) => {
|
|
|
|
comp.organization = this.organization;
|
|
|
|
comp.cipherId = cipher == null ? null : cipher.id;
|
|
|
|
comp.onSavedCipher.subscribe(async (c: CipherView) => {
|
|
|
|
modal.close();
|
|
|
|
await this.ciphersComponent.refresh();
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onDeletedCipher.subscribe(async (c: CipherView) => {
|
|
|
|
modal.close();
|
|
|
|
await this.ciphersComponent.refresh();
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.onRestoredCipher.subscribe(async (c: CipherView) => {
|
|
|
|
modal.close();
|
|
|
|
await this.ciphersComponent.refresh();
|
2018-07-11 21:22:55 +02:00
|
|
|
});
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
return childComponent;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async cloneCipher(cipher: CipherView) {
|
|
|
|
const component = await this.editCipher(cipher);
|
2020-02-10 20:03:36 +01:00
|
|
|
component.cloneMode = true;
|
|
|
|
component.organizationId = this.organization.id;
|
2021-10-05 18:12:44 +02:00
|
|
|
if (this.organization.canEditAnyCollection) {
|
2021-02-03 18:41:33 +01:00
|
|
|
component.collections = this.groupingsComponent.collections.filter((c) => !c.readOnly);
|
2018-07-11 21:22:55 +02:00
|
|
|
}
|
2020-02-10 20:03:36 +01:00
|
|
|
// Regardless of Admin state, the collection Ids need to passed manually as they are not assigned value
|
|
|
|
// in the add-edit componenet
|
2021-08-27 14:50:58 +02:00
|
|
|
component.collectionIds = cipher.collectionIds;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async viewEvents(cipher: CipherView) {
|
|
|
|
await this.modalService.openViewRef(EntityEventsComponent, this.eventsModalRef, (comp) => {
|
|
|
|
comp.name = cipher.name;
|
2020-02-10 20:03:36 +01:00
|
|
|
comp.organizationId = this.organization.id;
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.entityId = cipher.id;
|
2018-10-22 22:46:48 +02:00
|
|
|
comp.showUser = true;
|
2021-08-27 14:50:58 +02:00
|
|
|
comp.entity = "cipher";
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-04 05:33:12 +02:00
|
|
|
private clearFilters() {
|
|
|
|
this.collectionId = null;
|
|
|
|
this.type = null;
|
2020-04-08 22:48:30 +02:00
|
|
|
this.deleted = false;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
|
2018-07-04 05:33:12 +02:00
|
|
|
private go(queryParams: any = null) {
|
|
|
|
if (queryParams == null) {
|
|
|
|
queryParams = {
|
|
|
|
type: this.type,
|
|
|
|
collectionId: this.collectionId,
|
2020-04-08 22:48:30 +02:00
|
|
|
deleted: this.deleted ? true : null,
|
2021-12-17 15:57:11 +01:00
|
|
|
};
|
2018-07-04 05:33:12 +02:00
|
|
|
}
|
|
|
|
|
2018-11-30 16:28:46 +01:00
|
|
|
this.router.navigate([], {
|
|
|
|
relativeTo: this.route,
|
|
|
|
queryParams: queryParams,
|
|
|
|
replaceUrl: true,
|
|
|
|
});
|
2018-07-04 05:33:12 +02:00
|
|
|
}
|
2018-07-03 18:34:20 +02:00
|
|
|
}
|