This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
szurubooru/src/Routes/Posts/UpdatePost.php
Marcin Kurczewski d8d65ed24c Changed PUT requests to POST
HTTP spec disallows multipart/form-data requests using PUT method.
2014-11-22 14:30:29 +01:00

64 lines
1.8 KiB
PHP

<?php
namespace Szurubooru\Routes\Posts;
use Szurubooru\Controllers\ViewProxies\PostViewProxy;
use Szurubooru\FormData\PostEditFormData;
use Szurubooru\Helpers\InputReader;
use Szurubooru\Privilege;
use Szurubooru\Services\PostService;
use Szurubooru\Services\PrivilegeService;
class UpdatePost extends AbstractPostRoute
{
private $privilegeService;
private $postService;
private $inputReader;
private $postViewProxy;
public function __construct(
PrivilegeService $privilegeService,
PostService $postService,
InputReader $inputReader,
PostViewProxy $postViewProxy)
{
$this->privilegeService = $privilegeService;
$this->postService = $postService;
$this->inputReader = $inputReader;
$this->postViewProxy = $postViewProxy;
}
public function getMethods()
{
return ['POST'];
}
public function getUrl()
{
return '/api/posts/:postNameOrId';
}
public function work($args)
{
$postNameOrId = $args['postNameOrId'];
$post = $this->postService->getByNameOrId($postNameOrId);
$formData = new PostEditFormData($this->inputReader);
if ($formData->content !== null)
$this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_CONTENT);
if ($formData->thumbnail !== null)
$this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_THUMBNAIL);
if ($formData->safety !== null)
$this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_SAFETY);
if ($formData->source !== null)
$this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_SOURCE);
if ($formData->tags !== null)
$this->privilegeService->assertPrivilege(Privilege::CHANGE_POST_TAGS);
$this->postService->updatePost($post, $formData);
$post = $this->postService->getByNameOrId($postNameOrId);
return $this->postViewProxy->fromEntity($post, $this->getFullFetchConfig());
}
}