Skip to content

Commit abe74ad

Browse files
committed
partial remove onlyAllow from baked code, only keep in delete to be rfc compliant
1 parent 27d83ee commit abe74ad

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

lib/Cake/Console/Templates/default/actions/controller_actions.ctp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@
4747
/**
4848
* <?php echo $admin ?>add method
4949
*
50-
* @throws MethodNotAllowedException
5150
* @return void
5251
*/
5352
public function <?php echo $admin ?>add() {
54-
if ($this->request->data) {
55-
$this->request->onlyAllow('post');
53+
if ($this->request->is('post')) {
5654
$this-><?php echo $currentModelName; ?>->create();
5755
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
5856
<?php if ($wannaUseSession): ?>
@@ -88,7 +86,6 @@
8886
/**
8987
* <?php echo $admin ?>edit method
9088
*
91-
* @throws MethodNotAllowedException
9289
* @throws NotFoundException
9390
* @param string $id
9491
* @return void
@@ -98,8 +95,7 @@
9895
if (!$this-><?php echo $currentModelName; ?>->exists()) {
9996
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
10097
}
101-
if ($this->request->data) {
102-
$this->request->onlyAllow('post', 'put');
98+
if ($this->request->is('post') || $this->request->is('put')) {
10399
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
104100
<?php if ($wannaUseSession): ?>
105101
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
@@ -135,17 +131,17 @@
135131
/**
136132
* <?php echo $admin ?>delete method
137133
*
138-
* @throws MethodNotAllowedException
139134
* @throws NotFoundException
135+
* @throws MethodNotAllowedException
140136
* @param string $id
141137
* @return void
142138
*/
143139
public function <?php echo $admin; ?>delete($id = null) {
144-
$this->request->onlyAllow('post', 'delete');
145140
$this-><?php echo $currentModelName; ?>->id = $id;
146141
if (!$this-><?php echo $currentModelName; ?>->exists()) {
147142
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
148143
}
144+
$this->request->onlyAllow('post', 'delete');
149145
if ($this-><?php echo $currentModelName; ?>->delete()) {
150146
<?php if ($wannaUseSession): ?>
151147
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'));

lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,7 @@ public function testBakeActionsUsingSessions() {
353353
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
354354

355355
$this->assertContains('function add()', $result);
356-
$this->assertContains("if (\$this->request->data)", $result);
357-
$this->assertContains("\$this->request->onlyAllow('post')", $result);
356+
$this->assertContains("if (\$this->request->is('post'))", $result);
358357
$this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);
359358
$this->assertContains("\$this->Session->setFlash(__('The bake article has been saved'));", $result);
360359

@@ -393,8 +392,7 @@ public function testBakeActionsWithNoSessions() {
393392
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
394393

395394
$this->assertContains('function add()', $result);
396-
$this->assertContains("if (\$this->request->data)", $result);
397-
$this->assertContains("\$this->request->onlyAllow('post')", $result);
395+
$this->assertContains("if (\$this->request->is('post'))", $result);
398396
$this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);
399397

400398
$this->assertContains("\$this->flash(__('The bake article has been saved.'), array('action' => 'index'))", $result);
@@ -404,6 +402,7 @@ public function testBakeActionsWithNoSessions() {
404402
$this->assertContains("\$this->set(compact('bakeTags'))", $result);
405403

406404
$this->assertContains('function delete($id = null)', $result);
405+
$this->assertContains("\$this->request->onlyAllow('post', 'delete')", $result);
407406
$this->assertContains('if ($this->BakeArticle->delete())', $result);
408407
$this->assertContains("\$this->flash(__('Bake article deleted'), array('action' => 'index'))", $result);
409408
}

0 commit comments

Comments
 (0)