2017-11-01 19:46:15 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-11-21 04:58:53 +00:00
|
|
|
const constants = require('../libs/constants');
|
|
|
|
|
2017-10-29 21:04:13 +00:00
|
|
|
module.exports = {
|
2017-11-21 05:21:32 +00:00
|
|
|
removeKeysFromDict: function(dict, keys){
|
|
|
|
for(var i=0; i<keys.length; i++){
|
|
|
|
var curr_key = keys[i];
|
|
|
|
if( dict.hasOwnProperty(curr_key) ){
|
|
|
|
delete dict[curr_key];
|
2017-10-29 21:04:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-21 05:21:32 +00:00
|
|
|
},
|
|
|
|
removeSensitiveModelData: function(type, object){
|
2017-10-29 21:04:13 +00:00
|
|
|
switch(type){
|
|
|
|
case 'private_form':
|
2017-11-21 05:21:32 +00:00
|
|
|
this.this.removeKeysFromDict(object, constants.privateFields[type]);
|
2017-10-29 21:04:13 +00:00
|
|
|
if(object.admin){
|
2017-11-21 05:21:32 +00:00
|
|
|
this.removeKeysFromDict(object.admin, constants.privateFields.private_user);
|
2017-10-29 21:04:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'public_form':
|
2017-11-21 05:21:32 +00:00
|
|
|
this.removeKeysFromDict(object, constants.privateFields[type]);
|
2017-10-29 21:04:13 +00:00
|
|
|
if(object.admin){
|
2017-11-21 05:21:32 +00:00
|
|
|
this.removeKeysFromDict(object.admin, constants.privateFields.public_user);
|
2017-10-29 21:04:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-11-21 04:58:53 +00:00
|
|
|
if(constants.privateFields.hasOwnProperty(type)){
|
2017-11-21 05:21:32 +00:00
|
|
|
this.removeKeysFromDict(object, constants.privateFields[type]);
|
2017-10-29 21:04:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
2017-11-01 19:46:15 +00:00
|
|
|
};
|