Changeset 41657
- Timestamp:
- 10/01/2017 01:06:43 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/wp-api.js
r41553 r41657 771 771 /** @lends WPApiBaseModel.prototype */ 772 772 { 773 initialize: function( attributes, options ) { 774 775 /** 776 * Determine if a model requires ?force=true to actually delete them. 777 */ 778 if ( 779 ! _.isEmpty( 780 _.filter( 781 this.endpoints, 782 function( endpoint ) { 783 return ( 784 785 // Does the method support DELETE? 786 'DELETE' === endpoint.methods[0] && 787 788 // Exclude models that support trash (Post, Page). 789 ( 790 ! _.isUndefined( endpoint.args.force ) && 791 ! _.isUndefined( endpoint.args.force.description ) && 792 'Whether to bypass trash and force deletion.' !== endpoint.args.force.description 793 ) 794 ); 795 } 796 ) 797 ) 798 ) { 799 this.requireForceForDelete = true; 800 } 801 }, 802 773 803 /** 774 804 * Set nonce header before every Backbone sync. … … 1267 1297 methods: modelRoute.route.methods, 1268 1298 1269 initialize: function( attributes, options ) { 1270 wp.api.WPApiBaseModel.prototype.initialize.call( this, attributes, options ); 1271 1272 /** 1273 * Posts and pages support trashing, other types don't support a trash 1274 * and require that you pass ?force=true to actually delete them. 1275 * 1276 * @todo we should be getting trashability from the Schema, not hard coding types here. 1277 */ 1278 if ( 1279 'Posts' !== this.name && 1280 'Pages' !== this.name && 1281 _.includes( this.methods, 'DELETE' ) 1282 ) { 1283 this.requireForceForDelete = true; 1284 } 1285 } 1299 // Include the array of route endpoints for easy reference. 1300 endpoints: modelRoute.route.endpoints 1286 1301 } ); 1287 1302 } else { … … 1318 1333 1319 1334 // Include the array of route methods for easy reference. 1320 methods: modelRoute.route.methods 1335 methods: modelRoute.route.methods, 1336 1337 // Include the array of route endpoints for easy reference. 1338 endpoints: modelRoute.route.endpoints 1321 1339 } ); 1322 1340 } -
trunk/tests/qunit/wp-includes/js/wp-api.js
r41334 r41657 344 344 }); 345 345 346 // Test that models have the correct requireForceForDelete setting. 347 var modelsThatNeedrequireForceForDelete = [ 348 { name: 'Category', expect: true }, 349 { name: 'Comment', expect: undefined }, 350 { name: 'Media', expect: undefined }, 351 { name: 'Page', expect: undefined }, 352 { name: 'PageRevision', expect: true }, 353 { name: 'Post', expect: undefined }, 354 { name: 'PostRevision', expect: true }, 355 { name: 'Status', expect: undefined }, 356 { name: 'Tag', expect: true }, 357 { name: 'Taxonomy', expect: undefined }, 358 { name: 'Type', expect: undefined }, 359 { name: 'User', expect: true } 360 ]; 361 362 _.each( modelsThatNeedrequireForceForDelete, function( model ) { 363 QUnit.test( 'Test requireForceForDelete is correct for ' + model.name, function( assert ) { 364 var done = assert.async(); 365 assert.expect( 1 ); 366 wp.api.loadPromise.done( function() { 367 368 // Instantiate the model. 369 var theModel = new wp.api.models[ model.name ](); 370 371 // Verify the model's requireForceForDelete is set as expected. 372 assert.equal( 373 theModel.requireForceForDelete, 374 model.expect, 375 'wp.api.models.' + model.name + '.requireForceForDelete should be ' + model.expect + '.' 376 ); 377 378 // Trigger Qunit async completion. 379 done(); 380 } ); 381 } ); 382 } ); 383 346 384 } )( window.QUnit );
Note: See TracChangeset
for help on using the changeset viewer.