From 738f6c2e0bab1c39ca0576b696b8772632f51c39 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT <hdlaurent@afi-sa.fr> Date: Tue, 13 Apr 2021 17:05:22 +0200 Subject: [PATCH] hotline#132232 : MT : PNBHold could not be deleted --- VERSIONS_HOTLINE/132232 | 1 + .../modules/opac/controllers/AbonneController.php | 9 ++++++++- library/Class/User/CardsOperationDecorator.php | 5 +++++ library/ZendAfi/Controller/Action.php | 5 +++++ .../Intonation/Library/View/Wrapper/PNBHold.php | 7 ++++++- tests/scenarios/PnbDilicom/PnbDilicomDisplayTest.php | 9 ++++++++- tests/scenarios/Templates/TemplatesAbonneTest.php | 2 +- 7 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 VERSIONS_HOTLINE/132232 diff --git a/VERSIONS_HOTLINE/132232 b/VERSIONS_HOTLINE/132232 new file mode 100644 index 00000000000..68df2f0aad5 --- /dev/null +++ b/VERSIONS_HOTLINE/132232 @@ -0,0 +1 @@ + - ticket #132232 : Magasin de thèmes : Dans la liste des réservations de l'abonné, les réservations PNB peuvent maintenant être supprimées. \ No newline at end of file diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 17fdf620b5b..5c72af30655 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -93,10 +93,17 @@ class AbonneController extends ZendAfi_Controller_Action { public function deletePnbHoldAction() { $hold = Class_Hold_Pnb::find($this->_getParam('id')); + if (!$hold){ + $this->_helper->notify($this->_('La réservation recherchée avec l\'identifiant %s n\'a pas été trouvée.', + $this->_getParam('id'))); + $this->_redirectCloseReferer(); + return; + } + $hold->delete(); $this->_helper->notify($this->_('Votre réservation du document %s a bien été supprimée.', $hold->getTitle())); - $this->_redirectToReferer(); + $this->_redirectCloseReferer(); } diff --git a/library/Class/User/CardsOperationDecorator.php b/library/Class/User/CardsOperationDecorator.php index 97359ff7b1d..b4acf4a0d86 100644 --- a/library/Class/User/CardsOperationDecorator.php +++ b/library/Class/User/CardsOperationDecorator.php @@ -53,6 +53,11 @@ class Class_User_CardsOperationDecorator { } + public function getOperationId() { + return $this->_operation->getId(); + } + + public function isPNB() { return $this->_operation->isPNB(); } diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index 52614fdefae..4b90ff7c3c4 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -136,6 +136,11 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } + protected function _redirectCloseReferer() { + $this->_redirectClose($this->_getReferer()); + } + + public function setResourceDefinition($definitions) { $this->_definitions = $definitions; } diff --git a/library/templates/Intonation/Library/View/Wrapper/PNBHold.php b/library/templates/Intonation/Library/View/Wrapper/PNBHold.php index b646d06f7aa..235c4bb1e1d 100644 --- a/library/templates/Intonation/Library/View/Wrapper/PNBHold.php +++ b/library/templates/Intonation/Library/View/Wrapper/PNBHold.php @@ -55,12 +55,17 @@ class Intonation_Library_View_Wrapper_PNBHold extends Intonation_Library_View_Wr return [ new Intonation_Library_Link(['Url' => $this->_view->url(['controller' => 'abonne', 'action' => 'delete-pnb-hold', - 'id' => $this->_model->getId()]), + 'id' => $this->_getModelId()]), 'Text' => $this->_('Supprimer'), 'Image' => $this->getIco('delete', 'utils'), 'Title' => $this->_('Supprimer la réservation du document %s', $this->_model->getTitre()), + 'Popup' => true, 'Confirm' => $this->_('Confirmez-vous la suppression de la réservation du document %s ? ', $this->_model->getTitre())])]; } + + private function _getModelId() { + return $this->_model->getOperationId(); + } } \ No newline at end of file diff --git a/tests/scenarios/PnbDilicom/PnbDilicomDisplayTest.php b/tests/scenarios/PnbDilicom/PnbDilicomDisplayTest.php index 26f1426021a..8cb1743bd08 100644 --- a/tests/scenarios/PnbDilicom/PnbDilicomDisplayTest.php +++ b/tests/scenarios/PnbDilicom/PnbDilicomDisplayTest.php @@ -1635,7 +1635,7 @@ class PnbDilicomDisplayAbonneDeletePnbHoldTest extends PnbDilicomDisplayBibNumer /** @test */ - public function deleteHoldPNBWithUserSixAndIdOneShouldDeleteIt() { + public function deleteHoldPNBWithIdOneShouldDeleteIt() { $this->dispatch('/abonne/delete-pnb-hold/id/1'); $this->assertNull(Class_Hold_Pnb::find(1)); } @@ -1646,4 +1646,11 @@ class PnbDilicomDisplayAbonneDeletePnbHoldTest extends PnbDilicomDisplayBibNumer $this->dispatch('/abonne/delete-pnb-hold/id/1'); $this->assertFlashMessengerContentContains('Votre réservation du document Totem et Thora a bien été supprimée.'); } + + /** @test */ + public function whenDeletePnbHoldCalledWithInexistantIdShouldDisplayError() { + $this->dispatch('/abonne/delete-pnb-hold/id/42'); + $this->assertFlashMessengerContentContains('La réservation recherchée avec l\'identifiant 42 n\'a pas été trouvée.'); + + } } diff --git a/tests/scenarios/Templates/TemplatesAbonneTest.php b/tests/scenarios/Templates/TemplatesAbonneTest.php index 02f33a53673..e5e106b6ed7 100644 --- a/tests/scenarios/Templates/TemplatesAbonneTest.php +++ b/tests/scenarios/Templates/TemplatesAbonneTest.php @@ -1407,7 +1407,7 @@ class TemplatesAbonneWithPNBHoldsTest extends AbstractControllerTestCase { /** @test */ public function actionDeleteHoldShouldPresent() { - $this->assertXPathContentContains('//div//a[@href="/abonne/delete-pnb-hold/id/6_1"][@class="card-link"]', 'Supprimer'); + $this->assertXPathContentContains('//div//a[@href="/abonne/delete-pnb-hold/id/1"][@class="card-link"]', 'Supprimer'); } } -- GitLab