Skip to content
Commits on Source (2)
......@@ -9,6 +9,8 @@
namespace Minds\Api;
use Minds\Core\Di\Di;
use Minds\Core\Feeds\FeedSyncEntity;
use Minds\Core\Permissions\Manager;
use Minds\Core\Session;
class Exportable implements \JsonSerializable
......@@ -104,10 +106,24 @@ class Exportable implements \JsonSerializable
$exported = $item->export(...$this->exportArgs);
if ($item && Di::_()->get('Features\Manager')->has('permissions')) {
if ($item instanceof FeedSyncEntity && $item->getEntity()) {
$entity = $item->getEntity();
} else {
$entity = $item;
}
/** @var Manager $permissionsManager */
$permissionsManager = Di::_()->get('Permissions\Manager');
$permissions = $permissionsManager->getList(['user_guid' => Session::getLoggedinUser(),
'entities' => [$item]]);
$exported['permissions'] = $permissions->export();
$permissions = $permissionsManager->getList([
'user_guid' => Session::getLoggedinUser(),
'entities' => [$entity],
]);
if ($item instanceof FeedSyncEntity) {
$exported['entity']['permissions'] = $permissions->export();
} else {
$exported['permissions'] = $permissions->export();
}
}
// Shims
......
......@@ -209,13 +209,13 @@ class Factory
* @return array - an array of the entities
* @deprecated
*/
public static function exportable($entities, $exceptions = [], $exportContext = false)
public static function exportable($entities, $exceptions = [], $exportContext = false, $includePermissions = true)
{
$permissionsManager = Di::_()->get('Permissions\Manager');
if (!$entities) {
return [];
}
foreach ($entities as $k => $entity) {
if ($exportContext && method_exists($entity, 'setExportContext')) {
$entity->setExportContext($exportContext);
......@@ -223,9 +223,11 @@ class Factory
$entities[$k] = $entity->export();
//Calculate new permissions object with the entities
if ($entity && Di::_()->get('Features\Manager')->has('permissions')) {
$permissions = $permissionsManager->getList(['user_guid' => Session::getLoggedinUser(),
'entities' => [$entity]]);
if ($includePermissions && $entity && Di::_()->get('Features\Manager')->has('permissions')) {
$permissions = $permissionsManager->getList([
'user_guid' => Session::getLoggedinUser(),
'entities' => [$entity],
]);
$entities[$k]['permissions'] = $permissions->export();
}
$entities[$k]['guid'] = (string) $entities[$k]['guid']; //javascript doesn't like long numbers..
......
......@@ -41,7 +41,7 @@ class markers implements Interfaces\Api
return Factory::response([
'markers' => Factory::exportable($list),
'markers' => Factory::exportable($list, [], false, true),
]);
}
......
......@@ -8,7 +8,7 @@
namespace Minds\Core\Feeds;
use JsonSerializable;
use Minds\Traits\Exportable;
use Minds\Entities\Entity;
use Minds\Traits\MagicAttributes;
/**
......@@ -26,6 +26,7 @@ use Minds\Traits\MagicAttributes;
* @method FeedSyncEntity setAccessId(int $accessId)
* @method string getType()
* @method FeedSyncEntity setType(string $type)
* @method Entity getEntity()
*/
class FeedSyncEntity implements JsonSerializable
{
......@@ -68,7 +69,7 @@ class FeedSyncEntity implements JsonSerializable
{
return [
'guid' => (string) $this->guid,
'owner_guid' => (string) $this->ownerGuid,
'owner_guid' => (string) $this->ownerGuid,
'access_id' => $this->accessId,
'timestamp' => $this->timestamp,
'urn' => $this->urn,
......
......@@ -45,7 +45,7 @@ class Manager
}
$guids = $opts['guids'] ?: array_map(function ($item) {
return $item['guid'];
return $item->getGuid();
}, $opts['entities']);
$user = $this->entitiesBuilder->single($opts['user_guid']);
......