Moved post removal to API

This commit is contained in:
Marcin Kurczewski 2014-05-03 19:35:59 +02:00
parent 38a9e154f8
commit db8eab1c5c
3 changed files with 36 additions and 10 deletions

View file

@ -74,6 +74,7 @@ $postValidation =
\Chibi\Router::register(['PostController', 'uploadAction'], 'POST', '/posts/upload', $postValidation);
\Chibi\Router::register(['PostController', 'editView'], 'GET', '/post/{id}/edit', $postValidation);
\Chibi\Router::register(['PostController', 'editAction'], 'POST', '/post/{id}/edit', $postValidation);
\Chibi\Router::register(['PostController', 'deleteAction'], 'POST', '/post/{id}/delete', $postValidation);
\Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}', $postValidation);
\Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}/{query}', $postValidation);
@ -105,7 +106,6 @@ foreach (['GET', 'POST'] as $method)
\Chibi\Router::register(['PostController', 'thumbAction'], $method, '/post/{name}/thumb', $postValidation);
\Chibi\Router::register(['PostController', 'removeFavoriteAction'], $method, '/post/{id}/rem-fav', $postValidation);
\Chibi\Router::register(['PostController', 'addFavoriteAction'], $method, '/post/{id}/add-fav', $postValidation);
\Chibi\Router::register(['PostController', 'deleteAction'], $method, '/post/{id}/delete', $postValidation);
\Chibi\Router::register(['PostController', 'featureAction'], $method, '/post/{id}/feature', $postValidation);
\Chibi\Router::register(['PostController', 'scoreAction'], $method, '/post/{id}/score/{score}', $postValidation);

View file

@ -187,15 +187,8 @@ class PostController
public function deleteAction($id)
{
$post = PostModel::findByIdOrName($id);
Access::assert(Privilege::DeletePost, Access::getIdentity($post->getUploader()));
if (!InputHelper::get('submit'))
return;
PostModel::remove($post);
LogHelper::log('{user} deleted {post}', ['post' => TextHelper::reprPost($id)]);
Api::run(new DeletePostJob(), [
DeletePostJob::POST_ID => $id]);
}
public function addFavoriteAction($id)

View file

@ -0,0 +1,33 @@
<?php
class DeletePostJob extends AbstractPostEditJob
{
public function execute()
{
$post = $this->post;
PostModel::remove($post);
LogHelper::log('{user} deleted {post}', [
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
'post' => TextHelper::reprPost($post)]);
}
public function requiresPrivilege()
{
return
[
Privilege::DeletePost,
Access::getIdentity($this->post->getUploader())
];
}
public function requiresAuthentication()
{
return true;
}
public function requiresConfirmedEmail()
{
return getConfig()->registration->needEmailForCommenting;
}
}