Admin - Ask which apps to transfer (others are discarded) when deleting account

This commit is contained in:
nathangray 2019-07-19 14:31:27 -06:00
parent 4d858234ab
commit aefa8258a1
3 changed files with 61 additions and 52 deletions

View File

@ -264,6 +264,35 @@ class admin_account
{
$content = array('account_id' => (int)$_GET['account_id']);
}
//error_log(__METHOD__."() \$_GET[account_id]=$_GET[account_id], \$_GET[contact_id]=$_GET[contact_id] content=".array2string($content));
}
if ($GLOBALS['egw']->acl->check('account_access',32,'admin') ||
$GLOBALS['egw_info']['user']['account_id'] == $content['account_id'])
{
Framework::window_close(lang('Permission denied!!!'));
}
if ($content['delete'])
{
$cmd = new admin_cmd_delete_account(array(
'account' => $content['account_id'],
'new_user' => $content['new_owner'],
'is_user' => $content['account_id'] > 0,
'change_apps' => $content['delete_apps']
) + (array)$content['admin_cmd']);
$msg = $cmd->run();
if ($content['contact_id'])
{
Framework::refresh_opener($msg, 'addressbook', $content['contact_id'], 'delete');
}
else
{
Framework::refresh_opener($msg, 'admin', $content['account_id'], 'delete');
}
Framework::window_close();
}
$sel_options = array();
$preserve = $content;
// Get a count of entries owned by the user
$counts = $GLOBALS['egw']->accounts->get_account_entry_counts($content['account_id']);
@ -276,35 +305,15 @@ class admin_account
}
if($counts['total'])
{
$content['counts'][] = array(
'app' => $app,
'count' => $counts['total'] . ' '.$entry
$content['delete_apps'][] = $app;
$sel_options['delete_apps'][] = array(
'value' => $app,
'label' => lang($app) . ': ' . $counts['total'] . ' '.$entry
);
}
}
//error_log(__METHOD__."() \$_GET[account_id]=$_GET[account_id], \$_GET[contact_id]=$_GET[contact_id] content=".array2string($content));
}
if ($GLOBALS['egw']->acl->check('account_access',32,'admin') ||
$GLOBALS['egw_info']['user']['account_id'] == $content['account_id'])
{
Framework::window_close(lang('Permission denied!!!'));
}
if ($content['delete'])
{
$cmd = new admin_cmd_delete_account($content['account_id'], $content['new_owner'], $content['account_id'] > 0, (array)$content['admin_cmd']);
$msg = $cmd->run();
if ($content['contact_id'])
{
Framework::refresh_opener($msg, 'addressbook', $content['contact_id'], 'delete');
}
else
{
Framework::refresh_opener($msg, 'admin', $content['account_id'], 'delete');
}
Framework::window_close();
}
$tpl = new Etemplate('admin.account.delete');
$tpl->exec('admin_account::delete', $content, array(), array(), $content, 2);
$tpl->exec('admin_account::delete', $content, $sel_options, array(), $preserve, 2);
}
/**

View File

@ -198,8 +198,19 @@ class admin_cmd_delete_account extends admin_cmd
'new_owner' => (int)$new_user, // deleteaccount only
'location' => $is_user ? 'deleteaccount' : 'deletegroup',
);
// First do apps that were not selected
$skip_apps = array();
$do_last = array('preferences','admin');
if($this->change_apps)
{
foreach(array_diff(array_keys($GLOBALS['egw_info']['apps']), array_merge($this->change_apps,$do_last)) as $app)
{
$skip_apps[] = $app;
Api\Hooks::single(array_merge($GLOBALS['hook_values'], array('new_owner' => 0)), $app, true);
}
}
// first all other apps, then preferences and admin
foreach(array_merge(array_diff(array_keys($GLOBALS['egw_info']['apps']),array('preferences','admin')),array('preferences','admin')) as $app)
foreach(array_merge($this->change_apps,$do_last) as $app)
{
Api\Hooks::single($GLOBALS['hook_values'], $app, true);
}

View File

@ -2,40 +2,12 @@
<!DOCTYPE overlay PUBLIC "-//EGroupware GmbH//eTemplate 2//EN" "http://www.egroupware.org/etemplate2.dtd">
<!-- $Id$ -->
<overlay>
<template id="admin.account.delete" template="" lang="" group="0" version="18.1.001">
<box class="dialogHeader">
<select-account id="account_id" readonly="true" label="Delete"/>
</box>
<tabbox id="tabs" width="99%">
<tabs>
<tab id="main" label="Delete"/>
</tabs>
<tabpanels>
<template template="admin.account.delete.delete" width="99%"/>
</tabpanels>
</tabbox>
<hbox class="dialogFooterToolbar">
<button id="delete" label="Delete"/>
<button id="cancel" label="Cancel" onclick="window.close()"/>
</hbox>
</template>
<template id="admin.account.delete.delete" template="" lang="" group="0" version="18.1.001">
<vbox class="admin_account_delete">
<description value="Who would you like to transfer ALL records owned by the deleted user to?" class="dialogHeader2"/>
<description value="Who would you like to transfer records owned by the deleted user to?" class="dialogHeader2"/>
<select-account id="new_owner" empty_label="Delete all records" class="dialogHeader3"/>
<description value="Entries owned by the user:"/>
<grid id="counts">
<columns>
<column width="150"/>
<column/>
</columns>
<rows>
<row>
<select-app id="${row}[app]" readonly="true"/>
<description id="${row}[count]"/>
</row>
</rows>
</grid>
<description value="Transfer entries owned by the user:"/>
<select id="delete_apps" rows="8" multiple="true" span="2"/>
<grid>
<columns>
<column width="150"/>
@ -55,4 +27,21 @@
<description value="If you delete the user without selecting an account to move the data to, all entries get deleted!" font_style="b"/>
</vbox>
</template>
<template id="admin.account.delete" template="" lang="" group="0" version="18.1.001">
<box class="dialogHeader">
<select-account id="account_id" readonly="true" label="Delete" onchange="var apps = widget.getRoot().getWidgetById('delete_apps'); apps.set_enabled(widget.getValue());"/>
</box>
<tabbox id="tabs" width="99%">
<tabs>
<tab id="main" label="Delete"/>
</tabs>
<tabpanels>
<template template="admin.account.delete.delete" width="99%"/>
</tabpanels>
</tabbox>
<hbox class="dialogFooterToolbar">
<button id="delete" label="Delete"/>
<button id="cancel" label="Cancel" onclick="window.close()"/>
</hbox>
</template>
</overlay>