Merge pull request #206 from radiorabe/fix/delete-first-admin-user

Problem: Deleting the initial admin won't work since it doesn't re-assign files
This commit is contained in:
Robb 2017-05-25 11:25:12 -04:00 committed by GitHub
commit c1f38e536f
2 changed files with 20 additions and 13 deletions

View file

@ -204,7 +204,7 @@ class UserController extends Zend_Controller_Action
# TODO : remove this. we only use default for now not to break the UI. # TODO : remove this. we only use default for now not to break the UI.
if (!$files_action) { # set default action if (!$files_action) { # set default action
$files_action = "reassign_to"; $files_action = "reassign_to";
$new_owner = Application_Model_User::getFirstAdmin(); $new_owner = Application_Model_User::getFirstAdmin($delId);
} }
# only delete when valid action is selected for the owned files # only delete when valid action is selected for the owned files

View file

@ -253,12 +253,29 @@ class Application_Model_User
return CcSubjsQuery::create()->filterByDbType($type)->find(); return CcSubjsQuery::create()->filterByDbType($type)->find();
} }
public static function getFirstAdmin() { /**
* Get the first admin user from the database
*
* This function gets used in UserController in the delete action. The controller
* uses it to figure out who to reassign the deleted users files to.
*
* @param $ignoreUser String optional userid of a user that shall be ignored when
* when looking for the "first" admin.
*
* @return CcSubj|null
*/
public static function getFirstAdmin($ignoreUser = null) {
$superAdmins = Application_Model_User::getUsersOfType('S'); $superAdmins = Application_Model_User::getUsersOfType('S');
if (count($superAdmins) > 0) { // found superadmin => pick first one if (count($superAdmins) > 0) { // found superadmin => pick first one
return $superAdmins[0]; return $superAdmins[0];
} else { } else {
$admins = Application_Model_User::getUsersOfType('A'); // get all admin users
$query = CcSubjsQuery::create()->filterByDbType('A');
// ignore current user if one was specified
if ($ignoreUser !== null) {
$query->filterByDbId($ignoreUser, Criteria::NOT_EQUAL);
}
$admins = $query->find();
if (count($admins) > 0) { // found admin => pick first one if (count($admins) > 0) { // found admin => pick first one
return $admins[0]; return $admins[0];
} }
@ -267,16 +284,6 @@ class Application_Model_User
} }
} }
public static function getFirstAdminId()
{
$admin = self::getFirstAdmin();
if ($admin) {
return $admin->getDbId();
} else {
return null;
}
}
public static function getUsers(array $type, $search=null) public static function getUsers(array $type, $search=null)
{ {
$con = Propel::getConnection(); $con = Propel::getConnection();