Fix issues with defect custom field data

Signed-off-by: Marius David Wieschollek's avatarMarius David Wieschollek <passwords.public@mdns.eu>
parent 71c19da1
......@@ -3,7 +3,7 @@ import ObjectMerger from "../Utility/ObjectMerger";
export default class BasicClassLoader {
constructor(classes = {}) {
this._classes = ObjectMerger.merge(this._getDefaultClasses(), classes);
this._classes = Object.assign(this._getDefaultClasses(), classes);
this._instances = {};
}
......
......@@ -64,6 +64,8 @@ import ConfigurationError from "../Exception/ConfigruationError";
import MissingEncryptionKeyError from "../Exception/Encryption/MissingEncryptionKeyError";
import InvalidEncryptedTextLength from "../Exception/Encryption/InvalidEncryptedTextLength";
import HashService from "../Services/HashService";
import Logger from "../Logger/Logger";
import DefectField from "../Model/CustomField/DefectField";
export default class DefaultClassLoader extends BasicClassLoader {
......@@ -102,6 +104,7 @@ export default class DefaultClassLoader extends BasicClassLoader {
'model.secretField': SecretField,
'model.textField' : TextField,
'model.urlField' : UrlField,
'model.defectField': DefectField,
'model.setting' : Setting,
'network.request' : ApiRequest,
......@@ -120,10 +123,12 @@ export default class DefaultClassLoader extends BasicClassLoader {
'keychain.csev1': (k, p) => { return new CSEv1Keychain(this.getInstance('classes'), k, p); },
'service.hash' : () => { return new HashService(this.getInstance('classes')); },
'service.hash' : () => { return new HashService(this.getInstance('classes')); },
'service.model' : () => { return new ModelService(this.getInstance('classes')); },
'service.password': () => { return new PasswordService(this.getInstance('client')); },
'logger': Logger,
'cache.cache': Cache,
'state.boolean': BooleanState,
......
......@@ -65,6 +65,13 @@ export default class BasicPasswordsClient {
return this._server;
}
/**
* @returns {Logger}
*/
getLogger() {
return this._classes.getInstance('logger');
}
/**
* @returns {Boolean}
*/
......
export default class CustomFieldConverter {
/**
* @param {BasicPasswordsClient} api
* @param {BasicPasswordsClient} client
*/
constructor(api) {
this._api = api;
constructor(client) {
this._client = client;
}
/**
......@@ -31,9 +31,14 @@ export default class CustomFieldConverter {
* @api
*/
fromObject(object) {
if(!object.hasOwnProperty('type') || object.type === null) {
this._client.getLogger().warning('Ignoring invalid custom field data', {field: object});
this._client.getClass(`model.defectField`, {label:'##ERROR##', value:JSON.stringify(object)})
}
let type = object.type;
return this._api.getClass(`model.${type}Field`, object);
return this._client.getClass(`model.${type}Field`, object);
}
/**
......@@ -48,7 +53,7 @@ export default class CustomFieldConverter {
fields.push(this.fromObject(field));
}
return this._api.getClass('collection.field', fields);
return this._client.getClass('collection.field', fields);
}
/**
......
export default class Logger {
/**
* @returns {Number}
*/
get logLevel() {
return this._logLevel;
}
/**
* @param {Number} value
*/
set logLevel(value) {
this._logLevel = value;
}
/**
* @param {Number} [logLevel=0]
*/
constructor(logLevel = 0) {
this._logLevel = logLevel;
}
/**
* @param {String} message
* @param {Object} [context={}]
*/
debug(message, context = {}) {
if(this._logLevel > 0) return;
console.debug(message, context);
}
/**
* @param {String} message
* @param {Object} [context={}]
*/
info(message, context = {}) {
if(this._logLevel > 1) return;
console.info(message, context);
}
/**
* @param {String} message
* @param {Object} [context={}]
*/
log(message, context = {}) {
if(this._logLevel > 2) return;
console.log(message, context);
}
/**
* @param {String} message
* @param {Object} [context={}]
*/
warning(message, context = {}) {
if(this._logLevel > 3) return;
console.warn(message, context);
}
/**
* @param {String} message
* @param {Object} [context={}]
*/
error(message, context = {}) {
if(this._logLevel > 4) return;
console.error(message, context);
}
}
\ No newline at end of file
import AbstractField from './AbstractField';
import Properties from '../../Configuration/TextField.json';
export default class DefectField extends AbstractField {
/**
*
* @param {object} data
*/
constructor(data) {
data.type = 'defect';
super(Properties, data);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment