diff --git a/src/importers/aviraCsvImporter.ts b/src/importers/aviraCsvImporter.ts index bb10ad3927..15f9ddf491 100644 --- a/src/importers/aviraCsvImporter.ts +++ b/src/importers/aviraCsvImporter.ts @@ -10,6 +10,10 @@ import { CipherType } from '../enums/cipherType'; export class AviraCsvImporter extends BaseImporter implements Importer { parse(data: string): ImportResult { + if (this.organization) { + throw new Error('Organization import not supported.'); + } + const result = new ImportResult(); const results = this.parseCsv(data, true); if (results == null) { diff --git a/src/importers/baseImporter.ts b/src/importers/baseImporter.ts index d995d71221..009a7ccdc2 100644 --- a/src/importers/baseImporter.ts +++ b/src/importers/baseImporter.ts @@ -8,6 +8,8 @@ import { LoginUriView } from '../models/view/loginUriView'; import { Utils } from '../misc/utils'; export abstract class BaseImporter { + organization = false; + protected passwordFieldNames = [ 'password', 'pass word', 'passphrase', 'pass phrase', 'pass', 'code', 'code word', 'codeword', diff --git a/src/importers/bitwardenCsvImporter.ts b/src/importers/bitwardenCsvImporter.ts index acfdc3d1ed..29d83e70cb 100644 --- a/src/importers/bitwardenCsvImporter.ts +++ b/src/importers/bitwardenCsvImporter.ts @@ -15,7 +15,7 @@ import { FieldType } from '../enums/fieldType'; import { SecureNoteType } from '../enums/secureNoteType'; export class BitwardenCsvImporter extends BaseImporter implements Importer { - parse(data: string, organization = false): ImportResult { + parse(data: string): ImportResult { const result = new ImportResult(); const results = this.parseCsv(data, true); if (results == null) { @@ -24,7 +24,7 @@ export class BitwardenCsvImporter extends BaseImporter implements Importer { } results.forEach((value) => { - if (organization && !this.isNullOrWhitespace(value.collections)) { + if (this.organization && !this.isNullOrWhitespace(value.collections)) { const collections = (value.collections as string).split(','); collections.forEach((col) => { let addCollection = true; @@ -46,9 +46,9 @@ export class BitwardenCsvImporter extends BaseImporter implements Importer { result.collectionRelationships.set(result.ciphers.length, collectionIndex); }); - } else if (!organization) { + } else if (!this.organization) { let folderIndex = result.folders.length; - const hasFolder = !organization && !this.isNullOrWhitespace(value.folder); + const hasFolder = !this.organization && !this.isNullOrWhitespace(value.folder); let addFolder = hasFolder; if (hasFolder) { @@ -73,7 +73,7 @@ export class BitwardenCsvImporter extends BaseImporter implements Importer { } const cipher = new CipherView(); - cipher.favorite = !organization && this.getValueOrDefault(value.favorite, '0') !== '0' ? true : false; + cipher.favorite = !this.organization && this.getValueOrDefault(value.favorite, '0') !== '0' ? true : false; cipher.type = CipherType.Login; cipher.notes = this.getValueOrDefault(value.notes); cipher.name = this.getValueOrDefault(value.name, '--'); diff --git a/src/importers/blurCsvImporter.ts b/src/importers/blurCsvImporter.ts index 33620181b5..efe91de808 100644 --- a/src/importers/blurCsvImporter.ts +++ b/src/importers/blurCsvImporter.ts @@ -10,6 +10,10 @@ import { CipherType } from '../enums/cipherType'; export class BlurCsvImporter extends BaseImporter implements Importer { parse(data: string): ImportResult { + if (this.organization) { + throw new Error('Organization import not supported.'); + } + const result = new ImportResult(); const results = this.parseCsv(data, true); if (results == null) { diff --git a/src/importers/importer.ts b/src/importers/importer.ts index 78f838882f..fdd5c0c45d 100644 --- a/src/importers/importer.ts +++ b/src/importers/importer.ts @@ -1,5 +1,7 @@ import { ImportResult } from '../models/domain/importResult'; export interface Importer { - parse(data: string, organization?: boolean): ImportResult; + organization: boolean; + + parse(data: string): ImportResult; } diff --git a/src/importers/keepassxCsvImporter.ts b/src/importers/keepassxCsvImporter.ts index 610351fd09..59325efe9d 100644 --- a/src/importers/keepassxCsvImporter.ts +++ b/src/importers/keepassxCsvImporter.ts @@ -11,6 +11,10 @@ import { CipherType } from '../enums/cipherType'; export class KeePassXCsvImporter extends BaseImporter implements Importer { parse(data: string): ImportResult { + if (this.organization) { + throw new Error('Organization import not supported.'); + } + const result = new ImportResult(); const results = this.parseCsv(data, true); if (results == null) { diff --git a/src/importers/lastpassCsvImporter.ts b/src/importers/lastpassCsvImporter.ts index 0eba428ebc..fd9d9f1b94 100644 --- a/src/importers/lastpassCsvImporter.ts +++ b/src/importers/lastpassCsvImporter.ts @@ -14,7 +14,7 @@ import { CipherType } from '../enums/cipherType'; import { SecureNoteType } from '../enums/secureNoteType'; export class LastPassCsvImporter extends BaseImporter implements Importer { - parse(data: string, organization = false): ImportResult { + parse(data: string): ImportResult { const result = new ImportResult(); const results = this.parseCsv(data, true); if (results == null) { @@ -38,7 +38,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer { } } - const cipher = this.buildBaseCipher(value, organization); + const cipher = this.buildBaseCipher(value); if (cipher.name === '--' && results.length > 2 && index >= (results.length - 2)) { // LastPass file traditionally has two empty lines at the end return; @@ -60,7 +60,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer { cipher.notes = this.getValueOrDefault(value.notes); if (!this.isNullOrWhitespace(value.ccnum)) { // there is a card on this identity too - const cardCipher = this.buildBaseCipher(value, organization); + const cardCipher = this.buildBaseCipher(value); cardCipher.identity = null; cardCipher.type = CipherType.Card; cardCipher.card = this.parseCard(value); @@ -80,7 +80,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer { } }); - if (organization) { + if (this.organization) { this.moveFoldersToCollections(result); } @@ -88,7 +88,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer { return result; } - private buildBaseCipher(value: any, organization: boolean) { + private buildBaseCipher(value: any) { const cipher = new CipherView(); if (value.hasOwnProperty('profilename') && value.hasOwnProperty('profilelanguage')) { // form fill @@ -104,7 +104,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer { } } else { // site or secure note - cipher.favorite = !organization && this.getValueOrDefault(value.fav, '0') === '1'; + cipher.favorite = !this.organization && this.getValueOrDefault(value.fav, '0') === '1'; cipher.name = this.getValueOrDefault(value.name, '--'); cipher.type = value.url === 'http://sn' ? CipherType.SecureNote : CipherType.Login; }