diff --git a/VERSIONS_WIP/50572 b/VERSIONS_WIP/50572 new file mode 100644 index 0000000000000000000000000000000000000000..e25328b346bce1a57391d340e69b3a768c43f4ab --- /dev/null +++ b/VERSIONS_WIP/50572 @@ -0,0 +1 @@ + - ticket #50572 : Ajout d'un fonctionnement du portail en mode intranet \ No newline at end of file diff --git a/application/modules/admin/controllers/AuthController.php b/application/modules/admin/controllers/AuthController.php index 068fd8d94724064c0283e47fb5e5a2ba87d60575..e0544e3b09d36fdabc4b20971b30f9fa67d2a2e4 100644 --- a/application/modules/admin/controllers/AuthController.php +++ b/application/modules/admin/controllers/AuthController.php @@ -27,9 +27,7 @@ class Admin_AuthController extends Zend_Controller_Action { $viewRenderer->setLayoutScript('sansMenuGauche.phtml'); } - //---------------------------------------------------------------------------------- - // Retour à l'accueil apres authentification - //---------------------------------------------------------------------------------- + function indexAction() { $this->_redirect('admin/'); } @@ -37,10 +35,11 @@ class Admin_AuthController extends Zend_Controller_Action { function loginAction() { $this->view->message = ''; + $this->view->redirect = $this->_getParam('redirect'); + if (!$this->_request->isPost()) return; - // Champs de saisie $f = new Zend_Filter_StripTags(); $username = $f->filter($this->_request->getPost('username')); $password = $f->filter($this->_request->getPost('password')); @@ -54,10 +53,7 @@ class Admin_AuthController extends Zend_Controller_Action { if (!$auth->authenticateLoginPassword($username, $password, [$auth->newAuthDb()])) return; - $this->_redirect( - Class_Profil::getCurrentProfil()->isPublic() - ? 'admin/' - : 'opac/index/index/id_profil/'.Class_Profil::getCurrentProfil()->getId()); + $this->_redirect($this->_getParam('redirect', 'admin/')); } @@ -65,7 +61,4 @@ class Admin_AuthController extends Zend_Controller_Action { ZendAfi_Auth::getInstance()->clearIdentity(); $this->_redirect('admin/'); } - -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/application/modules/admin/views/scripts/accueil/kiosque.phtml b/application/modules/admin/views/scripts/accueil/kiosque.phtml index 17adb6640c80fc0c573ea3ec0a57db5917c1bb88..52e7f2f0a5409e44bd41de67985365bb61f0932a 100644 --- a/application/modules/admin/views/scripts/accueil/kiosque.phtml +++ b/application/modules/admin/views/scripts/accueil/kiosque.phtml @@ -1,4 +1,7 @@ - +<?php +Class_ScriptLoader::getInstance() +->addJqueryReady('formSelectToggleVisibilityForElement("#aleatoire", "#nb_analyse_option", "1")'); +?> <center> <h1><?php echo $this->_('Propriétés du Kiosque de notices');?></h1><br> <div class="formTable"> @@ -58,10 +61,6 @@ <td class="gauche"><?php echo $this->formSelect("aleatoire",$this->preferences["aleatoire"],"",array("0" => "non","1"=>"oui")) ?></td> </tr> - <script type="text/javascript"> - formSelectToggleVisibilityForElement("#aleatoire", "#nb_analyse_option", "1"); - </script> - <tr> <td class="droite">Tri du résultat </td> <td class="gauche"> diff --git a/application/modules/admin/views/scripts/auth/login.phtml b/application/modules/admin/views/scripts/auth/login.phtml index 259e5a35cc888be85187faf86f3aa16e1bc00a95..aef6ffdce73dff0c173049978b2f42a83b180ae7 100644 --- a/application/modules/admin/views/scripts/auth/login.phtml +++ b/application/modules/admin/views/scripts/auth/login.phtml @@ -1,24 +1,27 @@ <form name="form" action="<?php echo BASE_URL ?>/admin/auth/login" method="post"> -<center> - <div class="login" align="center"> - <table cellpadding="0" cellspacing="0" > - <tr class ="dark"> - <td colspan="2" align="center" height="60"> - <span id="abonne_erreur"><?php echo $this->_($this->message); ?><br /></span> -<?php echo $this->_("Entrez votre identité S.V.P.") ?></td> - </tr> - <tr class="light"> - <td width="50%" height="54" align="right"><label for="username"><?php echo $this->traduire("Identifiant") ?></label> </td> - <td width="50%" height="54" align="left" valign="middle"> <input type="text" name="username" value=""/></td> - </tr> - <tr class="light"> - <td width="50%" height="55" align="right"><label for="password"><?php echo $this->traduire("Mot de passe") ?></label> </td> - <td width="50%" height="55" align="left" valign="middle"> <input type="password" name="password" onkeypress="if (event.keyCode == 13) {javascript:PicToolbarOver( getElementById('menu_item975'), 'menu_item975');this.form.submit();return false;}" value=""/></td> - </tr> - <tr class="dark"> - <td colspan="2" width="50%" height="66" align="center"><?php echo $this->bouton('type=V'); ?></td> - </tr> - </table> - </div> -</center> + <?php if ($this->redirect) { ?> + <input type="hidden" name="redirect" value="<?php echo $this->escape($this->redirect);?>" /> + <?php } ?> + <center> + <div class="login" align="center"> + <table cellpadding="0" cellspacing="0" > + <tr class ="dark"> + <td colspan="2" align="center" height="60"> + <span id="abonne_erreur"><?php echo $this->_($this->message); ?><br /></span> + <?php echo $this->_("Entrez votre identité S.V.P.") ?></td> + </tr> + <tr class="light"> + <td width="50%" height="54" align="right"><label for="username"><?php echo $this->traduire("Identifiant") ?></label> </td> + <td width="50%" height="54" align="left" valign="middle"> <input type="text" name="username" value=""/></td> + </tr> + <tr class="light"> + <td width="50%" height="55" align="right"><label for="password"><?php echo $this->traduire("Mot de passe") ?></label> </td> + <td width="50%" height="55" align="left" valign="middle"> <input type="password" name="password" onkeypress="if (event.keyCode == 13) {javascript:PicToolbarOver( getElementById('menu_item975'), 'menu_item975');this.form.submit();return false;}" value=""/></td> + </tr> + <tr class="dark"> + <td colspan="2" width="50%" height="66" align="center"><?php echo $this->bouton('type=V'); ?></td> + </tr> + </table> + </div> + </center> </form> diff --git a/application/modules/admin/views/scripts/menus/news.phtml b/application/modules/admin/views/scripts/menus/news.phtml index fc4422ec7b378d5c0f572009c3f9b87a78962139..8388637c3bea39eab05871f31d0814eca4cd97aa 100644 --- a/application/modules/admin/views/scripts/menus/news.phtml +++ b/application/modules/admin/views/scripts/menus/news.phtml @@ -1,47 +1,44 @@ -<?php echo $this->render('menus/_debut.phtml'); ?> - -<?php - echo $this->partial("modules/_options_cms.phtml", - array('preferences' => $this->preferences, - 'id_bib' => $this->id_bib, - 'form_selector' => 'form')); +<?php +Class_ScriptLoader::getInstance() +->addJqueryReady('formSelectToggleVisibilityForElement("input.display_mode", "tr#option_summary_content", "Summary")'); + +echo $this->render('menus/_debut.phtml'); ?> + +<?php +echo $this->partial("modules/_options_cms.phtml", + ['preferences' => $this->preferences, + 'id_bib' => $this->id_bib, + 'form_selector' => 'form']); ?> <fieldset> - <legend>Mode d'affichage</legend> + <legend><?php echo $this->_('Mode d\'affichage'); ?></legend> <table> <tr> - <td class="droite">Clic sur le menu ouvre</td> + <td class="droite"><?php echo $this->_('Clic sur le menu ouvre'); ?></td> <td class="gauche"> - <?php - echo $this->formRadioButtons("display_mode", - $this->preferences["display_mode"], - array( - "Submenu" => "Sous-menu", - "Summary" => "Sommaire")); - ?> + <?php + echo $this->formRadioButtons("display_mode", + $this->preferences["display_mode"], + ['Submenu' => $this->_('sous-menu'), + 'Summary' => $this->_('sommaire')]); + ?> </td> </tr> <tr id="option_summary_content"> - <td class="droite">Contenu du sommaire</td> + <td class="droite"><?php echo $this->_('Contenu du sommaire'); ?></td> <td class="gauche"> <?php - echo $this->formRadioButtons("summary_content", - $this->preferences["summary_content"], - array( - "Summary" => "Résumés", - "TitlesOnly" => "Titres seulement", - "FullContent" => "Articles complets")); + echo $this->formRadioButtons("summary_content", + $this->preferences["summary_content"], + ['Summary' => $this->_('Résumés'), + 'TitlesOnly' => $this->_('Titres seulement'), + 'FullContent' => $this->_('Articles complets')]); ?> </td> </tr> </table> - <script type="text/javascript"> - formSelectToggleVisibilityForElement("input.display_mode", - "tr#option_summary_content", - "Summary"); - </script> </fieldset> - + <?php echo $this->render('menus/_fin.phtml'); ?> diff --git a/application/modules/admin/views/scripts/modules/_options_cms.phtml b/application/modules/admin/views/scripts/modules/_options_cms.phtml index dd91598e3a993538fe7afe15fc578ae0f9593ef1..90416bc6ac644d6bc46ca8ef4840ecd93c51e485 100644 --- a/application/modules/admin/views/scripts/modules/_options_cms.phtml +++ b/application/modules/admin/views/scripts/modules/_options_cms.phtml @@ -1,5 +1,17 @@ +<?php +Class_ScriptLoader::getInstance() +->addJqueryReady(' +formSelectToggleVisibilityForElement("input.display_order", "#nb_analyse_option", "Random"); +formSelectToggleVisibilityForElement("input.display_order", + "#options_nb_articles", + ["DateCreationDesc", + "DebutPublicationDesc", + "EventDebut", + "Random", + "CommentCount"]);'); +?> <fieldset> - <legend>Articles à afficher</legend> + <legend><?php echo $this->_('Articles à afficher'); ?></legend> <div id="table_selection"> <?php echo $this->treeSelect( @@ -16,40 +28,34 @@ <table> <tr> - <td class="droite">Ordre d'affichage </td> + <td class="droite"><?php echo $this->_('Ordre d\'affichage');?></td> <td class="gauche"> <?php - echo $this->formRadioButtons("display_order", - $this->preferences["display_order"], - ["Selection" => "Par ordre de sélection", - "DateCreationDesc" => "Par date de création (plus récent en premier)", - "DebutPublicationDesc" => "Par date de début de publication (plus récent en premier)", - "EventDebut" => "Par date de début d'événement (plus ancien en premier)", - "CommentCount" => "Par nombre d'avis", - "Random" => "Par ordre aléatoire"]); + echo $this->formRadioButtons('display_order', + $this->preferences['display_order'], + ['Selection' => $this->_('Par ordre de sélection'), + 'DateCreationDesc' => $this->_('Par date de création (plus récent en premier)'), + 'DebutPublicationDesc' => $this->_('Par date de début de publication (plus récent en premier)'), + 'EventDebut' => $this->_('Par date de début d\'événement (plus ancien en premier)'), + 'CommentCount' => $this->_('Par nombre d\'avis'), + 'Random' => $this->_('Par ordre aléatoire')]); ?> </td> </tr> - <script type="text/javascript"> - formSelectToggleVisibilityForElement("input.display_order", "#nb_analyse_option", "Random"); - formSelectToggleVisibilityForElement("input.display_order", - "#options_nb_articles", - ["DateCreationDesc", "DebutPublicationDesc", "EventDebut", "Random", "CommentCount"]); - </script> <tr id="options_nb_articles"> - <td class="droite">Afficher </td> + <td class="droite"><?php echo $this->_('Afficher'); ?></td> <td class="gauche"> <span id="nb_articles_aff"> <input type="text" name="nb_aff" size="2" maxlength="2" value="<?php print($this->preferences["nb_aff"]); ?>"> - articles + <?php echo $this->_('articles'); ?> </span> <span id="nb_analyse_option" style="display:none"> - parmi les + <?php echo $this->_('parmi les'); ?> <input type="text" name="nb_analyse" size="2" maxlength="3" value="<?php print($this->preferences["nb_analyse"]); ?>"> - plus récents + <?php echo $this->_('plus récents'); ?> </span> </td> </tr> diff --git a/application/modules/admin/views/scripts/profil/_formProfil.phtml b/application/modules/admin/views/scripts/profil/_formProfil.phtml index 63adde91425bbd55b221d9ffe7a2e5815860a720..689db59e8ddba5abb37ae820fd8dbf5c4536c5f5 100644 --- a/application/modules/admin/views/scripts/profil/_formProfil.phtml +++ b/application/modules/admin/views/scripts/profil/_formProfil.phtml @@ -1,30 +1,16 @@ <?php Class_ScriptLoader::getInstance() -->addStylesheet(URL_ADMIN_JS.'color_picker/jquery.vreboton.ColorPicker') -->addAdminScript('color_picker/jquery.vreboton.ColorPicker') -->addInlineStyle('div.ColorPickerDivSample {margin-top:4px; margin-right:0px}') -->addJQueryReady('$(".colorpicker").attachColorPicker()') -->addAdminScript('tag_selection') -->addInlineScript(" function changeBrowser(sBrowser){ - if (sBrowser=='telephone') { - $('.only_browser').hide(); - } else { - $('.only_browser').show(); - } - } - - $(function() { - changeBrowser($('select#browser').val()); - });") -->addJqueryReady("$('#barre_nav_on').change(function(){ - $('.display_current_profil_on_breadcrumb').toggle(this.checked); -}); - -$('.display_current_profil_on_breadcrumb').toggle($('#barre_nav_on').is(':checked')); -"); +->loadColorPicker() +->addJqueryReady(' +$(".colorpicker").attachColorPicker(); +formSelectToggleVisibilityForElement("#browser", ".only_browser", "opac"); +checkBoxToggleVisibilityForElement("#barre_nav_on", $("#display_current_profil_on_breadcrumb").closest("tr"), true); +toggleVisibilityForElement("#access_level", $("#login_page").closest("tr"), function(element) { return element.val() != "-1"; }); +checkBoxToggleVisibilityForElement("#header_img_cycle", "input[name=header_img]", false); +'); echo $this->partial('profil/_profil_panel.phtml', - array('profil' => $this->profil)); ?> + ['profil' => $this->profil]); ?> <div class="form" align="center" > <form name="form" action="<?php print(BASE_URL.'/admin/profil/'.$this->action.'/id_profil/'.$this->profil->getId()) ?>" method="post"> @@ -63,6 +49,20 @@ echo $this->partial('profil/_profil_panel.phtml', $this->profil->getAllAccessLevels()); ?></td> </tr> + <tr> + <td align="right" style="width:20%"><?php echo $this->_("Page d'authentification"); ?></td> + <td class="gauche"> + <?php + + echo $this->getHelper('ComboProfils') + ->setTagId('login_page') + ->setTagName('login_page') + ->addEmptyOption() + ->comboProfils('ALL', 'ALL', $this->profil->getLoginPage()) + ; + ?> + </tr> + <tr> <td class="droite"><?php echo $this->traduire('E-mail du Webmestre'); ?></td> <td class="gauche"><input type="text" style="width:100%" name="mail_site" value="<?php echo $this->escape(trim($this->profil->getMailSite()));?>" maxlength="150"/></td> @@ -103,11 +103,6 @@ echo $this->partial('profil/_profil_panel.phtml', </td> </tr> - - <script type="text/javascript"> - checkBoxToggleVisibilityForElement("#header_img_cycle", "input[name=header_img]", false); - </script> - <tr> <td align="right"><?php echo $this->traduire('Icône du navigateur'); ?></td> <td class="gauche" style="padding-left:5px"> @@ -151,21 +146,21 @@ echo $this->partial('profil/_profil_panel.phtml', <tr class="only_browser"> <td align="right"><?php echo $this->traduire('Hauteur'); ?></td> <td class="gauche" style="padding-left:5px"> - <input type="text" class="normal" name="hauteur_banniere" size="3" maxlength="3" value="<?php echo $this->profil->getHauteurBanniere()?>">pixels + <input type="text" class="normal" id="hauteur_banniere" name="hauteur_banniere" size="3" maxlength="3" value="<?php echo $this->profil->getHauteurBanniere()?>">pixels </td> </tr> <tr class="only_browser"> <td align="right"><?php echo $this->traduire('Couleur du texte'); ?></td> <td class="gauche"> - <input type="text" class="colorpicker" name="couleur_texte_bandeau" size="7" maxlength="7" value="<?php echo $this->profil->getCouleurTexteBandeau()?>"> + <input type="text" class="colorpicker" id="couleur_texte_bandeau" name="couleur_texte_bandeau" size="7" maxlength="7" value="<?php echo $this->profil->getCouleurTexteBandeau()?>"> </td> </tr> <tr class="only_browser"> <td align="right"><?php echo $this->traduire('Couleur des liens'); ?></td> <td class="gauche"> - <input type="text" class="colorpicker" name="couleur_lien_bandeau" size="7" maxlength="7" value="<?php echo $this->profil->getCouleurLienBandeau()?>"> + <input type="text" class="colorpicker" id="couleur_lien_bandeau" name="couleur_lien_bandeau" size="7" maxlength="7" value="<?php echo $this->profil->getCouleurLienBandeau()?>"> </td> </tr> @@ -265,7 +260,7 @@ echo $this->partial('profil/_profil_panel.phtml', <tr class="only_browser"> <td align="right"><?php echo $this->traduire('Nombre de divisons'); ?></td> <td class="gauche" style="padding-left:5px"> - <select name="nb_divisions"> + <select id="nb_divisions" name="nb_divisions"> <option value="1" <?php if($this->profil->getNbDivisions() == 1) echo 'selected="selected"';?>>1 Division</option> <option value="2" <?php if($this->profil->getNbDivisions() == 2) echo 'selected="selected"';?>>2 Divisions</option> <option value="3" <?php if($this->profil->getNbDivisions() == 3) echo 'selected="selected"';?>>3 Divisions</option> @@ -371,7 +366,7 @@ pixels </td> </tr> - <tr class="only_browser display_current_profil_on_breadcrumb"> + <tr class="only_browser"> <td class="droite"><?php echo $this->traduire('Afficher le profil courant dans la barre de navigation'); ?></td> <td class="gauche"> <?php diff --git a/application/modules/opac/controllers/AuthController.php b/application/modules/opac/controllers/AuthController.php index b6de93830137da704dc53442b93ec6004cf10aca..8bb4bcb411d9032039384e37469f5da12f3d0204 100644 --- a/application/modules/opac/controllers/AuthController.php +++ b/application/modules/opac/controllers/AuthController.php @@ -102,12 +102,12 @@ class AuthController extends ZendAfi_Controller_Action { $this->view->titreAdd($this->view->_('Connexion')); - $this->view->title = Class_Users::getLoader()->getIdentity() + $this->view->title = Class_Users::getIdentity() ? $this->view->preferences['titre_connecte'] : $this->view->preferences['titre']; $strategy = Auth_Strategy_Abstract::strategyForController($this); - $strategy->setDefaultUrl($this->_getParam('redirect','/opac')); + $strategy->setDefaultUrl($redirect); $strategy->onLoginSuccess(function($user) { $user->registerNotificationsOn($this->getHelper('notify')->bePopup()); }); diff --git a/library/Class/Profil.php b/library/Class/Profil.php index 5eaa09b0fc145a06182f14b023c4f735d83a6525..7d55fba7be9f0ff83f2c6cebf9c6cec02cad06e9 100644 --- a/library/Class/Profil.php +++ b/library/Class/Profil.php @@ -77,15 +77,42 @@ class ProfilLoader extends Storm_Model_Loader { return Class_Profil::findAllBy(['parent_id' => null, 'order' => 'libelle']); } + public function getRoot() { return isset($this->_root) ? $this->_root : ($this->_root = new Class_profil()); } + public function isAPhoneProfilEnabled() { return Class_profil::countBy(['browser' => 'telephone']) >= 1; } + + + public function findFirstPhone() { + return Class_Profil::findFirstBy(['browser' => 'telephone']); + } + + + public function findInControllerActionOf($request) { + if (!$profil = Class_Profil::findFirstBy(['rewrite_url' => $request->getControllerName()])) + return null; + + return ($child = Class_Profil::findFirstBy(['rewrite_url' => $request->getActionName(), + 'parent_id' => $profil->getId()])) + ? $child + : $profil; + } + + + public function findInSubDomainOf($request) { + $parts = explode('.', $request->getServer('SERVER_NAME', '')); + return (count($parts) > 2 + && ($profil = Class_Profil::findFirstBy(['rewrite_url' => $parts[0]]))) + ? $profil + : null; + } } @@ -209,6 +236,7 @@ class Class_Profil extends Storm_Model_Abstract { 'couleur_lien_bandeau', 'couleur_texte_bandeau', 'access_level', + 'login_page', 'favicon', 'logo_gauche_img', 'logo_gauche_link', @@ -347,6 +375,7 @@ class Class_Profil extends Storm_Model_Abstract { 'couleur_lien_bandeau' => '', 'couleur_texte_bandeau' => '', 'access_level' => -1, + 'login_page' => 1, 'parent_id' => null, 'favicon' => '', 'logo_gauche_img' => '', @@ -2237,5 +2266,18 @@ class Class_Profil extends Storm_Model_Abstract { return $class::getLoader()->findAllBy(['order' => 'libelle']); } + + + public function getAlienLoginPage() { + return ($login_page = $this->getLoginPage()) + && !$this->isMyselfMyOwnLoginPage() + && ($login_profil = Class_Profil::getLoader()->find($login_page)) + ? $login_profil + : null; + } + + + public function isMyselfMyOwnLoginPage() { + return $this->getLoginPage() == $this->getId(); + } } -?> diff --git a/library/Class/ScriptLoader.php b/library/Class/ScriptLoader.php index d3ca72ec45e7681638f9f29a35084b77f82c4ba9..3c13f6e7c4ed772619ce471819d425933dc549d0 100644 --- a/library/Class/ScriptLoader.php +++ b/library/Class/ScriptLoader.php @@ -134,6 +134,12 @@ class Class_ScriptLoader { } + public function loadColorPicker() { + return $this->addAdminScript('color_picker/jquery.vreboton.ColorPicker') + ->addStylesheet(URL_ADMIN_JS.'color_picker/jquery.vreboton.ColorPicker'); + } + + /** * @return ScriptLoader */ @@ -833,6 +839,4 @@ class Class_ScriptLoader { $label, '.menuGaucheAdmin tr, .titre, img, table, tbody, td'); } -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/library/Class/Url.php b/library/Class/Url.php index 17c287e3c1901713912fd5461cad1ce68773419c..467b4aee57e16e5eb0413d017ec3951e9464be9b 100644 --- a/library/Class/Url.php +++ b/library/Class/Url.php @@ -20,8 +20,10 @@ */ class Class_Url { - protected static $_do_not_add_base_url, - $_forbiden_urls; + protected static + $_do_not_add_base_url, + $_forbiden_urls, + $_base_url; public static function getForbidenUrls() { @@ -49,6 +51,9 @@ class Class_Url { public static function baseUrl() { + if (static::$_base_url) + return static::$_base_url; + $parts = array_diff(array_filter(explode('/', $_SERVER['SCRIPT_NAME'])), ['index.php']); return 0 < count($parts) @@ -57,6 +62,12 @@ class Class_Url { } + /** @category testing */ + public static function setBaseUrl($base_url) { + static::$_base_url = $base_url; + } + + public static function rootUrl() { return static::getProtocol() . static::getName() . static::getPort(); } diff --git a/library/ZendAfi/Controller/Dispatcher/Standard.php b/library/ZendAfi/Controller/Dispatcher/Standard.php index cad22339516ce55d10665440559096adfb2a237c..f02ea5f60413d33e4172e41fc78ecbecd557650e 100644 --- a/library/ZendAfi/Controller/Dispatcher/Standard.php +++ b/library/ZendAfi/Controller/Dispatcher/Standard.php @@ -26,13 +26,11 @@ class ZendAfi_Controller_Dispatcher_Standard extends Zend_Controller_Dispatcher_ catch (Zend_Controller_Dispatcher_Exception $e) { $controller_name = $request->getControllerName(); - if ($library = Class_Bib::findFirstBy(['rewrite_url' => $controller_name])) { + if ($library = Class_Bib::findFirstBy(['rewrite_url' => $controller_name])) return $this->_dispatchToLibrary($library, $request, $response); - } - if ($profil = Class_Profil::findFirstBy(['rewrite_url' => $controller_name])) { + if ($profil = Class_Profil::findInControllerActionOf($request)) return $this->_dispatchToProfil($profil, $request, $response); - } throw $e; } @@ -41,11 +39,6 @@ class ZendAfi_Controller_Dispatcher_Standard extends Zend_Controller_Dispatcher_ protected function _dispatchToProfil($profil, $request, $response) { $profil->beCurrentProfil(); - $page_rewrite_url = $request->getActionName(); - if ($page = Class_Profil::findFirstBy(['rewrite_url' => $page_rewrite_url, - 'parent_id' => $profil->getId()])) - $page->beCurrentProfil(); - $request->setControllerName('index'); $request->setActionName('index'); return parent::dispatch($request, $response); diff --git a/library/ZendAfi/Controller/Plugin/DefineURLs.php b/library/ZendAfi/Controller/Plugin/DefineURLs.php index cb4756a7868929c5ff8593c4b2dfbafa7b826543..f2ec5aa8b27a14182b5527138a8d71e28bfd27d7 100644 --- a/library/ZendAfi/Controller/Plugin/DefineURLs.php +++ b/library/ZendAfi/Controller/Plugin/DefineURLs.php @@ -18,130 +18,132 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -////////////////////////////////////////////////////////////////////////////////////////// -// OPAC3 : Activation du profil et du skin -////////////////////////////////////////////////////////////////////////////////////////// class ZendAfi_Controller_Plugin_DefineURLs extends Zend_Controller_Plugin_Abstract { - protected $_session; - function preDispatch(Zend_Controller_Request_Abstract $request) { - $this->_session = Zend_Registry::get('session'); + const + PHONE = 'telephone', + ADMIN = 'admin', + OPAC = 'opac'; + + public function preDispatch(Zend_Controller_Request_Abstract $request) { + $this->setRequest($request); $this->memorizeLastProfil(); - $profil = $this->selectProfilFromRequest($request); - $module = $this->getModuleNameForProfilAndRequest($profil, $request); - $profil->setSkin($request->getParam('skin',$profil->getSkin())); - $this->setUpSkin($module, $profil); + $this->updateRequest(); + $this->setUpSkin(); + $this->setUpBibZoneFilters(); + } - if ($module=="admin") - $this->setUpBibZoneFilters($request); + protected function memorizeLastProfil() { + $session = Zend_Registry::get('session'); + $session->previous_id_profil = isset($session->id_profil) + ? $session->id_profil + : 1; + + return $this; } - public function shouldSelectTelephone($request) { - return - ($request->getModuleName()=='telephone') - || ((new Class_UserAgent())->isMobile() and ('admin' !== $request->getModuleName())); - } + protected function updateRequest() { + $request = $this->getRequest(); + $detector = new ZendAfi_Controller_Plugin_DefineURLs_ProfileDetector(); + Class_Profil::setCurrentProfil($detector->detectFrom($request)); + $profil = Class_Profil::getCurrentProfil(); + if (static::ADMIN == $request->getModuleName()) + return $this->adminRequest(); - public function findProfilTelephoneId() { - if (!$profil = Class_Profil::getLoader()->findFirstBy(array('BROWSER' => 'telephone'))) - return 0; - return $profil->getId(); - } + if(!in_array($request->getModuleName(), [static::OPAC, static::PHONE])) + return; + $request->setModuleName($profil->getBrowser()); - protected function selectProfilFromSubDomain($request) { - if (sizeof($parts = explode('.',$_SERVER['SERVER_NAME'])) >2 - && $profil = Class_Profil::findFirstBy(['rewrite_url' => $parts[0]])) - return $profil->getId(); - return Class_Profil::DEFAULT_PROFIL;; + return $this->_userCanAccessProfil($profil) + ? null + : $this->authRequest($detector); } - protected function selectProfilFromRequest($request) { - $id_profil = $this->getIdProfilFromRequest($request); + protected function authRequest($detector) { + $profil = Class_Profil::getCurrentProfil(); - if ($id_profil <= 0 && ($this->_session->id_profil) && ($request->getModuleName() !== 'telephone')) - $id_profil = intval($this->_session->id_profil); + $redirect = $detector->isDetectedByName() + ? $profil->getUrl() + : Class_Url::absolute(['id_profil' => $profil->getId()]); - if ($id_profil <= 0 && $this->shouldSelectTelephone($request)) - $id_profil = $this->findProfilTelephoneId(); + return ($login_profil = $profil->getAlienLoginPage()) + ? $this->redirectToLoginProfil($login_profil, $redirect) + : $this->requestAuthLogin($profil, $redirect); + } - if ($id_profil <= 0) - $id_profil = $this->selectProfilFromSubDomain($request); + protected function redirectToLoginProfil($profil, $redirect) { + $this->getResponse() + ->setRedirect(Class_Url::absolute(['module' => static::OPAC, + 'controller' => 'auth', + 'action' => 'login', + 'id_profil' => $profil->getId()], + null, true) + . '?redirect=' . urlencode($redirect)); + } - if (!$profil = Class_Profil::find($id_profil)) - $profil = Class_Profil::findFirstBy(['order' => 'id_profil']); - $this->_session->id_profil = $profil->getId(); + protected function requestAuthLogin($profil, $redirect) { + $this->getRequest() + ->setControllerName('auth') + ->setActionName('login') + ->setParam('redirect', $this->getRequest()->getParam('redirect', $redirect)); - return Class_Profil::setCurrentProfil($profil); + return $profil->isMyselfMyOwnLoginPage() + ? null + : $this->getRequest()->setModuleName(static::ADMIN); } - protected function getIdProfilFromRequest($request) { - if($request->getModuleName() === 'admin') - return 0; - - if ($profil = Class_Profil::findFirstBy(['rewrite_url' => $request->getControllerName()])) - return $profil->getId(); + protected function adminRequest() { + $profil = Class_Profil::getCurrentProfil(); + if ($this->_userCanAccessProfil($profil)) + return; - return (int)$request->getParam('id_profil',0); + $this->getRequest() + ->setControllerName('auth') + ->setActionName('login') + ->setModuleName(static::ADMIN); } - protected function memorizeLastProfil() { - $this->_session->previous_id_profil = isset($this->_session->id_profil) ? $this->_session->id_profil : 1; - return $this; - } - + protected function _userCanAccessProfil($profil) { + $auth = ZendAfi_Auth::getInstance(); - protected function getModuleNameForProfilAndRequest($profil, $request) { - $module = $requested_module = $request->getModuleName(); - if (('telephone' == $profil->getBrowser()) && ($requested_module != 'admin')) - $module = 'telephone'; - - if ($requested_module == 'telephone' && $profil->getBrowser() == 'opac') - $module = 'opac'; - - /** - * Si l'ouverture du profil nécessite un niveau d'accès et que - * le niveau requis est trop faible, on redirige sur la page de login - */ - if (!$profil->isPublic()) { - $auth = ZendAfi_Auth::getInstance(); - if (!$auth->hasIdentity() or $auth->getIdentity()->ROLE_LEVEL < $profil->getAccessLevel()) { - if ($module != 'admin' && !$auth->hasIdentity()) { - $redirect = '?redirect=' . urlencode('/index/index/id_profil/' . $profil->getId()); - return $this->getResponse()->setRedirect(BASE_URL . '/auth/login/id_profil/1' . $redirect); - } - - $request->setControllerName('auth'); - $request->setActionName('login'); - } - } - - $request->setModuleName($module); - return $module; + return $profil->isPublic() + || ($auth->hasIdentity() + && $auth->getIdentity()->ROLE_LEVEL >= $profil->getAccessLevel()); } - protected function setUpSkin($module, $profil) { + protected function setUpSkin() { + $request = $this->getRequest(); + $profil = Class_Profil::getCurrentProfil(); + $profil->setSkin($request->getParam('skin', $profil->getSkin())); + $skindir = $profil->getPathTheme(); $url_skin = BASE_URL . $skindir; - $this->_defineConstants($profil->getBrowser(), $skindir, $url_skin); + defineConstant("PATH_SKIN", '.'.$skindir); + defineConstant("URL_IMG", $url_skin . "images/"); + defineConstant("URL_CSS", $url_skin . "css/"); } - protected function setUpBibZoneFilters($request) { - if (!array_key_exists('admin', $_SESSION)) - $_SESSION['admin'] = ['filtre_localisation' => ['id_zone' => 'ALL', + protected function setUpBibZoneFilters() { + $request = $this->getRequest(); + if (static::ADMIN != $request->getModuleName()) + return; + + if (!array_key_exists(static::ADMIN, $_SESSION)) + $_SESSION[static::ADMIN] = ['filtre_localisation' => ['id_zone' => 'ALL', 'id_bib' => 'ALL']]; $session=$_SESSION["admin"]["filtre_localisation"]; @@ -179,22 +181,53 @@ class ZendAfi_Controller_Plugin_DefineURLs extends Zend_Controller_Plugin_Abstra $session["id_bib"]=$id_bib; $_SESSION["admin"]["filtre_localisation"]=$session; } +} + + + +class ZendAfi_Controller_Plugin_DefineURLs_ProfileDetector { + protected $_by_name; + + public function detectFrom($request) { + $session = Zend_Registry::get('session'); + $this->_by_name = false; + + if ($request->getModuleName() !== ZendAfi_Controller_Plugin_DefineURLs::ADMIN + && ($profil = Class_Profil::find((int)$request->getParam('id_profil', 0)))) + return $profil; + if ($request->getModuleName() !== ZendAfi_Controller_Plugin_DefineURLs::ADMIN + && ($profil = Class_Profil::findInControllerActionOf($request))) { + $this->_by_name = true; + return $profil; + } + + if ($request->getModuleName() !== ZendAfi_Controller_Plugin_DefineURLs::PHONE + && ($profil = Class_Profil::find((int)$session->id_profil))) + return $profil; + + if ($this->shouldSelectTelephone($request) + && ($profil = Class_Profil::findFirstPhone())) + return $profil; + + if ($profil = Class_Profil::findInSubDomainOf($request)) + return $profil; - protected function _defineConstants($module, $skindir, $url_skin) { - if ($module !== 'admin' && $module !== 'telephone') - $module = 'opac'; - $this - ->_defineConstant("PATH_SKIN", '.'.$skindir) - ->_defineConstant("URL_IMG", $url_skin . "images/") - ->_defineConstant("URL_CSS", $url_skin . "css/"); + return ($profil = Class_Profil::find(Class_Profil::DEFAULT_PROFIL)) + ? $profil + : Class_Profil::findFirstBy(['order' => 'id_profil']); } - protected function _defineConstant($name, $value) { - if (!defined($name)) - define($name, $value); - return $this; + protected function shouldSelectTelephone($request) { + return + ($request->getModuleName() == ZendAfi_Controller_Plugin_DefineURLs::PHONE) + || ((new Class_UserAgent())->isMobile() + and (ZendAfi_Controller_Plugin_DefineURLs::ADMIN !== $request->getModuleName())); } + + public function isDetectedByName() { + return $this->_by_name; + } } \ No newline at end of file diff --git a/library/ZendAfi/Form/Admin/CustomFields.php b/library/ZendAfi/Form/Admin/CustomFields.php index bc0cdcbfc716052bceeda77bf179f1d8e536228c..7f7fbc6ed13c7cc352b177db0c3adac49f66f8ad 100644 --- a/library/ZendAfi/Form/Admin/CustomFields.php +++ b/library/ZendAfi/Form/Admin/CustomFields.php @@ -63,8 +63,6 @@ class ZendAfi_Form_Admin_CustomFields extends ZendAfi_Form { } - - protected function _toggleOptionsList() { Class_ScriptLoader::getInstance() ->addJQueryBackEnd('formSelectToggleVisibilityForElement("#field_type", "#fieldset-options", ["' . Class_CustomField_Meta::SELECT . '","' . Class_CustomField_Meta::MULTI_CHECKBOX . '"]);'); diff --git a/library/ZendAfi/Form/Admin/UserGroup.php b/library/ZendAfi/Form/Admin/UserGroup.php index 3066988df80a63fd35ce3f2ebbd6722b3490db5c..2386e8330b0572db2c99ba620fdcdc4ebb3f50e6 100644 --- a/library/ZendAfi/Form/Admin/UserGroup.php +++ b/library/ZendAfi/Form/Admin/UserGroup.php @@ -108,13 +108,13 @@ class ZendAfi_Form_Admin_UserGroup extends ZendAfi_Form { public function displayGroupFiltreVisibleOnlyOnDynamicGroup() { Class_ScriptLoader::getInstance() - ->addInlineScript('formSelectToggleVisibilityForElement("input[name=\'group_type\']", "#fieldset-dynamic_filter", ["1"]);'); + ->addJqueryReady('formSelectToggleVisibilityForElement("input[name=\'group_type\']", "#fieldset-dynamic_filter", ["1"]);'); } public function displayRightsGroupVisibleOnlyOnDynamicAndManuelGroup() { Class_ScriptLoader::getInstance() - ->addInlineScript('formSelectToggleVisibilityForElement("input[name=\'group_type\']", "#fieldset-rights_group", ["0","1"]);'); + ->addJqueryReady('formSelectToggleVisibilityForElement("input[name=\'group_type\']", "#fieldset-rights_group", ["0","1"]);'); } diff --git a/public/admin/css/global.css b/public/admin/css/global.css index e76adeb448faf14c91c0a3a8e6ab8ca85c8ba350..7adf89df71f270d591377fa0d4b20f3b91fbb549 100644 --- a/public/admin/css/global.css +++ b/public/admin/css/global.css @@ -1485,4 +1485,9 @@ a[class^="edit_"] { .header_actions .selected { border-bottom: 3px solid; +} + +div.ColorPickerDivSample { + margin-top: 4px; + margin-right: 0px; } \ No newline at end of file diff --git a/public/admin/js/global.js b/public/admin/js/global.js index db34cb37197731ad64268f8cd2757fec5f9d09ed..d40e4aba022ecdda7a7aa7c7a2811b41d2bcfd54 100644 --- a/public/admin/js/global.js +++ b/public/admin/js/global.js @@ -192,22 +192,20 @@ function checkBoxToggleVisibilityForElement(eventSourceSelector, objectToShowSel function toggleVisibilityForElement(eventSourceSelector, objectToShowSelector, testingAlgorithm) { - $("document").ready(function(){ - var objectToShow = $(objectToShowSelector); - - var toggleVisibility = function(element) { - if (element.length == 0) return; - if (testingAlgorithm(element)) - objectToShow.fadeIn(); - else - objectToShow.fadeOut(); - } + var objectToShow = $(objectToShowSelector); + + var toggleVisibility = function(element) { + if (element.length == 0) return; + if (testingAlgorithm(element)) + objectToShow.fadeIn(); + else + objectToShow.fadeOut(); + } - toggleVisibility($(eventSourceSelector)); - toggleVisibility($(eventSourceSelector+':checked')); - $(eventSourceSelector).change(function(event){ - toggleVisibility($(event.target)); - }); + toggleVisibility($(eventSourceSelector)); + toggleVisibility($(eventSourceSelector+':checked')); + $(eventSourceSelector).change(function(event){ + toggleVisibility($(event.target)); }); } diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php index 5f7537b0f5a1c17d22c91e93346d4a703ec626a9..4d1a542495757d136049883180df8c8022d5a97a 100644 --- a/tests/application/modules/AbstractControllerTestCase.php +++ b/tests/application/modules/AbstractControllerTestCase.php @@ -159,6 +159,7 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe Storm_Cache::setDefaultZendCache(null); Class_WebService_AllServices::setHttpClient(null); Class_SessionFormationInscription::beVolatile(); + Class_Url::setBaseUrl(BASE_URL); } @@ -175,6 +176,7 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe Class_WebService_AllServices::setHttpClient(null); Class_I18n::reset(); ZendAfi_Form_Element_Captcha::reset(); + Class_Url::setBaseUrl(null); } diff --git a/tests/application/modules/admin/controllers/AdminAuthControllerTest.php b/tests/application/modules/admin/controllers/AdminAuthControllerTest.php index 114c764b74eb2b0d9502f0f49a011b9fc1f57142..f582cbfc609e2105f36ada5f886f68e8e21b6acb 100644 --- a/tests/application/modules/admin/controllers/AdminAuthControllerTest.php +++ b/tests/application/modules/admin/controllers/AdminAuthControllerTest.php @@ -58,6 +58,21 @@ class AdminAuthControllerNobodyLoggedTest extends Admin_AbstractControllerTestCa } + /** @test */ + public function withAuthenticationSuccessfullAndRedirectShouldRedirectToIt() { + $this->_auth->whenCalled('authenticateLoginPassword') + ->with('foo', 'bar', [$this->_auth_db_adapter]) + ->answers(true); + + $this->postDispatch('/admin/auth/login', + ['username' => 'foo', + 'password' => 'bar', + 'redirect' => 'http://www.fsf.org']); + + $this->assertRedirectTo('http://www.fsf.org'); + } + + /** @test */ public function withAuthenticationFailureShouldNotRedirectToAdmin() { $this->postDispatch('/admin/auth/login', @@ -85,54 +100,43 @@ class AdminAuthControllerNobodyLoggedTest extends Admin_AbstractControllerTestCa class AdminAuthControllerWithRestrictedProfilTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + public function setup() { parent::setUp(); ZendAfi_Auth::getInstance()->clearIdentity(); - $this->fixture('Class_Profil', ['id' => 1, - 'access_level' => ZendAfi_Acl_AdminControllerRoles::INVITE, - 'cfg_menus' => '']); - - $this->fixture('Class_Profil', ['id' => 2, - 'access_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB, - 'cfg_menus' => '']); + $this->fixture('Class_Profil', + ['id' => 1, + 'access_level' => ZendAfi_Acl_AdminControllerRoles::INVITE, + 'login_page' => null, + 'cfg_menus' => '']); + + $this->fixture('Class_Profil', + ['id' => 2, + 'access_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB, + 'login_page' => null, + 'cfg_menus' => '']); } + /** @test */ public function guestAccessingAdminShouldBeRedirectedToOpac() { ZendAfi_Auth::getInstance()->logUser( - $this->fixture('Class_Users', ['id' => 5, - 'login' => 'tom', - 'password'=>'tom1', - 'idabon' => 789456, - 'role_level' => ZendAfi_Acl_AdminControllerRoles::INVITE, - 'id_site' => 1, - 'fiche_sigb' => []])); - - $this->dispatch('/admin/index/index/id_profil/2', true); + $this->fixture('Class_Users', + ['id' => 5, + 'login' => 'tom', + 'password'=>'tom1', + 'idabon' => 789456, + 'role_level' => ZendAfi_Acl_AdminControllerRoles::INVITE, + 'id_site' => 1, + 'fiche_sigb' => []])); + + $this->dispatch('/admin', true); $this->assertRedirectTo('/opac/index/index/id_profil/1'); } - - - /** @test */ - public function onSuccessfulLoginResponseShouldRedirectToRestrictedProfil() { - ZendAfi_Auth::setInstance( - Storm_Test_ObjectWrapper::mock() - ->whenCalled('authenticateLoginPassword')->answers(true) - ->whenCalled('hasIdentity')->answers(false) - ->whenCalled('getIdentity')->answers(null) - ->whenCalled('newAuthDb')->answers(Storm_Test_ObjectWrapper::mock())); - - $this->postDispatch('/admin/auth/login/id_profil/2', - ['username' => 'foo', 'password' => 'bar']); - - $this->assertRedirectTo('/opac/index/index/id_profil/2', - $this->getResponseLocation()); - } - - public function tearDown() { ZendAfi_Auth::setInstance(null); parent::tearDown(); diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index aef11553e5c6fb7fb83f060ae1dedfc9294d75b5..9829dca8e57d7da7547f7d7fb788dd9d20a04cd3 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -894,8 +894,6 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPer public function setUp() { parent::setUp(); - $_SERVER['SCRIPT_NAME'] = '/tom'; - $filesystem = new Storm_FileSystem_Volatile(); $thumbnail_paths = PATH_TEMP .'vignettes_titre/'; $filesystem @@ -904,7 +902,7 @@ class CmsControllerArticleConcertEditActionPostTest extends CmsControllerWithPer Class_Article::setFileWriter($this->mock() ->whenCalled('fileExists') - ->with('/tom/images/bonlieu.jpg') + ->with(BASE_URL.'/images/bonlieu.jpg') ->answers(false) ->whenCalled('fileExists') diff --git a/tests/application/modules/admin/controllers/ProfilControllerTest.php b/tests/application/modules/admin/controllers/ProfilControllerTest.php index d75a9a78a5c1d234673cb6c4f28235c1237d6e93..e16f1372da4df10b2ff0aa4b3bc00514d7bc9ab1 100644 --- a/tests/application/modules/admin/controllers/ProfilControllerTest.php +++ b/tests/application/modules/admin/controllers/ProfilControllerTest.php @@ -1504,4 +1504,45 @@ class Admin_ProfilControllerDuplicateCfgModulesTest extends Admin_ProfilControll -?> \ No newline at end of file + +class Admin_ProfilControllerProfilPortalLoginPageTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $this->dispatch('/admin/profil/edit/id_profil/1', true); + } + + + /** @test */ + public function loginPageSelectShouldBePresent() { + $this->assertXPath('//select[@name="login_page"]//option[@value=""]', + $this->_response->getBody()); + } + + + /** @test */ + public function loginPageValueShouldBeDefaultToPortal() { + $this->assertXPath('//select[@name="login_page"]//option[@selected][@value="1"]'); + } +} + + + +class Admin_ProfilControllerProfilPortalLoginPagePostTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $this->postDispatch('/admin/profil/edit/id_profil/1', + ['login_page' => 2]); + } + + + /** @test */ + public function loginPageShouldBe2() { + $this->assertEquals(2, Class_Profil::find(1)->getLoginPage()); + } +} diff --git a/tests/application/modules/opac/controllers/IndexControllerTest.php b/tests/application/modules/opac/controllers/IndexControllerTest.php index df68fb210633afc9fe82bdca6a8129f47488db3c..1a99fff76b0ce40d699de36ea7454021416fc689 100644 --- a/tests/application/modules/opac/controllers/IndexControllerTest.php +++ b/tests/application/modules/opac/controllers/IndexControllerTest.php @@ -21,17 +21,13 @@ class IndexControllerSetupDomainTest extends AbstractControllerTestCase { - public function setUp() { - parent::setUp(); - Class_Adminvar::beVolatile(); - } - + protected $_storm_default_to_volatile=true; /** @test */ public function accessingIndexShouldSetupNomDomain() { - Class_Url::setForbidenUrls(['opac3']); $this->dispatch('/'); - $this->assertEquals('http://localhost' . Class_Url::baseUrl(), Class_AdminVar::get('NOM_DOMAINE')); + $this->assertEquals('http://localhost' . Class_Url::baseUrl(), + Class_AdminVar::get('NOM_DOMAINE')); } @@ -160,17 +156,24 @@ class IndexControllerAsAdminWithCSSEditorTest extends IndexControllerAsAdminTest class IndexControllerWithInvitedLevelRestrictionForProfilTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + public function setup() { parent::setup(); + ZendAfi_Auth::getInstance()->clearIdentity(); - Class_Profil::newInstanceWithId(1, ['access_level' => '0' ,'cfg_menus' => '']); + $this->fixture('Class_Profil', ['id' => 1, + 'access_level' => '0', + 'cfg_menus' => '']); } - /** @test **/ - public function anonymousAccessingProfilWithAccessLevelShouldBeRedirectedToOpacLogin() { + /** @test */ + public function anonymousAccessingProfilWithAccessLevelShouldHaveAdminLoginScreen() { $this->dispatch('/opac/index/index/id_profil/1'); - $this->assertRedirectRegex('|^'.BASE_URL.'/auth/login/id_profil/1|'); + $this->assertModule('opac'); + $this->assertController('auth'); + $this->assertAction('login'); } } @@ -291,48 +294,200 @@ class IndexControllerSitemapTest extends AbstractControllerTestCase { -class IndexControllerRewriteUrlTest extends AbstractControllerTestCase { + +class IndexControllerAccessLevelWithLoginPageTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + public function setUp() { parent::setUp(); + ZendAfi_Auth::getInstance()->clearIdentity(); + Class_Profil::setCurrentProfil(Class_Profil::find(1)); + } + + + /** @test */ + public function sameLoginPageShouldNotRedirect() { + Class_Profil::find(1) + ->setAccessLevel(ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB) + ->setLoginPage(1) + ->assertSave(); + + $this->dispatch('/recherche/simple', true); + + $this->assertNotRedirect($this->getResponseLocation()); + $this->assertController('auth'); + $this->assertAction('login'); + $this->assertModule('opac'); + $this->assertEquals(Class_Url::absolute('/recherche/simple/id_profil/1'), + $this->_request->getParam('redirect')); + } + + + /** @test */ + public function otherLoginPageShouldRedirectToLoginPage() { + $this->fixture('Class_Profil', ['id' => 12]); + + Class_Profil::getCurrentProfil() + ->setAccessLevel(ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB) + ->setLoginPage(12) + ->assertSave(); + + $this->dispatch('/recherche/avancee', true); + + $this->assertRedirectTo(Class_Url::absolute('/auth/login/id_profil/12?redirect=' + . urlencode(Class_Url::absolute('/recherche/avancee/id_profil/1'))), + $this->getResponseLocation()); + } + + + /** @test */ + public function noLoginPageShouldNotRedirectToAdmin() { + Class_Profil::find(1) + ->setAccessLevel(ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB) + ->setLoginPage(null) + ->assertSave(); + + $this->dispatch('/recherche/simple', true); + + $this->assertNotRedirect($this->getResponseLocation()); + $this->assertController('auth'); + $this->assertAction('login'); + $this->assertModule('admin'); + + $absolute_url = Class_Url::absolute('/recherche/simple/id_profil/1'); + $this->assertXPath('//input[@name="redirect"][@value="'.$absolute_url.'"]'); + } +} + + + + +abstract class IndexControllerPrivateProfilesRewriteUrlTestCase + extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + ZendAfi_Auth::getInstance() + ->logUser($this->fixture('Class_Users', + ['id' => 1, + 'login' => 'guest', + 'password' => 'guest', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::INVITE])); - ZendAfi_Auth::getInstance()->logUser($this->fixture('Class_Users', - ['id' => 1, - 'login' => 'guest', - 'password' => 'guest', - 'role_level' => ZendAfi_Acl_AdminControllerRoles::INVITE])); $this->fixture('Class_Profil', ['id' => 345, 'libelle' => 'Zork - Main', 'parent_id' => null, 'rewrite_url' => 'zork', - 'access_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]); + 'access_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, + 'login_page' => null]); $this->fixture('Class_Profil', ['id' => 879, 'libelle' => 'Zork - Child', 'parent_id' => 345, 'rewrite_url' => 'zork-child']); + + $this->fixture('Class_Profil', ['id' => 23, + 'libelle' => 'Page d\'authentification']); + } +} - /** @test */ - public function privateProfilShouldRedirectToLogin() { - $this->dispatch('/zork', true); - $this->assertModule('opac'); + + +class IndexControllerPrivateProfilesRewriteUrlWithoutLoginTest + extends IndexControllerPrivateProfilesRewriteUrlTestCase { + + public function datas() { + return [ ['/zork'], ['/zork/zork-child'] ]; + } + + + /** + * @test + * @dataProvider datas + */ + public function shouldDisplayLoginScreenWithRedirect($url) { + $this->dispatch($url, true); + $this->assertModule('admin'); $this->assertController('auth'); $this->assertAction('login'); + $this->assertXPath('//input[@name="redirect"][contains(@value, "'. $url . '")]'); } +} - /** @test */ - public function publicProfilWithPrivateParentProfilShouldRedirectToLogin() { - $this->dispatch('/zork-child', true); - $this->assertModule('opac'); + + +class IndexControllerPrivateProfilesRewriteUrlWithLoginPageTest + extends IndexControllerPrivateProfilesRewriteUrlTestCase { + + public function setUp() { + parent::setUp(); + + Class_Profil::find(345) + ->setLoginPage(23) + ->assertSave(); + } + + + public function datas() { + return [ ['/zork'], ['/zork/zork-child'] ]; + } + + + /** + * @test + * @dataProvider datas + */ + public function shouldDisplayLoginScreenWithRedirect($url) { + $this->dispatch($url, true); + + $this->assertRedirectTo(Class_Url::absolute('/auth/login/id_profil/23?redirect=' + . urlencode(Class_Url::absolute($url))), + $this->getResponseLocation()); + } +} + + + +class IndexControllerPrivateProfilesRewriteUrlWithDeletedLoginPageTest + extends IndexControllerPrivateProfilesRewriteUrlTestCase { + + public function setUp() { + parent::setUp(); + + Class_Profil::find(345) + ->setLoginPage(23) + ->assertSave(); + + Class_Profil::find(23)->delete(); + } + + + public function datas() { + return [ ['/zork'], ['/zork/zork-child'] ]; + } + + + /** + * @test + * @dataProvider datas + */ + public function shouldDisplayLoginScreenWithRedirect($url) { + $this->dispatch($url, true); + $this->assertModule('admin'); $this->assertController('auth'); $this->assertAction('login'); + $this->assertXPath('//input[@name="redirect"][contains(@value, "'. $url . '")]'); } } + abstract class IndexControllerCnilTrackingTestCase extends AbstractControllerTestCase { protected $_storm_default_to_volatile = true; protected $_expected_message = 'showNotification({"message":"En poursuivant votre navigation sur ce site, vous acceptez l\'utilisation de cookies.","autoClose":false'; diff --git a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php index 58b5368ca1366902ce0220fa8b6bbe269c52ae81..13e0178d3b96ec314a7fdc1568d8434c9d0a2544 100644 --- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php +++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php @@ -956,7 +956,7 @@ class ProfilOptionsControllerUrlWithSubdomainTest extends ProfilOptionsControlle public function setUp() { parent::setUp(); $this->profil_jeunesse->setRewriteUrl('jeunesse')->assertSave(); - $this->servername=$_SERVER['SERVER_NAME']; + $this->servername = $_SERVER['SERVER_NAME']; Zend_Registry::get('session')->id_profil = null; $_SERVER['SERVER_NAME'] = "jeunesse.macaraguay.fr"; } @@ -1737,7 +1737,8 @@ class UserRoleLevelThreeViewPrivateProfilTest extends AbstractControllerTestCase $this->private_profil = Class_Profil::getCurrentProfil() ->setBrowser('opac') ->setTitreSite(null) - ->setLibelle('Profil privé'); + ->setLibelle('Profil privé') + ->setLoginPage(null); } @@ -1745,11 +1746,12 @@ class UserRoleLevelThreeViewPrivateProfilTest extends AbstractControllerTestCase public function shouldRenderLoginPageWhenProfilAccessLevelIsFour() { $this->private_profil->setAccessLevel(4); $this->dispatch('/opac/'); - $this->assertModule('opac'); + $this->assertModule('admin'); $this->assertController('auth'); $this->assertAction('login'); } + /** @test */ public function shouldRenderIndexPageWhenProfilAccessLevelIsThree() { $this->private_profil->setAccessLevel(3); @@ -1757,7 +1759,6 @@ class UserRoleLevelThreeViewPrivateProfilTest extends AbstractControllerTestCase $this->assertController('index'); $this->assertAction('index'); } - } diff --git a/tests/application/modules/telephone/controllers/CmsControllerTest.php b/tests/application/modules/telephone/controllers/CmsControllerTest.php index 9b44dbfc7b3c16bcebc29d056ebef4b4be8651b4..7bfc6615f7535ba6e9aaf3e75a1a30b2501f0d65 100644 --- a/tests/application/modules/telephone/controllers/CmsControllerTest.php +++ b/tests/application/modules/telephone/controllers/CmsControllerTest.php @@ -90,7 +90,7 @@ class CmsControllerTelephoneEmbeddedTest extends AbstractCmsControllerTelephoneT public function setUp() { parent::setUp(); - $this->dispatch('embed/cms/articleview/id/4'); + $this->dispatch('embed/cms/articleview/id/4', true); } diff --git a/tests/application/modules/telephone/controllers/IndexControllerTest.php b/tests/application/modules/telephone/controllers/IndexControllerTest.php index b66ba5604b28f5ca4849aa77c95a9663cff352e2..68d9d37c19a13d6adc9d84bd994a656ff2655eec 100644 --- a/tests/application/modules/telephone/controllers/IndexControllerTest.php +++ b/tests/application/modules/telephone/controllers/IndexControllerTest.php @@ -437,29 +437,24 @@ class IndexControllerWithProfilPortailGoBackPhoneTest extends AbstractIndexContr -class IndexControllerTelephoneTelephoneSwitchProfilTest extends Zend_Test_PHPUnit_ControllerTestCase { - public $bootstrap = 'bootstrap_frontcontroller.php'; +class IndexControllerTelephoneTelephoneSwitchProfilTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); $_SERVER['HTTP_USER_AGENT'] = 'iphone'; Zend_Registry::get('session')->id_profil = null; - Storm_Test_ObjectWrapper::onLoaderOfModel("Class_Profil") - ->whenCalled('findFirstBy') - ->with(array('BROWSER' => 'telephone')) - ->answers(Class_Profil::getLoader()->newInstanceWithId(4) - ->setBrowser('telephone') - ->setTitreSite('Smartphone')); + $this->fixture('Class_Profil', ['id' => 4, + 'browser' => 'telephone', + 'titre_site' => 'Smartphone']); $this->dispatch('/', true); } public function tearDown() { - unset ($_SERVER['HTTP_USER_AGENT']); + unset($_SERVER['HTTP_USER_AGENT']); parent::tearDown(); - } @@ -485,7 +480,8 @@ class IndexControllerTelephoneEmbedModuleTest extends AbstractIndexControllerTel parent::setUp(); $_SESSION['id_profil'] = 1; unset($_SERVER['HTTP_USER_AGENT']); - $this->dispatch('/embed'); + + $this->dispatch('/embed', true); } diff --git a/tests/application/modules/telephone/controllers/TelephoneAbstractControllerTestCase.php b/tests/application/modules/telephone/controllers/TelephoneAbstractControllerTestCase.php index d714ff9caf5e43846576d7e572373a4706ec4d66..fff38f0f996e96209a6516dc3cf7a1d7936b44b0 100644 --- a/tests/application/modules/telephone/controllers/TelephoneAbstractControllerTestCase.php +++ b/tests/application/modules/telephone/controllers/TelephoneAbstractControllerTestCase.php @@ -1,6 +1,6 @@ <?php /** - * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * Copyright (c) 2065, Agence Française Informatique (AFI). All rights reserved. * * BOKEH is free software; you can redistribute it and/or modify * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by @@ -16,30 +16,23 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -require_once 'AbstractControllerTestCase.php'; - abstract class TelephoneAbstractControllerTestCase extends AbstractControllerTestCase { + public function setUp() { parent::setUp(); $_SERVER['HTTP_USER_AGENT'] = 'iPhone'; - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Profil') - ->whenCalled('findFirstBy') - ->with(['BROWSER' => 'telephone']) - ->answers(Class_Profil::getCurrentProfil()->beTelephone()); - -/* $this->fixture('Class_Profil', ['id' => 2, - 'browser' => 'telephone']) - ->beCurrentProfil();*/ + Class_Profil::getCurrentProfil() + ->beTelephone() + ->assertSave(); } + public function tearDown() { unset($_SERVER['HTTP_USER_AGENT']); parent::tearDown(); } } - - ?> \ No newline at end of file