1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

move to organization property instead of param

This commit is contained in:
Kyle Spearrin 2018-07-05 19:00:00 -04:00
parent 56cf068acd
commit ed93fa9ea3
7 changed files with 28 additions and 12 deletions

View File

@ -10,6 +10,10 @@ import { CipherType } from '../enums/cipherType';
export class AviraCsvImporter extends BaseImporter implements Importer { export class AviraCsvImporter extends BaseImporter implements Importer {
parse(data: string): ImportResult { parse(data: string): ImportResult {
if (this.organization) {
throw new Error('Organization import not supported.');
}
const result = new ImportResult(); const result = new ImportResult();
const results = this.parseCsv(data, true); const results = this.parseCsv(data, true);
if (results == null) { if (results == null) {

View File

@ -8,6 +8,8 @@ import { LoginUriView } from '../models/view/loginUriView';
import { Utils } from '../misc/utils'; import { Utils } from '../misc/utils';
export abstract class BaseImporter { export abstract class BaseImporter {
organization = false;
protected passwordFieldNames = [ protected passwordFieldNames = [
'password', 'pass word', 'passphrase', 'pass phrase', 'password', 'pass word', 'passphrase', 'pass phrase',
'pass', 'code', 'code word', 'codeword', 'pass', 'code', 'code word', 'codeword',

View File

@ -15,7 +15,7 @@ import { FieldType } from '../enums/fieldType';
import { SecureNoteType } from '../enums/secureNoteType'; import { SecureNoteType } from '../enums/secureNoteType';
export class BitwardenCsvImporter extends BaseImporter implements Importer { export class BitwardenCsvImporter extends BaseImporter implements Importer {
parse(data: string, organization = false): ImportResult { parse(data: string): ImportResult {
const result = new ImportResult(); const result = new ImportResult();
const results = this.parseCsv(data, true); const results = this.parseCsv(data, true);
if (results == null) { if (results == null) {
@ -24,7 +24,7 @@ export class BitwardenCsvImporter extends BaseImporter implements Importer {
} }
results.forEach((value) => { results.forEach((value) => {
if (organization && !this.isNullOrWhitespace(value.collections)) { if (this.organization && !this.isNullOrWhitespace(value.collections)) {
const collections = (value.collections as string).split(','); const collections = (value.collections as string).split(',');
collections.forEach((col) => { collections.forEach((col) => {
let addCollection = true; let addCollection = true;
@ -46,9 +46,9 @@ export class BitwardenCsvImporter extends BaseImporter implements Importer {
result.collectionRelationships.set(result.ciphers.length, collectionIndex); result.collectionRelationships.set(result.ciphers.length, collectionIndex);
}); });
} else if (!organization) { } else if (!this.organization) {
let folderIndex = result.folders.length; let folderIndex = result.folders.length;
const hasFolder = !organization && !this.isNullOrWhitespace(value.folder); const hasFolder = !this.organization && !this.isNullOrWhitespace(value.folder);
let addFolder = hasFolder; let addFolder = hasFolder;
if (hasFolder) { if (hasFolder) {
@ -73,7 +73,7 @@ export class BitwardenCsvImporter extends BaseImporter implements Importer {
} }
const cipher = new CipherView(); 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.type = CipherType.Login;
cipher.notes = this.getValueOrDefault(value.notes); cipher.notes = this.getValueOrDefault(value.notes);
cipher.name = this.getValueOrDefault(value.name, '--'); cipher.name = this.getValueOrDefault(value.name, '--');

View File

@ -10,6 +10,10 @@ import { CipherType } from '../enums/cipherType';
export class BlurCsvImporter extends BaseImporter implements Importer { export class BlurCsvImporter extends BaseImporter implements Importer {
parse(data: string): ImportResult { parse(data: string): ImportResult {
if (this.organization) {
throw new Error('Organization import not supported.');
}
const result = new ImportResult(); const result = new ImportResult();
const results = this.parseCsv(data, true); const results = this.parseCsv(data, true);
if (results == null) { if (results == null) {

View File

@ -1,5 +1,7 @@
import { ImportResult } from '../models/domain/importResult'; import { ImportResult } from '../models/domain/importResult';
export interface Importer { export interface Importer {
parse(data: string, organization?: boolean): ImportResult; organization: boolean;
parse(data: string): ImportResult;
} }

View File

@ -11,6 +11,10 @@ import { CipherType } from '../enums/cipherType';
export class KeePassXCsvImporter extends BaseImporter implements Importer { export class KeePassXCsvImporter extends BaseImporter implements Importer {
parse(data: string): ImportResult { parse(data: string): ImportResult {
if (this.organization) {
throw new Error('Organization import not supported.');
}
const result = new ImportResult(); const result = new ImportResult();
const results = this.parseCsv(data, true); const results = this.parseCsv(data, true);
if (results == null) { if (results == null) {

View File

@ -14,7 +14,7 @@ import { CipherType } from '../enums/cipherType';
import { SecureNoteType } from '../enums/secureNoteType'; import { SecureNoteType } from '../enums/secureNoteType';
export class LastPassCsvImporter extends BaseImporter implements Importer { export class LastPassCsvImporter extends BaseImporter implements Importer {
parse(data: string, organization = false): ImportResult { parse(data: string): ImportResult {
const result = new ImportResult(); const result = new ImportResult();
const results = this.parseCsv(data, true); const results = this.parseCsv(data, true);
if (results == null) { 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)) { if (cipher.name === '--' && results.length > 2 && index >= (results.length - 2)) {
// LastPass file traditionally has two empty lines at the end // LastPass file traditionally has two empty lines at the end
return; return;
@ -60,7 +60,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
cipher.notes = this.getValueOrDefault(value.notes); cipher.notes = this.getValueOrDefault(value.notes);
if (!this.isNullOrWhitespace(value.ccnum)) { if (!this.isNullOrWhitespace(value.ccnum)) {
// there is a card on this identity too // there is a card on this identity too
const cardCipher = this.buildBaseCipher(value, organization); const cardCipher = this.buildBaseCipher(value);
cardCipher.identity = null; cardCipher.identity = null;
cardCipher.type = CipherType.Card; cardCipher.type = CipherType.Card;
cardCipher.card = this.parseCard(value); cardCipher.card = this.parseCard(value);
@ -80,7 +80,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
} }
}); });
if (organization) { if (this.organization) {
this.moveFoldersToCollections(result); this.moveFoldersToCollections(result);
} }
@ -88,7 +88,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
return result; return result;
} }
private buildBaseCipher(value: any, organization: boolean) { private buildBaseCipher(value: any) {
const cipher = new CipherView(); const cipher = new CipherView();
if (value.hasOwnProperty('profilename') && value.hasOwnProperty('profilelanguage')) { if (value.hasOwnProperty('profilename') && value.hasOwnProperty('profilelanguage')) {
// form fill // form fill
@ -104,7 +104,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
} }
} else { } else {
// site or secure note // 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.name = this.getValueOrDefault(value.name, '--');
cipher.type = value.url === 'http://sn' ? CipherType.SecureNote : CipherType.Login; cipher.type = value.url === 'http://sn' ? CipherType.SecureNote : CipherType.Login;
} }