Browse Source

Merge pull request #9147 from annando/Issue-8882

Issue 8882: Fixes permissions of pinned posts
pull/9156/head
Hypolite Petovan 1 year ago
committed by GitHub
parent
commit
b530ef709d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Database/DBA.php
  2. 14
      src/Model/Item.php
  3. 13
      src/Module/Profile/Status.php

8
src/Database/DBA.php

@ -669,10 +669,18 @@ class DBA
*/
public static function mergeConditions(array ...$conditions)
{
if (count($conditions) == 1) {
return current($conditions);
}
$conditionStrings = [];
$result = [];
foreach ($conditions as $key => $condition) {
if (!$condition) {
continue;
}
$condition = self::collapseCondition($condition);
$conditionStrings[] = array_shift($condition);

14
src/Model/Item.php

@ -201,19 +201,7 @@ class Item
return [];
}
if (empty($condition) || !is_array($condition)) {
$condition = ['iid' => $pinned];
} else {
reset($condition);
$first_key = key($condition);
if (!is_int($first_key)) {
$condition['iid'] = $pinned;
} else {
$values_string = substr(str_repeat("?, ", count($pinned)), 0, -2);
$condition[0] = '(' . $condition[0] . ") AND `iid` IN (" . $values_string . ")";
$condition = array_merge($condition, $pinned);
}
}
$condition = DBA::mergeConditions(['iid' => $pinned], $condition);
return self::selectThreadForUser($uid, $selected, $condition, $params);
}

13
src/Module/Profile/Status.php

@ -232,7 +232,18 @@ class Status extends BaseProfile
$items = DBA::toArray($items_stmt);
if ($pager->getStart() == 0 && !empty($a->profile['uid'])) {
$pinned_items = Item::selectPinned($a->profile['uid'], ['uri', 'pinned']);
$condition = ['private' => [Item::PUBLIC, Item::UNLISTED]];
if (remote_user()) {
$permissionSets = DI::permissionSet()->selectByContactId(remote_user(), $a->profile['uid']);
if (!empty($permissionSets)) {
$condition = ['psid' => array_merge($permissionSets->column('id'),
[DI::permissionSet()->getIdFromACL($a->profile['uid'], '', '', '', '')])];
}
} elseif ($a->profile['uid'] == local_user()) {
$condition = [];
}
$pinned_items = Item::selectPinned($a->profile['uid'], ['uri', 'pinned'], $condition);
$pinned = Item::inArray($pinned_items);
$items = array_merge($items, $pinned);
}

Loading…
Cancel
Save