From 729d5ebaf11eb071baa79c998cfd30664f1ca7b1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Aug 2020 17:39:38 +0000 Subject: [PATCH] Support fetching private posts --- src/Module/Objects.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Module/Objects.php b/src/Module/Objects.php index 8080289f1..e03265486 100644 --- a/src/Module/Objects.php +++ b/src/Module/Objects.php @@ -25,9 +25,11 @@ use Friendica\BaseModule; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Network\HTTPException; use Friendica\Protocol\ActivityPub; +use Friendica\Util\HTTPSignature; use Friendica\Util\Network; /** @@ -45,17 +47,27 @@ class Objects extends BaseModule DI::baseUrl()->redirect(str_replace('objects/', 'display/', DI::args()->getQueryString())); } - /// @todo Add Authentication to enable fetching of non public content - // $requester = HTTPSignature::getSigner('', $_SERVER); + $item = Item::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid'], + ['guid' => $parameters['guid']], ['order' => ['origin' => true]]); + + $validated = false; + $requester = HTTPSignature::getSigner('', $_SERVER); + if (!empty($requester) && $item['origin']) { + $requester_id = Contact::getIdForURL($requester, $item['uid']); + if (!empty($requester_id)) { + $permissionSets = DI::permissionSet()->selectByContactId($requester_id, $item['uid']); + if (!empty($permissionSets)) { + $psid = array_merge($permissionSets->column('id'), + [DI::permissionSet()->getIdFromACL($item['uid'], '', '', '', '')]); + $validated = in_array($item['psid'], $psid); + } + } + } + + if (!$validated && !in_array($item['private'], [Item::PUBLIC, Item::UNLISTED])) { + unset($item); + } - $item = Item::selectFirst( - ['id', 'origin', 'author-link', 'changed'], - [ - 'guid' => $parameters['guid'], - 'private' => [Item::PUBLIC, Item::UNLISTED] - ], - ['order' => ['origin' => true]] - ); // Valid items are original post or posted from this node (including in the case of a forum) if (!DBA::isResult($item) || !$item['origin'] && (parse_url($item['author-link'], PHP_URL_HOST) != parse_url(DI::baseUrl()->get(), PHP_URL_HOST))) { throw new HTTPException\NotFoundException();