Commit 3f2d80e8 authored by Brian Hatchet's avatar Brian Hatchet :speech_balloon:

Exporting single entities properly

1 merge request!349Chore refactor permissions export
Pipeline #86148417 passed with stages
in 9 minutes and 45 seconds
......@@ -209,35 +209,39 @@ class Factory
* @return array - an array of the entities
* @deprecated
*/
public static function exportable($entities, $exceptions = [], $exportContext = false, $includePermissions = true)
public static function exportable($entities, $exceptions = [], $exportContext = false, $includePermissions = true) : array
{
$permissionsManager = Di::_()->get('Permissions\Manager');
if (!$entities) {
return [];
foreach ($entities as $k => $entity) {
$entities[$k] = Factory::export($entity, $exceptions, $exportContext, $includePermissions);
}
return $entities;
}
foreach ($entities as $k => $entity) {
if ($exportContext && method_exists($entity, 'setExportContext')) {
$entity->setExportContext($exportContext);
}
/**
* Exports a single entity, called by exportable for arrays
*/
public static function export($entity, $exceptions = false, $exportContext=false, $includePermissions = true) : array
{
if ($exportContext && method_exists($entity, 'setExportContext')) {
$entity->setExportContext($exportContext);
}
$entities[$k] = $entity->export();
//Calculate new permissions object with the entities
if ($includePermissions && $entity && Di::_()->get('Features\Manager')->has('permissions')) {
$permissions = $permissionsManager->getList([
'user_guid' => Session::getLoggedinUser(),
'entities' => [$entity],
]);
$entities[$k]['permissions'] = $permissions->exportPermission($entity->getGuid());
}
$entities[$k]['guid'] = (string) $entities[$k]['guid']; //javascript doesn't like long numbers..
if (isset($entities[$k]['ownerObj']['guid'])) {
$entities[$k]['ownerObj']['guid'] = (string) $entity->ownerObj['guid'];
}
foreach ($exceptions as $exception) {
$entities[$k][$exception] = $entity->$exception;
}
$export = $entity->export();
//Calculate new permissions object with the entities
if ($includePermissions && $entity && Di::_()->get('Features\Manager')->has('permissions')) {
$permissions = $permissionsManager->getList([
'user_guid' => Session::getLoggedinUser(),
'entities' => [$entity],
]);
$export['permissions'] = $permissions->exportPermission($entity->getGuid());
}
return $entities;
$export['guid'] = (string) $export['guid']; //javascript doesn't like long numbers..
if (isset($export['ownerObj']['guid'])) {
$export['ownerObj']['guid'] = (string) $entity->ownerObj['guid'];
}
foreach ($exceptions as $exception) {
$export[$exception] = $export->$exception;
}
return $export;
}
}
......@@ -42,6 +42,7 @@ class newsfeed implements Interfaces\Api
switch ($pages[0]) {
case 'single':
$activity = new Activity($pages[1]);
if (!Security\ACL::_()->read($activity)) {
return Factory::response([
'status' => 'error',
......@@ -53,7 +54,7 @@ class newsfeed implements Interfaces\Api
return Factory::response(['status' => 'error']);
}
return Factory::response(['activity' => factory::exportable([$activity])]);
return Factory::response(['activity' => Factory::export($activity)]);
break;
default:
case 'personal':
......
This diff is collapsed.
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