diff --git a/VERSIONS_WIP/80976 b/VERSIONS_WIP/80976 new file mode 100644 index 0000000000000000000000000000000000000000..7e4f5109fd342d73d847ab8e60fe00bd99ec350f --- /dev/null +++ b/VERSIONS_WIP/80976 @@ -0,0 +1 @@ + - ticket #80976 : page notice : lorque connecté en tant qu'administrateur, l'outil "Inspector Gadget" permet de supprimer un exemplaire \ No newline at end of file diff --git a/application/modules/admin/controllers/RecordsController.php b/application/modules/admin/controllers/RecordsController.php index 1b5e2ee32b486f235f54ee6773f9d8fc5d1af20c..5287122d64b5b2dbbc5a884c9dfa0024196bf85e 100644 --- a/application/modules/admin/controllers/RecordsController.php +++ b/application/modules/admin/controllers/RecordsController.php @@ -111,4 +111,17 @@ 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'))) + $item->delete(); + + $this->_helper->notify($item + ? $this->_('Exemplaire "%s" supprimé', + $item->getCodeBarres()) + : $this->_('Exemplaire non trouvé')); + + $this->_redirectToReferer(); + } } diff --git a/library/ZendAfi/View/Helper/Notice/Unimarc.php b/library/ZendAfi/View/Helper/Notice/Unimarc.php index 2e4a2294581c87d3093a605e8ce2463b8fbc0468..20c0baa7a8bddaf1dbc7e644e32015a34f1dccfa 100644 --- a/library/ZendAfi/View/Helper/Notice/Unimarc.php +++ b/library/ZendAfi/View/Helper/Notice/Unimarc.php @@ -152,7 +152,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); @@ -210,6 +211,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 ad318269f17b9adc00ba20e3e54d977075504658..6dfbd331c463b2b049d88a1dbdeed0c17900409d 100644 --- a/tests/application/modules/admin/controllers/RecordsControllerTest.php +++ b/tests/application/modules/admin/controllers/RecordsControllerTest.php @@ -502,3 +502,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 2f5cac70a8a6b996bf808f7b9fac4fee37ba7a00..0a598c72ce3564dab18abae097bab97b44a1a37e 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerViewnoticeTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerViewnoticeTest.php @@ -65,16 +65,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")]'); + } }