Merge pull request #11251 from annando/forum2

Fix for private communities
This commit is contained in:
Hypolite Petovan 2022-02-15 20:16:07 -05:00 committed by GitHub
commit 6c0dbc1775
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 31 deletions

View file

@ -1442,26 +1442,36 @@ class Item
} }
$post = Post::selectFirst(['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'private'], ['uri-id' => $uriid, 'origin' => true]); $post = Post::selectFirst(['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'private'], ['uri-id' => $uriid, 'origin' => true]);
if (empty($post)) { if (!empty($post)) {
if (Post::exists(['uri-id' => $uriid, 'uid' => 0])) { if (in_array($post['private'], [Item::PUBLIC, Item::UNLISTED])) {
return 0; return $post['uid'];
} else { }
$pcid = Contact::getPublicIdByUserId($uid);
if (empty($pcid)) {
return null; return null;
} }
}
if (in_array($post['private'], [Item::PUBLIC, Item::UNLISTED])) { foreach (Item::enumeratePermissions($post, true) as $receiver) {
return $post['uid']; if ($receiver == $pcid) {
} return $post['uid'];
}
}
$pcid = Contact::getPublicIdByUserId($uid);
if (empty($pcid)) {
return null; return null;
} }
foreach (Item::enumeratePermissions($post, true) as $receiver) { if (Post::exists(['uri-id' => $uriid, 'uid' => 0])) {
if ($receiver == $pcid) { return 0;
return $post['uid']; }
// When the post belongs to a a forum then all forum users are allowed to access it
foreach (Tag::getByURIId($uriid, [Tag::EXCLUSIVE_MENTION]) as $tag) {
if (DBA::exists('contact', ['uid' => $uid, 'nurl' => Strings::normaliseLink($tag['url']), 'contact-type' => Contact::TYPE_COMMUNITY])) {
$target_uid = User::getIdForURL($tag['url']);
if (!empty($target_uid)) {
return $target_uid;
}
} }
} }

View file

@ -70,9 +70,7 @@ class Objects extends BaseModule
} }
} }
$item = Post::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid', 'gravity', 'deleted', 'parent-uri-id'], $item = Post::selectFirst([], ['uri-id' => $itemuri['id'], 'origin' => true]);
['uri-id' => $itemuri['id']], ['order' => ['origin' => true]]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
throw new HTTPException\NotFoundException(); throw new HTTPException\NotFoundException();
} }
@ -81,25 +79,16 @@ class Objects extends BaseModule
if (!$validated) { if (!$validated) {
$requester = HTTPSignature::getSigner('', $_SERVER); $requester = HTTPSignature::getSigner('', $_SERVER);
if (!empty($requester) && $item['origin']) { if (!empty($requester)) {
$requester_id = Contact::getIdForURL($requester, $item['uid']); $receivers = Item::enumeratePermissions($item, false);
if (!empty($requester_id)) {
$permissionSets = DI::permissionSet()->selectByContactId($requester_id, $item['uid']); $validated = in_array(Contact::getIdForURL($requester, $item['uid']), $receivers);
$psids = array_merge($permissionSets->column('id'), [PermissionSet::PUBLIC]); if (!$validated) {
$validated = in_array($item['psid'], $psids); $validated = in_array(Contact::getIdForURL($requester), $receivers);
} }
} }
} }
if ($validated) {
// Valid items are original post or posted from this node (including in the case of a forum)
$validated = ($item['origin'] || (parse_url($item['author-link'], PHP_URL_HOST) == parse_url(DI::baseUrl()->get(), PHP_URL_HOST)));
if (!$validated && $item['deleted']) {
$validated = Post::exists(['origin' => true, 'uri-id' => $item['parent-uri-id']]);
}
}
if (!$validated) { if (!$validated) {
throw new HTTPException\NotFoundException(); throw new HTTPException\NotFoundException();
} }