Avoid a notice - restructured validation check

This commit is contained in:
Michael 2020-08-31 15:01:46 +00:00
parent 523694538a
commit b8ac601582

View file

@ -50,26 +50,29 @@ class Objects extends BaseModule
$item = Item::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid'], $item = Item::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid'],
['guid' => $parameters['guid']], ['order' => ['origin' => true]]); ['guid' => $parameters['guid']], ['order' => ['origin' => true]]);
$validated = false; if (!DBA::isResult($item)) {
$requester = HTTPSignature::getSigner('', $_SERVER); throw new HTTPException\NotFoundException();
if (!empty($requester) && $item['origin']) { }
$requester_id = Contact::getIdForURL($requester, $item['uid']);
if (!empty($requester_id)) { $validated = in_array($item['private'], [Item::PUBLIC, Item::UNLISTED]);
$permissionSets = DI::permissionSet()->selectByContactId($requester_id, $item['uid']);
if (!empty($permissionSets)) { if (!$validated) {
$psid = array_merge($permissionSets->column('id'), $requester = HTTPSignature::getSigner('', $_SERVER);
[DI::permissionSet()->getIdFromACL($item['uid'], '', '', '', '')]); if (!empty($requester) && $item['origin']) {
$validated = in_array($item['psid'], $psid); $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);
}
// Valid items are original post or posted from this node (including in the case of a forum) // 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))) { if (!$validated || !$item['origin'] && (parse_url($item['author-link'], PHP_URL_HOST) != parse_url(DI::baseUrl()->get(), PHP_URL_HOST))) {
throw new HTTPException\NotFoundException(); throw new HTTPException\NotFoundException();
} }