Commit 130486a45f80c4c597991dd54b996305289f7014
1 parent
4c36d357
KTS-1796
"CLONE -No easy way to delete users/User.inc(SUP-163)" Fixed: Added functionality to soft delete a user. Committed By: Jonathan Byrne Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7310 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
4 changed files
with
138 additions
and
63 deletions
lib/session/Session.inc
lib/users/User.inc
| ... | ... | @@ -285,7 +285,8 @@ class User extends KTEntity { |
| 285 | 285 | function getList($sWhereClause = null, $aOptions = null) { |
| 286 | 286 | if(!is_array($aOptions)) $aOptions = array($aOptions); |
| 287 | 287 | $aOptions['orderby'] = KTUtil::arrayGet($aOptions, 'orderby', 'name'); |
| 288 | - | |
| 288 | + //if disabled = 2 then the user is deleted | |
| 289 | + $sWhereClause = 'disabled != \'2\''; | |
| 289 | 290 | return KTEntityUtil::getList2('User', $sWhereClause, $aOptions); |
| 290 | 291 | } |
| 291 | 292 | |
| ... | ... | @@ -388,7 +389,7 @@ class User extends KTEntity { |
| 388 | 389 | function isAnonymous() { return $this->iId == -2; } |
| 389 | 390 | |
| 390 | 391 | function disable() { |
| 391 | - $this->setDisabled(true); | |
| 392 | + $this->setDisabled(1); | |
| 392 | 393 | $this->update(); |
| 393 | 394 | if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { |
| 394 | 395 | require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); |
| ... | ... | @@ -398,7 +399,7 @@ class User extends KTEntity { |
| 398 | 399 | } |
| 399 | 400 | |
| 400 | 401 | function enable() { |
| 401 | - $this->setDisabled(false); | |
| 402 | + $this->setDisabled(0); | |
| 402 | 403 | $this->update(); |
| 403 | 404 | if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { |
| 404 | 405 | require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); |
| ... | ... | @@ -417,4 +418,35 @@ class User extends KTEntity { |
| 417 | 418 | } |
| 418 | 419 | return parent::create(); |
| 419 | 420 | } |
| 421 | + | |
| 422 | + function delete() | |
| 423 | + { | |
| 424 | + $this->setDisabled(2); | |
| 425 | + $this->setEmailNotification(false); | |
| 426 | + //change username | |
| 427 | + $tempUsername = $this->getUsername(); | |
| 428 | + $this->getUserID($tempUsername); | |
| 429 | + $tempUserID = $this->iId; | |
| 430 | + $DeletedUsername = 'kt_deleted_'.$tempUsername.'_'.$tempUserID; | |
| 431 | + $this->setUsername($DeletedUsername); | |
| 432 | + | |
| 433 | + //nullify all authentication_xxx fields | |
| 434 | + $this->setAuthenticationSourceId(null); | |
| 435 | + $this->setAuthenticationDetails(null); | |
| 436 | + $this->setAuthenticationDetails2(null); | |
| 437 | + $this->setAuthenticationDetailsInt1(null); | |
| 438 | + $this->setAuthenticationDetailsInt2(null); | |
| 439 | + $this->setAuthenticationDetailsDate1(null); | |
| 440 | + $this->setAuthenticationDetailsDate2(null); | |
| 441 | + $this->setAuthenticationDetailsBool1(null); | |
| 442 | + $this->setAuthenticationDetailsBool2(null); | |
| 443 | + | |
| 444 | + $this->update(); | |
| 445 | + if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { | |
| 446 | + require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); | |
| 447 | + BaobabKeyUtil::allocateUser($this); | |
| 448 | + } | |
| 449 | + return; | |
| 450 | + | |
| 451 | + } | |
| 420 | 452 | } | ... | ... |
plugins/ktcore/admin/userManagement.php
| ... | ... | @@ -645,6 +645,7 @@ class KTUserAdminDispatcher extends KTAdminDispatcher { |
| 645 | 645 | |
| 646 | 646 | // change enabled / disabled status of users |
| 647 | 647 | function do_change_enabled() { |
| 648 | + | |
| 648 | 649 | $this->startTransaction(); |
| 649 | 650 | $iLicenses = 0; |
| 650 | 651 | $bRequireLicenses = false; |
| ... | ... | @@ -655,33 +656,56 @@ class KTUserAdminDispatcher extends KTAdminDispatcher { |
| 655 | 656 | } |
| 656 | 657 | // admin and anonymous are automatically ignored here. |
| 657 | 658 | $iEnabledUsers = User::getNumberEnabledUsers(); |
| 658 | - | |
| 659 | - foreach(KTUtil::arrayGet($_REQUEST, 'disable_user', array()) as $sUserId => $v) { | |
| 660 | - $oUser = User::get((int)$sUserId); | |
| 661 | - if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); } | |
| 662 | - $oUser->disable(); | |
| 663 | - $res = $oUser->update(); | |
| 664 | - if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); } | |
| 665 | - $iEnabledUsers--; | |
| 666 | - } | |
| 667 | - | |
| 668 | - foreach(KTUtil::arrayGet($_REQUEST, 'enable_user', array()) as $sUserId => $v) { | |
| 669 | - // check that we haven't hit max user limit | |
| 670 | - if($bRequireLicenses && $iEnabledUsers >= $iLicenses) { | |
| 671 | - // if so, add to error messages, but commit transaction (break this loop) | |
| 672 | - $_SESSION['KTErrorMessage'][] = _kt('You may only have ') . $iLicenses . _kt(' users enabled at one time.'); | |
| 673 | - break; | |
| 674 | - } | |
| 675 | - | |
| 676 | - // else enable user | |
| 677 | - $oUser = User::get((int)$sUserId); | |
| 678 | - if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); } | |
| 679 | - $oUser->enable(); | |
| 680 | - $res = $oUser->update(); | |
| 681 | - if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); } | |
| 682 | - $iEnabledUsers++; | |
| 683 | - } | |
| 684 | - | |
| 659 | + | |
| 660 | + if($_REQUEST['update_value'] == 'enable') | |
| 661 | + { | |
| 662 | + foreach(KTUtil::arrayGet($_REQUEST, 'edit_user', array()) as $sUserId => $v) { | |
| 663 | + // check that we haven't hit max user limit | |
| 664 | + if($bRequireLicenses && $iEnabledUsers >= $iLicenses) { | |
| 665 | + // if so, add to error messages, but commit transaction (break this loop) | |
| 666 | + $_SESSION['KTErrorMessage'][] = _kt('You may only have ') . $iLicenses . _kt(' users enabled at one time.'); | |
| 667 | + break; | |
| 668 | + } | |
| 669 | + | |
| 670 | + // else enable user | |
| 671 | + $oUser = User::get((int)$sUserId); | |
| 672 | + if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); } | |
| 673 | + $oUser->enable(); | |
| 674 | + $res = $oUser->update(); | |
| 675 | + if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); } | |
| 676 | + $iEnabledUsers++; | |
| 677 | + } | |
| 678 | + } | |
| 679 | + | |
| 680 | + if($_REQUEST['update_value'] == 'disable') | |
| 681 | + { | |
| 682 | + //echo 'got into disable'; | |
| 683 | + //exit; | |
| 684 | + | |
| 685 | + foreach(KTUtil::arrayGet($_REQUEST, 'edit_user', array()) as $sUserId => $v) { | |
| 686 | + $oUser = User::get((int)$sUserId); | |
| 687 | + if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); } | |
| 688 | + $oUser->disable(); | |
| 689 | + $res = $oUser->update(); | |
| 690 | + if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); } | |
| 691 | + $iEnabledUsers--; | |
| 692 | + } | |
| 693 | + } | |
| 694 | + | |
| 695 | + if($_REQUEST['update_value'] == 'delete') | |
| 696 | + { | |
| 697 | + //echo 'Delete called'; | |
| 698 | + | |
| 699 | + foreach(KTUtil::arrayGet($_REQUEST, 'edit_user', array()) as $sUserId => $v) { | |
| 700 | + $oUser = User::get((int)$sUserId); | |
| 701 | + if(PEAR::isError($oUser)) { $this->errorRedirectToMain(_kt('Error getting user object')); } | |
| 702 | + $oUser->delete(); | |
| 703 | + $res = $oUser->update(); | |
| 704 | + if(PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error updating user')); } | |
| 705 | + $iEnabledUsers--; | |
| 706 | + } | |
| 707 | + } | |
| 708 | + | |
| 685 | 709 | $this->commitTransaction(); |
| 686 | 710 | $this->successRedirectToMain(_kt('Users updated')); |
| 687 | 711 | |
| ... | ... | @@ -689,4 +713,4 @@ class KTUserAdminDispatcher extends KTAdminDispatcher { |
| 689 | 713 | |
| 690 | 714 | } |
| 691 | 715 | |
| 692 | 716 | -?> |
| 717 | +?> | |
| 693 | 718 | \ No newline at end of file | ... | ... |
templates/ktcore/principals/useradmin.smarty
| 1 | 1 | <h2>{i18n}User Management{/i18n}</h2> |
| 2 | - | |
| 2 | +{literal} | |
| 3 | +<script type="text/javascript"> | |
| 4 | + function updateUser(updateAction) | |
| 5 | + { | |
| 6 | + var hiddenBox = document.getElementById("update_value"); | |
| 7 | + hiddenBox.value = updateAction; | |
| 8 | + document.editUserForm.submit(); | |
| 9 | + } | |
| 10 | + function confirmDelete () | |
| 11 | + { | |
| 12 | + if(confirm("Are you sure you want to delete?")) | |
| 13 | + { | |
| 14 | + updateUser('delete'); | |
| 15 | + } | |
| 16 | + } | |
| 17 | +</script> | |
| 18 | +{/literal} | |
| 3 | 19 | |
| 4 | 20 | {if $can_add} |
| 5 | 21 | <fieldset> <legend>{i18n}Add new users{/i18n}</legend> <p |
| ... | ... | @@ -69,16 +85,16 @@ very slow if you have many users).{/i18n}</p> |
| 69 | 85 | {if (!empty($search_results))} |
| 70 | 86 | |
| 71 | 87 | <br /> |
| 72 | -<form action="{$smarty.server.PHP_SELF}" method="post"> | |
| 88 | +<form name="editUserForm" action="{$smarty.server.PHP_SELF}" method="post"> | |
| 73 | 89 | <table class="kt_collection narrow" cellspacing="0" cellpadding="5"> |
| 74 | 90 | <thead> |
| 75 | 91 | <tr> |
| 92 | + <th> </th> | |
| 76 | 93 | <th>{i18n}Name{/i18n}</th> |
| 77 | 94 | <th>{i18n}Username{/i18n}</th> |
| 78 | 95 | <th>{i18n}Edit{/i18n}</th> |
| 79 | 96 | <th>{i18n}Enabled{/i18n}</th> |
| 80 | - <th>{i18n}Enable{/i18n}</th> | |
| 81 | - <th>{i18n}Disable{/i18n}</th> | |
| 97 | + | |
| 82 | 98 | <th>{i18n}Group Memberships{/i18n}</th> |
| 83 | 99 | <th>{i18n}Current Groups{/i18n}</th> |
| 84 | 100 | </tr> |
| ... | ... | @@ -86,39 +102,42 @@ very slow if you have many users).{/i18n}</p> |
| 86 | 102 | <tbody> |
| 87 | 103 | <!-- do we want to batch here? --> |
| 88 | 104 | {foreach item=oUser from=$search_results} |
| 89 | - <tr class="{cycle values=odd,even}"> | |
| 90 | - <td>{$oUser->getName()}</td> | |
| 91 | - <td>{$oUser->getUsername()}</td> | |
| 92 | - <td><a href="{addQS}action=editUser&user_id={$oUser->getId()}&old_search={$old_search}{/addQS}" class="ktAction ktEdit">{i18n}Edit{/i18n}</a></td> | |
| 93 | - <td class="centered"> | |
| 94 | - {if ($oUser->getDisabled())} | |
| 95 | - <span class="ktAction ktDenied" title="{i18n}Disabled{/i18n}">{i18n}Disabled{/i18n}</a> | |
| 96 | - {else} | |
| 97 | - <span class="ktAction ktAllowed" title="{i18n}Enabled{/i18n}">{i18n}Enabled{/i18n}</a> | |
| 98 | - {/if} | |
| 99 | - </td> | |
| 100 | - | |
| 101 | - <td class="centered"> | |
| 102 | - {if ($oUser->getDisabled() && $oUser->getId() != ADMIN_USER_ID)}<input type="checkbox" name="enable_user[{$oUser->getId()}]" value="1" /> | |
| 103 | - {else}—{/if} | |
| 104 | - </td> | |
| 105 | - | |
| 106 | - <td class="centered"> | |
| 107 | - {if (!$oUser->getDisabled() && $oUser->getId() != ADMIN_USER_ID)}<input type="checkbox" name="disable_user[{$oUser->getId()}]" value="1" /> | |
| 108 | - {else}—{/if} | |
| 109 | - </td> | |
| 110 | - | |
| 111 | - | |
| 112 | - <td><a href="{addQS}action=editgroups&user_id={$oUser->getId()}&old_search={$old_search}{/addQS}">{i18n}Manage Groups{/i18n}</a></td> | |
| 113 | - <td class="title"><span class="descriptiveText">{$context->getGroupStringForUser($oUser)}</span></td> | |
| 114 | - </tr> | |
| 105 | + {if ($oUser->getDisabled() != 2)} | |
| 106 | + <tr class="{cycle values=odd,even}"> | |
| 107 | + <td class="centered"> | |
| 108 | + {if ($oUser->getId() != ADMIN_USER_ID)}<input type="checkbox" name="edit_user[{$oUser->getId()}]" value="1"/> | |
| 109 | + {else}—{/if} | |
| 110 | + </td> | |
| 111 | + <td class="centered"> | |
| 112 | + {$oUser->getName()}</td> | |
| 113 | + <td>{$oUser->getUsername()}</td> | |
| 114 | + <td><a href="{addQS}action=editUser&user_id={$oUser->getId()}&old_search={$old_search}{/addQS}" class="ktAction ktEdit">{i18n}Edit{/i18n}</a></td> | |
| 115 | + <td class="centered"> | |
| 116 | + {if ($oUser->getDisabled() == 1)} | |
| 117 | + <span class="ktAction ktDenied" title="{i18n}Disabled{/i18n}">{i18n}Disabled{/i18n}</a> | |
| 118 | + {else} | |
| 119 | + <span class="ktAction ktAllowed" title="{i18n}Enabled{/i18n}">{i18n}Enabled{/i18n}</a> | |
| 120 | + {/if} | |
| 121 | + </td> | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + <td><a href="{addQS}action=editgroups&user_id={$oUser->getId()}&old_search={$old_search}{/addQS}">{i18n}Manage Groups{/i18n}</a></td> | |
| 127 | + <td class="title"><span class="descriptiveText">{$context->getGroupStringForUser($oUser)}</span></td> | |
| 128 | + </tr> | |
| 129 | + {/if} | |
| 115 | 130 | {/foreach} |
| 116 | 131 | |
| 117 | 132 | </tbody> |
| 118 | 133 | </table> |
| 119 | 134 | <div class="form_actions"> |
| 120 | 135 | <input type="hidden" name="action" value="change_enabled" /> |
| 121 | -<input type="submit" value="{i18n}Apply Changes{/i18n}" /> | |
| 136 | +<input type="hidden" name="update_value" id="update_value" value="" /> | |
| 137 | +<input type="button" value="{i18n}Enable{/i18n}" id="enableButton" onclick="updateUser('enable');"> | |
| 138 | +<input type="button" value="{i18n}Disable{/i18n}" id="disableButton" onclick="updateUser('disable');"> | |
| 139 | +<input type="button" value="{i18n}Delete{/i18n}" id="deleteButton" onclick="confirmDelete();"> | |
| 140 | + | |
| 122 | 141 | </div> |
| 123 | 142 | </form> |
| 124 | 143 | {else} | ... | ... |