From b3e6af2a54985e997f33168690cd55c600b23bee Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Thu, 25 Oct 2018 16:17:01 +0200 Subject: [PATCH] dev #80976 add administration action on inspector gadget to delete an item --- VERSIONS_WIP/80976 | 1 + .../admin/controllers/RecordsController.php | 16 +++++- .../ZendAfi/View/Helper/Notice/Unimarc.php | 28 +++++++++- .../controllers/RecordsControllerTest.php | 55 +++++++++++++++++++ .../RechercheControllerViewnoticeTest.php | 27 ++++++++- 5 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 VERSIONS_WIP/80976 diff --git a/VERSIONS_WIP/80976 b/VERSIONS_WIP/80976 new file mode 100644 index 00000000000..68fa36c80c5 --- /dev/null +++ b/VERSIONS_WIP/80976 @@ -0,0 +1 @@ + - ticket #80976 : gestion des integrations hotline niveau 1 \ No newline at end of file diff --git a/application/modules/admin/controllers/RecordsController.php b/application/modules/admin/controllers/RecordsController.php index 9c92ea3ef03..7a9c35bb837 100644 --- a/application/modules/admin/controllers/RecordsController.php +++ b/application/modules/admin/controllers/RecordsController.php @@ -30,7 +30,7 @@ class Admin_RecordsController extends ZendAfi_Controller_Action { if ($album = $record->getAlbum()){ $album->createThumbnail(); $url_vignette = $album->getThumbnailUrl(); - + $record->setUrlVignette($url_vignette); $record->setUrlImage(($poster = $album->getPoster()) ? $poster : $url_vignette); $record->save(); @@ -107,4 +107,18 @@ class Admin_RecordsController extends ZendAfi_Controller_Action { $this->_helper->notify($this->_('La bande-annonce a bien été mise à jour')); $this->_redirectClose($this->_getReferer()); } + + + public function deleteItemAction() { + if (!$item = Class_Exemplaire::find($this->_getParam('id'))) + $this->_helper->notify($this->_('Exemplaire non trouvé')); + + if ($item) { + $item->delete(); + $this->_helper->notify($this->_('Exemplaire "%s" supprimé', + $item->getCodeBarres())); + } + + $this->_redirectToReferer(); + } } diff --git a/library/ZendAfi/View/Helper/Notice/Unimarc.php b/library/ZendAfi/View/Helper/Notice/Unimarc.php index 41330ec655e..9e67feea247 100644 --- a/library/ZendAfi/View/Helper/Notice/Unimarc.php +++ b/library/ZendAfi/View/Helper/Notice/Unimarc.php @@ -136,7 +136,8 @@ class ZendAfi_View_Helper_Notice_Unimarc extends Zend_View_Helper_HtmlElement { . $this->_tag('br'); $html .= $this->renderItem995($item) - . $this->renderItemDownload($item); + . $this->renderItemDownload($item) + . $this->renderItemDelete($item); return $this->_tag('h3', $item->getBibLibelle() . ' ' . $item->getCodeBarres()) . $this->_tag('div', $html); @@ -194,6 +195,31 @@ class ZendAfi_View_Helper_Notice_Unimarc extends Zend_View_Helper_HtmlElement { } + protected function renderItemDelete($item) { + if (!Class_Users::isCurrentUserAdmin()) + return ''; + + $delete_url = $this->view->url(['module' => 'admin', + 'controller' => 'records', + 'action' => 'delete-item', + 'id' => $item->getId()], + null, true); + + return $this->view->tag('a', + Class_Admin_Skin::current()->renderActionIconOn('delete', $this->view) . $this->_('Supprimer l\'exemplaire'), + ['style' => 'float:right;', + 'onclick' => 'return confirm(\'' . $this->_('Supprimer cet exemplaire ?') . '\');', + 'href' => $delete_url]); + + $button = (new Class_Entity) + ->setText($this->_('Supprimer l\'exemplaire')) + ->setImage(Class_Admin_Skin::current()->renderActionIconOn('delete', $this->view)) + ->setAttribs(); + + return $this->view->admin_Button($button); + } + + public function __call($name, $args) { if ('visit' != substr($name, 0, 5)) throw new RuntimeException('Call to unknown method ' . get_class($this) . '::' . $name); diff --git a/tests/application/modules/admin/controllers/RecordsControllerTest.php b/tests/application/modules/admin/controllers/RecordsControllerTest.php index 526b154471e..a787390ba24 100644 --- a/tests/application/modules/admin/controllers/RecordsControllerTest.php +++ b/tests/application/modules/admin/controllers/RecordsControllerTest.php @@ -500,3 +500,58 @@ class RecordsControllerTrailerPostTest extends RecordsControllerTestCase { 'Le service n\'a pas répondu'); } } + + + + +class RecordsControllerDeleteItemTest extends RecordsControllerTestCase { + public function setUp() { + parent::setUp(); + $this->fixture('Class_Exemplaire', + ['id' => 4, + 'id_notice' => '12345', + 'cote' => '234', + 'code_barres' => 'ABC4' ]); + $this->dispatch('/admin/records/delete-item/id/4', true); + } + + + /** @test */ + public function itemShouldBeDeleted() { + $this->assertNull(Class_Exemplaire::find(4)); + } + + + /** @test */ + public function responseShouldRedirectToReferer() { + $this->assertRedirect(); + } + + + /** @test */ + public function responseShouldNotifyDeletion() { + $this->assertFlashMessengerContentContains('Exemplaire "ABC4" supprimé'); + } +} + + + + +class RecordsControllerDeleteInexistingItemTest extends RecordsControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/records/delete-item/id/4', true); + } + + + /** @test */ + public function responseShouldRedirectToReferer() { + $this->assertRedirect(); + } + + + /** @test */ + public function responseShouldNotifyDeletion() { + $this->assertFlashMessengerContentContains('Exemplaire non trouvé'); + } +} \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/RechercheControllerViewnoticeTest.php b/tests/application/modules/opac/controllers/RechercheControllerViewnoticeTest.php index bb8096623d2..d950afa71e8 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerViewnoticeTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerViewnoticeTest.php @@ -30,16 +30,37 @@ class RechercheControllerViewnoticeWithInspectorGadgetTest extends AbstractContr ['id' => 2, 'unimarc' => '', 'alpha_titre' => '', - 'alpha_auteur' => '']); - - $this->dispatch('/opac/recherche/viewnotice/id/2/inspector_gadget/1', true); + 'alpha_auteur' => '', + 'exemplaires' => [ $this->fixture('Class_Exemplaire', + ['id' => 4, + 'cote' => '234', + 'code_barres' => 'ABC4' ]) ]]); } /** @test */ public function buttonNoticeBokehShouldBePresent() { + $this->dispatch('/opac/recherche/viewnotice/id/2/inspector_gadget/1', true); + $this->assertXPathContentContains('//button', 'Notice Bokeh'); } + + + /** @test */ + public function inspectorShouldContainsButtonToDeleteItem() { + $this->dispatch('/opac/recherche/viewnotice/id/2/inspector_gadget/1', true); + + $this->assertXPath('//button[contains(@onclick, "\/admin\/records\/delete-item\/id\/4")]'); + } + + + /** @test */ + public function inspectorAsRegularUserShouldNotContainsButtonToDeleteItem() { + Class_Users::getIdentity()->beModoBib(); + $this->dispatch('/opac/recherche/viewnotice/id/2/inspector_gadget/1', true); + + $this->assertNotXPath('//button[contains(@onclick, "\/admin\/records\/delete-item\/id\/4")]'); + } } -- GitLab