2018-04-06 05:49:04 +02:00
|
|
|
import { Location } from '@angular/common';
|
2018-10-23 16:29:05 +02:00
|
|
|
import { Component } from '@angular/core';
|
2018-04-06 05:49:04 +02:00
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
|
|
|
|
2021-10-14 23:58:59 +02:00
|
|
|
import { first } from 'rxjs/operators';
|
|
|
|
|
2020-06-12 17:01:08 +02:00
|
|
|
import { BrowserApi } from '../../browser/browserApi';
|
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { AuditService } from 'jslib-common/abstractions/audit.service';
|
|
|
|
import { CipherService } from 'jslib-common/abstractions/cipher.service';
|
|
|
|
import { CollectionService } from 'jslib-common/abstractions/collection.service';
|
|
|
|
import { EventService } from 'jslib-common/abstractions/event.service';
|
|
|
|
import { FolderService } from 'jslib-common/abstractions/folder.service';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
|
|
|
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
|
|
|
|
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
|
|
|
import { PolicyService } from 'jslib-common/abstractions/policy.service';
|
|
|
|
import { StateService } from 'jslib-common/abstractions/state.service';
|
|
|
|
import { StorageService } from 'jslib-common/abstractions/storage.service';
|
|
|
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
|
|
|
|
|
|
|
import { ConstantsService } from 'jslib-common/services/constants.service';
|
2021-02-04 21:23:12 +01:00
|
|
|
import { PopupUtilsService } from '../services/popup-utils.service';
|
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { LoginUriView } from 'jslib-common/models/view/loginUriView';
|
2020-06-12 17:01:08 +02:00
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { AddEditComponent as BaseAddEditComponent } from 'jslib-angular/components/add-edit.component';
|
2021-05-17 06:32:48 +02:00
|
|
|
|
2021-06-07 19:25:37 +02:00
|
|
|
import { CipherType } from 'jslib-common/enums/cipherType';
|
2018-04-06 05:49:04 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-vault-add-edit',
|
2018-04-06 17:48:45 +02:00
|
|
|
templateUrl: 'add-edit.component.html',
|
2018-04-06 05:49:04 +02:00
|
|
|
})
|
2018-10-23 16:29:05 +02:00
|
|
|
export class AddEditComponent extends BaseAddEditComponent {
|
2020-06-12 18:50:39 +02:00
|
|
|
currentUris: string[];
|
2018-07-25 05:23:44 +02:00
|
|
|
showAttachments = true;
|
2021-01-15 06:58:38 +01:00
|
|
|
openAttachmentsInPopup: boolean;
|
2021-05-17 05:46:39 +02:00
|
|
|
showAutoFillOnPageLoadOptions: boolean;
|
2018-04-14 20:56:30 +02:00
|
|
|
|
2018-04-06 05:49:04 +02:00
|
|
|
constructor(cipherService: CipherService, folderService: FolderService,
|
|
|
|
i18nService: I18nService, platformUtilsService: PlatformUtilsService,
|
2018-04-09 23:35:16 +02:00
|
|
|
auditService: AuditService, stateService: StateService,
|
2018-10-23 16:29:05 +02:00
|
|
|
userService: UserService, collectionService: CollectionService,
|
2019-01-03 16:22:55 +01:00
|
|
|
messagingService: MessagingService, private route: ActivatedRoute,
|
2019-07-12 16:41:14 +02:00
|
|
|
private router: Router, private location: Location,
|
2021-01-13 09:27:23 +01:00
|
|
|
eventService: EventService, policyService: PolicyService,
|
2021-05-17 05:46:39 +02:00
|
|
|
private popupUtilsService: PopupUtilsService, private storageService: StorageService) {
|
2018-10-23 16:29:05 +02:00
|
|
|
super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService,
|
2020-12-09 21:11:25 +01:00
|
|
|
userService, collectionService, messagingService, eventService, policyService);
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|
|
|
|
|
2018-10-23 16:29:05 +02:00
|
|
|
async ngOnInit() {
|
|
|
|
await super.ngOnInit();
|
2020-09-15 16:50:45 +02:00
|
|
|
|
2021-10-14 23:58:59 +02:00
|
|
|
this.route.queryParams.pipe(first()).subscribe(async params => {
|
2018-04-06 05:49:04 +02:00
|
|
|
if (params.cipherId) {
|
|
|
|
this.cipherId = params.cipherId;
|
|
|
|
}
|
2018-04-10 06:04:49 +02:00
|
|
|
if (params.folderId) {
|
|
|
|
this.folderId = params.folderId;
|
|
|
|
}
|
2018-10-30 13:56:38 +01:00
|
|
|
if (params.collectionId) {
|
2021-03-02 19:31:52 +01:00
|
|
|
const collection = this.writeableCollections.find(c => c.id === params.collectionId);
|
2019-05-10 20:10:40 +02:00
|
|
|
if (collection != null) {
|
|
|
|
this.collectionIds = [collection.id];
|
|
|
|
this.organizationId = collection.organizationId;
|
2018-10-30 13:56:38 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-10 06:04:49 +02:00
|
|
|
if (params.type) {
|
|
|
|
const type = parseInt(params.type, null);
|
|
|
|
this.type = type;
|
|
|
|
}
|
2018-04-06 05:49:04 +02:00
|
|
|
this.editMode = !params.cipherId;
|
2020-02-04 22:08:13 +01:00
|
|
|
|
|
|
|
if (params.cloneMode != null) {
|
2020-02-10 18:05:06 +01:00
|
|
|
this.cloneMode = params.cloneMode === 'true';
|
2020-02-04 22:08:13 +01:00
|
|
|
}
|
2018-04-06 05:49:04 +02:00
|
|
|
await this.load();
|
2018-04-10 06:04:49 +02:00
|
|
|
|
2020-02-19 21:00:37 +01:00
|
|
|
if (!this.editMode || this.cloneMode) {
|
2021-05-05 19:59:42 +02:00
|
|
|
if (!this.popupUtilsService.inPopout(window) && params.name &&
|
|
|
|
(this.cipher.name == null || this.cipher.name === '')) {
|
|
|
|
this.cipher.name = params.name;
|
2018-04-10 06:04:49 +02:00
|
|
|
}
|
2021-05-05 19:59:42 +02:00
|
|
|
if (!this.popupUtilsService.inPopout(window) && params.uri &&
|
|
|
|
(this.cipher.login.uris[0].uri == null || this.cipher.login.uris[0].uri === '')) {
|
|
|
|
this.cipher.login.uris[0].uri = params.uri;
|
2018-04-10 06:04:49 +02:00
|
|
|
}
|
|
|
|
}
|
2021-01-15 06:58:38 +01:00
|
|
|
|
|
|
|
this.openAttachmentsInPopup = this.popupUtilsService.inPopup(window);
|
2018-04-06 05:49:04 +02:00
|
|
|
});
|
2018-04-10 06:04:49 +02:00
|
|
|
|
2020-06-12 17:01:08 +02:00
|
|
|
if (!this.editMode) {
|
|
|
|
const tabs = await BrowserApi.tabsQuery({ windowType: 'normal' });
|
2020-06-12 18:50:39 +02:00
|
|
|
this.currentUris = tabs == null ? null :
|
2021-03-02 19:31:52 +01:00
|
|
|
tabs.filter(tab => tab.url != null && tab.url !== '').map(tab => tab.url);
|
2020-06-12 17:01:08 +02:00
|
|
|
}
|
|
|
|
|
2018-04-18 21:49:03 +02:00
|
|
|
window.setTimeout(() => {
|
2018-04-10 06:04:49 +02:00
|
|
|
if (!this.editMode) {
|
|
|
|
if (this.cipher.name != null && this.cipher.name !== '') {
|
|
|
|
document.getElementById('loginUsername').focus();
|
|
|
|
} else {
|
|
|
|
document.getElementById('name').focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 200);
|
2021-05-17 06:32:48 +02:00
|
|
|
}
|
2021-05-17 05:46:39 +02:00
|
|
|
|
2021-05-17 06:32:48 +02:00
|
|
|
async load() {
|
|
|
|
await super.load();
|
2021-05-17 05:46:39 +02:00
|
|
|
this.showAutoFillOnPageLoadOptions = this.cipher.type === CipherType.Login &&
|
|
|
|
await this.storageService.get<boolean>(ConstantsService.enableAutoFillOnPageLoadKey);
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|
|
|
|
|
2018-04-06 05:51:58 +02:00
|
|
|
async submit(): Promise<boolean> {
|
2018-04-06 05:49:04 +02:00
|
|
|
if (await super.submit()) {
|
2020-02-04 22:08:13 +01:00
|
|
|
if (this.cloneMode) {
|
|
|
|
this.router.navigate(['/tabs/vault']);
|
|
|
|
} else {
|
|
|
|
this.location.back();
|
|
|
|
}
|
2018-04-06 05:51:58 +02:00
|
|
|
return true;
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|
2018-04-06 05:51:58 +02:00
|
|
|
|
|
|
|
return false;
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|
|
|
|
|
2018-04-11 19:51:09 +02:00
|
|
|
attachments() {
|
|
|
|
super.attachments();
|
2021-01-13 09:27:23 +01:00
|
|
|
|
2021-01-15 06:58:38 +01:00
|
|
|
if (this.openAttachmentsInPopup) {
|
|
|
|
const destinationUrl = this.router.createUrlTree(['/attachments'], { queryParams: { cipherId: this.cipher.id } }).toString();
|
|
|
|
const currentBaseUrl = window.location.href.replace(this.router.url, '');
|
2021-01-13 09:27:23 +01:00
|
|
|
this.popupUtilsService.popOut(window, currentBaseUrl + destinationUrl);
|
|
|
|
} else {
|
|
|
|
this.router.navigate(['/attachments'], { queryParams: { cipherId: this.cipher.id } });
|
|
|
|
}
|
2018-04-11 19:51:09 +02:00
|
|
|
}
|
|
|
|
|
2018-10-23 15:25:44 +02:00
|
|
|
|
2018-10-23 18:16:27 +02:00
|
|
|
editCollections() {
|
2018-10-23 21:41:55 +02:00
|
|
|
super.editCollections();
|
2018-10-23 18:16:27 +02:00
|
|
|
if (this.cipher.organizationId != null) {
|
|
|
|
this.router.navigate(['/collections'], { queryParams: { cipherId: this.cipher.id } });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 05:49:04 +02:00
|
|
|
cancel() {
|
|
|
|
super.cancel();
|
|
|
|
this.location.back();
|
|
|
|
}
|
2018-04-09 23:35:16 +02:00
|
|
|
|
2018-04-10 20:20:03 +02:00
|
|
|
async generatePassword(): Promise<boolean> {
|
|
|
|
const confirmed = await super.generatePassword();
|
|
|
|
if (confirmed) {
|
2019-06-25 03:12:52 +02:00
|
|
|
this.stateService.save('addEditCipherInfo', {
|
|
|
|
cipher: this.cipher,
|
|
|
|
collectionIds: this.collections == null ? [] :
|
2021-03-02 19:31:52 +01:00
|
|
|
this.collections.filter(c => (c as any).checked).map(c => c.id),
|
2019-06-25 03:12:52 +02:00
|
|
|
});
|
2018-04-10 20:20:03 +02:00
|
|
|
this.router.navigate(['generator']);
|
|
|
|
}
|
|
|
|
return confirmed;
|
2018-04-09 23:35:16 +02:00
|
|
|
}
|
2018-04-11 22:23:05 +02:00
|
|
|
|
2018-04-12 04:33:32 +02:00
|
|
|
async delete(): Promise<boolean> {
|
|
|
|
const confirmed = await super.delete();
|
|
|
|
if (confirmed) {
|
2018-04-11 22:27:20 +02:00
|
|
|
this.router.navigate(['/tabs/vault']);
|
|
|
|
}
|
2018-04-12 04:33:32 +02:00
|
|
|
return confirmed;
|
2018-04-11 22:23:05 +02:00
|
|
|
}
|
2020-06-12 17:01:08 +02:00
|
|
|
|
|
|
|
toggleUriInput(uri: LoginUriView) {
|
|
|
|
const u = (uri as any);
|
2020-06-12 18:50:39 +02:00
|
|
|
u.showCurrentUris = !u.showCurrentUris;
|
2020-06-12 17:01:08 +02:00
|
|
|
}
|
2020-12-09 21:11:25 +01:00
|
|
|
|
|
|
|
allowOwnershipOptions(): boolean {
|
|
|
|
return (!this.editMode || this.cloneMode) && this.ownershipOptions
|
|
|
|
&& (this.ownershipOptions.length > 1 || !this.allowPersonal);
|
|
|
|
}
|
2018-04-06 05:49:04 +02:00
|
|
|
}
|