mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
use new onlyAllow() method in baked code, to ensure 405 responses have required Allow header included
This commit is contained in:
parent
17ba713651
commit
27d83eedfe
2 changed files with 11 additions and 7 deletions
|
@ -47,10 +47,12 @@
|
|||
/**
|
||||
* <?php echo $admin ?>add method
|
||||
*
|
||||
* @throws MethodNotAllowedException
|
||||
* @return void
|
||||
*/
|
||||
public function <?php echo $admin ?>add() {
|
||||
if ($this->request->is('post')) {
|
||||
if ($this->request->data) {
|
||||
$this->request->onlyAllow('post');
|
||||
$this-><?php echo $currentModelName; ?>->create();
|
||||
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
|
@ -86,6 +88,7 @@
|
|||
/**
|
||||
* <?php echo $admin ?>edit method
|
||||
*
|
||||
* @throws MethodNotAllowedException
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
|
@ -95,7 +98,8 @@
|
|||
if (!$this-><?php echo $currentModelName; ?>->exists()) {
|
||||
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
||||
}
|
||||
if ($this->request->is('post') || $this->request->is('put')) {
|
||||
if ($this->request->data) {
|
||||
$this->request->onlyAllow('post', 'put');
|
||||
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
|
||||
|
@ -137,9 +141,7 @@
|
|||
* @return void
|
||||
*/
|
||||
public function <?php echo $admin; ?>delete($id = null) {
|
||||
if (!$this->request->is('post')) {
|
||||
throw new MethodNotAllowedException();
|
||||
}
|
||||
$this->request->onlyAllow('post', 'delete');
|
||||
$this-><?php echo $currentModelName; ?>->id = $id;
|
||||
if (!$this-><?php echo $currentModelName; ?>->exists()) {
|
||||
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
|
||||
|
|
|
@ -353,7 +353,8 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
|
||||
|
||||
$this->assertContains('function add()', $result);
|
||||
$this->assertContains("if (\$this->request->is('post'))", $result);
|
||||
$this->assertContains("if (\$this->request->data)", $result);
|
||||
$this->assertContains("\$this->request->onlyAllow('post')", $result);
|
||||
$this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);
|
||||
$this->assertContains("\$this->Session->setFlash(__('The bake article has been saved'));", $result);
|
||||
|
||||
|
@ -392,7 +393,8 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
|
||||
|
||||
$this->assertContains('function add()', $result);
|
||||
$this->assertContains("if (\$this->request->is('post'))", $result);
|
||||
$this->assertContains("if (\$this->request->data)", $result);
|
||||
$this->assertContains("\$this->request->onlyAllow('post')", $result);
|
||||
$this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);
|
||||
|
||||
$this->assertContains("\$this->flash(__('The bake article has been saved.'), array('action' => 'index'))", $result);
|
||||
|
|
Loading…
Add table
Reference in a new issue