Support fetching private posts

2022.09-rc
Michael 2020-08-30 17:39:38 +00:00
rodzic bdd834d313
commit 729d5ebaf1
1 zmienionych plików z 22 dodań i 10 usunięć

Wyświetl plik

@ -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();