diff --git a/VERSIONS_WIP/76768 b/VERSIONS_WIP/76768 index 28f5199f0b21043c8a3386243a68b55eb561f205..796a873b90e49055c58cabb908a950f7892cf5ad 100644 --- a/VERSIONS_WIP/76768 +++ b/VERSIONS_WIP/76768 @@ -1 +1,2 @@ - - ticket #76768 : sandbox : manage user swaping \ No newline at end of file + - ticket #76768 : Administration : amélioration de la fonction "Se connecter en tant que". + \ No newline at end of file diff --git a/application/modules/opac/controllers/AuthController.php b/application/modules/opac/controllers/AuthController.php index 50ed60690d14103c218a5432deeb779237cf1001..7f9c6832a68a6be2780c7c97173129fa912d61b4 100644 --- a/application/modules/opac/controllers/AuthController.php +++ b/application/modules/opac/controllers/AuthController.php @@ -622,8 +622,6 @@ class AuthController extends ZendAfi_Controller_Action { } - - public function becomeAction() { if (!ZendAfi_Auth_Others::getInstance()->isSuperAdminLogged()) { $this->_helper->notify($this->_('Vous n\'avez pas les droits suffisants pour utiliser cette fonctionnalité.')); diff --git a/library/ZendAfi/Auth/Others.php b/library/ZendAfi/Auth/Others.php index 251a78fcb4b435fc5ffff37e3475046c4e68401c..d7b5add8929adc8e4cfe5af8d5e9ed4ec501d11b 100644 --- a/library/ZendAfi/Auth/Others.php +++ b/library/ZendAfi/Auth/Others.php @@ -28,7 +28,7 @@ class ZendAfi_Auth_Others { public function swapNonAdminWithSuperAdmin($user) { - if($user->isAdmin()) + if ($user->isAdmin()) return $user; return $this->swapUserWith($user, $this->getCurrentSuperAdmin())->getUser(); @@ -43,10 +43,10 @@ class ZendAfi_Auth_Others { if (!$user || !$other || !$this->isSuperAdminLogged()) return $result; - if(($user->getId() == $other->getId())) + if (($user->getId() == $other->getId())) return $result->setSuccess(true); - if(!$this->_tryLogOther($other)) + if (!$this->_tryLogOther($other)) return $result; $this->clearIdentity($other); @@ -64,55 +64,6 @@ class ZendAfi_Auth_Others { } - protected function _tryLogOther($other) { - $auth = ZendAfi_Auth::getInstance(); - - if ($other->isAbonne()) - return $auth - ->authenticateLoginPassword($other->getLogin(), $other->getPassword()); - - $auth->logUser($other); - return true; - } - - - protected function _getIdentities() { - return $this->_getIdentitiesStorage() - ->collect(function($storage) - { - if(!$object = $storage->read()) - return null; - return Class_Users::find($object->ID_USER); - }) - ->reject(function($data) - { - return !$data; - }); - } - - - protected function _getIdentitiesStorage() { - if($this->_identities_storage) - return $this->_identities_storage; - - return $this->_identities_storage = $this->_initIdentitiesStorage(); - } - - - protected function _initIdentitiesStorage() { - $collection = new Storm_Collection; - foreach(range(1, 10) as $key) { - $session_name = implode('_', - [ZendAfi_Auth_Storage_Session::NAMESPACE_OTHERS, - $key, - (new Class_AdminVar_BUID())->getValue()]); - $collection->append(new ZendAfi_Auth_Storage_Session($session_name)); - } - - return $collection; - } - - public function getIdentities() { return $this->_getIdentities(); } @@ -124,7 +75,7 @@ class ZendAfi_Auth_Others { $selected = $collection ->select(function($storage) use ($user) { - if(!$session_object = $storage->read()) + if (!$session_object = $storage->read()) return true; $object = $user->toStdClass(); @@ -132,7 +83,7 @@ class ZendAfi_Auth_Others { }); - if(!$selected->isEmpty()) { + if (!$selected->isEmpty()) { $selected->first()->write($user->toStdClass()); return $this; } @@ -157,11 +108,11 @@ class ZendAfi_Auth_Others { $this->_getIdentitiesStorage() ->eachDo(function($storage) use ($user) { - if(!$session_object = $storage->read()) + if (!$session_object = $storage->read()) return; $object = $user->toStdClass(); - if($object->ID_USER == $session_object->ID_USER) + if ($object->ID_USER == $session_object->ID_USER) $storage->clear(); }); return $this; @@ -169,15 +120,15 @@ class ZendAfi_Auth_Others { public function getCurrentAdmin() { - if(Class_Users::isCurrentUserCanAccesBackend()) + if (Class_Users::isCurrentUserCanAccesBackend()) return Class_Users::getIdentity(); return $this->getSuperAdminInIdentities(); } - public function getCurrentSuperAdmin() { - if(Class_Users::isCurrentUserSuperAdmin()) + public function getCurrentSuperAdmin() { + if (Class_Users::isCurrentUserSuperAdmin()) return Class_Users::getIdentity(); return $this->getSuperAdminInIdentities(); @@ -192,7 +143,7 @@ class ZendAfi_Auth_Others { public function getSuperAdminInIdentities() { $identities = $this->_getIdentities(); - if($identities->isEmpty()) + if ($identities->isEmpty()) return null; $admins = $identities @@ -205,4 +156,53 @@ class ZendAfi_Auth_Others { ? null : $admins->first(); } + + + protected function _tryLogOther($other) { + $auth = ZendAfi_Auth::getInstance(); + + if ($other->isAbonne()) + return $auth + ->authenticateLoginPassword($other->getLogin(), $other->getPassword()); + + $auth->logUser($other); + return true; + } + + + protected function _getIdentities() { + return $this->_getIdentitiesStorage() + ->collect(function($storage) + { + if (!$object = $storage->read()) + return null; + return Class_Users::find($object->ID_USER); + }) + ->reject(function($data) + { + return !$data; + }); + } + + + protected function _getIdentitiesStorage() { + if ($this->_identities_storage) + return $this->_identities_storage; + + return $this->_identities_storage = $this->_initIdentitiesStorage(); + } + + + protected function _initIdentitiesStorage() { + $collection = new Storm_Collection; + foreach(range(1, 10) as $key) { + $session_name = implode('_', + [ZendAfi_Auth_Storage_Session::NAMESPACE_OTHERS, + $key, + (new Class_AdminVar_BUID())->getValue()]); + $collection->append(new ZendAfi_Auth_Storage_Session($session_name)); + } + + return $collection; + } } \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Admin/FrontNav.php b/library/ZendAfi/View/Helper/Admin/FrontNav.php index 92735eb872e679ccfe8f3ad977f23250665fda72..947792eeb7e60c2e2dfb1f5ad703bd94c6a19385 100644 --- a/library/ZendAfi/View/Helper/Admin/FrontNav.php +++ b/library/ZendAfi/View/Helper/Admin/FrontNav.php @@ -27,10 +27,6 @@ class ZendAfi_View_Helper_Admin_FrontNav extends ZendAfi_View_Helper_BaseHelper if(!$this->_user = ZendAfi_Auth_Others::getInstance()->getCurrentAdmin()) return ''; - Class_ScriptLoader::getInstance() - ->addAdminScript('cfg.accueil') - ->addInlineScript('window.activateOpacBlocksSorting = window.deactiveOpacBlocksSorting = function() {};'); - $instance = Class_ScriptLoader::getInstance(); Class_Admin_Skin::current()->renderAdminFrontNavCssOn($instance); @@ -392,6 +388,10 @@ class ZendAfi_View_Helper_Admin_FrontNav extends ZendAfi_View_Helper_BaseHelper protected function _moduleSort() { + Class_ScriptLoader::getInstance() + ->addAdminScript('cfg.accueil') + ->addInlineScript('window.activateOpacBlocksSorting = window.deactiveOpacBlocksSorting = function() {};'); + return $this->_toggleAnchor($this->_('Déplacement des boites'), 'block_sorting', sprintf('opacBlocksSorting(\'%s\',%d); $("div.layout-division>div").sortable("enable");', Class_Url::absolute('/admin/profil/module-sort'), Class_Profil::getCurrentProfil()->getId()), diff --git a/tests/scenarios/Become/BecomeTest.php b/tests/scenarios/Become/BecomeTest.php index ae23805fe00641e17e5acec132331029d9e2a253..a33fbb2d4b7f0e884c6f80d03c46f7ac050700ab 100644 --- a/tests/scenarios/Become/BecomeTest.php +++ b/tests/scenarios/Become/BecomeTest.php @@ -254,9 +254,6 @@ class BecomeAdminAuthLogoutTest extends Admin_AbstractControllerTestCase { - - - class BecomeUsersControllerWithSuperAdminTest extends Admin_AbstractControllerTestCase { protected $_storm_default_to_volatile = true;