Commit 11046c94 authored by Brian Hatchet's avatar Brian Hatchet :speech_balloon:

Removing the kudzu, now we don't need to touch every entity

1 merge request!335Feat/permissions on entities 737
Pipeline #85821429 failed with stages
in 4 minutes and 22 seconds
......@@ -73,7 +73,7 @@ class media implements Interfaces\Api, Interfaces\ApiIgnorePam
Security\ACL::$ignore = $ignore;
}
/* no break */
/* No break */
default:
$entity->fullExport = true;
$response['entity'] = $entity->export();
......@@ -92,8 +92,6 @@ class media implements Interfaces\Api, Interfaces\ApiIgnorePam
$response['entity']['canEdit'] = $entity->canEdit();
Security\ACL::$ignore = $ignore;
}
}
}
......
......@@ -112,19 +112,9 @@ class recommended implements Interfaces\Api
// Trim to correct length
$entities = array_slice($entities, 0, $limit);
$permissions = null;
$currentUser = Core\Session::getLoggedinUser();
//Calculate new permissions object with the entities
if (Di::_()->get('Features\Manager')->has('permissions')) {
$permissionsManager = Core\Di\Di::_()->get('Permissions\Manager');
$permissions = $permissionsManager->getList(['user_guid' => $currentUser,
'entities' => $entities]);
}
return Factory::response([
'entities' => Factory::exportable($entities),
'permissions' => $permissions,
'entities' => Factory::exportable($entities)
]);
}
......
......@@ -40,7 +40,6 @@ class newsfeed implements Interfaces\Api
$pinned_guids = null;
switch ($pages[0]) {
/* Refactored to it's own controller
case 'single':
$activity = new Activity($pages[1]);
......@@ -57,7 +56,6 @@ class newsfeed implements Interfaces\Api
return Factory::response(['activity' => $activity->export()]);
break;
*/
default:
case 'personal':
$options = [
......@@ -170,8 +168,6 @@ class newsfeed implements Interfaces\Api
array_shift($activity);
}
$loadPrevious = $activity ? (string) current($activity)->guid : '';
// \Minds\Helpers\Counters::incrementBatch($activity, 'impression');
......@@ -215,7 +211,7 @@ class newsfeed implements Interfaces\Api
}
}
}
if ($activity) {
if (!$loadNext) {
$loadNext = (string) end($activity)->guid;
......
<?php
/**
* Minds Newsfeed Single refactor API
*
* @version 1
* @author Brian Hatchet
*/
namespace Minds\Controllers\api\v1;
use Minds\Api\Factory;
use Minds\Core;
use Minds\Core\Security;
use Minds\Entities;
use Minds\Entities\Activity;
use Minds\Helpers;
use Minds\Entities\Factory as EntitiesFactory;
use Minds\Helpers\Counters;
use Minds\Interfaces;
use Minds\Interfaces\Flaggable;
use Minds\Core\Di\Di;
use Minds\Core\Entities\Actions\Save;
class newsfeed implements Interfaces\Api
{
/**
* Returns the newsfeed
* @param array $pages
*
* API:: /v1/newsfeed/single/:guid
*/
public function get($pages)
{
$activity = new Activity($pages[1]);
if (!Security\ACL::_()->read($activity)) {
return Factory::response([
'status' => 'error',
'message' => 'You do not have permission to view this post'
]);
}
if (!$activity->guid || Helpers\Flags::shouldFail($activity)) {
return Factory::response(['status' => 'error']);
}
$response = [
'activity' => $activity->export()
];
return Factory::response($response);
}
public function post($pages)
{
}
public function put($pages)
{
}
public function delete($pages)
{
}
}
......@@ -153,7 +153,6 @@ class feed implements Interfaces\Api
return Factory::response([
'entities' => Exportable::_($boosts),
'permissions' => $permissions,
'load-next' => $next ?: null,
]);
}
......
......@@ -13,15 +13,12 @@ use Minds\Common\Urn;
use Minds\Core\Entities\Resolver;
use Minds\Core\Session;
use Minds\Interfaces;
use Minds\Core\Di\Di;
class entities implements Interfaces\Api
{
/**
* Equivalent to HTTP GET method.
*
* @param array $pages
*
* Equivalent to HTTP GET method
* @param array $pages
* @return mixed|null
*/
public function get($pages)
......@@ -34,7 +31,7 @@ class entities implements Interfaces\Api
->setUser(Session::getLoggedinUser() ?: null)
->setUrns($urns)
->setOpts([
'asActivities' => $asActivities,
'asActivities' => $asActivities
]);
$entities = $resolver->fetch();
......@@ -42,15 +39,12 @@ class entities implements Interfaces\Api
// Return
return Factory::response([
'entities' => Exportable::_(array_values($entities)),
'permissions' => $permissions,
]);
}
/**
* Equivalent to HTTP POST method.
*
* @param array $pages
*
* Equivalent to HTTP POST method
* @param array $pages
* @return mixed|null
*/
public function post($pages)
......@@ -59,10 +53,8 @@ class entities implements Interfaces\Api
}
/**
* Equivalent to HTTP PUT method.
*
* @param array $pages
*
* Equivalent to HTTP PUT method
* @param array $pages
* @return mixed|null
*/
public function put($pages)
......@@ -71,10 +63,8 @@ class entities implements Interfaces\Api
}
/**
* Equivalent to HTTP DELETE method.
*
* @param array $pages
*
* Equivalent to HTTP DELETE method
* @param array $pages
* @return mixed|null
*/
public function delete($pages)
......
......@@ -13,10 +13,8 @@ use Minds\Interfaces;
class feeds implements Interfaces\Api
{
/**
* Gets a list of suggested hashtags, including the ones the user has opted in.
*
* Gets a list of suggested hashtags, including the ones the user has opted in
* @param array $pages
*
* @throws \Exception
*/
public function get($pages)
......@@ -31,7 +29,7 @@ class feeds implements Interfaces\Api
if (!$filter) {
return Factory::response([
'status' => 'error',
'message' => 'Invalid filter',
'message' => 'Invalid filter'
]);
}
......@@ -40,7 +38,7 @@ class feeds implements Interfaces\Api
if (!$algorithm) {
return Factory::response([
'status' => 'error',
'message' => 'Invalid algorithm',
'message' => 'Invalid algorithm'
]);
}
......@@ -74,6 +72,8 @@ class feeds implements Interfaces\Api
$period = '1y';
}
//
$hardLimit = 600;
if ($currentUser && $currentUser->isAdmin()) {
......@@ -105,6 +105,8 @@ class feeds implements Interfaces\Api
]);
}
//
$hashtag = null;
if (isset($_GET['hashtag'])) {
$hashtag = strtolower($_GET['hashtag']);
......@@ -130,7 +132,7 @@ class feeds implements Interfaces\Api
if (!$container || !Core\Security\ACL::_()->read($container)) {
return Factory::response([
'status' => 'error',
'message' => 'Forbidden',
'message' => 'Forbidden'
]);
}
}
......@@ -200,11 +202,9 @@ class feeds implements Interfaces\Api
'status' => 'success',
'entities' => Exportable::_($result),
'load-next' => $limit + $offset,
'permissions' => $permissions,
]);
} catch (\Exception $e) {
error_log($e);
return Factory::response(['status' => 'error', 'message' => $e->getMessage()]);
}
}
......
......@@ -13,12 +13,9 @@ use Minds\Interfaces;
class container implements Interfaces\Api
{
/**
* Equivalent to HTTP GET method.
*
* Equivalent to HTTP GET method
* @param array $pages
*
* @return mixed|null
*
* @throws \Exception
*/
public function get($pages)
......@@ -26,6 +23,8 @@ class container implements Interfaces\Api
/** @var User $currentUser */
$currentUser = Core\Session::getLoggedinUser();
//
$container_guid = $pages[0] ?? null;
if (!$container_guid) {
......@@ -63,6 +62,8 @@ class container implements Interfaces\Api
break;
}
//
$hardLimit = 5000;
$offset = 0;
......@@ -89,6 +90,8 @@ class container implements Interfaces\Api
]);
}
//
$sync = (bool) ($_GET['sync'] ?? false);
$fromTimestamp = $_GET['from_timestamp'] ?? 0;
......@@ -158,20 +161,16 @@ class container implements Interfaces\Api
'status' => 'success',
'entities' => Exportable::_($result),
'load-next' => $result->getPagingToken(),
'permissions' => $permissions,
]);
} catch (\Exception $e) {
error_log($e);
return Factory::response(['status' => 'error', 'message' => $e->getMessage()]);
}
}
/**
* Equivalent to HTTP POST method.
*
* Equivalent to HTTP POST method
* @param array $pages
*
* @return mixed|null
*/
public function post($pages)
......@@ -180,10 +179,8 @@ class container implements Interfaces\Api
}
/**
* Equivalent to HTTP PUT method.
*
* Equivalent to HTTP PUT method
* @param array $pages
*
* @return mixed|null
*/
public function put($pages)
......@@ -192,10 +189,8 @@ class container implements Interfaces\Api
}
/**
* Equivalent to HTTP DELETE method.
*
* Equivalent to HTTP DELETE method
* @param array $pages
*
* @return mixed|null
*/
public function delete($pages)
......
......@@ -6,18 +6,16 @@ use Minds\Api\Exportable;
use Minds\Api\Factory;
use Minds\Core;
use Minds\Core\Di\Di;
use Minds\Entities\Factory as EntitiesFactory;
use Minds\Entities\User;
use Minds\Interfaces;
class subscribed implements Interfaces\Api
{
/**
* Equivalent to HTTP GET method.
*
* Equivalent to HTTP GET method
* @param array $pages
*
* @return mixed|null
*
* @throws \Exception
*/
public function get($pages)
......@@ -43,6 +41,8 @@ class subscribed implements Interfaces\Api
break;
}
//
$hardLimit = 5000;
$offset = 0;
......@@ -69,6 +69,8 @@ class subscribed implements Interfaces\Api
]);
}
//
$sync = (bool) ($_GET['sync'] ?? false);
$fromTimestamp = $_GET['from_timestamp'] ?? 0;
......@@ -124,20 +126,16 @@ class subscribed implements Interfaces\Api
'status' => 'success',
'entities' => Exportable::_($result),
'load-next' => $result->getPagingToken(),
'permissions' => $permissions,
]);
} catch (\Exception $e) {
error_log($e);
return Factory::response(['status' => 'error', 'message' => $e->getMessage()]);
}
}
/**
* Equivalent to HTTP POST method.
*
* Equivalent to HTTP POST method
* @param array $pages
*
* @return mixed|null
*/
public function post($pages)
......@@ -146,10 +144,8 @@ class subscribed implements Interfaces\Api
}
/**
* Equivalent to HTTP PUT method.
*
* Equivalent to HTTP PUT method
* @param array $pages
*
* @return mixed|null
*/
public function put($pages)
......@@ -158,10 +154,8 @@ class subscribed implements Interfaces\Api
}
/**
* Equivalent to HTTP DELETE method.
*
* Equivalent to HTTP DELETE method
* @param array $pages
*
* @return mixed|null
*/
public function delete($pages)
......
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