Skip to content

Commit

Permalink
partial remove onlyAllow from baked code, only keep in delete to be r…
Browse files Browse the repository at this point in the history
…fc compliant
  • Loading branch information
ceeram committed Aug 26, 2012
1 parent 27d83ee commit abe74ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
Expand Up @@ -47,12 +47,10 @@
/**
* <?php echo $admin ?>add method
*
* @throws MethodNotAllowedException
* @return void
*/
public function <?php echo $admin ?>add() {
if ($this->request->data) {
$this->request->onlyAllow('post');
if ($this->request->is('post')) {
$this-><?php echo $currentModelName; ?>->create();
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
<?php if ($wannaUseSession): ?>
Expand Down Expand Up @@ -88,7 +86,6 @@
/**
* <?php echo $admin ?>edit method
*
* @throws MethodNotAllowedException
* @throws NotFoundException
* @param string $id
* @return void
Expand All @@ -98,8 +95,7 @@
if (!$this-><?php echo $currentModelName; ?>->exists()) {
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
}
if ($this->request->data) {
$this->request->onlyAllow('post', 'put');
if ($this->request->is('post') || $this->request->is('put')) {
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
Expand Down Expand Up @@ -135,17 +131,17 @@
/**
* <?php echo $admin ?>delete method
*
* @throws MethodNotAllowedException
* @throws NotFoundException
* @throws MethodNotAllowedException
* @param string $id
* @return void
*/
public function <?php echo $admin; ?>delete($id = null) {
$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); ?>'));
}
$this->request->onlyAllow('post', 'delete');
if ($this-><?php echo $currentModelName; ?>->delete()) {
<?php if ($wannaUseSession): ?>
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'));
Expand Down
Expand Up @@ -353,8 +353,7 @@ public function testBakeActionsUsingSessions() {
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);

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

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

$this->assertContains('function add()', $result);
$this->assertContains("if (\$this->request->data)", $result);
$this->assertContains("\$this->request->onlyAllow('post')", $result);
$this->assertContains("if (\$this->request->is('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);
Expand All @@ -404,6 +402,7 @@ public function testBakeActionsWithNoSessions() {
$this->assertContains("\$this->set(compact('bakeTags'))", $result);

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

0 comments on commit abe74ad

Please sign in to comment.