mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Updated base model to remove extraAllowedProperties
refs #9881 This is because when extending these methods, you need to know the contents of the extraAllowedProperties to replicate it in the subclass, breaking the principle of open/closed.
This commit is contained in:
parent
b913618c03
commit
b326cfaab7
1 changed files with 16 additions and 10 deletions
|
@ -498,12 +498,18 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||||
* @return {Object} Keys allowed in the `options` hash of every model's method.
|
* @return {Object} Keys allowed in the `options` hash of every model's method.
|
||||||
*/
|
*/
|
||||||
permittedOptions: function permittedOptions(methodName) {
|
permittedOptions: function permittedOptions(methodName) {
|
||||||
if (methodName === 'toJSON') {
|
const baseOptions = ['context', 'withRelated'];
|
||||||
return ['shallow', 'withRelated', 'context', 'columns', 'absolute_urls'];
|
const extraOptions = ['transacting', 'importing', 'forUpdate', 'migrating'];
|
||||||
}
|
|
||||||
|
|
||||||
// terms to whitelist for all methods.
|
switch (methodName) {
|
||||||
return ['context', 'withRelated', 'transacting', 'importing', 'forUpdate', 'migrating'];
|
case 'toJSON':
|
||||||
|
return baseOptions.concat('shallow', 'columns', 'absolute_urls');
|
||||||
|
case 'destroy':
|
||||||
|
case 'edit':
|
||||||
|
return baseOptions.concat(extraOptions, ['id']);
|
||||||
|
default:
|
||||||
|
return baseOptions.concat(extraOptions);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -753,9 +759,9 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||||
* @return {Promise(ghostBookshelf.Model)} Edited Model
|
* @return {Promise(ghostBookshelf.Model)} Edited Model
|
||||||
*/
|
*/
|
||||||
edit: function edit(data, unfilteredOptions) {
|
edit: function edit(data, unfilteredOptions) {
|
||||||
var options = this.filterOptions(unfilteredOptions, 'edit', {extraAllowedProperties: ['id']}),
|
const options = this.filterOptions(unfilteredOptions, 'edit');
|
||||||
id = options.id,
|
const id = options.id;
|
||||||
model = this.forge({id: id});
|
const model = this.forge({id: id});
|
||||||
|
|
||||||
data = this.filterData(data);
|
data = this.filterData(data);
|
||||||
|
|
||||||
|
@ -804,8 +810,8 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||||
* @return {Promise(ghostBookshelf.Model)} Empty Model
|
* @return {Promise(ghostBookshelf.Model)} Empty Model
|
||||||
*/
|
*/
|
||||||
destroy: function destroy(unfilteredOptions) {
|
destroy: function destroy(unfilteredOptions) {
|
||||||
var options = this.filterOptions(unfilteredOptions, 'destroy', {extraAllowedProperties: ['id']}),
|
const options = this.filterOptions(unfilteredOptions, 'destroy');
|
||||||
id = options.id;
|
const id = options.id;
|
||||||
|
|
||||||
// Fetch the object before destroying it, so that the changed data is available to events
|
// Fetch the object before destroying it, so that the changed data is available to events
|
||||||
return this.forge({id: id})
|
return this.forge({id: id})
|
||||||
|
|
Loading…
Add table
Reference in a new issue