Skip to content
Snippets Groups Projects
Commit 7147b29f authored by gloas's avatar gloas
Browse files

plugin adminAuth: utilsation de zend controller action helper redirector pour rediriger vers l opac

parent 7de42460
Branches
Tags
No related merge requests found
......@@ -50,16 +50,15 @@ class ZendAfi_Controller_Plugin_AdminAuth extends Zend_Controller_Plugin_Abstrac
Zend_Controller_Front::getInstance()
->getPlugin('Zend_Controller_Plugin_ErrorHandler')
->setErrorHandlerModule('admin');
if (!$user = Class_Users::getIdentity()) {
$controller = 'auth';
$action = 'login';
} else if (!$this->userCanAccessAdminPage($user)) {
$module = 'opac';
$controller = 'index';
$action = 'index';
$redirector_helper = new Zend_Controller_Action_Helper_Redirector();
$redirector_helper->setExit(false);
$redirector_helper->goToUrl('opac/');
}
} else {
} else {
// Entree dans opac on teste si le site a été désactivé
if (Class_AdminVar::get("SITE_OK") == "0" and $module == 'opac') {
$controller = 'index';
......@@ -80,6 +79,8 @@ class ZendAfi_Controller_Plugin_AdminAuth extends Zend_Controller_Plugin_Abstrac
protected function userCanAccessAdminPage($user) {
xdebug_break();
$acl = new ZendAfi_Acl_AdminControllerRoles();
$resource = $this->_request->getControllerName();
$role = $user->getRole();
......
......@@ -84,4 +84,32 @@ class AdminAuthControllerNobodyLoggedTest extends Admin_AbstractControllerTestCa
}
}
class AdminAuthControllerWithRestrcitedProfilTest extends AbstractControllerTestCase {
public function setup() {
parent::setUp();
Class_Users::beVolatile();
$tom= Class_Users::newInstanceWithId(5,
['login' => 'tom',
'password'=>'tom1',
'idabon' => 789456,
'role_level' => ZendAfi_Acl_AdminControllerRoles::INVITE,
'id_site' => 1,
'fiche_sigb' => []]);
$tom->save();
Class_Profil::beVolatile();
$profil_invite = Class_Profil::newInstanceWithId(1, ['access_level' => '0' ,'cfg_menus' => '']);
$profil_invite->save();
ZendAfi_Auth::getInstance()->logUser($tom);
$this->dispatch('/admin/index');
}
/** @test */
public function withAuthenticatedGuestAdminIndexShouldRedirectToOpac() {
$this->assertRedirectTo('/opac/');
}
}
?>
\ No newline at end of file
......@@ -107,4 +107,39 @@ class IndexControllerAsAdminWithCSSEditorTest extends IndexControllerAsAdminTest
}
?>
class IndexControllerWithInvitedLevelRestrictionForProfilTest extends AbstractControllerTestCase {
public function setup() {
ZendAfi_Auth::getInstance()->clearIdentity();
Class_Profil::newInstanceWithId(1, ['access_level' => '0' ,'cfg_menus' => '']);
}
/** @test **/
public function profilWithAccessLevelShouldContainsFormAdminAuthLogin() {
$this->dispatch('/opac/index/index/id_profil/1');
$this->assertXPath('//form[@name="form"][contains(@action,"/admin/auth/login")]',$this->_response->getBody());
}
/** @test **/
public function postLoginShouldRedirectToOpac() {
ZendAfi_Auth::getInstance()->logUser(
Class_Users::newInstanceWithId(5,
['login' => 'tom',
'username' => 'tom',
'password'=>'tom1',
'idabon' => 789456,
'role_level' => ZendAfi_Acl_AdminControllerRoles::INVITE,
'id_site' => 1,
'fiche_sigb' => []]));
$this->postDispatch('/admin/auth/login',['username'=>'tom',
'password'=>'tom1']);
$this->assertXPath('//article',$this->_response->getBody());
}
}
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment