Skip to content
This repository
Browse code

partial remove onlyAllow from baked code, only keep in delete to be r…

…fc compliant
  • Loading branch information...
commit abe74adf8acbe9096c8f5e0339840ee68d2b0e81 1 parent 27d83ee
ceeram authored
12  lib/Cake/Console/Templates/default/actions/controller_actions.ctp
@@ -47,12 +47,10 @@
47 47
 /**
48 48
  * <?php echo $admin ?>add method
49 49
  *
50  
- * @throws MethodNotAllowedException
51 50
  * @return void
52 51
  */
53 52
 	public function <?php echo $admin ?>add() {
54  
-		if ($this->request->data) {
55  
-			$this->request->onlyAllow('post');
  53
+		if ($this->request->is('post')) {
56 54
 			$this-><?php echo $currentModelName; ?>->create();
57 55
 			if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
58 56
 <?php if ($wannaUseSession): ?>
@@ -88,7 +86,6 @@
88 86
 /**
89 87
  * <?php echo $admin ?>edit method
90 88
  *
91  
- * @throws MethodNotAllowedException
92 89
  * @throws NotFoundException
93 90
  * @param string $id
94 91
  * @return void
@@ -98,8 +95,7 @@
98 95
 		if (!$this-><?php echo $currentModelName; ?>->exists()) {
99 96
 			throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
100 97
 		}
101  
-		if ($this->request->data) {
102  
-			$this->request->onlyAllow('post', 'put');
  98
+		if ($this->request->is('post') || $this->request->is('put')) {
103 99
 			if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
104 100
 <?php if ($wannaUseSession): ?>
105 101
 				$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
@@ -135,17 +131,17 @@
135 131
 /**
136 132
  * <?php echo $admin ?>delete method
137 133
  *
138  
- * @throws MethodNotAllowedException
139 134
  * @throws NotFoundException
  135
+ * @throws MethodNotAllowedException
140 136
  * @param string $id
141 137
  * @return void
142 138
  */
143 139
 	public function <?php echo $admin; ?>delete($id = null) {
144  
-		$this->request->onlyAllow('post', 'delete');
145 140
 		$this-><?php echo $currentModelName; ?>->id = $id;
146 141
 		if (!$this-><?php echo $currentModelName; ?>->exists()) {
147 142
 			throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
148 143
 		}
  144
+		$this->request->onlyAllow('post', 'delete');
149 145
 		if ($this-><?php echo $currentModelName; ?>->delete()) {
150 146
 <?php if ($wannaUseSession): ?>
151 147
 			$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'));
7  lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php
@@ -353,8 +353,7 @@ public function testBakeActionsUsingSessions() {
353 353
 		$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
354 354
 
355 355
 		$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);
358 357
 		$this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);
359 358
 		$this->assertContains("\$this->Session->setFlash(__('The bake article has been saved'));", $result);
360 359
 
@@ -393,8 +392,7 @@ public function testBakeActionsWithNoSessions() {
393 392
 		$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
394 393
 
395 394
 		$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);
398 396
 		$this->assertContains('if ($this->BakeArticle->save($this->request->data))', $result);
399 397
 
400 398
 		$this->assertContains("\$this->flash(__('The bake article has been saved.'), array('action' => 'index'))", $result);
@@ -404,6 +402,7 @@ public function testBakeActionsWithNoSessions() {
404 402
 		$this->assertContains("\$this->set(compact('bakeTags'))", $result);
405 403
 
406 404
 		$this->assertContains('function delete($id = null)', $result);
  405
+		$this->assertContains("\$this->request->onlyAllow('post', 'delete')", $result);
407 406
 		$this->assertContains('if ($this->BakeArticle->delete())', $result);
408 407
 		$this->assertContains("\$this->flash(__('Bake article deleted'), array('action' => 'index'))", $result);
409 408
 	}

0 notes on commit abe74ad

Please sign in to comment.
Something went wrong with that request. Please try again.