From 130486a45f80c4c597991dd54b996305289f7014 Mon Sep 17 00:00:00 2001 From: Jonathan Byrne Date: Tue, 9 Oct 2007 14:24:33 +0000 Subject: [PATCH] KTS-1796 "CLONE -No easy way to delete users/User.inc(SUP-163)" --- lib/session/Session.inc | 2 +- lib/users/User.inc | 38 +++++++++++++++++++++++++++++++++++--- plugins/ktcore/admin/userManagement.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- templates/ktcore/principals/useradmin.smarty | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- 4 files changed, 138 insertions(+), 63 deletions(-) diff --git a/lib/session/Session.inc b/lib/session/Session.inc index 039f510..028811a 100644 --- a/lib/session/Session.inc +++ b/lib/session/Session.inc @@ -55,7 +55,7 @@ class Session { } } - if ($oUser->getDisabled()) { + if ($oUser->getDisabled() == 1) { return PEAR::raiseError(_kt("Your account has been disabled. Please contact the system administrator for assistance.")); } diff --git a/lib/users/User.inc b/lib/users/User.inc index d73fe71..ba71b5e 100644 --- a/lib/users/User.inc +++ b/lib/users/User.inc @@ -285,7 +285,8 @@ class User extends KTEntity { function getList($sWhereClause = null, $aOptions = null) { if(!is_array($aOptions)) $aOptions = array($aOptions); $aOptions['orderby'] = KTUtil::arrayGet($aOptions, 'orderby', 'name'); - + //if disabled = 2 then the user is deleted + $sWhereClause = 'disabled != \'2\''; return KTEntityUtil::getList2('User', $sWhereClause, $aOptions); } @@ -388,7 +389,7 @@ class User extends KTEntity { function isAnonymous() { return $this->iId == -2; } function disable() { - $this->setDisabled(true); + $this->setDisabled(1); $this->update(); if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); @@ -398,7 +399,7 @@ class User extends KTEntity { } function enable() { - $this->setDisabled(false); + $this->setDisabled(0); $this->update(); if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); @@ -417,4 +418,35 @@ class User extends KTEntity { } return parent::create(); } + + function delete() + { + $this->setDisabled(2); + $this->setEmailNotification(false); + //change username + $tempUsername = $this->getUsername(); + $this->getUserID($tempUsername); + $tempUserID = $this->iId; + $DeletedUsername = 'kt_deleted_'.$tempUsername.'_'.$tempUserID; + $this->setUsername($DeletedUsername); + + //nullify all authentication_xxx fields + $this->setAuthenticationSourceId(null); + $this->setAuthenticationDetails(null); + $this->setAuthenticationDetails2(null); + $this->setAuthenticationDetailsInt1(null); + $this->setAuthenticationDetailsInt2(null); + $this->setAuthenticationDetailsDate1(null); + $this->setAuthenticationDetailsDate2(null); + $this->setAuthenticationDetailsBool1(null); + $this->setAuthenticationDetailsBool2(null); + + $this->update(); + if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { + require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); + BaobabKeyUtil::allocateUser($this); + } + return; + + } } diff --git a/plugins/ktcore/admin/userManagement.php b/plugins/ktcore/admin/userManagement.php index a916913..dadaed3 100755 --- a/plugins/ktcore/admin/userManagement.php +++ b/plugins/ktcore/admin/userManagement.php @@ -645,6 +645,7 @@ class KTUserAdminDispatcher extends KTAdminDispatcher { // change enabled / disabled status of users function do_change_enabled() { + $this->startTransaction(); $iLicenses = 0; $bRequireLicenses = false; @@ -655,33 +656,56 @@ class KTUserAdminDispatcher extends KTAdminDispatcher { } // admin and anonymous are automatically ignored here. $iEnabledUsers = User::getNumberEnabledUsers(); - - foreach(KTUtil::arrayGet($_REQUEST, 'disable_user', array()) as $sUserId => $v) { - $oUser = User::get((int)$sUserId); - if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); } - $oUser->disable(); - $res = $oUser->update(); - if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); } - $iEnabledUsers--; - } - - foreach(KTUtil::arrayGet($_REQUEST, 'enable_user', array()) as $sUserId => $v) { - // check that we haven't hit max user limit - if($bRequireLicenses && $iEnabledUsers >= $iLicenses) { - // if so, add to error messages, but commit transaction (break this loop) - $_SESSION['KTErrorMessage'][] = _kt('You may only have ') . $iLicenses . _kt(' users enabled at one time.'); - break; - } - - // else enable user - $oUser = User::get((int)$sUserId); - if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); } - $oUser->enable(); - $res = $oUser->update(); - if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); } - $iEnabledUsers++; - } - + + if($_REQUEST['update_value'] == 'enable') + { + foreach(KTUtil::arrayGet($_REQUEST, 'edit_user', array()) as $sUserId => $v) { + // check that we haven't hit max user limit + if($bRequireLicenses && $iEnabledUsers >= $iLicenses) { + // if so, add to error messages, but commit transaction (break this loop) + $_SESSION['KTErrorMessage'][] = _kt('You may only have ') . $iLicenses . _kt(' users enabled at one time.'); + break; + } + + // else enable user + $oUser = User::get((int)$sUserId); + if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); } + $oUser->enable(); + $res = $oUser->update(); + if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); } + $iEnabledUsers++; + } + } + + if($_REQUEST['update_value'] == 'disable') + { + //echo 'got into disable'; + //exit; + + foreach(KTUtil::arrayGet($_REQUEST, 'edit_user', array()) as $sUserId => $v) { + $oUser = User::get((int)$sUserId); + if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); } + $oUser->disable(); + $res = $oUser->update(); + if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); } + $iEnabledUsers--; + } + } + + if($_REQUEST['update_value'] == 'delete') + { + //echo 'Delete called'; + + foreach(KTUtil::arrayGet($_REQUEST, 'edit_user', array()) as $sUserId => $v) { + $oUser = User::get((int)$sUserId); + if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); } + $oUser->delete(); + $res = $oUser->update(); + if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); } + $iEnabledUsers--; + } + } + $this->commitTransaction(); $this->successRedirectToMain(_kt('Users updated')); @@ -689,4 +713,4 @@ class KTUserAdminDispatcher extends KTAdminDispatcher { } -?> +?> \ No newline at end of file diff --git a/templates/ktcore/principals/useradmin.smarty b/templates/ktcore/principals/useradmin.smarty index c9f6f8a..918891d 100644 --- a/templates/ktcore/principals/useradmin.smarty +++ b/templates/ktcore/principals/useradmin.smarty @@ -1,5 +1,21 @@

{i18n}User Management{/i18n}

- +{literal} + +{/literal} {if $can_add}
{i18n}Add new users{/i18n}

{if (!empty($search_results))}
-

+ + - - + @@ -86,39 +102,42 @@ very slow if you have many users).{/i18n}

{foreach item=oUser from=$search_results} - - - - - - - - - - - - - - + {if ($oUser->getDisabled() != 2)} + + + + + + + + + + + + + + {/if} {/foreach}
  {i18n}Name{/i18n} {i18n}Username{/i18n} {i18n}Edit{/i18n} {i18n}Enabled{/i18n}{i18n}Enable{/i18n}{i18n}Disable{/i18n}{i18n}Group Memberships{/i18n} {i18n}Current Groups{/i18n}
{$oUser->getName()}{$oUser->getUsername()}{i18n}Edit{/i18n} - {if ($oUser->getDisabled())} - {i18n}Disabled{/i18n} - {else} - {i18n}Enabled{/i18n} - {/if} - - {if ($oUser->getDisabled() && $oUser->getId() != ADMIN_USER_ID)} - {else}—{/if} - - {if (!$oUser->getDisabled() && $oUser->getId() != ADMIN_USER_ID)} - {else}—{/if} - {i18n}Manage Groups{/i18n}{$context->getGroupStringForUser($oUser)}
+ {if ($oUser->getId() != ADMIN_USER_ID)} + {else}—{/if} + + {$oUser->getName()}{$oUser->getUsername()}{i18n}Edit{/i18n} + {if ($oUser->getDisabled() == 1)} + {i18n}Disabled{/i18n} + {else} + {i18n}Enabled{/i18n} + {/if} + {i18n}Manage Groups{/i18n}{$context->getGroupStringForUser($oUser)}
- + + + + +
{else} -- libgit2 0.21.4