Commit c0411b84 authored by Mark Harding's avatar Mark Harding

(wip): staging work in progress changes

1 merge request!100Epic/reporting and moderation
Pipeline #61523350 failed with stages
in 3 minutes and 54 seconds
......@@ -19,7 +19,7 @@ class jury implements Interfaces\Api
$juryType = $pages[0] ?? 'appeal';
if ($juryType !== 'appeal' && !Core\Session::isAdmin()) {
//exit;
exit;
}
$juryManager = Di::_()->get('Moderation\Jury\Manager');
......@@ -39,7 +39,7 @@ class jury implements Interfaces\Api
public function post($pages)
{
$juryType = $pages[0] ?? null;
$entityGuid = $pages[1] ?? null;
$urn = $pages[1] ?? null;
$uphold = $_POST['uphold'] ?? null;
if (!$juryType) {
......@@ -49,10 +49,10 @@ class jury implements Interfaces\Api
]);
}
if (!$entityGuid) {
if (!$urn) {
return Factory::response([
'status' => 'error',
'message' => 'You must supply the entity guid in the URI like /:juryType/:entityGuid',
'message' => 'You must supply the entity urn in the URI like /:juryType/:urn',
]);
}
......@@ -63,7 +63,7 @@ class jury implements Interfaces\Api
]);
}
if (!Core\Session::getLoggedInUser()->getPhoneNumberHash() && false) {
if (!Core\Session::getLoggedInUser()->getPhoneNumberHash()) {
return Factory::response([
'status' => 'error',
'message' => 'juror must be in the rewards program',
......@@ -72,7 +72,7 @@ class jury implements Interfaces\Api
$juryManager = Di::_()->get('Moderation\Jury\Manager');
$moderationManager = Di::_()->get('Moderation\Manager');
$report = $moderationManager->getReport($entityGuid);
$report = $moderationManager->getReport($urn);
$decision = new Decision();
$decision
......
......@@ -69,6 +69,10 @@ class report implements Interfaces\Api
->setReporterGuid($user->getGuid())
->setTimestamp(round(microtime(true) * 1000));
if ($user->getPhoneNumberHash()) {
$userReport->setReporterHash($user->getPhoneNumberHash());
}
if (!$manager->add($userReport)) {
return Factory::response([
'status' => 'error',
......
......@@ -34,7 +34,7 @@ class EntityGuidResolverDelegate implements ResolverDelegate
*/
public function shouldResolve(Urn $urn)
{
return $urn->getNid() === 'entity' || $urn->getNid() === 'activity';
return $urn->getNid() === 'entity' || $urn->getNid() === 'activity' || $urn->getNid() === 'user';
}
/**
......
......@@ -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() === false) {
$skip = true;
}
break;
case 'rejected':
if ($report->getState() != 'appeal_jury_decided' && $report->isUpheld() === true) {
if ($report->getState() !== 'appeal_jury_decided' || $report->isUpheld() === true) {
$skip = true;
}
break;
......
......@@ -40,9 +40,9 @@ class Manager
return $this->repository->getList($opts);
}
public function getReport($entity_guid)
public function getReport($urn)
{
return $this->repository->get($entity_guid);
return $this->repository->get($urn);
}
/**
......
......@@ -104,12 +104,12 @@ class Repository
$values[] = $opts['entity_urn'];
}
if ($opts['reason_code']) {
if (isset($opts['reason_code'])) {
$where[] = "reason_code = ?";
$values[] = new Tinyint($opts['reason_code']);
}
if ($opts['sub_reason_code']) {
if (isset($opts['sub_reason_code'])) {
$where[] = "sub_reason_code = ?";
$values[] = new Decimal($opts['sub_reason_code']);
}
......@@ -156,7 +156,7 @@ class Repository
'sub_reason_code' => $subReasonCode,
'timestamp' => $timestamp,
]);
if (!$response[0]) {
return null;
}
......
......@@ -7,8 +7,8 @@ namespace Minds\Core\Reports\Strikes;
class Manager
{
//const STRIKE_TIME_WINDOW = (60 * 60) * 24; // 24 hours
const STRIKE_TIME_WINDOW = 60;
const STRIKE_TIME_WINDOW = (60 * 60) * 24; // 24 hours
//const STRIKE_TIME_WINDOW = 60;
const STRIKE_RETENTION_WINDOW = (60 * 60) * 24 * 90; // 90 days
/** @var Repository $repository */
......@@ -70,4 +70,14 @@ class Manager
return count($strikes);
}
}
\ No newline at end of file
/**
* Delete a strike
* @param Strike $strike
* @return bool
*/
public function delete($strike)
{
return $this->repository->delete($strike);
}
}
......@@ -55,12 +55,12 @@ class Repository
new Bigint($opts['user_guid']),
];
if ($opts['reason_code']) {
if (isset($opts['reason_code'])) {
$statement .= " AND reason_code = ?";
$values[] = new Tinyint($opts['reason_code']);
}
if ($opts['sub_reason_code']) {
if (isset($opts['sub_reason_code'])) {
$statement .= " AND sub_reason_code = ?";
$values[] = new Decimal($opts['sub_reason_code']);
}
......@@ -80,7 +80,7 @@ class Repository
$values[] = new Timestamp($opts['to'] * 1000);
}
if (!$opts['reason_code'] && !$opts['sub_reason_code']) {
if (!isset($opts['reason_code']) && !isset($opts['sub_reason_code'])) {
$statement .= " ALLOW FILTERING";
}
......@@ -160,4 +160,4 @@ class Repository
}
}
\ No newline at end of file
}
......@@ -75,7 +75,7 @@ class Repository
AND timestamp = ?";
$values[] = $report->getReport()->getEntityUrn();
$values[] = new Tinyint($report->getReport()->getReasonCode());
$values[] = new Decimal($report->getReport()->getSubReasonCode());
$values[] = new Decimal($report->getReport()->getSubReasonCode() ?? 0);
$values[] = new Timestamp($report->getReport()->getTimestamp());
$prepared = new Prepared;
......
......@@ -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 ActionDelegate
{
......@@ -19,6 +20,9 @@ class ActionDelegate
/** @var Actions $actions */
private $actions;
/** @var SaveAction $saveAction */
private $saveAction;
/** @var Urn $urn */
private $urn;
......@@ -29,18 +33,21 @@ class ActionDelegate
$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 onAction(Verdict $verdict)
{
if ($verdict->isAppeal()) {
if ($verdict->isAppeal() || !$verdict->isUpheld()) {
error_log('Not upheld so no action');
return; // Can not
}
......@@ -56,6 +63,7 @@ class ActionDelegate
switch ($report->getReasonCode()) {
case 1: // Illegal (not appealable)
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
// Ban the owner of the post too
$this->applyBan($report);
break;
......@@ -63,22 +71,25 @@ class ActionDelegate
$nsfw = $report->getSubReasonCode();
$entity->setNsfw(array_merge([$nsfw], $entity->getNsfw()));
$entity->setNsfwLock(array_merge([$nsfw], $entity->getNsfwLock()));
$entity->save();
$this->saveAction->setEntity($entity)->save();
// Apply a strike to the owner
$this->applyStrike($report);
break;
case 3: // Incites violence
$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();
// 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();
// Ban the owner of the post too
$this->applyBan($report);
break;
......@@ -88,6 +99,8 @@ class ActionDelegate
break;
case 8: // Spam
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
error_log('marked as spam');
// Apply a strike to the owner
$this->applyStrike($report);
break;
......@@ -97,6 +110,7 @@ class ActionDelegate
// break;
case 13: // Malware
$this->actions->setDeletedFlag($entity, true);
$this->saveAction->setEntity($entity)->save();
// Ban the owner
$this->applyBan($report);
break;
......@@ -194,4 +208,4 @@ class ActionDelegate
$user->save();
}
}
\ No newline at end of file
}
......@@ -65,7 +65,8 @@ class Repository
$statement = "UPDATE moderation_reports
SET state = ?,
state_changes += ?
state_changes += ?,
uphold = ?
WHERE entity_urn = ?
AND reason_code = ?
AND sub_reason_code = ?
......@@ -79,6 +80,7 @@ class Repository
$values = [
$state,
$stateChangesMap,
(bool) $verdict->isUpheld(),
$verdict->getReport()->getEntityUrn(),
new Tinyint($verdict->getReport()->getReasonCode()),
new Decimal($verdict->getReport()->getSubReasonCode()),
......
......@@ -147,6 +147,13 @@ class ACL
return false;
}
/**
* If the user is banned or in a limited state
*/
if ($user->isBanned() || !$user->isEnabled()) {
return false;
}
/**
* Does the user own the entity, or is it the container?
*/
......@@ -227,6 +234,13 @@ class ACL
return false;
}
/**
* If the user is banned or in a limited state
*/
if ($user->isBanned() || !$user->isEnabled()) {
return false;
}
/**
* Check if we are the owner
*/
......
......@@ -1035,4 +1035,13 @@ class User extends \ElggUser
return $this;
}
/**
* Preferred urn
* @return string
*/
public function getUrn()
{
return "urn:user:{$this->getGuid()}";
}
}
......@@ -734,7 +734,8 @@ class ElggUser extends ElggEntity
'icontime',
'legacy_guid',
'featured_id',
'banned'
'banned',
'ban_reason',
));
}
......
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