From 3233ccd151fc39a7ebf74f645a9e35b696afe9b7 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Mon, 22 May 2017 00:10:38 +0200 Subject: [PATCH 1/2] Remove dead code in user model --- airtime_mvc/application/models/User.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/airtime_mvc/application/models/User.php b/airtime_mvc/application/models/User.php index 76e563155..35d473ae7 100644 --- a/airtime_mvc/application/models/User.php +++ b/airtime_mvc/application/models/User.php @@ -267,16 +267,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) { $con = Propel::getConnection(); From 2ea19f20fedea75d8f7442755853cd6b143ba900 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Mon, 22 May 2017 00:11:27 +0200 Subject: [PATCH 2/2] Re-assign files to first non deleted admin user --- .../controllers/UserController.php | 2 +- airtime_mvc/application/models/User.php | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/application/controllers/UserController.php b/airtime_mvc/application/controllers/UserController.php index e4b48a90e..0e2c5e65e 100644 --- a/airtime_mvc/application/controllers/UserController.php +++ b/airtime_mvc/application/controllers/UserController.php @@ -204,7 +204,7 @@ class UserController extends Zend_Controller_Action # TODO : remove this. we only use default for now not to break the UI. if (!$files_action) { # set default action $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 diff --git a/airtime_mvc/application/models/User.php b/airtime_mvc/application/models/User.php index 35d473ae7..0b105e125 100644 --- a/airtime_mvc/application/models/User.php +++ b/airtime_mvc/application/models/User.php @@ -253,12 +253,29 @@ class Application_Model_User 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'); if (count($superAdmins) > 0) { // found superadmin => pick first one return $superAdmins[0]; } 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 return $admins[0]; }