Commit aa36b0eb authored by Mark Harding's avatar Mark Harding

(feat): do not allow to participate in jury unless summoned

1 merge request!100Epic/reporting and moderation
Pipeline #61813319 canceled with stages
......@@ -12,6 +12,7 @@ use Minds\Interfaces;
use Minds\Core\Di\Di;
use Minds\Core\Reports\Jury\Decision;
use Minds\Core\Reports\Jury\JuryClosedException;
use Minds\Core\Reports\Summons\SummonsNotFoundException;
class jury implements Interfaces\Api
{
......@@ -19,7 +20,7 @@ class jury implements Interfaces\Api
{
$juryType = $pages[0] ?? 'appeal';
if ($juryType !== 'appeal' && !Core\Session::isAdmin()) {
if ($juryType === 'appeal' || !Core\Session::isAdmin()) {
exit;
}
......@@ -98,6 +99,11 @@ class jury implements Interfaces\Api
'status' => 'error',
'message' => 'The jury has already closed'
]);
} catch (SummonsNotFoundException $e) {
return Factory::response([
'status' => 'error',
'message' => 'A summons could not be found'
]);
}
return Factory::response([]);
......
......@@ -14,6 +14,8 @@ use Minds\Entities\NormalizedEntity;
use Minds\Common\Repository\Response;
use Minds\Common\Urn;
use Minds\Core\Entities\Resolver as EntitiesResolver;
use Minds\Core\Reports\Summons\SummonsNotFoundException;
use Minds\Core\Reports\Summons\Summon as SummonsEntity;
class Manager
{
......@@ -27,6 +29,9 @@ class Manager
/** @var VerdictManager $verdictManager */
private $verdictManager;
/** @var SummonsManager $summonsManager */
private $summonsManager;
/** @var string $juryType */
private $juryType;
......@@ -36,12 +41,14 @@ class Manager
public function __construct(
$repository = null,
$entitiesResolver = null,
$verdictManager = null
$verdictManager = null,
$summonsManager = null
)
{
$this->repository = $repository ?: new Repository;
$this->entitiesResolver = $entitiesResolver ?: new EntitiesResolver;
$this->verdictManager = $verdictManager ?: Di::_()->get('Moderation\Verdict\Manager');
$this->summonsManager = $summonsManager ?: Di::_()->get('Moderation\Summons\Manager');
}
/**
......@@ -135,6 +142,10 @@ class Manager
throw new JuryClosedException();
}
if ($decision->isAppeal() && !$this->hasSummons($decision)) {
throw new SummonsNotFoundException();
}
$success = $this->repository->add($decision);
if ($decision->isAppeal()) {
......@@ -152,4 +163,18 @@ class Manager
return $success;
}
/**
* Return if a summons exists
* @param Decision $decision
* @return boolean
*/
private function hasSummons(Decision $decision)
{
$summons = new SummonsEntity();
$summons->setReportUrn($decision->getReport()->getUrn())
->setJurorGuid($decision->getJurorGuid())
->setJuryType('appeal_jury');
return $this->summonsManager->isSummoned($summons);
}
}
<?php
namespace Minds\Core\Reports\Summons;
class SummonsNotFoundException extends \Exception
{
protected $message = "A summons could not be found";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment