Commit 07b675ea authored by Marcelo Rivera's avatar Marcelo Rivera

(fix): a few issues in subscriptions/incoming

1 merge request!350WIP: Epic/permissions 28
Pipeline #86112352 passed with stages
in 9 minutes and 29 seconds
......@@ -5,22 +5,23 @@ namespace Minds\Controllers\api\v2\subscriptions;
use Minds\Api\Factory;
use Minds\Core\Di\Di;
use Minds\Core\Session;
use Minds\Core\Subscriptions\Requests\Manager;
use Minds\Interfaces;
/**
* Incoming subscritions
* Incoming subscriptions
*/
class incoming implements Interfaces\Api
{
public function get($pages): bool
{
if (!isset($pages[0])) {
if (isset($pages[0])) {
return $this->getSingle($pages[0]);
} else {
return $this->getList($pages[0]);
return $this->getList();
}
}
/**
* Return a single request
* @param string $subscriberGuid
......@@ -29,11 +30,12 @@ class incoming implements Interfaces\Api
private function getSingle(string $subscriberGuid): bool
{
// Return a single request
/** @var Manager $manager */
$manager = Di::_()->get('Subscriptions\Requests\Manager');
// Construct URN on the fly
$urn = "urn:subscription-request:" . implode('-', [ Session::getLoggedInUserGuid(), $subscriberGuid ]);
$request = $manager->get($urn);
if (!$request || $request->getPublisherGuid() != Session::getLoggedInUserGuid()) {
......@@ -55,10 +57,11 @@ class incoming implements Interfaces\Api
private function getList(): bool
{
// Return a list of subscription requests
/** @var Manager $manager */
$manager = Di::_()->get('Subscriptions\Requests\Manager');
$requests = $manager->getIncomingList(Session::getLoggedInUserGuid(), []);
return Factory::response([
'requests' => Factory::exportable($requests),
'next' => $requests->getPagingToken(),
......@@ -74,14 +77,15 @@ class incoming implements Interfaces\Api
public function put($pages)
{
// Accept / Deny
/** @var Manager $manager */
$manager = Di::_()->get('Subscriptions\Requests\Manager');
// Construct URN on the fly
$subscriberGuid = $pages[0];
$urn = "urn:subscription-request:" . implode('-', [ Session::getLoggedInUserGuid(), $subscriberGuid ]);
$request = $manager->get($urn);
if (!$request || $request->getPublisherGuid() != Session::getLoggedInUserGuid()) {
return Factory::response([
'status' => 'error',
......
......@@ -45,7 +45,7 @@ class Manager
'hydrate' => true,
], $opts);
$opts['publisher_guid'] = $user_guid;
$opts['publisher_guid'] = $userGuid;
$response = $this->repository->getList($opts);
if ($opts['hydrate']) {
......@@ -109,7 +109,7 @@ class Manager
if ($existing->isDeclined()) {
throw new SubscriptionRequestAlreadyCompletedException();
}
$this->repository->delete($subscriptionRequest);
$this->notificationsDelegate->onAccept($subscriptionRequest);
......
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