parent
2105c22ab1
commit
2fa5affd12
18
lib/dao.js
18
lib/dao.js
|
@ -1646,22 +1646,32 @@ function coerceArray(val) {
|
||||||
|
|
||||||
DataAccessObject._getHiddenProperties = function() {
|
DataAccessObject._getHiddenProperties = function() {
|
||||||
var settings = this.definition.settings || {};
|
var settings = this.definition.settings || {};
|
||||||
var result = settings.hiddenProperties || settings.hidden;
|
var result = settings.hiddenProperties || settings.hidden || [];
|
||||||
if (typeof result === 'string') {
|
if (typeof result === 'string') {
|
||||||
result = [result];
|
result = [result];
|
||||||
}
|
}
|
||||||
result = result || [];
|
if (Array.isArray(result)) {
|
||||||
return result;
|
return result;
|
||||||
|
} else {
|
||||||
|
// See https://github.com/strongloop/loopback-datasource-juggler/issues/1646
|
||||||
|
// `ModelBaseClass` normalize the properties to an object such as `{secret: true}`
|
||||||
|
return Object.keys(result);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
DataAccessObject._getProtectedProperties = function() {
|
DataAccessObject._getProtectedProperties = function() {
|
||||||
var settings = this.definition.settings || {};
|
var settings = this.definition.settings || {};
|
||||||
var result = settings.protectedProperties || settings.protected;
|
var result = settings.protectedProperties || settings.protected || [];
|
||||||
if (typeof result === 'string') {
|
if (typeof result === 'string') {
|
||||||
result = [result];
|
result = [result];
|
||||||
}
|
}
|
||||||
result = result || [];
|
if (Array.isArray(result)) {
|
||||||
return result;
|
return result;
|
||||||
|
} else {
|
||||||
|
// See https://github.com/strongloop/loopback-datasource-juggler/issues/1646
|
||||||
|
// `ModelBaseClass` normalize the properties to an object such as `{secret: true}`
|
||||||
|
return Object.keys(result);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
DataAccessObject._sanitize = function(query, options) {
|
DataAccessObject._sanitize = function(query, options) {
|
||||||
|
|
|
@ -551,7 +551,7 @@ ModelBaseClass.prototype.toObject = function(onlySchema, removeHidden, removePro
|
||||||
/**
|
/**
|
||||||
* Checks if property is protected.
|
* Checks if property is protected.
|
||||||
* @param {String} propertyName Property name
|
* @param {String} propertyName Property name
|
||||||
* @returns {Boolean} true or false if proptected or not.
|
* @returns {Boolean} true or false if protected or not.
|
||||||
*/
|
*/
|
||||||
ModelBaseClass.isProtectedProperty = function(propertyName) {
|
ModelBaseClass.isProtectedProperty = function(propertyName) {
|
||||||
var Model = this;
|
var Model = this;
|
||||||
|
|
|
@ -338,7 +338,9 @@ describe('ModelDefinition class', function() {
|
||||||
|
|
||||||
describe('hidden properties', function() {
|
describe('hidden properties', function() {
|
||||||
var Child;
|
var Child;
|
||||||
beforeEach(givenChildren);
|
|
||||||
|
describe('with hidden array', function() {
|
||||||
|
beforeEach(function() { givenChildren(); });
|
||||||
|
|
||||||
it('should be removed if used in where', function() {
|
it('should be removed if used in where', function() {
|
||||||
return Child.find({
|
return Child.find({
|
||||||
|
@ -351,13 +353,31 @@ describe('ModelDefinition class', function() {
|
||||||
where: {and: [{secret: 'guess'}]},
|
where: {and: [{secret: 'guess'}]},
|
||||||
}).then(assertHiddenPropertyIsIgnored);
|
}).then(assertHiddenPropertyIsIgnored);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with hidden object', function() {
|
||||||
|
beforeEach(function() { givenChildren({hiddenProperties: {secret: true}}); });
|
||||||
|
|
||||||
|
it('should be removed if used in where', function() {
|
||||||
|
return Child.find({
|
||||||
|
where: {secret: 'guess'},
|
||||||
|
}).then(assertHiddenPropertyIsIgnored);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be removed if used in where.and', function() {
|
||||||
|
return Child.find({
|
||||||
|
where: {and: [{secret: 'guess'}]},
|
||||||
|
}).then(assertHiddenPropertyIsIgnored);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create two children with a hidden property, one with a matching
|
* Create two children with a hidden property, one with a matching
|
||||||
* value, the other with a non-matching value
|
* value, the other with a non-matching value
|
||||||
*/
|
*/
|
||||||
function givenChildren() {
|
function givenChildren(hiddenProps) {
|
||||||
Child = memory.createModel('child', {}, {hidden: ['secret']});
|
hiddenProps = hiddenProps || {hidden: ['secret']};
|
||||||
|
Child = memory.createModel('child', {}, hiddenProps);
|
||||||
return Child.create([{
|
return Child.create([{
|
||||||
name: 'childA',
|
name: 'childA',
|
||||||
secret: 'secret',
|
secret: 'secret',
|
||||||
|
|
Loading…
Reference in New Issue