Commit 01194111 authored by Mark Harding's avatar Mark Harding

(fix): allow for groups and channels to be reports more than once but not single posts

1 merge request!100Epic/reporting and moderation
Pipeline #61704035 passed with stages
in 6 minutes and 3 seconds
......@@ -61,7 +61,7 @@ class report implements Interfaces\Api
->setEntity($entity)
->setEntityOwnerGuid($entity->getOwnerGuid())
->setReasonCode((int) $_POST['reason_code'])
->setSubReasonCode($_POST['sub_reason_code'] ?? null);
->setSubReasonCode($_POST['sub_reason_code'] ?? 0);
$userReport = new Reports\UserReports\UserReport();
$userReport
......
......@@ -11,6 +11,8 @@ use Minds\Core\Data\Cassandra\Prepared;
use Minds\Entities;
use Minds\Entities\DenormalizedEntity;
use Minds\Entities\NormalizedEntity;
use Minds\Core\Entities\Resolver as EntitiesResolver;
use Minds\Common\Urn;
class Manager
{
......@@ -21,10 +23,18 @@ class Manager
/** @var PreFeb2019Repository $preFeb2019Repository */
private $preFeb2019Repository;
public function __construct($repository = null, $preFeb2019Repository = null)
/** @var EntitiesResolver $entitiesResolver */
private $entitiesResolver;
public function __construct(
$repository = null,
$preFeb2019Repository = null,
$entitiesResolver = null
)
{
$this->repository = $repository ?: new Repository;
$this->preFeb2019Repository = $preFeb2019Repository ?: new PreFeb2019Repository();
$this->entitiesResolver = $entitiesResolver ?: new EntitiesResolver;
}
/**
......@@ -37,7 +47,20 @@ class Manager
'hydrate' => false,
], $opts);
return $this->repository->getList($opts);
$response = $this->repository->getList($opts);
$response = $this->repository->getList($opts);
if ($opts['hydrate']) {
foreach ($response as $report) {
$entity = $this->entitiesResolver->single(
(new Urn())->setUrn($report->getEntityUrn())
);
$report->setEntity($entity);
}
}
return $response;
}
public function getReport($urn)
......@@ -70,6 +93,7 @@ class Manager
'entity_urn' => $report->getEntityUrn(),
'reason_code' => $report->getReasonCode(),
'sub_reason_code' => $report->getSubReasonCode(),
'hydrate' => true,
]);
if (!$reports || !count($reports)) {
......
......@@ -146,7 +146,7 @@ class Repository
$entityUrn = substr($parts[0], 1, -1); // Remove the parenthases
$reasonCode = $parts[1];
$subReasonCode = $parts[2];
$subReasonCode = $parts[2] ?? 0;
$timestamp = $parts[3];
......
......@@ -67,10 +67,24 @@ class Manager
&& !in_array($report->getEntity()->type, [ 'user', 'group' ])
) {
return true; // Already past report threshold
} elseif ($report->getState() === 'initial_jury_decided') {
$report->setTimestamp(time());
}
if ($report->getState() === 'initial_jury_decided' && $report->isUpheld()) {
return true; // Until appealed, don't accept any more reports
}
if ($report->getState() === 'appealed') {
return true; // Do not accept further reports while awaiting appeal jury decision
}
if ($report->getState() === 'appeal_jury_decided' && $report->isUpheld()) {
return true; // Do not accept further reports if appeal jury uphols
}
if ($report->getState() !== 'reported') {
$report->setTimestamp(time()); // Create a new report
}
$userReport->setReport($report);
$this->repository->add($userReport);
......
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