More rework to make private communities working

This commit is contained in:
Michael 2022-02-16 22:56:55 +00:00
parent 6c0dbc1775
commit 9ac24a0f36
8 changed files with 79 additions and 67 deletions

View File

@ -239,7 +239,6 @@ function settings_post(App $a)
$allow_location = ((!empty($_POST['allow_location']) && (intval($_POST['allow_location']) == 1)) ? 1: 0); $allow_location = ((!empty($_POST['allow_location']) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
$publish = ((!empty($_POST['profile_in_directory']) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0); $publish = ((!empty($_POST['profile_in_directory']) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
$net_publish = ((!empty($_POST['profile_in_netdirectory']) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0); $net_publish = ((!empty($_POST['profile_in_netdirectory']) && (intval($_POST['profile_in_netdirectory']) == 1)) ? 1: 0);
$old_visibility = ((!empty($_POST['visibility']) && (intval($_POST['visibility']) == 1)) ? 1 : 0);
$account_type = ((!empty($_POST['account-type']) && (intval($_POST['account-type']))) ? intval($_POST['account-type']) : 0); $account_type = ((!empty($_POST['account-type']) && (intval($_POST['account-type']))) ? intval($_POST['account-type']) : 0);
$page_flags = ((!empty($_POST['page-flags']) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0); $page_flags = ((!empty($_POST['page-flags']) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0);
$blockwall = ((!empty($_POST['blockwall']) && (intval($_POST['blockwall']) == 1)) ? 0: 1); // this setting is inverted! $blockwall = ((!empty($_POST['blockwall']) && (intval($_POST['blockwall']) == 1)) ? 0: 1); // this setting is inverted!
@ -361,16 +360,21 @@ function settings_post(App $a)
DI::pConfig()->set(local_user(), 'system', 'unlisted', $unlisted); DI::pConfig()->set(local_user(), 'system', 'unlisted', $unlisted);
DI::pConfig()->set(local_user(), 'system', 'accessible-photos', $accessiblephotos); DI::pConfig()->set(local_user(), 'system', 'accessible-photos', $accessiblephotos);
if ($account_type == User::ACCOUNT_TYPE_COMMUNITY) {
$str_group_allow = '';
$str_contact_allow = '';
$str_group_deny = '';
$str_contact_deny = '';
DI::pConfig()->set(local_user(), 'system', 'unlisted', true);
$blockwall = true;
$blocktags = true;
$hide_friends = true;
}
if ($page_flags == User::PAGE_FLAGS_PRVGROUP) { if ($page_flags == User::PAGE_FLAGS_PRVGROUP) {
$hidewall = 1; $str_group_allow = '<' . Group::FOLLOWERS . '>';
if (!$str_contact_allow && !$str_group_allow && !$str_contact_deny && !$str_group_deny) {
if ($def_gid) {
info(DI::l10n()->t('Private forum has no privacy permissions. Using default privacy group.'));
$str_group_allow = '<' . $def_gid . '>';
} else {
notice(DI::l10n()->t('Private forum has no privacy permissions and no default privacy group.'));
}
}
} }
$fields = ['username' => $username, 'email' => $email, 'timezone' => $timezone, $fields = ['username' => $username, 'email' => $email, 'timezone' => $timezone,
@ -756,7 +760,7 @@ function settings_content(App $a)
'$allowloc' => ['allow_location', DI::l10n()->t('Use Browser Location:'), ($user['allow_location'] == 1), ''], '$allowloc' => ['allow_location', DI::l10n()->t('Use Browser Location:'), ($user['allow_location'] == 1), ''],
'$h_prv' => DI::l10n()->t('Security and Privacy Settings'), '$h_prv' => DI::l10n()->t('Security and Privacy Settings'),
'$visibility' => $profile['net-publish'], '$is_community' => ($user['account-type'] == User::ACCOUNT_TYPE_COMMUNITY),
'$maxreq' => ['maxreq', DI::l10n()->t('Maximum Friend Requests/Day:'), $maxreq , DI::l10n()->t("\x28to prevent spam abuse\x29")], '$maxreq' => ['maxreq', DI::l10n()->t('Maximum Friend Requests/Day:'), $maxreq , DI::l10n()->t("\x28to prevent spam abuse\x29")],
'$profile_in_dir' => $profile_in_dir, '$profile_in_dir' => $profile_in_dir,
'$profile_in_net_dir' => ['profile_in_netdirectory', DI::l10n()->t('Allow your profile to be searchable globally?'), $profile['net-publish'], DI::l10n()->t("Activate this setting if you want others to easily find and follow you. Your profile will be searchable on remote systems. This setting also determines whether Friendica will inform search engines that your profile should be indexed or not.") . $net_pub_desc], '$profile_in_net_dir' => ['profile_in_netdirectory', DI::l10n()->t('Allow your profile to be searchable globally?'), $profile['net-publish'], DI::l10n()->t("Activate this setting if you want others to easily find and follow you. Your profile will be searchable on remote systems. This setting also determines whether Friendica will inform search engines that your profile should be indexed or not.") . $net_pub_desc],

View File

@ -1994,10 +1994,8 @@ class Item
Logger::info('Community post will be distributed', ['uri' => $item['uri'], 'uid' => $uid, 'id' => $item_id, 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]); Logger::info('Community post will be distributed', ['uri' => $item['uri'], 'uid' => $uid, 'id' => $item_id, 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
if ($owner['page-flags'] == User::PAGE_FLAGS_PRVGROUP) { if ($owner['page-flags'] == User::PAGE_FLAGS_PRVGROUP) {
Group::getMembersForForum($owner['id']); $allow_cid = '';
$allow_gid = '<' . Group::FOLLOWERS . '>';
$allow_cid = '<' . $owner['id'] . '>';
$allow_gid = '<' . Group::getIdForForum($owner['id']) . '>';
$deny_cid = ''; $deny_cid = '';
$deny_gid = ''; $deny_gid = '';
self::performActivity($item['id'], 'announce', $uid, $allow_cid, $allow_gid, $deny_cid, $deny_gid); self::performActivity($item['id'], 'announce', $uid, $allow_cid, $allow_gid, $deny_cid, $deny_gid);
@ -3210,30 +3208,20 @@ class Item
} }
/** /**
* Is the given item array a post that is sent as starting post to a forum? * Does the given uri-id belongs to a post that is sent as starting post to a forum?
* *
* @param array $item * @param int $uri_id
* @param array $owner
* *
* @return boolean "true" when it is a forum post * @return boolean "true" when it is a forum post
*/ */
public static function isForumPost(array $item, array $owner = []) public static function isForumPost(int $uri_id)
{ {
if (empty($owner)) { foreach (Tag::getByURIId($uri_id, [Tag::EXCLUSIVE_MENTION]) as $tag) {
$owner = User::getOwnerDataById($item['uid']); if (DBA::exists('contact', ['uid' => 0, 'nurl' => Strings::normaliseLink($tag['url']), 'contact-type' => Contact::TYPE_COMMUNITY])) {
if (empty($owner)) { return true;
return false;
} }
} }
return false;
if (($item['author-id'] == $item['owner-id']) ||
($owner['id'] == $item['contact-id']) ||
($item['uri-id'] != $item['parent-uri-id']) ||
$item['origin']) {
return false;
}
return Contact::isForum($item['contact-id']);
} }
/** /**

View File

@ -81,6 +81,7 @@ class Objects extends BaseModule
$requester = HTTPSignature::getSigner('', $_SERVER); $requester = HTTPSignature::getSigner('', $_SERVER);
if (!empty($requester)) { if (!empty($requester)) {
$receivers = Item::enumeratePermissions($item, false); $receivers = Item::enumeratePermissions($item, false);
$receivers[] = $item['contact-id'];
$validated = in_array(Contact::getIdForURL($requester, $item['uid']), $receivers); $validated = in_array(Contact::getIdForURL($requester, $item['uid']), $receivers);
if (!$validated) { if (!$validated) {

View File

@ -667,6 +667,15 @@ class Receiver
$uid = $receiver['uid']; $uid = $receiver['uid'];
} }
} }
// When we haven't found any user yet, we just chose a user who most likely could have access to the content
if (empty($uid)) {
$contact = Contact::selectFirst(['uid'], ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND]]);
if (!empty($contact['uid'])) {
$uid = $contact['uid'];
}
}
return $uid; return $uid;
} }

View File

@ -509,28 +509,33 @@ class Transmitter
/** /**
* Creates an array of permissions from an item thread * Creates an array of permissions from an item thread
* *
* @param array $item Item array * @param array $item Item array
* @param boolean $blindcopy addressing via "bcc" or "cc"? * @param boolean $blindcopy addressing via "bcc" or "cc"?
* @param integer $last_id Last item id for adding receivers * @param integer $last_id Last item id for adding receivers
* @param boolean $forum_post "true" means that we are sending content to a forum
* *
* @return array with permission data * @return array with permission data
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
private static function createPermissionBlockForItem($item, $blindcopy, $last_id = 0, $forum_post = false) private static function createPermissionBlockForItem($item, $blindcopy, $last_id = 0)
{ {
if ($last_id == 0) { if ($last_id == 0) {
$last_id = $item['id']; $last_id = $item['id'];
} }
$always_bcc = false; $always_bcc = false;
$is_forum = false;
$follower = '';
// Check if we should always deliver our stuff via BCC // Check if we should always deliver our stuff via BCC
if (!empty($item['uid'])) { if (!empty($item['uid'])) {
$profile = User::getOwnerDataById($item['uid']); $owner = User::getOwnerDataById($item['uid']);
if (!empty($profile)) { if (!empty($owner)) {
$always_bcc = $profile['hide-friends']; $always_bcc = $owner['hide-friends'];
$is_forum = ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && $owner['manually-approve'];
$profile = APContact::getByURL($owner['url'], false);
$follower = $profile['followers'] ?? '';
} }
} }
@ -613,7 +618,9 @@ class Transmitter
} }
} }
if (!$exclusive) { if ($is_forum && !$exclusive && !empty($follower)) {
$data['cc'][] = $follower;
} elseif (!$exclusive) {
foreach ($receiver_list as $receiver) { foreach ($receiver_list as $receiver) {
$contact = DBA::selectFirst('contact', ['url', 'hidden', 'network', 'protocol', 'gsid'], ['id' => $receiver, 'network' => Protocol::FEDERATED]); $contact = DBA::selectFirst('contact', ['url', 'hidden', 'network', 'protocol', 'gsid'], ['id' => $receiver, 'network' => Protocol::FEDERATED]);
if (!DBA::isResult($contact) || !self::isAPContact($contact, $networks)) { if (!DBA::isResult($contact) || !self::isAPContact($contact, $networks)) {
@ -652,9 +659,7 @@ class Transmitter
} }
} elseif (!$exclusive) { } elseif (!$exclusive) {
// Public thread parent post always are directed to the followers. // Public thread parent post always are directed to the followers.
// This mustn't be done by posts that are directed to forum servers via the exclusive mention. if ($item['private'] != Item::PRIVATE) {
// But possibly in that case we could add the "followers" collection of the forum to the message.
if (($item['private'] != Item::PRIVATE) && !$forum_post) {
$data['cc'][] = $actor_profile['followers']; $data['cc'][] = $actor_profile['followers'];
} }
} }
@ -820,18 +825,17 @@ class Transmitter
/** /**
* Fetches an array of inboxes for the given item and user * Fetches an array of inboxes for the given item and user
* *
* @param array $item Item array * @param array $item Item array
* @param integer $uid User ID * @param integer $uid User ID
* @param boolean $personal fetch personal inboxes * @param boolean $personal fetch personal inboxes
* @param integer $last_id Last item id for adding receivers * @param integer $last_id Last item id for adding receivers
* @param boolean $forum_post "true" means that we are sending content to a forum
* @return array with inboxes * @return array with inboxes
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function fetchTargetInboxes($item, $uid, $personal = false, $last_id = 0, $forum_post = false) public static function fetchTargetInboxes($item, $uid, $personal = false, $last_id = 0)
{ {
$permissions = self::createPermissionBlockForItem($item, true, $last_id, $forum_post); $permissions = self::createPermissionBlockForItem($item, true, $last_id);
if (empty($permissions)) { if (empty($permissions)) {
return []; return [];
} }

View File

@ -235,13 +235,13 @@ class Notifier
} }
// Special treatment for forum posts // Special treatment for forum posts
if (Item::isForumPost($target_item, $owner)) { if (Item::isForumPost($target_item['uri-id'])) {
$relay_to_owner = true; $relay_to_owner = true;
$direct_forum_delivery = true; $direct_forum_delivery = true;
} }
// Avoid that comments in a forum thread are sent to OStatus // Avoid that comments in a forum thread are sent to OStatus
if (Item::isForumPost($parent, $owner)) { if (Item::isForumPost($parent['uri-id'])) {
$direct_forum_delivery = true; $direct_forum_delivery = true;
} }
@ -729,6 +729,14 @@ class Notifier
$uid = $target_item['contact-uid'] ?: $target_item['uid']; $uid = $target_item['contact-uid'] ?: $target_item['uid'];
// Update the locally stored follower list when we deliver to a forum
foreach (Tag::getByURIId($target_item['uri-id'], [Tag::EXCLUSIVE_MENTION]) as $tag) {
$target_contact = Contact::getByURL(Strings::normaliseLink($tag['url']), null, [], $uid);
if (($target_contact['contact-type'] == Contact::TYPE_COMMUNITY) && $target_contact['manually-approve']) {
Group::getMembersForForum($target_contact['id']);
}
}
if ($target_item['origin']) { if ($target_item['origin']) {
$inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid); $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid);
@ -738,9 +746,6 @@ class Notifier
} }
Logger::info('Origin item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.'); Logger::info('Origin item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.');
} elseif (Item::isForumPost($target_item, $owner)) {
$inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid, false, 0, true);
Logger::info('Forum item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.');
} elseif (!DBA::exists('conversation', ['item-uri' => $target_item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB])) { } elseif (!DBA::exists('conversation', ['item-uri' => $target_item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB])) {
Logger::info('Remote item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.'); Logger::info('Remote item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.');
return ['count' => 0, 'contacts' => []]; return ['count' => 0, 'contacts' => []];

View File

@ -39,28 +39,28 @@
<h2 class="settings-heading"><a href="javascript:;">{{$h_prv}}</a></h2> <h2 class="settings-heading"><a href="javascript:;">{{$h_prv}}</a></h2>
<div class="settings-content-block"> <div class="settings-content-block">
<input type="hidden" name="visibility" value="{{$visibility}}"/>
{{include file="field_input.tpl" field=$maxreq}} {{include file="field_input.tpl" field=$maxreq}}
{{$profile_in_dir nofilter}} {{$profile_in_dir nofilter}}
{{include file="field_checkbox.tpl" field=$profile_in_net_dir}} {{include file="field_checkbox.tpl" field=$profile_in_net_dir}}
{{include file="field_checkbox.tpl" field=$hide_friends}} {{if not $is_community}}{{include file="field_checkbox.tpl" field=$hide_friends}}{{/if}}
{{include file="field_checkbox.tpl" field=$hide_wall}} {{include file="field_checkbox.tpl" field=$hide_wall}}
{{include file="field_checkbox.tpl" field=$unlisted}} {{if not $is_community}}{{include file="field_checkbox.tpl" field=$unlisted}}{{/if}}
{{include file="field_checkbox.tpl" field=$accessiblephotos}} {{include file="field_checkbox.tpl" field=$accessiblephotos}}
{{if not $is_community}}
{{include file="field_checkbox.tpl" field=$blockwall}} {{include file="field_checkbox.tpl" field=$blockwall}}
{{include file="field_checkbox.tpl" field=$blocktags}} {{include file="field_checkbox.tpl" field=$blocktags}}
{{/if}}
{{include file="field_checkbox.tpl" field=$unkmail}} {{include file="field_checkbox.tpl" field=$unkmail}}
{{include file="field_input.tpl" field=$cntunkmail}} {{include file="field_input.tpl" field=$cntunkmail}}
{{$group_select nofilter}} {{$group_select nofilter}}
{{if not $is_community}}
<h3>{{$permissions}}</h3> <h3>{{$permissions}}</h3>
{{$aclselect nofilter}} {{$aclselect nofilter}}
{{/if}}
<div class="settings-submit-wrapper"> <div class="settings-submit-wrapper">
<input type="submit" name="submit" class="settings-submit" value="{{$submit}}"/> <input type="submit" name="submit" class="settings-submit" value="{{$submit}}"/>
</div> </div>

View File

@ -70,28 +70,29 @@
</div> </div>
<div id="privacy-settings-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="privacy-settings"> <div id="privacy-settings-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="privacy-settings">
<div class="panel-body"> <div class="panel-body">
<input type="hidden" name="visibility" value="{{$visibility}}" />
{{include file="field_input.tpl" field=$maxreq}} {{include file="field_input.tpl" field=$maxreq}}
{{$profile_in_dir nofilter}} {{$profile_in_dir nofilter}}
{{include file="field_checkbox.tpl" field=$profile_in_net_dir}} {{include file="field_checkbox.tpl" field=$profile_in_net_dir}}
{{include file="field_checkbox.tpl" field=$hide_friends}} {{if not $is_community}}{{include file="field_checkbox.tpl" field=$hide_friends}}{{/if}}
{{include file="field_checkbox.tpl" field=$hide_wall}} {{include file="field_checkbox.tpl" field=$hide_wall}}
{{include file="field_checkbox.tpl" field=$unlisted}} {{if not $is_community}}{{include file="field_checkbox.tpl" field=$unlisted}}{{/if}}
{{include file="field_checkbox.tpl" field=$accessiblephotos}} {{include file="field_checkbox.tpl" field=$accessiblephotos}}
{{if not $is_community}}
{{include file="field_checkbox.tpl" field=$blockwall}} {{include file="field_checkbox.tpl" field=$blockwall}}
{{include file="field_checkbox.tpl" field=$blocktags}} {{include file="field_checkbox.tpl" field=$blocktags}}
{{/if}}
{{include file="field_checkbox.tpl" field=$unkmail}} {{include file="field_checkbox.tpl" field=$unkmail}}
{{include file="field_input.tpl" field=$cntunkmail}} {{include file="field_input.tpl" field=$cntunkmail}}
{{$group_select nofilter}} {{$group_select nofilter}}
{{if not $is_community}}
<h3>{{$permissions}}</h3> <h3>{{$permissions}}</h3>
{{$aclselect nofilter}} {{$aclselect nofilter}}
{{/if}}
</div> </div>
<div class="panel-footer"> <div class="panel-footer">
<button type="submit" name="submit" class="btn btn-primary" value="{{$submit}}">{{$submit}}</button> <button type="submit" name="submit" class="btn btn-primary" value="{{$submit}}">{{$submit}}</button>