Commits (3)
......@@ -11,6 +11,7 @@ use Minds\Entities\Activity;
use Minds\Interfaces;
use Minds\Core\Di\Di;
use Minds\Core\Reports\Jury\Decision;
use Minds\Core\Reports\Jury\JuryClosedException;
class jury implements Interfaces\Api
{
......@@ -26,6 +27,13 @@ class jury implements Interfaces\Api
$juryManager->setJuryType($juryType)
->setUser(Core\Session::getLoggedInUser());
if (isset($pages[1])) {
$report = $juryManager->getReport($pages[1]);
return Factory::response([
'report' => $report ? $report->export() : null,
]);
}
$reports = $juryManager->getUnmoderatedList([
'limit' => 12,
'hydrate' => true,
......@@ -83,7 +91,14 @@ class jury implements Interfaces\Api
->setJurorGuid(Core\Session::getLoggedInUser()->getGuid())
->setJurorHash(Core\Session::getLoggedInUser()->getPhoneNumberHash());
$juryManager->cast($decision);
try {
$juryManager->cast($decision);
} catch (JuryClosedException $e) {
return Factory::response([
'status' => 'error',
'message' => 'The jury has already closed'
]);
}
return Factory::response([]);
}
......
<?php
namespace Minds\Core\Reports\Jury;
class JuryClosedException extends \Exception
{
protected $message = "The jury has closed";
}
......@@ -105,6 +105,23 @@ class Manager
return $response;
}
/**
* Return a single report
* @param string $urn
* @return Report
*/
public function getReport($urn)
{
$report = $this->repository->get($urn);
if ($report) {
$entity = $this->entitiesResolver->single(
(new Urn())->setUrn($report->getEntityUrn())
);
$report->setEntity($entity);
}
return $report;
}
/**
* Cast a decision
* @param Decision $decision
......@@ -112,9 +129,14 @@ class Manager
*/
public function cast(Decision $decision)
{
$report = $decision->getReport();
if (!in_array($report->getState(), [ 'reported', 'appealed' ])) {
throw new JuryClosedException();
}
$success = $this->repository->add($decision);
$report = $decision->getReport();
if ($decision->isAppeal()) {
$decisions = $report->getAppealJuryDecisions();
$decisions[] = $decision;
......
......@@ -53,7 +53,7 @@ class Repository
], $opts);
if (!$opts['user']->getPhoneNumberHash()) {
//return null;
return null;
}
$statement = "SELECT * FROM moderation_reports_by_state
......@@ -89,6 +89,18 @@ class Repository
return $response;
}
/**
* Return a single report
* @param string $urn
* @return Report
*/
public function get($urn)
{
// TODO: Do not return if we no longer meet criteria
return $this->reportsRepository->get($urn);
}
/**
* Add a decision for a report
* @param Decision $decision
......
......@@ -72,12 +72,12 @@ class Repository
if ($opts['from']) {
$statement .= " AND timestamp > ?";
$values[] = new Timestamp($opts['from'] * 1000);
$values[] = new Timestamp($opts['from']);
}
if ($opts['to']) {
$statement .= " AND timestamp < ?";
$values[] = new Timestamp($opts['to'] * 1000);
$values[] = new Timestamp($opts['to']);
}
if (!isset($opts['reason_code']) && !isset($opts['sub_reason_code'])) {
......