diff --git a/VERSIONS_HOTLINE/36925 b/VERSIONS_HOTLINE/36925 new file mode 100644 index 0000000000000000000000000000000000000000..51d804711ce1e10c013de2d2235bd111ff09a8ef --- /dev/null +++ b/VERSIONS_HOTLINE/36925 @@ -0,0 +1 @@ + - ticket #36925 : Correction de la création d'un compte utilisateur diff --git a/library/ZendAfi/Form/Admin/User.php b/library/ZendAfi/Form/Admin/User.php index 08a4e957a25c1be80fb4dc40c65aa6cd03f8a6be..5d87321eea16eafc70c6ebf832e6040039a3ec58 100644 --- a/library/ZendAfi/Form/Admin/User.php +++ b/library/ZendAfi/Form/Admin/User.php @@ -21,16 +21,30 @@ class ZendAfi_Form_Admin_User extends ZendAfi_Form { + protected $_user; + public static function newWith($datas = [], $custom_form = null) { - $form = parent::newWith($datas, $custom_form); + $form = (new static()); + + $user = ((isset($datas['id_user'])) && ($user = Class_Users::find($datas['id_user']))) + ? $user + : new Class_Users(); + + $form->setUser($user); + $form->addElements(); $form->addValidity($datas['date_debut'],$datas['date_fin']); - return $form; + return $form->populate($datas) + ->setCustomForm($custom_form); } - public function init() { - parent::init(); + public function setUser($user) { + $this->_user = $user; + return $this; + } + + public function addElements() { $this ->addBasicUserInfo() ->addAdminUserInfo() @@ -97,32 +111,25 @@ class ZendAfi_Form_Admin_User extends ZendAfi_Form { protected function addAdminUserInfo() { - $user = $this->getView()->user; - - $multi_options = $user->isSuperAdmin() + $multi_options = $this->_user->isSuperAdmin() ? ZendAfi_Acl_AdminControllerRoles::getRolesLabels() : ZendAfi_Acl_AdminControllerRoles::getRolesLabelsWithOutSuperAdmin(); $option=[]; - if ($user->isSuperAdmin() || $user->isAbonne() || (Class_Users::getIdentity()->getRoleLevel() <= ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL)) + if ($this->_user->isSuperAdmin() || $this->_user->isAbonne() || (Class_Users::getIdentity()->getRoleLevel() <= ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL)) $option=['disabled' => 'disabled']; $this ->addElement('select', 'role_level', array_merge(['label' => $this->_('Niveau d\'accès'), - 'multiOptions' => $multi_options],$option)); - $bib_option=[]; - if ($user->getRoleLevel() <= ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB) - $bib_option=['disabled' => 'disabled']; - - $this + 'multiOptions' => $multi_options],$option)) ->addElement('select', 'id_site', array_merge( ['label' => $this->_('Bibliothèque'), - 'multiOptions' => array_merge(['0' => $this->_('Portail')], Class_Zone::findAllLabels())], - $bib_option)) + 'multiOptions' => array_merge(['0' => $this->_('Portail')], Class_Bib::findAllLabels())], + $option)) ->addElement('userGroup', 'user_group_ids', @@ -136,9 +143,7 @@ class ZendAfi_Form_Admin_User extends ZendAfi_Form { 'user_group_ids'], 'admin_user_info', ['legend' => $this->_('Droits')]); - return $this; - } @@ -204,8 +209,7 @@ class ZendAfi_Form_Admin_User extends ZendAfi_Form { protected function addSIGB() { - $user = $this->getView()->user; - $disabled = $user->getRoleLevel() <= ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB + $disabled = $this->_user->getRoleLevel() <= ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB ? ['disabled' => 'disabled'] : []; @@ -251,12 +255,10 @@ class ZendAfi_Form_Admin_User extends ZendAfi_Form { if (!Class_AdminVar::isRedmineEnabled()) return $this; - $user = $this->getView()->user; - - if($user->getRoleLevel() <= ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB) + if($this->_user->getRoleLevel() <= ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB) return $this; - $user_library = $user->getRedmineLibrary(); + $user_library = $this->_user->getRedmineLibrary(); $value = $user_library ? $user_library->getId() : 0; $options = $this->_getLibraries(); $this @@ -278,7 +280,6 @@ class ZendAfi_Form_Admin_User extends ZendAfi_Form { $this->getElement('redmine_status') ->addDecorator('Redmine', ['view' => $this->getView(), 'library' => $user_library]); - return $this; } diff --git a/tests/application/modules/admin/controllers/UsersControllerTest.php b/tests/application/modules/admin/controllers/UsersControllerTest.php index 0e8afd2dae1cf3d116bcb7fc8b429e0381e06f77..47b38c9760c47c52f8af7ee3c5f8096e1c0fb08b 100644 --- a/tests/application/modules/admin/controllers/UsersControllerTest.php +++ b/tests/application/modules/admin/controllers/UsersControllerTest.php @@ -581,10 +581,11 @@ class UsersControllerPostValidDataWithCommOpsysTest extends UsersControllerWithM } + class UsersControllerAddViewTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/admin/users/add'); + $this->dispatch('/admin/users/add', true); } public function testActionAdd() { @@ -607,9 +608,14 @@ class UsersControllerAddViewTest extends AbstractControllerTestCase { $this->assertXPath("//input[@name='pseudo'][@value='']"); } + /** @test */ + public function idSiteSelectorShouldNotBeDisabled() { + $this->assertXPath('//form//select[@id="id_site"][not(@disabled)]'); + } } + class UsersControllerReferentIndexTest extends UsersControllerWithMarcusTestCase { use Trait_UserGroupFixtures; @@ -818,20 +824,32 @@ class Admin_UsersControllerFormEditAdminTest extends Admin_UsersControllerEditAd } /** @test */ - public function portalilShouldBePresent() { - $this->assertXPath('//fieldset//table//tr//td//select[@name="id_site"]//option[@value="0"]'); + public function portailShouldBePresent() { + $this->assertXPath('//form//select[@name="id_site"]//option[@value="0"]'); + } + + + /** @test */ + public function libACSHouldBeSelected() { + $this->assertXPathContentContains('//form//select[@name="id_site"]//option[@value="1"][@selected]', 'AC'); + } + + + /** @test */ + public function idSiteSelectorShouldNotBeDisabled() { + $this->assertXPath('//form//select[@name="id_site"][not(@disabled)]'); } /** @test */ public function roleLevelSuperShouldNotBePresent() { - $this->assertNotXPath('//fieldset//table//tr//td//select[@name="role_level"]//option[@value="7"]'); + $this->assertNotXPath('//form//select[@name="role_level"]//option[@value="7"]'); } /** @test */ public function withModoPortailRedmineLibrarySelectorShouldBePresent() { - $this->assertXPath('//fieldset//table//tr//td//select[@name="redmine_library"]', $this->_response->getBody()); + $this->assertXPath('//form//select[@name="redmine_library"]', $this->_response->getBody()); } @@ -895,7 +913,7 @@ class UsersControllerEditSuperAdminTest extends Admin_AbstractControllerTestCase /** @test */ public function roleLevelSuperShouldBePresent() { - $this->assertXPath('//fieldset//table//tr//td//select[@name="role_level"][@disabled="disabled"]//option[@value="7"]'); + $this->assertXPath('//form//select[@name="role_level"][@disabled="disabled"]//option[@value="7"]'); } } @@ -919,6 +937,6 @@ class UsersControllerEditUserAsModoPortalTest extends AbstractControllerTestCase /** @test */ public function roleLevelShouldBeDisabled() { - $this->assertXPath('//fieldset//table//tr//td//select[@name="role_level"][@disabled="disabled"]'); + $this->assertXPath('//form//select[@name="role_level"][@disabled="disabled"]'); } } \ No newline at end of file