...
 
Commits (5)
......@@ -43,7 +43,6 @@ class notifications implements Interfaces\Api
{
Factory::isLoggedIn();
$response = [];
return;
if (!isset($pages[0])) {
$pages = ['list'];
......
......@@ -58,7 +58,7 @@ class appeals implements Interfaces\Api
$appeal = new Appeal();
$appeal->setNote($_POST['note'])
->setReport($report)
->setTimestamp(round(microtime(true) * 1000));
->setTimestamp(time());
$success = $appealManager->appeal($appeal);
......
......@@ -79,7 +79,7 @@ class jury implements Interfaces\Api
->setAppeal($juryType === 'appeal')
->setUphold($uphold)
->setReport($report)
->setTimestamp(round(microtime(true) * 1000))
->setTimestamp(time())
->setJurorGuid(Core\Session::getLoggedInUser()->getGuid())
->setJurorHash(Core\Session::getLoggedInUser()->getPhoneNumberHash());
......
......@@ -67,7 +67,7 @@ class report implements Interfaces\Api
$userReport
->setReport($report)
->setReporterGuid($user->getGuid())
->setTimestamp(round(microtime(true) * 1000));
->setTimestamp(time());
if ($user->getPhoneNumberHash()) {
$userReport->setReporterHash($user->getPhoneNumberHash());
......
......@@ -79,12 +79,12 @@ class Repository
}
break;
case 'approved':
if ($report->getState() !== 'appeal_jury_decided' || $report->isUpheld() === false) {
if ($report->getState() !== 'appeal_jury_decided' || $report->isUpheld() === true) {
$skip = true;
}
break;
case 'rejected':
if ($report->getState() !== 'appeal_jury_decided' || $report->isUpheld() === true) {
if ($report->getState() !== 'appeal_jury_decided' || $report->isUpheld() === false) {
$skip = true;
}
break;
......
......@@ -64,7 +64,7 @@ class Manager
public function getLatestReport($report)
{
$report->setState('reported')
->setTimestamp(round(microtime(true) * 1000));
->setTimestamp(time());
$reports = $this->getList([
'entity_urn' => $report->getEntityUrn(),
......
......@@ -234,7 +234,7 @@ class Repository
->setUphold(isset($row['uphold']) ? (bool) $row['uphold'] : null)
->setStateChanges(isset($row['state_changes']) ?
array_map(function ($timestamp) {
return $timestamp->microtime(true);
return $timestamp->time();
}, $this->mapToAssoc($row['state_changes']))
: null
)
......
......@@ -157,7 +157,22 @@ class Repository
public function delete(Strike $strike)
{
$statement = "DELETE FROM moderation_strikes
WHERE user_guid = ?
AND reason_code = ?
AND sub_reason_code = ?
AND timestamp = ?";
$values = [
new Bigint($strike->getUserGuid()),
new Tinyint($strike->getReasonCode()),
new Decimal($strike->getSubReasonCode()),
new Timestamp($strike->getTimestamp()),
];
$prepared = new Prepared();
$prepared->query($statement, $values);
return (bool) $this->cql->request($prepared);
}
}
......@@ -66,9 +66,9 @@ class Manager
if ($report->getState() !== 'reported'
&& !in_array($report->getEntity()->type, [ 'user', 'group' ])
) {
return; // Already past report threshold
} elseif ($report->getState() === 'closed') {
$report->setTimestamp(round(microtime(true) * 1000));
return true; // Already past report threshold
} elseif ($report->getState() === 'initial_jury_decided') {
$report->setTimestamp(time());
}
$userReport->setReport($report);
......
......@@ -61,9 +61,11 @@ class ActionDelegate
$entity = $this->entitiesBuilder->single($entityGuid);
switch ($report->getReasonCode()) {
case 1: // Illegal (not appealable)
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
case 1: // Illegal (not appealable)
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
}
// Ban the owner of the post too
$this->applyBan($report);
break;
......@@ -76,20 +78,26 @@ class ActionDelegate
$this->applyStrike($report);
break;
case 3: // Incites violence
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
}
// Ban the owner of the post
$this->applyBan($report);
break;
case 4: // Harrasment
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
}
// Apply a strike to the owner
$this->applyStrike($report);
break;
case 5: // Personal and confidential information (not appelable)
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
}
// Ban the owner of the post too
$this->applyBan($report);
break;
......@@ -98,9 +106,10 @@ class ActionDelegate
$this->applyBan($report);
break;
case 8: // Spam
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
error_log('marked as spam');
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
}
// Apply a strike to the owner
$this->applyStrike($report);
break;
......@@ -109,8 +118,10 @@ class ActionDelegate
// Apply a strike to the owner
// break;
case 13: // Malware
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
}
// Ban the owner
$this->applyBan($report);
break;
......@@ -157,7 +168,7 @@ class ActionDelegate
->setUserGuid($report->getEntityOwnerGuid())
->setReasonCode($report->getReasonCode())
->setSubReasonCode($report->getSubReasonCode())
->setTimestamp(round(microtime(true) * 1000));
->setTimestamp($report->getTimestamp()); // Strike is recored for date of first report
$count = $this->strikesManager->countStrikesInTimeWindow($strike, $this->strikesManager::STRIKE_TIME_WINDOW);
......
......@@ -10,6 +10,7 @@ use Minds\Core\Di\Di;
use Minds\Common\Urn;
use Minds\Core\Reports\Report;
use Minds\Core\Reports\Strikes\Strike;
use Minds\Core\Entities\Actions\Save as SaveAction;
class ReverseActionDelegate
{
......@@ -19,6 +20,9 @@ class ReverseActionDelegate
/** @var Actions $actions */
private $actions;
/** @var SaveAction $saveAction */
private $saveAction;
/** @var Urn $urn */
private $urn;
......@@ -29,18 +33,20 @@ class ReverseActionDelegate
$entitiesBuilder = null,
$actions = null,
$urn = null,
$strikesManager = null
$strikesManager = null,
$saveAction = null
)
{
$this->entitiesBuilder = $entitiesBuilder ?: Di::_()->get('EntitiesBuilder');
$this->actions = $actions ?: Di::_()->get('Reports\Actions');
$this->urn = $urn ?: new Urn;
$this->strikesManager = $strikesManager ?: Di::_()->get('Moderation\Strikes\Manager');
$this->saveAction = $saveAction ?: new SaveAction();
}
public function onReverse(Verdict $verdict)
{
if (!$verdict->isAppeal() && $verdict->isUpheld()) {
if (!$verdict->isAppeal() || $verdict->isUpheld()) {
return; // Can not be reversed
}
......@@ -55,7 +61,10 @@ class ReverseActionDelegate
switch ($report->getReasonCode()) {
case 1: // Illegal (not appealable)
$this->actions->setDeletedFlag($entity, false);
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, false);
$this->saveAction->setEntity($entity)->save();
}
// Ban the owner of the post too
$this->unBan($report);
break;
......@@ -63,22 +72,31 @@ class ReverseActionDelegate
$nsfw = $report->getSubReasonCode();
$entity->setNsfw(array_diff([$nsfw], $entity->getNsfw()));
$entity->setNsfwLock(array_diff([$nsfw], $entity->getNsfwLock()));
$entity->save();
$this->saveAction->setEntity($entity)->save();
// Apply a strike to the owner
$this->removeStrike($report);
break;
case 3: // Incites violence
$this->actions->setDeletedFlag($entity, false);
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, false);
$this->saveAction->setEntity($entity)->save();
}
// Ban the owner of the post
$this->unBan($report);
break;
case 4: // Harrasment
$this->actions->setDeletedFlag($entity, false);
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, false);
$this->saveAction->setEntity($entity)->save();
}
// Apply a strike to the owner
$this->removeStrike($report);
break;
case 5: // Personal and confidential information (not appelable)
$this->actions->setDeletedFlag($entity, false);
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, false);
$this->saveAction->setEntity($entity)->save();
}
// Ban the owner of the post too
$this->unBan($report);
break;
......@@ -87,7 +105,10 @@ class ReverseActionDelegate
$this->unBan($report);
break;
case 8: // Spam
$this->actions->setDeletedFlag($entity, false);
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, false);
$this->saveAction->setEntity($entity)->save();
}
// Apply a strike to the owner
$this->removeStrike($report);
break;
......@@ -96,7 +117,10 @@ class ReverseActionDelegate
// Apply a strike to the owner
// break;
case 13: // Malware
$this->actions->setDeletedFlag($entity, false);
if ($entity->type !== 'user') {
$this->actions->setDeletedFlag($entity, false);
$this->saveAction->setEntity($entity)->save();
}
// Ban the owner
$this->unBan($report);
break;
......@@ -125,17 +149,15 @@ class ReverseActionDelegate
->setUserGuid($report->getEntityOwnerGuid())
->setReasonCode($report->getReasonCode())
->setSubReasonCode($report->getSubReasonCode())
->setTimestamp(round(microtime(true) * 1000));
->setTimestamp($report->getTimestamp()); // Strike is recored for date of first report
$this->strikesManager->delete($strike);
// If 3 or more strikes, ban or apply NSFW lock
if ($this->strikesManager->countStrikesInTimeWindow($strike, $this->strikesManager::STRIKE_RETENTION_WINDOW) >= 3) {
if ($report->getReasonCode() === 2) {
$this->removeNsfwLock($report);
} else {
$this->unBan($report);
}
// Remove any bans or nsfw locks
if ($report->getReasonCode() === 2) {
$this->removeNsfwLock($report);
} else {
$this->unBan($report);
}
}
......@@ -168,4 +190,4 @@ class ReverseActionDelegate
$user->save();
}
}
\ No newline at end of file
}
......@@ -104,7 +104,7 @@ class Manager
{
$uphold = $this->isUpheld($verdict);
$verdict->setUphold($uphold);
$verdict->setTimestamp(round(microtime(true) * 1000));
$verdict->setTimestamp(time());
if ($verdict->isUpheld() === null) {
error_log("{$verdict->getReport()->getEntityGuid()} not actionable");
......