aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Lib/AccessList.php10
-rw-r--r--Zotlabs/Module/Permcats.php96
-rw-r--r--Zotlabs/Widget/Permcats.php53
-rw-r--r--view/tpl/permcats.tpl44
4 files changed, 134 insertions, 69 deletions
diff --git a/Zotlabs/Lib/AccessList.php b/Zotlabs/Lib/AccessList.php
index 51c100afb..f47440714 100644
--- a/Zotlabs/Lib/AccessList.php
+++ b/Zotlabs/Lib/AccessList.php
@@ -346,12 +346,12 @@ class AccessList {
}
return replace_macros(get_markup_template('group_side.tpl'), [
- '$title' => t('Lists'),
- '$edittext' => t('Edit list'),
- '$createtext' => t('Create new list'),
- '$ungrouped' => (($every === 'contacts') ? t('Channels not in any access list') : ''),
+ '$title' => t('Privacy Groups'),
+ '$edittext' => t('Edit group'),
+ '$createtext' => t('Create new group'),
+ '$ungrouped' => (($every === 'contacts') ? t('Channels not in any privacy group') : ''),
'$groups' => $groups,
- '$add' => t('add'),
+ '$add' => t('Add'),
]);
}
diff --git a/Zotlabs/Module/Permcats.php b/Zotlabs/Module/Permcats.php
index a46253ec2..c33580f06 100644
--- a/Zotlabs/Module/Permcats.php
+++ b/Zotlabs/Module/Permcats.php
@@ -19,13 +19,47 @@ class Permcats extends Controller {
check_form_security_token_redirectOnErr('/permcats', 'permcats');
-
- $name = escape_tags(trim($_POST['name']));
- $is_system_role = isset($_POST['is_system_role']);
- $return_path = z_root() . '/permcats/' . $_POST['return_path'];
- $group_hash = ((isset($_POST['group_select'])) ? $_POST['group_select'] : '');
+ $name = escape_tags(trim($_REQUEST['name']));
+ $is_system_role = isset($_REQUEST['is_system_role']);
+ $return_path = z_root() . '/permcats/' . $_REQUEST['return_path'];
+ $group_hash = $_REQUEST['group_select'] ?? '';
+ $deleted_role = $_REQUEST['deleted_role'] ?? '';
+ $new_role = $_REQUEST['new_role'] ?? '';
$contacts = [];
+ if (argv(1) && hex2bin(argv(1)) !== $name) {
+ $return_path = z_root() . '/permcats/' . bin2hex($name);
+ }
+
+ if($deleted_role && $new_role) {
+ $r = q("SELECT abook_xchan FROM abook WHERE abook_channel = %d AND abook_role = '%s' AND abook_self = 0 AND abook_pending = 0",
+ intval(local_channel()),
+ dbesc($deleted_role)
+ );
+
+ if ($r) {
+ $contacts = ids_to_array($r, 'abook_xchan');
+ }
+
+ if ($contacts) {
+ \Zotlabs\Lib\Permcat::assign($channel, $new_role, $contacts);
+ }
+
+ \Zotlabs\Lib\Permcat::delete(local_channel(), $deleted_role);
+
+ $default_role = get_pconfig(local_channel(), 'system', 'default_permcat', 'default');
+ if($deleted_role === $default_role) {
+ set_pconfig(local_channel(), 'system', 'default_permcat', $new_role);
+ }
+
+ Libsync::build_sync_packet();
+ info(t('Contact role deleted.') . EOL);
+
+ goaway(z_root() . '/permcats/' . bin2hex($new_role));
+
+ return;
+ }
+
if ($group_hash === 'all_contacts') {
$r = q("SELECT abook_xchan FROM abook WHERE abook_channel = %d and abook_self = 0 and abook_pending = 0",
intval(local_channel())
@@ -51,14 +85,15 @@ class Permcats extends Controller {
set_pconfig(local_channel(), 'system', 'default_permcat', 'default');
- if (isset($_POST['default_role'])) {
+ if (isset($_REQUEST['default_role'])) {
set_pconfig(local_channel(), 'system', 'default_permcat', $name);
}
if ($is_system_role) {
// if we have a system role just set the default and assign if aplicable and be done with it
- if ($contacts)
+ if ($contacts) {
\Zotlabs\Lib\Permcat::assign($channel, $name, $contacts);
+ }
info( t('Contact role saved.') . EOL);
Libsync::build_sync_packet();
@@ -99,19 +134,10 @@ class Permcats extends Controller {
$channel = App::get_channel();
- if(argc() > 1)
+ if(argc() > 1) {
$name = hex2bin(argv(1));
-
- if(argc() > 2 && argv(2) === 'drop') {
- \Zotlabs\Lib\Permcat::delete(local_channel(),$name);
-
- // TODO: assign all members of the deleted role to the default role
-
- Libsync::build_sync_packet();
- json_return_and_die([ 'success' => true ]);
}
-
$existing = [];
$pcat = new \Zotlabs\Lib\Permcat(local_channel());
@@ -134,7 +160,9 @@ class Permcats extends Controller {
*/
$is_system_role = false;
- $permcats = [];
+ $delete_role_select_options = [];
+ $is_default_role = (get_pconfig(local_channel(),'system','default_permcat','default') === $name);
+
if($pcatlist) {
foreach($pcatlist as $pc) {
if(($pc['name']) && ($name) && ($pc['name'] == $name)) {
@@ -143,13 +171,26 @@ class Permcats extends Controller {
$is_system_role = $pc['name'];
}
- $permcats[bin2hex($pc['name'])] = $pc['localname'];
-
- if($pc['name'] == $name)
+ if($pc['name'] == $name) {
$localname = $pc['localname'];
+ }
+
+ if ($pc['name'] !== $name) {
+ $delete_role_select_options[$pc['name']] = $pc['localname'];
+ }
+
}
}
+ // select for delete action
+ $delete_role_select = [
+ 'new_role',
+ (($is_default_role) ? t('Role to assign affected contacts and default role to') : t('Role to assign affected contacts to')),
+ '',
+ '',
+ $delete_role_select_options
+ ];
+
$global_perms = \Zotlabs\Access\Permissions::Perms();
foreach($global_perms as $k => $v) {
@@ -171,7 +212,6 @@ class Permcats extends Controller {
];
}
- $is_default_role = (get_pconfig(local_channel(),'system','default_permcat','default') == $name);
$group_select_options = [
'selected' => '',
@@ -189,15 +229,11 @@ class Permcats extends Controller {
$tpl = get_markup_template("permcats.tpl");
$o .= replace_macros($tpl, array(
'$form_security_token' => get_form_security_token("permcats"),
- '$default_role' => array('default_role', t('Use this role as default for new contacts'), intval($is_default_role), '', [t('No'), t('Yes')]),
-
+ '$default_role' => array('default_role', t('Automatically assign this role to new contacts'), intval($is_default_role), '', [t('No'), t('Yes')]),
'$title' => t('Contact Roles'),
- '$tokens' => $t,
- '$permcats' => $permcats,
- '$atoken' => $atoken,
- '$url1' => z_root() . '/channel/' . $channel['channel_address'],
- '$url2' => z_root() . '/photos/' . $channel['channel_address'],
'$name' => ['name', t('Role name') . ' <span class="required">*</span>', (($localname) ? $localname : ''), (($is_system_role) ? t('System role - not editable') : '') , '', (($is_system_role) ? 'disabled' : '')],
+ '$delete_label' => t('Deleting') . ' ' . $localname,
+ '$current_role' => $name,
'$perms' => $perms,
'$inherited' => t('inherited'),
'$is_system_role' => $is_system_role,
@@ -206,6 +242,8 @@ class Permcats extends Controller {
'$submit' => t('Submit'),
'$return_path' => argv(1),
'$group_select' => $group_select,
+ '$delete_role_select' => $delete_role_select,
+ '$delet_role_button' => t('Delete')
));
return $o;
diff --git a/Zotlabs/Widget/Permcats.php b/Zotlabs/Widget/Permcats.php
index 72c80ca0c..97ae6cba2 100644
--- a/Zotlabs/Widget/Permcats.php
+++ b/Zotlabs/Widget/Permcats.php
@@ -11,26 +11,25 @@ class Permcats {
$pcat = new Permcat(local_channel());
$pcatlist = $pcat->listing();
- $list = '<b>Roles:</b><br>';
- $active = '';
- $active_role = '';
+ if (!$pcatlist) {
+ return;
+ }
- if($pcatlist) {
- $i = 0;
- foreach($pcatlist as $pc) {
- if(argc() > 1) {
- if($pc['name'] == hex2bin(argv(1))) {
- $active = $i;
- $active_role = $pc['name'];
- }
- }
+ $roles = [];
+ $active_role = '';
- $list .= '<a href="permcats/' . bin2hex($pc['name']) . '">' . $pc['localname'] . '</a><br>';
- $i++;
+ foreach($pcatlist as $pc) {
+ if (!$active_role) {
+ $active_role = ((argc() > 1 && $pc['name'] === hex2bin(argv(1))) ? $pc['name'] : '');
}
+ $roles[] = [
+ 'name' => $pc['localname'],
+ 'url' => z_root() . '/permcats/' . bin2hex($pc['name']),
+ 'active' => (argc() > 1 && $pc['name'] === hex2bin(argv(1)))
+ ];
}
- if(argc() > 1) {
+ if($active_role) {
/* get role members based on permissions
$test = $pcatlist[$active]['perms'];
@@ -64,16 +63,28 @@ class Permcats {
dbesc($active_role)
);
- $members = '<b>Role members:</b><br>';
- $members .= '<div class="border rounded" style="height: 20rem; overflow: auto;">';
+ $members = [];
foreach ($r as $rr) {
- $addr = (($rr['xchan_addr']) ? $rr['xchan_addr'] : $rr['xchan_url']);
- $members .= '<a href="connections#' . $rr['abook_id'] . '" class="lh-sm border-bottom p-2 d-block text-truncate"><img src="' . $rr['xchan_photo_s'] . '" class="float-start rounded me-2" style="height: 2.2rem; width: 2.2rem;" loading="lazy">' . $rr['xchan_name'] . '<br><span class="text-muted small">' . $addr . '</span></a>';
+ $members[] = [
+ 'name' => $rr['xchan_name'],
+ 'addr' => (($rr['xchan_addr']) ? $rr['xchan_addr'] : $rr['xchan_url']),
+ 'url' => z_root() . '/connections#' . $rr['abook_id'],
+ 'photo' => $rr['xchan_photo_s']
+ ];
}
- $members .= '</div>';
}
- return $list . '<br>' . $members. '<br>' . $others;
+
+ $tpl = get_markup_template("permcats_widget.tpl");
+ $o .= replace_macros($tpl, [
+ '$roles_label' => t('Contact roles'),
+ '$members_label' => t('Role members'),
+ '$roles' => $roles,
+ '$members' => $members
+
+ ]);
+
+ return $o;
}
}
diff --git a/view/tpl/permcats.tpl b/view/tpl/permcats.tpl
index 279903048..d0f175cfb 100644
--- a/view/tpl/permcats.tpl
+++ b/view/tpl/permcats.tpl
@@ -4,7 +4,7 @@
<div class="clear"></div>
</div>
<div class="section-content-tools-wrapper">
- <form action="permcats" id="settings-permcats-form" method="post" autocomplete="off" >
+ <form action="permcats/{{$return_path}}" id="settings-permcats-form" method="post" autocomplete="off" >
<input type="hidden" name="form_security_token" value="{{$form_security_token}}">
<input type="hidden" name="return_path" value="{{$return_path}}">
@@ -31,20 +31,36 @@
{{include file="field_acheckbox.tpl" field=$prm}}
{{/foreach}}
</table>
- <div class="settings-submit-wrapper" >
- <button type="submit" name="submit" class="btn btn-primary">{{$submit}}</button>
+ <div class="clearfix">
+ {{if !$is_system_role && $return_path}}
+ <button type="button" class="btn btn-outline-danger" data-bs-toggle="modal" data-bs-target="#delete-modal">{{$delet_role_button}}</button>
+ {{/if}}
+ <button type="submit" name="submit" class="btn btn-primary float-end">{{$submit}}</button>
</div>
- {{**if $permcats}}
- <table id="permcat-index">
- {{foreach $permcats as $k => $v}}
- <tr class="permcat-row-{{$k}}">
- <td width="99%"><a href="permcats/{{$k}}">{{$v}}</a></td>
- <td width="1%"><i class="fa fa-trash-o drop-icons" onClick="dropItem('permcats/{{$k}}/drop', '.permcat-row-{{$k}}')"></i></td>
- </tr>
- {{/foreach}}
- </table>
- {{/if**}}
-
</form>
</div>
</div>
+{{if !$is_system_role && $return_path}}
+<div id="delete-modal" class="modal" tabindex="-1">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <div class="h3">
+ {{$delete_label}}
+ </div>
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
+ </div>
+ <form action="permcats" id="delete-permcat-form" method="post">
+ <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
+ <input type="hidden" name="deleted_role" value="{{$current_role}}">
+ <div id="edit-modal-body" class="modal-body">
+ {{include file="field_select.tpl" field=$delete_role_select}}
+ </div>
+ <div class="modal-footer">
+ <button id="" type="submit" class="btn btn-danger">{{$delet_role_button}}</button>
+ </div>
+ </form>
+ </div>
+ </div>
+</div>
+{{/if}}