Update Object.prototype.hasOwnProperty.call to lodash.has

This commit is contained in:
Abdón Rodríguez Davila 2019-08-23 14:13:19 +02:00
parent fa4d792d04
commit f04f372442
15 changed files with 67 additions and 65 deletions

View File

@ -480,7 +480,7 @@ module.exports = function(strapi) {
_.keyBy(
_.filter(definition.attributes, (value, key) => {
if (
Object.prototype.hasOwnProperty.call(value, 'columnName') &&
_.has(value, 'columnName') &&
!_.isEmpty(value.columnName) &&
value.columnName !== key
) {
@ -576,9 +576,9 @@ module.exports = function(strapi) {
.attributes,
details => {
if (
Object.prototype.hasOwnProperty.call(details, 'model') &&
_.has(details, 'model') &&
details.model === model &&
Object.prototype.hasOwnProperty.call(details, 'via') &&
_.has(details, 'via') &&
details.via === name
) {
return details;
@ -589,9 +589,9 @@ module.exports = function(strapi) {
strapi.models[details.model].attributes,
details => {
if (
Object.prototype.hasOwnProperty.call(details, 'model') &&
_.has(details, 'model') &&
details.model === model &&
Object.prototype.hasOwnProperty.call(details, 'via') &&
_.has(details, 'via') &&
details.via === name
) {
return details;

View File

@ -21,7 +21,7 @@ module.exports = {
// This is not a Bookshelf collection, only the name.
if (_.isString(collectionIdentity) && !_.isUndefined(models)) {
const PK = _.findKey(_.get(models, collectionIdentity + '.attributes'), o => {
return Object.prototype.hasOwnProperty.call(o, 'primary');
return _.has(o, 'primary');
});
if (!_.isEmpty(PK)) {

View File

@ -27,7 +27,7 @@ module.exports = strapi => {
if (_.isPlainObject(views) && !_.isEmpty(views)) {
const opts = _.clone(views);
if (Object.prototype.hasOwnProperty.call(opts, 'default')) {
if (_.has(opts, 'default')) {
opts.extension = opts.default;
delete opts.default;
}

View File

@ -5,7 +5,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { get } from 'lodash';
import { get, has } from 'lodash';
import {
InputDate,
@ -36,7 +36,7 @@ class InputWithAutoFocus extends React.Component {
if (this.props.filterToFocus === this.props.index) {
return new Promise(resolve => {
setTimeout(() => {
if (Object.prototype.hasOwnProperty.call(this.inputEl, 'openCalendar')) {
if (has(this.inputEl, 'openCalendar')) {
this.inputEl.openCalendar();
} else {
this.inputEl.focus();

View File

@ -13,6 +13,7 @@ import {
capitalize,
findIndex,
get,
has,
isEmpty,
isUndefined,
toInteger,
@ -141,8 +142,8 @@ export class ListPage extends React.Component {
return Object.keys(attributes).filter(attr => {
return (
!Object.prototype.hasOwnProperty.call(attributes[attr], 'collection') &&
!Object.prototype.hasOwnProperty.call(attributes[attr], 'model')
!has(attributes[attr], 'collection') &&
!has(attributes[attr], 'model')
);
});
};

View File

@ -7,7 +7,7 @@ import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux';
import { createStructuredSelector } from 'reselect';
import { findIndex, get, isEmpty, upperFirst } from 'lodash';
import { findIndex, get, has, isEmpty, upperFirst } from 'lodash';
import cn from 'classnames';
import HTML5Backend from 'react-dnd-html5-backend';
import { DragDropContext } from 'react-dnd';
@ -191,8 +191,8 @@ class SettingPage extends React.PureComponent {
.filter(attr => {
return (
findIndex(this.getListDisplay(), ['name', attr]) === -1 &&
!Object.prototype.hasOwnProperty.call(attributes[attr], 'collection') &&
!Object.prototype.hasOwnProperty.call(attributes[attr], 'model')
!has(attributes[attr], 'collection') &&
!has(attributes[attr], 'model')
);
})
.map(attr => {

View File

@ -30,8 +30,8 @@ module.exports = async (ctx, next) => {
if (controller && action) {
// Redirect to specific controller.
if (
Object.prototype.hasOwnProperty.call(ctx.request.body, 'fields') &&
Object.prototype.hasOwnProperty.call(ctx.request.body, 'files')
_.has(ctx.request.body, 'fields') &&
_.has(ctx.request.body, 'files')
) {
let { files, fields } = ctx.request.body;

View File

@ -73,8 +73,8 @@ module.exports = {
add: async (params, values, source) => {
// Multipart/form-data.
if (
Object.prototype.hasOwnProperty.call(values, 'fields') &&
Object.prototype.hasOwnProperty.call(values, 'files')
_.has(values, 'fields') &&
_.has(values, 'files')
) {
// Silent recursive parser.
const parser = value => {
@ -138,8 +138,8 @@ module.exports = {
edit: async (params, values, source) => {
// Multipart/form-data.
if (
Object.prototype.hasOwnProperty.call(values, 'fields') &&
Object.prototype.hasOwnProperty.call(values, 'files')
_.has(values, 'fields') &&
_.has(values, 'files')
) {
// Silent recursive parser.
const parser = value => {

View File

@ -6,6 +6,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { has } from 'lodash';
import pluginId from '../../pluginId';
@ -49,7 +50,7 @@ class AttributesPickerModal extends React.Component {
const appPlugins = plugins;
return attributes.filter(attr => {
if (Object.prototype.hasOwnProperty.call(appPlugins, 'upload')) {
if (has(appPlugins, 'upload')) {
return true;
}

View File

@ -381,8 +381,8 @@ module.exports = {
(acc, curr) => {
const attribute = attributes[curr];
const isField =
!Object.prototype.hasOwnProperty.call(attribute, 'model') &&
!Object.prototype.hasOwnProperty.call(attribute, 'collection');
!_.has(attribute, 'model') &&
!_.has(attribute, 'collection');
if (attribute.required) {
acc.required.push(curr);
@ -1525,8 +1525,8 @@ module.exports = {
.map(attr => {
const attribute = modelAttributes[attr];
const isField =
!Object.prototype.hasOwnProperty.call(attribute, 'model') &&
!Object.prototype.hasOwnProperty.call(attribute, 'collection');
!_.has(attribute, 'model') &&
!_.has(attribute, 'collection');
if (!isField) {
const name = attribute.model || attribute.collection;
@ -1730,7 +1730,7 @@ module.exports = {
mergeComponents: (initObj, srcObj) => {
const cleanedObj = Object.keys(_.get(initObj, 'schemas', {})).reduce(
(acc, current) => {
const targetObj = Object.prototype.hasOwnProperty.call(_.get(srcObj, ['schemas'], {}), current)
const targetObj = _.has(_.get(srcObj, ['schemas'], {}), current)
? srcObj
: initObj;
@ -1750,7 +1750,7 @@ module.exports = {
mergePaths: function(initObj, srcObj) {
return Object.keys(initObj.paths).reduce((acc, current) => {
if (Object.prototype.hasOwnProperty.call(_.get(srcObj, ['paths'], {}), current)) {
if (_.has(_.get(srcObj, ['paths'], {}), current)) {
const verbs = Object.keys(initObj.paths[current]).reduce(
(acc1, curr) => {
const verb = this.mergeVerbObject(

View File

@ -15,7 +15,7 @@ module.exports = (api, controller) => {
throw new Error('Should be an object');
}
if (_.isObject(controller) && Object.prototype.hasOwnProperty.call(controller, 'identity')) {
if (_.isObject(controller) && _.has(controller, 'identity')) {
controller = controller.identity.toLowerCase();
} else if (_.isString(controller)) {
controller = controller.toLowerCase();

View File

@ -108,8 +108,8 @@ module.exports = {
}
if (
(Object.prototype.hasOwnProperty.call(association, 'collection') && association.collection === '*') ||
(Object.prototype.hasOwnProperty.call(association, 'model') && association.model === '*')
(_.has(association, 'collection') && association.collection === '*') ||
(_.has(association, 'model') && association.model === '*')
) {
if (association.model) {
types.current = 'morphToD';
@ -130,13 +130,13 @@ module.exports = {
// We have to find if they are a model linked to this key
_.forIn(allModels, model => {
_.forIn(model.attributes, attribute => {
if (Object.prototype.hasOwnProperty.call(attribute, 'via') && attribute.via === key && attribute.model === currentModelName) {
if (Object.prototype.hasOwnProperty.call(attribute, 'collection')) {
if (_.has(attribute, 'via') && attribute.via === key && attribute.model === currentModelName) {
if (_.has(attribute, 'collection')) {
types.other = 'collection';
// Break loop
return false;
} else if (Object.prototype.hasOwnProperty.call(attribute, 'model')) {
} else if (_.has(attribute, 'model')) {
types.other = 'model';
// Break loop
@ -145,7 +145,7 @@ module.exports = {
}
});
});
} else if (Object.prototype.hasOwnProperty.call(association, 'via') && Object.prototype.hasOwnProperty.call(association, 'collection')) {
} else if (_.has(association, 'via') && _.has(association, 'collection')) {
const relatedAttribute = models[association.collection].attributes[association.via];
if (!relatedAttribute) {
@ -159,23 +159,23 @@ module.exports = {
types.current = 'collection';
if (
Object.prototype.hasOwnProperty.call(relatedAttribute, 'collection') &&
_.has(relatedAttribute, 'collection') &&
relatedAttribute.collection !== '*' &&
Object.prototype.hasOwnProperty.call(relatedAttribute, 'via')
_.has(relatedAttribute, 'via')
) {
types.other = 'collection';
} else if (
Object.prototype.hasOwnProperty.call(relatedAttribute, 'collection') &&
_.has(relatedAttribute, 'collection') &&
relatedAttribute.collection !== '*' &&
!Object.prototype.hasOwnProperty.call(relatedAttribute, 'via')
!_.has(relatedAttribute, 'via')
) {
types.other = 'collectionD';
} else if (Object.prototype.hasOwnProperty.call(relatedAttribute, 'model') && relatedAttribute.model !== '*') {
} else if (_.has(relatedAttribute, 'model') && relatedAttribute.model !== '*') {
types.other = 'model';
} else if (Object.prototype.hasOwnProperty.call(relatedAttribute, 'collection') || Object.prototype.hasOwnProperty.call(relatedAttribute, 'model')) {
} else if (_.has(relatedAttribute, 'collection') || _.has(relatedAttribute, 'model')) {
types.other = 'morphTo';
}
} else if (Object.prototype.hasOwnProperty.call(association, 'via') && Object.prototype.hasOwnProperty.call(association, 'model')) {
} else if (_.has(association, 'via') && _.has(association, 'model')) {
types.current = 'modelD';
// We have to find if they are a model linked to this key
@ -183,30 +183,30 @@ module.exports = {
const attribute = model.attributes[association.via];
if (
Object.prototype.hasOwnProperty.call(attribute, 'via') &&
_.has(attribute, 'via') &&
attribute.via === key &&
Object.prototype.hasOwnProperty.call(attribute, 'collection') &&
_.has(attribute, 'collection') &&
attribute.collection !== '*'
) {
types.other = 'collection';
} else if (Object.prototype.hasOwnProperty.call(attribute, 'model') && attribute.model !== '*') {
} else if (_.has(attribute, 'model') && attribute.model !== '*') {
types.other = 'model';
} else if (Object.prototype.hasOwnProperty.call(attribute, 'collection') || Object.prototype.hasOwnProperty.call(attribute, 'model')) {
} else if (_.has(attribute, 'collection') || _.has(attribute, 'model')) {
types.other = 'morphTo';
}
} else if (Object.prototype.hasOwnProperty.call(association, 'model')) {
} else if (_.has(association, 'model')) {
types.current = 'model';
// We have to find if they are a model linked to this key
_.forIn(models, model => {
_.forIn(model.attributes, attribute => {
if (Object.prototype.hasOwnProperty.call(attribute, 'via') && attribute.via === key) {
if (Object.prototype.hasOwnProperty.call(attribute, 'collection')) {
if (_.has(attribute, 'via') && attribute.via === key) {
if (_.has(attribute, 'collection')) {
types.other = 'collection';
// Break loop
return false;
} else if (Object.prototype.hasOwnProperty.call(attribute, 'model')) {
} else if (_.has(attribute, 'model')) {
types.other = 'modelD';
// Break loop
@ -215,19 +215,19 @@ module.exports = {
}
});
});
} else if (Object.prototype.hasOwnProperty.call(association, 'collection')) {
} else if (_.has(association, 'collection')) {
types.current = 'collectionD';
// We have to find if they are a model linked to this key
_.forIn(models, model => {
_.forIn(model.attributes, attribute => {
if (Object.prototype.hasOwnProperty.call(attribute, 'via') && attribute.via === key) {
if (Object.prototype.hasOwnProperty.call(attribute, 'collection')) {
if (_.has(attribute, 'via') && attribute.via === key) {
if (_.has(attribute, 'collection')) {
types.other = 'collection';
// Break loop
return false;
} else if (Object.prototype.hasOwnProperty.call(attribute, 'model')) {
} else if (_.has(attribute, 'model')) {
types.other = 'modelD';
// Break loop
@ -268,14 +268,14 @@ module.exports = {
nature: 'oneMorphToOne',
verbose: 'belongsToMorph',
};
} else if (types.current === 'morphTo' && (types.other === 'model' || Object.prototype.hasOwnProperty.call(association, 'model'))) {
} else if (types.current === 'morphTo' && (types.other === 'model' || _.has(association, 'model'))) {
return {
nature: 'manyMorphToOne',
verbose: 'belongsToManyMorph',
};
} else if (
types.current === 'morphTo' &&
(types.other === 'collection' || Object.prototype.hasOwnProperty.call(association, 'collection'))
(types.other === 'collection' || _.has(association, 'collection'))
) {
return {
nature: 'manyMorphToMany',
@ -383,7 +383,7 @@ module.exports = {
}
// Exclude non-relational attribute
if (!Object.prototype.hasOwnProperty.call(association, 'collection') && !Object.prototype.hasOwnProperty.call(association, 'model')) {
if (!_.has(association, 'collection') && !_.has(association, 'model')) {
return undefined;
}
@ -399,7 +399,7 @@ module.exports = {
}
// Build associations object
if (Object.prototype.hasOwnProperty.call(association, 'collection') && association.collection !== '*') {
if (_.has(association, 'collection') && association.collection !== '*') {
const ast = {
alias: key,
type: 'collection',
@ -417,7 +417,7 @@ module.exports = {
}
definition.associations.push(ast);
} else if (Object.prototype.hasOwnProperty.call(association, 'model') && association.model !== '*') {
} else if (_.has(association, 'model') && association.model !== '*') {
definition.associations.push({
alias: key,
type: 'model',
@ -429,7 +429,7 @@ module.exports = {
plugin: association.plugin || undefined,
filter: details.filter,
});
} else if (Object.prototype.hasOwnProperty.call(association, 'collection') || Object.prototype.hasOwnProperty.call(association, 'model')) {
} else if (_.has(association, 'collection') || _.has(association, 'model')) {
const pluginsModels = Object.keys(strapi.plugins).reduce((acc, current) => {
Object.keys(strapi.plugins[current].models).forEach(entity => {
Object.keys(strapi.plugins[current].models[entity].attributes).forEach(attribute => {
@ -505,7 +505,7 @@ module.exports = {
}, {}),
);
if (!Object.prototype.hasOwnProperty.call(models, model)) {
if (!_.has(models, model)) {
return this.log.error(`The model ${model} can't be found.`);
}

View File

@ -258,7 +258,7 @@ module.exports = function(strapi) {
);
acc[current] = !_.isObject(currentSettings) ? {} : currentSettings;
if (!Object.prototype.hasOwnProperty.call(acc[current], 'enabled')) {
if (!_.has(acc[current], 'enabled')) {
strapi.log.warn(
`(middleware:${current}) wasn't loaded due to missing key \`enabled\` in the configuration`
);
@ -284,7 +284,7 @@ module.exports = function(strapi) {
acc[current] = !_.isObject(currentSettings) ? {} : currentSettings;
if (!Object.prototype.hasOwnProperty.call(acc[current], 'enabled')) {
if (!_.has(acc[current], 'enabled')) {
strapi.log.warn(
`(hook:${current}) wasn't loaded due to missing key \`enabled\` in the configuration`
);

View File

@ -56,7 +56,7 @@ module.exports = strapi => {
// Exclude routes with prefix.
const excludedRoutes = _.omitBy(
plugin.config.routes,
o => !Object.prototype.hasOwnProperty.call(o.config, 'prefix')
o => !_.has(o.config, 'prefix')
);
_.forEach(

View File

@ -24,7 +24,7 @@ module.exports = strapi => {
strapi.config.hooks.session.secretKeys;
if (
Object.prototype.hasOwnProperty.call(strapi.config.middleware.settings.session, 'client') &&
_.has(strapi.config.middleware.settings.session, 'client') &&
_.isString(strapi.config.middleware.settings.session.client) &&
strapi.config.middleware.settings.session.client !== 'cookie'
) {
@ -52,7 +52,7 @@ module.exports = strapi => {
});
}
} else if (
Object.prototype.hasOwnProperty.call(strapi.config.middleware.settings.session, 'client') &&
_.has(strapi.config.middleware.settings.session, 'client') &&
_.isString(strapi.config.middleware.settings.session.client) &&
strapi.config.middleware.settings.session.client === 'cookie'
) {