From 85909397092a3af13ec69f6513ec08fb6d5a4c92 Mon Sep 17 00:00:00 2001 From: nathangray Date: Mon, 2 Mar 2020 16:00:58 -0700 Subject: [PATCH] * Admin: Add copy account action --- admin/inc/class.admin_account.inc.php | 58 +++++++++++++++++++++++---- admin/inc/class.admin_ui.inc.php | 9 ++++- admin/js/app.js | 17 +++++--- admin/js/app.ts | 20 +++++---- 4 files changed, 82 insertions(+), 22 deletions(-) diff --git a/admin/inc/class.admin_account.inc.php b/admin/inc/class.admin_account.inc.php index a576f3e43d..586bfef0cd 100644 --- a/admin/inc/class.admin_account.inc.php +++ b/admin/inc/class.admin_account.inc.php @@ -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 * diff --git a/admin/inc/class.admin_ui.inc.php b/admin/inc/class.admin_ui.inc.php index 7142af55f1..72e57db834 100644 --- a/admin/inc/class.admin_ui.inc.php +++ b/admin/inc/class.admin_ui.inc.php @@ -11,10 +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 @@ -154,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'); diff --git a/admin/js/app.js b/admin/js/app.js index e68e7f8cbc..966e2d7a7b 100644 --- a/admin/js/app.js +++ b/admin/js/app.js @@ -760,11 +760,17 @@ var AdminApp = /** @class */ (function (_super) { AdminApp.prototype.account = function (_action, _senders) { var params = jQuery.extend({}, this.egw.link_get_registry('addressbook', 'edit')); var popup = this.egw.link_get_registry('addressbook', 'edit_popup'); - if (_action.id == 'add') { - params.owner = '0'; - } - else { - params.account_id = _senders[0].id.split('::').pop(); // get last :: separated part + switch (_action.id) { + case 'add': + params.owner = '0'; + break; + case 'copy': + params.owner = '0'; + params.copy = true; + // Fall through + default: + params.account_id = _senders[0].id.split('::').pop(); // get last :: separated part + break; } this.egw.open_link(this.egw.link('/index.php', params), 'admin', popup); }; @@ -1217,4 +1223,3 @@ var AdminApp = /** @class */ (function (_super) { */ )); app.classes.admin = AdminApp; -//# sourceMappingURL=app.js.map \ No newline at end of file diff --git a/admin/js/app.ts b/admin/js/app.ts index 8c6212fff3..f9e23f0a29 100644 --- a/admin/js/app.ts +++ b/admin/js/app.ts @@ -17,7 +17,7 @@ import 'jqueryui'; import '../jsapi/egw_global'; import '../etemplate/et2_types'; -import { EgwApp } from '../../api/js/jsapi/egw_app'; +import {EgwApp} from '../../api/js/jsapi/egw_app'; /** * UI for Admin @@ -888,14 +888,20 @@ class AdminApp extends EgwApp var params = jQuery.extend({}, this.egw.link_get_registry('addressbook', 'edit')); var popup = this.egw.link_get_registry('addressbook', 'edit_popup'); - if (_action.id == 'add') + switch(_action.id) { - params.owner = '0'; - } - else - { - params.account_id = _senders[0].id.split('::').pop(); // get last :: separated part + case 'add': + params.owner = '0'; + break; + case 'copy': + params.owner = '0'; + params.copy = true; + // Fall through + default: + params.account_id = _senders[0].id.split('::').pop(); // get last :: separated part + break; } + this.egw.open_link(this.egw.link('/index.php', params), 'admin', popup); }