Check null for acl-fields

This commit is contained in:
Philipp Holzer 2019-10-28 18:16:10 +01:00
parent aa94d27e6e
commit 3eda62bfa6
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
5 changed files with 29 additions and 16 deletions

View file

@ -64,10 +64,10 @@ function lockview_content(App $a)
/** @var ACLFormatter $aclFormatter */ /** @var ACLFormatter $aclFormatter */
$aclFormatter = BaseObject::getClass(ACLFormatter::class); $aclFormatter = BaseObject::getClass(ACLFormatter::class);
$allowed_users = $aclFormatter->expand($item['allow_cid']); $allowed_users = $aclFormatter->expand($item['allow_cid'] ?? '');
$allowed_groups = $aclFormatter->expand($item['allow_gid']); $allowed_groups = $aclFormatter->expand($item['allow_gid'] ?? '');
$deny_users = $aclFormatter->expand($item['deny_cid']); $deny_users = $aclFormatter->expand($item['deny_cid'] ?? '');
$deny_groups = $aclFormatter->expand($item['deny_gid']); $deny_groups = $aclFormatter->expand($item['deny_gid'] ?? '');
$o = L10n::t('Visible to:') . '<br />'; $o = L10n::t('Visible to:') . '<br />';
$l = []; $l = [];

View file

@ -2904,10 +2904,10 @@ class Item extends BaseObject
/** @var ACLFormatter $aclFormater */ /** @var ACLFormatter $aclFormater */
$aclFormater = self::getClass(ACLFormatter::class); $aclFormater = self::getClass(ACLFormatter::class);
$allow_people = $aclFormater->expand($obj['allow_cid']); $allow_people = $aclFormater->expand($obj['allow_cid'] ?? '');
$allow_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['allow_gid']), $check_dead); $allow_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['allow_gid'] ?? ''), $check_dead);
$deny_people = $aclFormater->expand($obj['deny_cid']); $deny_people = $aclFormater->expand($obj['deny_cid'] ?? '');
$deny_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['deny_gid']), $check_dead); $deny_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['deny_gid'] ?? ''), $check_dead);
$recipients = array_unique(array_merge($allow_people, $allow_groups)); $recipients = array_unique(array_merge($allow_people, $allow_groups));
$deny = array_unique(array_merge($deny_people, $deny_groups)); $deny = array_unique(array_merge($deny_people, $deny_groups));
$recipients = array_diff($recipients, $deny); $recipients = array_diff($recipients, $deny);

View file

@ -74,8 +74,8 @@ class Compose extends BaseModule
$compose_title = L10n::t('Compose new post'); $compose_title = L10n::t('Compose new post');
$type = 'post'; $type = 'post';
$doesFederate = true; $doesFederate = true;
$contact_allow = implode(',', $aclFormatter->expand($user['allow_cid'])); $contact_allow = implode(',', $aclFormatter->expand($user['allow_cid'] ?? ''));
$group_allow = implode(',', $aclFormatter->expand($user['allow_gid'])) ?: Group::FOLLOWERS; $group_allow = implode(',', $aclFormatter->expand($user['allow_gid'] ?? '')) ?: Group::FOLLOWERS;
break; break;
} }
@ -86,8 +86,8 @@ class Compose extends BaseModule
$wall = $_REQUEST['wall'] ?? $type == 'post'; $wall = $_REQUEST['wall'] ?? $type == 'post';
$contact_allow = $_REQUEST['contact_allow'] ?? $contact_allow; $contact_allow = $_REQUEST['contact_allow'] ?? $contact_allow;
$group_allow = $_REQUEST['group_allow'] ?? $group_allow; $group_allow = $_REQUEST['group_allow'] ?? $group_allow;
$contact_deny = $_REQUEST['contact_deny'] ?? implode(',', $aclFormatter->expand($user['deny_cid'])); $contact_deny = $_REQUEST['contact_deny'] ?? implode(',', $aclFormatter->expand($user['deny_cid'] ?? ''));
$group_deny = $_REQUEST['group_deny'] ?? implode(',', $aclFormatter->expand($user['deny_gid'])); $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'; $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]]); $acl_contacts = Contact::selectToArray(['id', 'name', 'addr', 'micro'], ['uid' => local_user(), 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]);

View file

@ -276,10 +276,10 @@ class Notifier
/** @var ACLFormatter $aclFormatter */ /** @var ACLFormatter $aclFormatter */
$aclFormatter = BaseObject::getClass(ACLFormatter::class); $aclFormatter = BaseObject::getClass(ACLFormatter::class);
$allow_people = $aclFormatter->expand($parent['allow_cid']); $allow_people = $aclFormatter->expand($parent['allow_cid'] ?? '');
$allow_groups = Group::expand($uid, $aclFormatter->expand($parent['allow_gid']),true); $allow_groups = Group::expand($uid, $aclFormatter->expand($parent['allow_gid'] ?? ''),true);
$deny_people = $aclFormatter->expand($parent['deny_cid']); $deny_people = $aclFormatter->expand($parent['deny_cid'] ?? '');
$deny_groups = Group::expand($uid, $aclFormatter->expand($parent['deny_gid'])); $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 // 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 // a delivery fork. private groups (forum_mode == 2) do not uplink

View file

@ -2,6 +2,7 @@
namespace Friendica\Test\src\Util; namespace Friendica\Test\src\Util;
use Error;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Util\ACLFormatter; use Friendica\Util\ACLFormatter;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -162,6 +163,18 @@ class ACLFormaterTest extends TestCase
$this->assertEquals(array('1', '3'), $aclFormatter->expand($text)); $this->assertEquals(array('1', '3'), $aclFormatter->expand($text));
} }
/**
* Test expected exception in case of wrong typehint
*
* @expectedException Error
*/
public function testExpandNull()
{
$aclFormatter = new ACLFormatter();
$aclFormatter->expand(null);
}
public function dataAclToString() public function dataAclToString()
{ {
return [ return [