Commit bdbd8404 authored by Mark Harding's avatar Mark Harding

(fix): acl issues

1 merge request!100Epic/reporting and moderation
Pipeline #61855477 failed with stages
in 4 minutes and 47 seconds
......@@ -128,8 +128,8 @@ class Resolver
// Filter out forbidden entities
$sorted = array_filter($sorted, function($entity) {
return $this->acl->read($entity, $this->user)
&& !Flags::shouldFail($entity);
return $this->acl->read($entity, $this->user);
//&& !Flags::shouldFail($entity);
});
// Filter out pending activities
......
......@@ -13,6 +13,7 @@ use Minds\Entities\DenormalizedEntity;
use Minds\Entities\NormalizedEntity;
use Minds\Core\Entities\Resolver as EntitiesResolver;
use Minds\Common\Urn;
use Minds\Core\Security\ACL;
class Manager
{
......@@ -29,17 +30,22 @@ class Manager
/** @var Delegates\SummonDelegate $summonDelegate */
private $summonDelegate;
/** @var ACL $acl */
private $acl;
public function __construct(
$repository = null,
$entitiesResolver = null,
$notificationDelegate = null,
$summonDelegate = null
$summonDelegate = null,
$acl = null
)
{
$this->repository = $repository ?: new Repository;
$this->entitiesResolver = $entitiesResolver ?: new EntitiesResolver;
$this->notificationDelegate = $notificationDelegate ?: new Delegates\NotificationDelegate;
$this->summonDelegate = $summonDelegate ?: new Delegates\SummonDelegate();
$this->acl = $acl ?: new ACL();
}
/**
......@@ -59,9 +65,11 @@ class Manager
if ($opts['hydrate']) {
foreach ($response as $appeal) {
$report = $appeal->getReport();
$ignore = $this->acl->setIgnore(true);
$entity = $this->entitiesResolver->single(
(new Urn())->setUrn($report->getEntityUrn())
);
$this->acl->setIgnore($ignore); // Restore ACL
$report->setEntity($entity);
$appeal->setReport($report);
}
......
......@@ -16,6 +16,7 @@ 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;
use Minds\Core\Security\ACL;
class Manager
{
......@@ -32,6 +33,9 @@ class Manager
/** @var SummonsManager $summonsManager */
private $summonsManager;
/** @var ACL $acl */
private $acl;
/** @var string $juryType */
private $juryType;
......@@ -42,13 +46,15 @@ class Manager
$repository = null,
$entitiesResolver = null,
$verdictManager = null,
$summonsManager = null
$summonsManager = null,
$acl = 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');
$this->acl = $acl ?: new ACL;
}
/**
......@@ -121,9 +127,11 @@ class Manager
{
$report = $this->repository->get($urn);
if ($report) {
$ignore = $this->acl->setIgnore(true);
$entity = $this->entitiesResolver->single(
(new Urn())->setUrn($report->getEntityUrn())
);
$this->acl->setIgnore($ignore);
$report->setEntity($entity);
}
return $report;
......
......@@ -13,6 +13,7 @@ use Minds\Entities\DenormalizedEntity;
use Minds\Entities\NormalizedEntity;
use Minds\Core\Entities\Resolver as EntitiesResolver;
use Minds\Common\Urn;
use Minds\Core\Security\ACL;
class Manager
{
......@@ -26,15 +27,20 @@ class Manager
/** @var EntitiesResolver $entitiesResolver */
private $entitiesResolver;
/** @var ACL $acl */
private $acl;
public function __construct(
$repository = null,
$preFeb2019Repository = null,
$entitiesResolver = null
$entitiesResolver = null,
$acl = null
)
{
$this->repository = $repository ?: new Repository;
$this->preFeb2019Repository = $preFeb2019Repository ?: new PreFeb2019Repository();
$this->entitiesResolver = $entitiesResolver ?: new EntitiesResolver;
$this->acl = $acl ?: new ACL;
}
/**
......@@ -49,13 +55,13 @@ class Manager
$response = $this->repository->getList($opts);
$response = $this->repository->getList($opts);
if ($opts['hydrate']) {
foreach ($response as $report) {
$ignore = $this->acl->setIgnore(true);
$entity = $this->entitiesResolver->single(
(new Urn())->setUrn($report->getEntityUrn())
);
$this->acl->setIgnore($ignore);
$report->setEntity($entity);
}
}
......@@ -71,9 +77,11 @@ class Manager
public function getReport($urn)
{
$report = $this->repository->get($urn);
$ignore = $this->acl->setIgnore(true);
$entity = $this->entitiesResolver->single(
(new Urn())->setUrn($report->getEntityUrn())
);
$this->acl->setIgnore($ignore);
$report->setEntity($entity);
return $report;
}
......
......@@ -112,10 +112,10 @@ class Manager
$verdict->setTimestamp(time());
if ($verdict->isUpheld() === null) {
error_log("{$verdict->getReport()->getEntityGuid()} not actionable");
error_log("{$verdict->getReport()->getEntityUrn()} not actionable");
return false;
} else {
error_log("{$verdict->getReport()->getEntityGuid()} decided with {$verdict->getAction()}");
error_log("{$verdict->getReport()->getEntityUrn()} decided with {$verdict->getAction()}");
return $this->cast($verdict);
}
}
......
......@@ -7,6 +7,7 @@ namespace Minds\Core\Security;
use Minds\Core;
use Minds\Entities;
use Minds\Core\Security\RateLimits\Manager as RateLimitsManager;
use Minds\Helpers\Flags;
class ACL
{
......@@ -29,9 +30,16 @@ class ACL
ACL\Block::_()->listen();
}
/**
* Override the ACL and return the previous status
* @param boolean $ignore
* @return boolean
*/
public function setIgnore($ignore = false)
{
$previous = self::$ignore;
self::$ignore = $ignore;
return $previous;
}
/**
......@@ -51,6 +59,10 @@ class ACL
return true;
}
if (Flags::shouldFail($entity)) {
return false;
}
// If logged out and public and not container
if (!Core\Session::isLoggedIn()) {
if (
......
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