Commit 63c28906 authored by Juan Manuel Solaro's avatar Juan Manuel Solaro

(feat) add filter by scheduled for entities resolver and adapt code as per review

1 merge request!294WIP: epic/post-scheduler
Pipeline #79426407 failed with stages
in 4 minutes and 56 seconds
......@@ -67,6 +67,12 @@ class scheduled implements Interfaces\Api
'status' => 'success',
'count' => $manager->getScheduledCount(['container_guid' => $container_guid, 'type' => $type])
]);
default:
return Factory::response([
'status' => 'error',
'message' => 'Invalid type',
]);
}
$hardLimit = 5000;
......
......@@ -23,7 +23,7 @@ class TimeCreatedDelegate
}
/**
* Validates time_created date and set it to activity
* Validates time_created date and sets it to activity
* @param $entity
* @param string $time_created
* @return bool
......
<?php
/**
* ResolverDelegate.
*
* @author juanmsolaro
*/
namespace Minds\Core\Entities\Delegates;
use Minds\Core\Security\ACL;
use Minds\Entities\User;
class FilterEntitiesDelegate
{
/** @var ACL */
protected $acl;
/** @var User */
protected $user;
protected $time;
public function __construct($user, $time, $acl = null)
{
$this->acl = $acl ?: ACL::_();
$this->user = $user;
$this->time = $time;
}
/**
* Filter entities by read rights and write rights for scheduled activities, images, videos or blogs
* @param array $entities
* @return array
*/
public function filter($entities) {
return array_values(array_filter($entities, function ($entity) {
$filterByScheduled = false;
if ($this->shouldFilterScheduled($entity->getType())) {
$filterByScheduled = !ACL::_()->write($entity, $this->user)
|| !($entity->getTimeCreated() <= $this->time);
}
return $this->acl->read($entity, $this->user) && !$filterByScheduled;
}));
}
private function shouldFilterScheduled($type) {
return $type == 'activity'
|| $type == 'blog'
|| $type == 'video'
|| $type == 'image';
}
}
......@@ -12,6 +12,7 @@ use Minds\Core\Entities\Delegates\BoostGuidResolverDelegate;
use Minds\Core\Entities\Delegates\CommentGuidResolverDelegate;
use Minds\Core\Entities\Delegates\EntityGuidResolverDelegate;
use Minds\Core\Entities\Delegates\ResolverDelegate;
use Minds\Core\Entities\Delegates\FilterEntitiesDelegate;
use Minds\Core\Security\ACL;
use Minds\Entities\User;
......@@ -128,11 +129,8 @@ class Resolver
});
// Filter out forbidden entities
$sorted = array_filter($sorted, function ($entity) {
return $this->acl->read($entity, $this->user);
//&& !Flags::shouldFail($entity);
});
$filterDelegate = new FilterEntitiesDelegate($this->user, time(), $this->acl);
$sorted = $filterDelegate->filter($sorted);
//
......
......@@ -219,7 +219,7 @@ class Activity extends Entity
'ephemeral',
'hide_impressions',
'pinned',
'time_sent'
'time_sent',
]);
}
......
......@@ -192,7 +192,7 @@ class Image extends File
'width',
'height',
'gif',
'time_sent'
'time_sent',
]);
}
......@@ -281,7 +281,7 @@ class Image extends File
'mature',
'boost_rejection_reason',
'rating',
'time_sent'
'time_sent',
];
foreach ($allowed as $field) {
......
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