* Admin: Add copy account action

This commit is contained in:
nathangray 2020-03-02 16:00:58 -07:00
parent 02ce5e878d
commit 8ea3a5e430
3 changed files with 1297 additions and 1470 deletions

View File

@ -10,9 +10,9 @@
*/
use EGroupware\Api;
use EGroupware\Api\Framework;
use EGroupware\Api\Acl;
use EGroupware\Api\Etemplate;
use EGroupware\Api\Framework;
/**
* UI for admin: edit/add account
@ -28,6 +28,13 @@ class admin_account
'delete' => true,
);
// Copying account uses addressbook fields, but we explicitly clear these
protected static $copy_clear_fields = array(
'account_firstname','account_lastname','account_fullname', 'person_id',
'account_id','account_lid',
'account_lastlogin','accountlastloginfrom','account_lastpwd_change'
);
/**
* Hook to edit account data via "Account" tab in addressbook edit dialog
*
@ -104,18 +111,24 @@ class admin_account
}
$readonlys['account_passwd'] = $readonlys['account_passwd2'] = true;
}
// save old values to only trigger save, if one of the following values change (contact data get saved anyway)
$preserve = empty($content['id']) ? array() :
array('old_account' => array_intersect_key($account, array_flip(array(
'account_lid', 'account_status', 'account_groups', 'anonymous', 'changepassword',
'mustchangepassword', 'account_primary_group', 'homedirectory', 'loginshell',
'account_expires', 'account_firstname', 'account_lastname', 'account_email'))),
'deny_edit' => $deny_edit);
if($content && $_GET['copy'])
{
$this->copy($content, $account, $preserve);
}
return array(
'name' => 'admin.account',
'prepend' => true,
'label' => 'Account',
'data' => $account,
// save old values to only trigger save, if one of the following values change (contact data get saved anyway)
'preserve' => empty($content['id']) ? array() :
array('old_account' => array_intersect_key($account, array_flip(array(
'account_lid', 'account_status', 'account_groups', 'anonymous', 'changepassword',
'mustchangepassword', 'account_primary_group', 'homedirectory', 'loginshell',
'account_expires', 'account_firstname', 'account_lastname', 'account_email'))),
'deny_edit' => $deny_edit),
'preserve' => $preserve,
'readonlys' => $readonlys,
'pre_save_callback' => $deny_edit ? null : 'admin_account::addressbook_pre_save',
);
@ -243,6 +256,35 @@ class admin_account
}
}
public function copy(array &$content, array &$account, array &$preserve)
{
// We skipped the addressbook copy, call it now
$ab_ui = new addressbook_ui();
$ab_ui->copy_contact($content, true);
// copy_contact() reset the owner, fix it
$content['owner'] = '0';
// Explicitly, always clear these
static $clear_content = Array(
'n_family','n_given','n_middle','n_suffix','n_fn','n_fileas',
'account_id','contact_id','id','etag','carddav_name','uid'
);
foreach($clear_content as $field)
{
$account[$field] ='';
$preserve[$field] = '';
}
$account['link_to']['to_id'] = 0;
unset($preserve['old_account']);
// Never copy these on an account
foreach(static::$copy_clear_fields as $field)
{
unset($account[$field]);
}
}
/**
* Delete an account
*

View File

@ -11,9 +11,10 @@
*/
use EGroupware\Api;
use EGroupware\Api\Link;
use EGroupware\Api\Egw;
use EGroupware\Api\Etemplate;
use EGroupware\Api\Etemplate\Widget\Tree;
use EGroupware\Api\Link;
/**
* UI for admin
@ -153,6 +154,13 @@ class admin_ui
'onExecute' => 'javaScript:app.admin.account',
'group' => $group,
),
'copy' => array(
'caption' => 'Copy',
'url' => 'menuaction=addressbook.addressbook_ui.edit&makecp=1&contact_id=$id',
'onExecute' => 'javaScript:app.admin.account',
'allowOnMultiple' => false,
'icon' => 'copy',
),
);
// generate urls for add/edit accounts via addressbook
$edit = Link::get_registry('addressbook', 'edit');
@ -418,7 +426,7 @@ class admin_ui
*/
public static function tree_data($root = '/')
{
$tree = array('id' => $root === '/' ? 0 : $root, 'item' => array(), 'child' => 1);
$tree = array(Tree::ID => $root === '/' ? 0 : $root, Tree::CHILDREN => array(), 'child' => 1);
if ($root == '/')
{
@ -438,32 +446,32 @@ class admin_ui
'link' => $data,
);
}
if (empty($data['text'])) $data['text'] = $text;
if (empty($data['id']))
if (empty($data[Tree::LABEL])) $data[Tree::LABEL] = $text;
if (empty($data[Tree::ID]))
{
$data['id'] = $root.($app == 'admin' ? 'admin' : 'apps/'.$app).'/';
$matches = null;
if (preg_match_all('/(menuaction|load)=([^&]+)/', $data['link'], $matches))
{
$data['id'] .= $matches[2][(int)array_search('load', $matches[1])];
$data[Tree::ID] .= $matches[2][(int)array_search('load', $matches[1])];
}
}
if (!empty($data['icon']))
{
$icon = Etemplate\Widget\Tree::imagePath($data['icon']);
if ($data['child'] || $data['item'])
if ($data['child'] || $data[Tree::CHILDREN])
{
$data['im1'] = $data['im2'] = $icon;
$data[Tree::IMAGE_FOLDER_OPEN] = $data[Tree::IMAGE_FOLDER_CLOSED] = $icon;
}
else
{
$data['im0'] = $icon;
$data[Tree::IMAGE_LEAF] = $icon;
}
}
unset($data['icon']);
$parent =& $tree['item'];
$parts = explode('/', $data['id']);
if ($data['id'][0] == '/') array_shift($parts); // remove root
$parent =& $tree[Tree::CHILDREN];
$parts = explode('/', $data[Tree::ID]);
if ($data[Tree::ID][0] == '/') array_shift($parts); // remove root
array_pop($parts);
$path = '';
foreach($parts as $part)
@ -474,23 +482,23 @@ class admin_ui
$icon = Etemplate\Widget\Tree::imagePath($part == 'apps' ? Api\Image::find('api', 'home') :
(($i=Api\Image::find($part, 'navbar')) ? $i : Api\Image::find('api', 'nonav')));
$parent[$path] = array(
'id' => $path,
'text' => $part == 'apps' ? lang('Applications') : lang($part),
Tree::ID => $path,
Tree::LABEL => $part == 'apps' ? lang('Applications') : lang($part),
//'im0' => 'folderOpen.gif',
'im1' => $icon,
'im2' => $icon,
'item' => array(),
Tree::IMAGE_FOLDER_OPEN => $icon,
Tree::IMAGE_FOLDER_CLOSED => $icon,
Tree::CHILDREN => array(),
'child' => 1,
);
if ($path == '/admin') $parent[$path]['open'] = true;
}
$parent =& $parent[$path]['item'];
$parent =& $parent[$path][Tree::CHILDREN];
}
$data['text'] = lang($data['text']);
$data[Tree::LABEL] = lang($data[Tree::LABEL]);
if (!empty($data['tooltip'])) $data['tooltip'] = lang($data['tooltip']);
// make sure keys are unique, as we overwrite tree entries otherwise
if (isset($parent[$data['id']])) $data['id'] .= md5($data['link']);
$parent[$data['id']] = self::fix_userdata($data);
if (isset($parent[$data[Tree::ID]])) $data[Tree::ID] .= md5($data['link']);
$parent[$data[Tree::ID]] = self::fix_userdata($data);
}
}
}
@ -502,14 +510,14 @@ class admin_ui
'sort' => 'ASC',
)) as $group)
{
$tree['item'][] = self::fix_userdata(array(
'text' => $group['account_lid'],
'tooltip' => $group['account_description'],
'id' => $root.'/'.$group['account_id'],
$tree[Tree::CHILDREN][] = self::fix_userdata(array(
Tree::LABEL => $group['account_lid'],
Tree::TOOLTIP => $group['account_description'],
Tree::ID => $root.'/'.$group['account_id'],
));
}
}
self::strip_item_keys($tree['item']);
self::strip_item_keys($tree[Tree::CHILDREN]);
//_debug_array($tree); exit;
return $tree;
}
@ -522,9 +530,13 @@ class admin_ui
*/
private static function fix_userdata(array $data)
{
if(!$data[Tree::LABEL])
{
$data[Tree::LABEL] = $data['text'];
}
// store link as userdata, maybe we should store everything not directly understood by tree this way ...
foreach(array_diff_key($data, array_flip(array(
'id','text','tooltip','im0','im1','im2','item','child','select','open','call',
Tree::ID,Tree::LABEL,Tree::TOOLTIP,'im0','im1','im2','item','child','select','open','call',
))) as $name => $content)
{
$data['userdata'][] = array(

File diff suppressed because it is too large Load Diff