- Jobs specify main privilege and sub privileges separately Rationale: increase maintenance, restrict what can be done runtime - Renamed ChangeUser* to EditUser* (consistency with EditPost*) - Simplified enum names and configuration reading - IJob interface members must be explicitly implemented Rationale: reduce chances of forgetting something, or typos in inherited method names - Invalid privileges names in configuration yield exceptions
54 lines
912 B
PHP
54 lines
912 B
PHP
<?php
|
|
class GetPostJob extends AbstractJob
|
|
{
|
|
protected $postRetriever;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->postRetriever = new PostRetriever($this);
|
|
}
|
|
|
|
public function execute()
|
|
{
|
|
$post = $this->postRetriever->retrieve();
|
|
|
|
CommentModel::preloadCommenters($post->getComments());
|
|
|
|
return $post;
|
|
}
|
|
|
|
public function getRequiredArguments()
|
|
{
|
|
return JobArgs::Conjunction(
|
|
$this->postRetriever->getRequiredArguments(),
|
|
null);
|
|
}
|
|
|
|
public function getRequiredMainPrivilege()
|
|
{
|
|
return Privilege::ViewPost;
|
|
}
|
|
|
|
public function getRequiredSubPrivileges()
|
|
{
|
|
$post = $this->postRetriever->retrieve();
|
|
$privileges = [];
|
|
|
|
if ($post->isHidden())
|
|
$privileges []= 'hidden';
|
|
|
|
$privileges []= $post->getSafety()->toString();
|
|
|
|
return $privileges;
|
|
}
|
|
|
|
public function isAuthenticationRequired()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function isConfirmedEmailRequired()
|
|
{
|
|
return false;
|
|
}
|
|
}
|