mirror of
https://github.com/friendica/friendica
synced 2025-04-26 15:10:11 +00:00
Move expand_acl to ACLFormatter::expand()
- including tests
This commit is contained in:
parent
7a9c5d10ee
commit
f65f7f11c3
8 changed files with 224 additions and 160 deletions
|
@ -24,6 +24,7 @@ use Friendica\Database\DBA;
|
|||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Protocol\OStatus;
|
||||
use Friendica\Util\ACLFormatter;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Map;
|
||||
use Friendica\Util\Network;
|
||||
|
@ -2892,10 +2893,13 @@ class Item extends BaseObject
|
|||
*/
|
||||
public static function enumeratePermissions(array $obj, bool $check_dead = false)
|
||||
{
|
||||
$allow_people = expand_acl($obj['allow_cid']);
|
||||
$allow_groups = Group::expand($obj['uid'], expand_acl($obj['allow_gid']), $check_dead);
|
||||
$deny_people = expand_acl($obj['deny_cid']);
|
||||
$deny_groups = Group::expand($obj['uid'], expand_acl($obj['deny_gid']), $check_dead);
|
||||
/** @var ACLFormatter $aclFormater */
|
||||
$aclFormater = self::getClass(ACLFormatter::class);
|
||||
|
||||
$allow_people = $aclFormater->expand($obj['allow_cid']);
|
||||
$allow_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['allow_gid']), $check_dead);
|
||||
$deny_people = $aclFormater->expand($obj['deny_cid']);
|
||||
$deny_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['deny_gid']), $check_dead);
|
||||
$recipients = array_unique(array_merge($allow_people, $allow_groups));
|
||||
$deny = array_unique(array_merge($deny_people, $deny_groups));
|
||||
$recipients = array_diff($recipients, $deny);
|
||||
|
|
|
@ -16,6 +16,7 @@ use Friendica\Model\Item;
|
|||
use Friendica\Model\User;
|
||||
use Friendica\Module\Login;
|
||||
use Friendica\Network\HTTPException\NotImplementedException;
|
||||
use Friendica\Util\ACLFormatter;
|
||||
use Friendica\Util\Crypto;
|
||||
|
||||
class Compose extends BaseModule
|
||||
|
@ -58,6 +59,9 @@ class Compose extends BaseModule
|
|||
|
||||
$user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
|
||||
|
||||
/** @var ACLFormatter $aclFormatter */
|
||||
$aclFormatter = self::getClass(ACLFormatter::class);
|
||||
|
||||
switch ($posttype) {
|
||||
case Item::PT_PERSONAL_NOTE:
|
||||
$compose_title = L10n::t('Compose new personal note');
|
||||
|
@ -70,8 +74,8 @@ class Compose extends BaseModule
|
|||
$compose_title = L10n::t('Compose new post');
|
||||
$type = 'post';
|
||||
$doesFederate = true;
|
||||
$contact_allow = implode(',', expand_acl($user['allow_cid']));
|
||||
$group_allow = implode(',', expand_acl($user['allow_gid'])) ?: Group::FOLLOWERS;
|
||||
$contact_allow = implode(',', $aclFormatter->expand($user['allow_cid']));
|
||||
$group_allow = implode(',', $aclFormatter->expand($user['allow_gid'])) ?: Group::FOLLOWERS;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -82,8 +86,8 @@ class Compose extends BaseModule
|
|||
$wall = $_REQUEST['wall'] ?? $type == 'post';
|
||||
$contact_allow = $_REQUEST['contact_allow'] ?? $contact_allow;
|
||||
$group_allow = $_REQUEST['group_allow'] ?? $group_allow;
|
||||
$contact_deny = $_REQUEST['contact_deny'] ?? implode(',', expand_acl($user['deny_cid']));
|
||||
$group_deny = $_REQUEST['group_deny'] ?? implode(',', expand_acl($user['deny_gid']));
|
||||
$contact_deny = $_REQUEST['contact_deny'] ?? implode(',', $aclFormatter->expand($user['deny_cid']));
|
||||
$group_deny = $_REQUEST['group_deny'] ?? implode(',', $aclFormatter->expand($user['deny_gid']));
|
||||
$visibility = ($contact_allow . $user['allow_gid'] . $user['deny_cid'] . $user['deny_gid']) ? 'custom' : 'public';
|
||||
|
||||
$acl_contacts = Contact::selectToArray(['id', 'name', 'addr', 'micro'], ['uid' => local_user(), 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]);
|
||||
|
|
27
src/Util/ACLFormatter.php
Normal file
27
src/Util/ACLFormatter.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Util;
|
||||
|
||||
use Friendica\Model\Group;
|
||||
|
||||
/**
|
||||
* Util class for ACL formatting
|
||||
*/
|
||||
final class ACLFormatter
|
||||
{
|
||||
/**
|
||||
* Turn user/group ACLs stored as angle bracketed text into arrays
|
||||
*
|
||||
* @param string $ids A angle-bracketed list of IDs
|
||||
*
|
||||
* @return array The array based on the IDs
|
||||
*/
|
||||
public function expand(string $ids)
|
||||
{
|
||||
// turn string array of angle-bracketed elements into numeric array
|
||||
// e.g. "<1><2><3>" => array(1,2,3);
|
||||
preg_match_all('/<(' . Group::FOLLOWERS . '|'. Group::MUTUALS . '|[0-9]+)>/', $ids, $matches, PREG_PATTERN_ORDER);
|
||||
|
||||
return $matches[1];
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ use Friendica\Protocol\ActivityPub;
|
|||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Protocol\OStatus;
|
||||
use Friendica\Protocol\Salmon;
|
||||
use Friendica\Util\ACLFormatter;
|
||||
|
||||
require_once 'include/items.php';
|
||||
|
||||
|
@ -272,10 +273,13 @@ class Notifier
|
|||
$public_message = false; // private recipients, not public
|
||||
}
|
||||
|
||||
$allow_people = expand_acl($parent['allow_cid']);
|
||||
$allow_groups = Group::expand($uid, expand_acl($parent['allow_gid']),true);
|
||||
$deny_people = expand_acl($parent['deny_cid']);
|
||||
$deny_groups = Group::expand($uid, expand_acl($parent['deny_gid']));
|
||||
/** @var ACLFormatter $aclFormatter */
|
||||
$aclFormatter = BaseObject::getClass(ACLFormatter::class);
|
||||
|
||||
$allow_people = $aclFormatter->expand($parent['allow_cid']);
|
||||
$allow_groups = Group::expand($uid, $aclFormatter->expand($parent['allow_gid']),true);
|
||||
$deny_people = $aclFormatter->expand($parent['deny_cid']);
|
||||
$deny_groups = Group::expand($uid, $aclFormatter->expand($parent['deny_gid']));
|
||||
|
||||
// if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
|
||||
// a delivery fork. private groups (forum_mode == 2) do not uplink
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue