mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 21:35:13 +00:00
change default group
This commit is contained in:
parent
d51dd9feb2
commit
5525231ee5
5 changed files with 56 additions and 76 deletions
|
@ -139,6 +139,24 @@ class AccessList
|
|||
return false;
|
||||
}
|
||||
|
||||
public static function hashbyname($uid, $name): mixed
|
||||
{
|
||||
if (!($uid && $name)) {
|
||||
return false;
|
||||
}
|
||||
$r = q(
|
||||
"SELECT hash FROM pgrp WHERE uid = %d AND gname = '%s' LIMIT 1",
|
||||
intval($uid),
|
||||
dbesc($name)
|
||||
);
|
||||
if ($r) {
|
||||
return $r[0]['hash'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function by_id($uid, $id): mixed
|
||||
{
|
||||
if (!($uid && $id)) {
|
||||
|
|
|
@ -82,6 +82,10 @@ class Libacl
|
|||
|
||||
$groups = EMPTY_STR;
|
||||
|
||||
$selection = (($single_group && !$selected && 'connections:' . $channel['channel_hash'] === $allow_gid[0]) ? ' selected = "selected" ' : '');
|
||||
$selected = $selection ?: $selected;
|
||||
$groups .= '<option id="vg1" value="connections:' . $channel['channel_hash'] . '"' . $selection . '>' . t('Connections') . '</option>' . "\r\n";
|
||||
|
||||
$r = q(
|
||||
"SELECT id, hash, gname FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
|
||||
intval(local_channel())
|
||||
|
@ -89,25 +93,24 @@ class Libacl
|
|||
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
$selected = (($single_group && $rr['hash'] === $allow_gid[0]) ? ' selected = "selected" ' : '');
|
||||
$groups .= '<option id="' . $rr['id'] . '" value="' . $rr['hash'] . '"' . $selected . '>' . $rr['gname'] . ' ' . t('(List)') . '</option>' . "\r\n";
|
||||
$selection = (($single_group && !$selected && $rr['hash'] === $allow_gid[0]) ? ' selected = "selected" ' : '');
|
||||
$selected = $selection ?: $selected;
|
||||
$groups .= '<option id="' . $rr['id'] . '" value="' . $rr['hash'] . '"' . $selection . '>' . $rr['gname'] . ' ' . t('(List)') . '</option>' . "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
$selected = (($single_group && 'connections:' . $channel['channel_hash'] === $allow_gid[0]) ? ' selected = "selected" ' : '');
|
||||
$groups .= '<option id="vg1" value="connections:' . $channel['channel_hash'] . '"' . $selected . '>' . t('My connections') . '</option>' . "\r\n";
|
||||
|
||||
$forums = get_forum_channels(local_channel(), 1);
|
||||
$selected = false;
|
||||
if ($forums) {
|
||||
foreach ($forums as $f) {
|
||||
$selected = (($single_group && $f['hash'] === $allow_cid[0]) ? ' selected = "selected" ' : '');
|
||||
$groups .= '<option id="^' . $f['abook_id'] . '" value="^' . $f['xchan_hash'] . '"' . $selected . '>' . $f['xchan_name'] . ' ' . t('(Group)') . '</option>' . "\r\n";
|
||||
$selection = (($single_group && !$selected && $f['hash'] === $allow_cid[0]) ? ' selected = "selected" ' : '');
|
||||
$selected = $selection ?: $selected;
|
||||
$groups .= '<option id="^' . $f['abook_id'] . '" value="^' . $f['xchan_hash'] . '"' . $selection . '>' . $f['xchan_name'] . ' ' . t('(Group)') . '</option>' . "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
// preset acl with DM to a single xchan (not a group)
|
||||
if ($selected === false && count($allow_cid) === 1 && $channel && $allow_cid[0] !== $channel['channel_hash'] && (! $allow_gid) && (! $deny_gid) && (! $deny_cid)) {
|
||||
if (!$selected && count($allow_cid) === 1 && $channel && $allow_cid[0] !== $channel['channel_hash'] && (! $allow_gid) && (! $deny_gid) && (! $deny_cid)) {
|
||||
$f = q(
|
||||
"select * from xchan where xchan_hash = '%s'",
|
||||
dbesc($allow_cid[0])
|
||||
|
|
|
@ -83,7 +83,6 @@ class Channel
|
|||
$preview_outbox = ((x($_POST, 'preview_outbox')) ? intval($_POST['preview_outbox']) : 0);
|
||||
$allow_location = (((x($_POST, 'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1 : 0);
|
||||
$blocktags = (((x($_POST, 'blocktags')) && (intval($_POST['blocktags']) == 1)) ? 0 : 1); // this setting is inverted!
|
||||
$suggestme = ((x($_POST, 'suggestme')) ? intval($_POST['suggestme']) : 0);
|
||||
$hyperdrive = ((x($_POST, 'hyperdrive')) ? intval($_POST['hyperdrive']) : 0);
|
||||
$activitypub = ((x($_POST, 'activitypub')) ? intval($_POST['activitypub']) : 0);
|
||||
$tag_username = ((x($_POST, 'tag_username')) ? intval($_POST['tag_username']) : 0);
|
||||
|
@ -160,7 +159,6 @@ class Channel
|
|||
|
||||
set_pconfig(local_channel(), 'system', 'followed_tags', ($ntags) ?: EMPTY_STR);
|
||||
set_pconfig(local_channel(), 'system', 'use_browser_location', $allow_location);
|
||||
set_pconfig(local_channel(), 'system', 'suggestme', $suggestme);
|
||||
set_pconfig(local_channel(), 'system', 'post_newfriend', $post_newfriend);
|
||||
set_pconfig(local_channel(), 'system', 'post_joingroup', $post_joingroup);
|
||||
set_pconfig(local_channel(), 'system', 'post_profilechange', $post_profilechange);
|
||||
|
@ -308,9 +306,6 @@ class Channel
|
|||
|
||||
$hide_presence = intval(get_pconfig(local_channel(), 'system', 'hide_online_status'));
|
||||
|
||||
$suggestme = get_pconfig(local_channel(), 'system', 'suggestme');
|
||||
$suggestme = (($suggestme === false) ? '0' : $suggestme); // default if not set: 0
|
||||
|
||||
$post_newfriend = get_pconfig(local_channel(), 'system', 'post_newfriend');
|
||||
$post_newfriend = (($post_newfriend === false) ? '0' : $post_newfriend); // default if not set: 0
|
||||
|
||||
|
@ -332,11 +327,6 @@ class Channel
|
|||
]);
|
||||
}
|
||||
|
||||
$suggestme = replace_macros($opt_tpl, [
|
||||
'$field' => ['suggestme', t('Allow us to suggest you as a potential friend to new members?'), $suggestme, '', $yes_no],
|
||||
|
||||
]);
|
||||
|
||||
$subdir = ((strlen(App::get_path())) ? '<br>' . t('or') . ' ' . z_root() . '/channel/' . $nickname : '');
|
||||
|
||||
$webbie = $nickname . '@' . App::get_hostname();
|
||||
|
@ -372,9 +362,6 @@ class Channel
|
|||
$acl = new AccessControl($channel);
|
||||
$perm_defaults = $acl->get();
|
||||
|
||||
$group_select = AccessList::select(local_channel(), $channel['channel_default_group']);
|
||||
|
||||
|
||||
$m1 = Menu::list(local_channel());
|
||||
$menu = false;
|
||||
if ($m1) {
|
||||
|
@ -484,8 +471,6 @@ class Channel
|
|||
'$allow_gid' => acl2json($perm_defaults['allow_gid']),
|
||||
'$deny_cid' => acl2json($perm_defaults['deny_cid']),
|
||||
'$deny_gid' => acl2json($perm_defaults['deny_gid']),
|
||||
'$suggestme' => $suggestme,
|
||||
'$group_select' => $group_select,
|
||||
'$can_change_role' => !in_array($permissions_role, ['collection', 'collection_restricted']),
|
||||
'$permissions_role' => $permissions_role,
|
||||
'$role' => ['permissions_role', t('Channel type and privacy'), $permissions_role, '', $perm_roles, ' onchange="update_role_text(); return false;"'],
|
||||
|
@ -599,13 +584,6 @@ class Channel
|
|||
protected function set_custom_role($channel)
|
||||
{
|
||||
$hide_presence = (((x($_POST, 'hide_presence')) && (intval($_POST['hide_presence']) == 1)) ? 1 : 0);
|
||||
$def_group = ((x($_POST, 'group-selection')) ? notags(trim($_POST['group-selection'])) : '');
|
||||
q(
|
||||
"update channel set channel_default_group = '%s' where channel_id = %d",
|
||||
dbesc($def_group),
|
||||
intval(local_channel())
|
||||
);
|
||||
|
||||
$global_perms = Permissions::Perms();
|
||||
|
||||
foreach ($global_perms as $k => $v) {
|
||||
|
@ -634,49 +612,29 @@ class Channel
|
|||
return;
|
||||
}
|
||||
$hide_presence = 1 - (intval($role_permissions['online']));
|
||||
if ($role_permissions['default_collection']) {
|
||||
$default_list = q("select channel_default_group from channel where channel_id = %d",
|
||||
(int)local_channel(),
|
||||
);
|
||||
if (!empty($default_list[0]['channel_default_group'])) {
|
||||
$r = q("select hash from pgrp where uid = %d and hash = '%s' limit 1",
|
||||
(int)local_channel(),
|
||||
dbesc($default_list[0]['channel_default_group'])
|
||||
);
|
||||
}
|
||||
else {
|
||||
$r = q(
|
||||
"select hash from pgrp where uid = %d and gname = '%s' limit 1",
|
||||
intval(local_channel()),
|
||||
dbesc(t('Friends'))
|
||||
);
|
||||
}
|
||||
if (!$r) {
|
||||
AccessList::add(local_channel(), t('Friends'));
|
||||
AccessList::member_add(local_channel(), t('Friends'), $channel['channel_hash']);
|
||||
$r = q(
|
||||
"select hash from pgrp where uid = %d and gname = '%s' limit 1",
|
||||
intval(local_channel()),
|
||||
dbesc(t('Friends'))
|
||||
);
|
||||
}
|
||||
if ($r) {
|
||||
q(
|
||||
"update channel set channel_default_group = '%s', channel_allow_gid = '%s', channel_allow_cid = '', channel_deny_gid = '', channel_deny_cid = '' where channel_id = %d",
|
||||
dbesc($r[0]['hash']),
|
||||
dbesc('<' . $r[0]['hash'] . '>'),
|
||||
intval(local_channel())
|
||||
);
|
||||
} else {
|
||||
notice(sprintf('Default access list \'%s\' not found. Please create and re-submit permission change.', t('Friends')) . EOL);
|
||||
return;
|
||||
}
|
||||
} // no default permissions
|
||||
else {
|
||||
q("update channel set channel_allow_gid = '', channel_allow_cid = '', channel_deny_gid = '', channel_deny_cid = '' where channel_id = %d",
|
||||
intval(local_channel())
|
||||
);
|
||||
|
||||
$defquery = q("select channel_default_group from channel where channel_id = %d",
|
||||
(int)local_channel(),
|
||||
);
|
||||
$default_list = $defquery ? $defquery[0]['channel_default_group'] : null;
|
||||
if (!$default_list) {
|
||||
$default_list = AccessList::hashbyname(local_channel(), t('Friends'));
|
||||
}
|
||||
if (!$default_list) {
|
||||
$default_list = AccessList::add(local_channel(), t('Friends'));
|
||||
AccessList::member_add(local_channel(), t('Friends'), $channel['channel_hash']);
|
||||
}
|
||||
|
||||
q("update channel set channel_default_group = '%s', channel_allow_gid = '%s',
|
||||
channel_allow_cid = '', channel_deny_gid = '', channel_deny_cid = ''
|
||||
where channel_id = %d",
|
||||
dbesc((string)$default_list),
|
||||
dbesc(($role_permissions['default_collection'])
|
||||
? ('<' . 'connections:' . $channel['channel_hash'] . '>')
|
||||
:
|
||||
''),
|
||||
intval(local_channel())
|
||||
);
|
||||
|
||||
if ($role_permissions['perms_connect']) {
|
||||
$x = Permissions::FilledPerms($role_permissions['perms_connect']);
|
||||
|
|
|
@ -731,13 +731,16 @@ function get_security_ids($channel_id, $ob_hash)
|
|||
}
|
||||
}
|
||||
|
||||
// virtual groups this identity is a member of
|
||||
// virtual groups this identity is a member of
|
||||
|
||||
$r = q("select channel_hash from channel left join abook on channel_id = abook_channel where abook_xchan in ( " . protect_sprintf($hashes) . " ) and abook_self = 0 and abook_pending = 0 and abook_archived = 0 ");
|
||||
if ($r) {
|
||||
foreach ($r as $rv) {
|
||||
$groups[] = 'connections:' . $rv['channel_hash'];
|
||||
if (in_array($xchans[0]['xchan_network'],['nomad','zot6'])) {
|
||||
if ($xchans[0]['xchan_network'] === 'nomad') {
|
||||
$groups[] = 'nomad:' . $rv['channel_hash'];
|
||||
}
|
||||
if ($xchans[0]['xchan_network'] === 'zot6') {
|
||||
$groups[] = 'zot:' . $rv['channel_hash'];
|
||||
}
|
||||
if ($xchans[0]['xchan_network'] === 'activitypub') {
|
||||
|
|
|
@ -65,7 +65,6 @@
|
|||
{{include file="field_input.tpl" field=$unless_tag_count}}
|
||||
{{include file="field_checkbox.tpl" field=$preview_outbox}}
|
||||
{{include file="field_checkbox.tpl" field=$nomadic_ids_in_profile}}
|
||||
{{$group_select}}
|
||||
<div id="advanced-perm" style="display:{{if $permissions_set}}none{{else}}block{{/if}};">
|
||||
<div class="form-group">
|
||||
<button type="button" class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#apsModal">{{$lbl_p2macro}}</button>
|
||||
|
@ -98,7 +97,6 @@
|
|||
<div class="settings-common-perms">
|
||||
{{$profile_in_dir}}
|
||||
{{include file="field_checkbox.tpl" field=$noindex}}
|
||||
{{$suggestme}}
|
||||
{{include file="field_input.tpl" field=$expire}}
|
||||
{{include file="field_checkbox.tpl" field=$hyperdrive}}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue