Moved post removal to API
This commit is contained in:
parent
38a9e154f8
commit
db8eab1c5c
3 changed files with 36 additions and 10 deletions
|
@ -74,6 +74,7 @@ $postValidation =
|
||||||
\Chibi\Router::register(['PostController', 'uploadAction'], 'POST', '/posts/upload', $postValidation);
|
\Chibi\Router::register(['PostController', 'uploadAction'], 'POST', '/posts/upload', $postValidation);
|
||||||
\Chibi\Router::register(['PostController', 'editView'], 'GET', '/post/{id}/edit', $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', '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}', $postValidation);
|
||||||
\Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}/{query}', $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', 'thumbAction'], $method, '/post/{name}/thumb', $postValidation);
|
||||||
\Chibi\Router::register(['PostController', 'removeFavoriteAction'], $method, '/post/{id}/rem-fav', $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', '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', 'featureAction'], $method, '/post/{id}/feature', $postValidation);
|
||||||
\Chibi\Router::register(['PostController', 'scoreAction'], $method, '/post/{id}/score/{score}', $postValidation);
|
\Chibi\Router::register(['PostController', 'scoreAction'], $method, '/post/{id}/score/{score}', $postValidation);
|
||||||
|
|
||||||
|
|
|
@ -187,15 +187,8 @@ class PostController
|
||||||
|
|
||||||
public function deleteAction($id)
|
public function deleteAction($id)
|
||||||
{
|
{
|
||||||
$post = PostModel::findByIdOrName($id);
|
Api::run(new DeletePostJob(), [
|
||||||
Access::assert(Privilege::DeletePost, Access::getIdentity($post->getUploader()));
|
DeletePostJob::POST_ID => $id]);
|
||||||
|
|
||||||
if (!InputHelper::get('submit'))
|
|
||||||
return;
|
|
||||||
|
|
||||||
PostModel::remove($post);
|
|
||||||
|
|
||||||
LogHelper::log('{user} deleted {post}', ['post' => TextHelper::reprPost($id)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addFavoriteAction($id)
|
public function addFavoriteAction($id)
|
||||||
|
|
33
src/Jobs/DeletePostJob.php
Normal file
33
src/Jobs/DeletePostJob.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue