Moved post un/hiding to API
This commit is contained in:
parent
c0dce6775e
commit
38a9e154f8
3 changed files with 48 additions and 22 deletions
|
@ -88,6 +88,8 @@ $postValidation =
|
||||||
\Chibi\Router::register(['PostController', 'upvotedView'], 'GET', '/upvoted/{page}', $postValidation);
|
\Chibi\Router::register(['PostController', 'upvotedView'], 'GET', '/upvoted/{page}', $postValidation);
|
||||||
\Chibi\Router::register(['PostController', 'toggleTagAction'], 'POST', '/post/{id}/toggle-tag/{tag}/{enable}', $postValidation);
|
\Chibi\Router::register(['PostController', 'toggleTagAction'], 'POST', '/post/{id}/toggle-tag/{tag}/{enable}', $postValidation);
|
||||||
\Chibi\Router::register(['PostController', 'flagAction'], 'POST', '/post/{id}/flag', $postValidation);
|
\Chibi\Router::register(['PostController', 'flagAction'], 'POST', '/post/{id}/flag', $postValidation);
|
||||||
|
\Chibi\Router::register(['PostController', 'hideAction'], 'POST', '/post/{id}/hide', $postValidation);
|
||||||
|
\Chibi\Router::register(['PostController', 'unhideAction'], 'POST', '/post/{id}/unhide', $postValidation);
|
||||||
|
|
||||||
\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments');
|
\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments');
|
||||||
\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments/{page}', ['page' => '\d+']);
|
\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments/{page}', ['page' => '\d+']);
|
||||||
|
@ -104,8 +106,6 @@ foreach (['GET', 'POST'] as $method)
|
||||||
\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', 'deleteAction'], $method, '/post/{id}/delete', $postValidation);
|
||||||
\Chibi\Router::register(['PostController', 'hideAction'], $method, '/post/{id}/hide', $postValidation);
|
|
||||||
\Chibi\Router::register(['PostController', 'unhideAction'], $method, '/post/{id}/unhide', $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);
|
||||||
|
|
||||||
|
|
|
@ -173,30 +173,16 @@ class PostController
|
||||||
|
|
||||||
public function hideAction($id)
|
public function hideAction($id)
|
||||||
{
|
{
|
||||||
$post = PostModel::findByIdOrName($id);
|
Api::run(new TogglePostVisibilityJob(), [
|
||||||
Access::assert(Privilege::HidePost, Access::getIdentity($post->getUploader()));
|
TogglePostVisibilityJob::POST_ID => $id,
|
||||||
|
TogglePostVisibilityJob::STATE => false]);
|
||||||
if (!InputHelper::get('submit'))
|
|
||||||
return;
|
|
||||||
|
|
||||||
$post->setHidden(true);
|
|
||||||
PostModel::save($post);
|
|
||||||
|
|
||||||
LogHelper::log('{user} hidden {post}', ['post' => TextHelper::reprPost($post)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unhideAction($id)
|
public function unhideAction($id)
|
||||||
{
|
{
|
||||||
$post = PostModel::findByIdOrName($id);
|
Api::run(new TogglePostVisibilityJob(), [
|
||||||
Access::assert(Privilege::HidePost, Access::getIdentity($post->getUploader()));
|
TogglePostVisibilityJob::POST_ID => $id,
|
||||||
|
TogglePostVisibilityJob::STATE => true]);
|
||||||
if (!InputHelper::get('submit'))
|
|
||||||
return;
|
|
||||||
|
|
||||||
$post->setHidden(false);
|
|
||||||
PostModel::save($post);
|
|
||||||
|
|
||||||
LogHelper::log('{user} unhidden {post}', ['post' => TextHelper::reprPost($post)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteAction($id)
|
public function deleteAction($id)
|
||||||
|
|
40
src/Jobs/TogglePostVisibilityJob.php
Normal file
40
src/Jobs/TogglePostVisibilityJob.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
class TogglePostVisibilityJob extends AbstractPostEditJob
|
||||||
|
{
|
||||||
|
public function execute()
|
||||||
|
{
|
||||||
|
$post = $this->post;
|
||||||
|
$visible = boolval($this->getArgument(self::STATE));
|
||||||
|
|
||||||
|
$post->setHidden(!$visible);
|
||||||
|
PostModel::save($post);
|
||||||
|
|
||||||
|
LogHelper::log(
|
||||||
|
$visible
|
||||||
|
? '{user} unhidden {post}'
|
||||||
|
: '{user} hidden {post}', [
|
||||||
|
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
||||||
|
'post' => TextHelper::reprPost($post)]);
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requiresPrivilege()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
[
|
||||||
|
Privilege::HidePost,
|
||||||
|
Access::getIdentity($this->post->getUploader())
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requiresAuthentication()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requiresConfirmedEmail()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue