Disallow posting to restricted groups

This commit is contained in:
Michael 2024-08-24 14:07:59 +00:00
parent a3a8b6c9ec
commit dace658d5d
3 changed files with 29 additions and 15 deletions

View file

@ -259,6 +259,17 @@ class Contact
return DBA::update('contact', $fields, $condition, $old_fields); return DBA::update('contact', $fields, $condition, $old_fields);
} }
/**
* @param integer $id Contact ID
* @param array $fields Array of selected fields, empty for all
* @return array|boolean Contact record if it exists, false otherwise
* @throws \Exception
*/
public static function getAccountById(int $id, array $fields = [])
{
return DBA::selectFirst('account-user-view', $fields, ['id' => $id]);
}
/** /**
* @param integer $id Contact ID * @param integer $id Contact ID
* @param array $fields Array of selected fields, empty for all * @param array $fields Array of selected fields, empty for all
@ -2375,7 +2386,8 @@ class Contact
if ($default_avatar && Proxy::isLocalImage($avatar)) { if ($default_avatar && Proxy::isLocalImage($avatar)) {
$fields = [ $fields = [
'avatar' => $avatar, 'avatar-date' => DateTimeFormat::utcNow(), 'avatar' => $avatar,
'avatar-date' => DateTimeFormat::utcNow(),
'photo' => $avatar, 'photo' => $avatar,
'thumb' => self::getDefaultAvatar($contact, Proxy::SIZE_THUMB), 'thumb' => self::getDefaultAvatar($contact, Proxy::SIZE_THUMB),
'micro' => self::getDefaultAvatar($contact, Proxy::SIZE_MICRO) 'micro' => self::getDefaultAvatar($contact, Proxy::SIZE_MICRO)

View file

@ -86,7 +86,7 @@ class Conversations extends BaseModule
throw new NotFoundException($this->t('Contact not found.')); throw new NotFoundException($this->t('Contact not found.'));
} }
$contact = Model\Contact::getById($pcid); $contact = Model\Contact::getAccountById($pcid);
if (empty($contact)) { if (empty($contact)) {
throw new NotFoundException($this->t('Contact not found.')); throw new NotFoundException($this->t('Contact not found.'));
} }
@ -111,6 +111,7 @@ class Conversations extends BaseModule
Nav::setSelected('contact'); Nav::setSelected('contact');
if (!$contact['ap-posting-restricted']) {
$options = [ $options = [
'lockstate' => ACL::getLockstateForUserId($this->userSession->getLocalUserId()) ? 'lock' : 'unlock', 'lockstate' => ACL::getLockstateForUserId($this->userSession->getLocalUserId()) ? 'lock' : 'unlock',
'acl' => ACL::getFullSelectorHTML($this->page, $this->userSession->getLocalUserId(), true, []), 'acl' => ACL::getFullSelectorHTML($this->page, $this->userSession->getLocalUserId(), true, []),
@ -118,6 +119,7 @@ class Conversations extends BaseModule
'content' => ($contact['contact-type'] == ModelContact::TYPE_COMMUNITY ? '!' : '@') . ($contact['addr'] ?: $contact['url']), 'content' => ($contact['contact-type'] == ModelContact::TYPE_COMMUNITY ? '!' : '@') . ($contact['addr'] ?: $contact['url']),
]; ];
$o = $this->conversation->statusEditor($options); $o = $this->conversation->statusEditor($options);
}
$o .= Contact::getTabsHTML($contact, Contact::TAB_CONVERSATIONS); $o .= Contact::getTabsHTML($contact, Contact::TAB_CONVERSATIONS);
$o .= Model\Contact::getThreadsFromId($contact['id'], $this->userSession->getLocalUserId(), 0, 0, $request['last_created'] ?? ''); $o .= Model\Contact::getThreadsFromId($contact['id'], $this->userSession->getLocalUserId(), 0, 0, $request['last_created'] ?? '');

View file

@ -156,30 +156,30 @@ class Acl extends BaseModule
switch ($type) { switch ($type) {
case self::TYPE_MENTION_CONTACT_CIRCLE: case self::TYPE_MENTION_CONTACT_CIRCLE:
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
["NOT `self` AND NOT `blocked` AND `notify` != ? AND `network` != ?", '', Protocol::OSTATUS ["NOT `self` AND NOT `blocked` AND `network` != ?", Protocol::OSTATUS
]); ]);
break; break;
case self::TYPE_MENTION_CONTACT: case self::TYPE_MENTION_CONTACT:
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
["NOT `self` AND NOT `blocked` AND `notify` != ?", '' ["NOT `self` AND NOT `blocked`",
]); ]);
break; break;
case self::TYPE_MENTION_GROUP: case self::TYPE_MENTION_GROUP:
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
["NOT `self` AND NOT `blocked` AND `notify` != ? AND `contact-type` = ?", '', Contact::TYPE_COMMUNITY ["NOT `self` AND NOT `blocked` AND (NOT `ap-posting-restricted` OR `ap-posting-restricted` IS NULL) AND `contact-type` = ?", Contact::TYPE_COMMUNITY
]); ]);
break; break;
case self::TYPE_PRIVATE_MESSAGE: case self::TYPE_PRIVATE_MESSAGE:
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
["NOT `self` AND NOT `blocked` AND `notify` != ? AND `network` IN (?, ?, ?)", '', Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA ["NOT `self` AND NOT `blocked` AND `network` IN (?, ?, ?)", Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA
]); ]);
break; break;
} }
$contact_count = $this->database->count('contact', $condition); $contact_count = $this->database->count('account-user-view', $condition);
$resultTotal = $circle_count + $contact_count; $resultTotal = $circle_count + $contact_count;
@ -220,7 +220,7 @@ class Acl extends BaseModule
$contacts = []; $contacts = [];
if ($type != self::TYPE_MENTION_CIRCLE) { if ($type != self::TYPE_MENTION_CIRCLE) {
$contacts = Contact::selectToArray([], $condition, ['order' => ['name']]); $contacts = Contact::selectAccountToArray([], $condition, ['order' => ['name']]);
} }
$groups = []; $groups = [];