From 8fc8a2ac88ec7ea7dafc6a220fb7286170223bbb Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Mon, 12 Jan 2015 17:52:51 +0100 Subject: [PATCH] PHRAS-260 Remove collection banner --- .../Phrasea/Controller/Admin/Collection.php | 119 ------------------ .../web/admin/collection/collection.html.twig | 9 -- .../Controller/Admin/AdminCollectionTest.php | 59 --------- 3 files changed, 187 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php index 3b0b870744..1ab8e0cd85 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php @@ -325,40 +325,6 @@ class Collection implements ControllerProviderInterface ->assert('bas_id', '\d+') ->bind('admin_collection_delete_stamp'); - /** - * Set a new banner - * - * name : admin_collection_submit_banner - * - * description : Set a new logo - * - * method : POST - * - * parameters : none - * - * return : REDIRECT Response - */ - $controllers->post('/{bas_id}/picture/banner/', $this->call('setBanner')) - ->assert('bas_id', '\d+') - ->bind('admin_collection_submit_banner'); - - /** - * Delete a banner - * - * name : admin_collection_delete_banner - * - * description : Delete a mini logo - * - * method : POST - * - * parameters : none - * - * return : REDIRECT Response - */ - $controllers->post('/{bas_id}/picture/banner/delete/', $this->call('deleteBanner')) - ->assert('bas_id', '\d+') - ->bind('admin_collection_delete_banner'); - /** * Get document details in the requested collection * @@ -523,41 +489,6 @@ class Collection implements ControllerProviderInterface )); } - /** - * Delete the collection banner - * - * @param Application $app The silex application - * @param Request $request The current request - * @param integer $bas_id The collection base_id - * @return JsonResponse|RedirectResponse - */ - public function deleteBanner(Application $app, Request $request, $bas_id) - { - $success = false; - - $collection = \collection::get_from_base_id($app, $bas_id); - - try { - $app['phraseanet.appbox']->write_collection_pic($app['media-alchemyst'], $app['filesystem'], $collection, null, \collection::PIC_PRESENTATION); - $success = true; - } catch (\Exception $e) { - - } - - if ('json' === $app['request']->getRequestFormat()) { - return $app->json(array( - 'success' => $success, - 'msg' => $success ? _('Successful removal') : _('An error occured'), - 'bas_id' => $collection->get_base_id() - )); - } - - return $app->redirectPath('admin_display_collection', array( - 'bas_id' => $collection->get_base_id(), - 'success' => (int) $success, - )); - } - /** * Delete the collection stamp * @@ -664,56 +595,6 @@ class Collection implements ControllerProviderInterface )); } - /** - * Set a collection banner - * - * @param Application $app The silex application - * @param Request $request The current request - * @param integer $bas_id The collection base_id - * @return RedirectResponse - */ - public function setBanner(Application $app, Request $request, $bas_id) - { - if (null === $file = $request->files->get('newBanner')) { - $app->abort(400); - } - - if ($file->getClientSize() > 1024 * 1024) { - return $app->redirectPath('admin_display_collection', array( - 'bas_id' => $bas_id, - 'success' => 0, - 'error' => 'file-too-big', - )); - } - - if (!$file->isValid()) { - return $app->redirectPath('admin_display_collection', array( - 'bas_id' => $bas_id, - 'success' => 0, - 'error' => 'file-invalid', - )); - } - - $collection = \collection::get_from_base_id($app, $bas_id); - - try { - $app['phraseanet.appbox']->write_collection_pic($app['media-alchemyst'], $app['filesystem'], $collection, $file, \collection::PIC_PRESENTATION); - - $app['filesystem']->remove($file->getPathname()); - } catch (\Exception $e) { - return $app->redirectPath('admin_display_collection', array( - 'bas_id' => $bas_id, - 'success' => 0, - 'error' => 'file-error', - )); - } - - return $app->redirectPath('admin_display_collection', array( - 'bas_id' => $bas_id, - 'success' => 1, - )); - } - /** * Set a collection stamp * diff --git a/templates/web/admin/collection/collection.html.twig b/templates/web/admin/collection/collection.html.twig index 4a681cc3cc..020ae778b8 100644 --- a/templates/web/admin/collection/collection.html.twig +++ b/templates/web/admin/collection/collection.html.twig @@ -226,15 +226,6 @@ {% endif%} - {% elseif app['authentication'].getUser().ACL.has_right_on_base(bas_id, 'manage') %} - {% trans 'admin::base:collection: aucun fichier (minilogo, watermark ...)' %} -
- - - {% trans %}Select files...{% endtrans %} - - -
{% endif %} diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php index e07e696b50..8bc4c61d63 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/AdminCollectionTest.php @@ -615,17 +615,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertBadResponse(self::$DI['client']->getResponse()); } - /** - * @covers Alchemy\Phrasea\Controller\Admin\Bas::setBanner - */ - public function testSetBannerBadRequest() - { - $this->setAdmin(true); - - self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/banner/'); - - $this->assertBadResponse(self::$DI['client']->getResponse()); - } /** * @covers Alchemy\Phrasea\Controller\Admin\Bas::setMiniLogo @@ -769,54 +758,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertTrue($json->success); } - /** - * @covers Alchemy\Phrasea\Controller\Admin\Bas::setBanner - */ - public function testSetBanner() - { - $this->setAdmin(true); - - $target = tempnam(sys_get_temp_dir(), 'p4logo') . '.jpg'; - self::$DI['app']['filesystem']->copy(__DIR__ . '/../../../../../files/p4logo.jpg', $target); - $files = array( - 'newBanner' => new \Symfony\Component\HttpFoundation\File\UploadedFile($target, 'logo.jpg') - ); - self::$DI['client']->request('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/banner/', array(), $files); - $this->checkRedirection(self::$DI['client']->getResponse(), '/admin/collection/' . self::$DI['collection']->get_base_id() . '/?success=1'); - $this->assertEquals(1, count(\collection::getPresentation(self::$DI['collection']->get_base_id()))); - } - - /** - * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteBanner - */ - public function testDeleteBannerNotJson() - { - $this->setAdmin(true); - - $collection = $this->createOneCollection(); - - self::$DI['client']->request('POST', '/admin/collection/' . $collection->get_base_id() . '/picture/banner/delete/'); - - $this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); - } - - /** - * @covers Alchemy\Phrasea\Controller\Admin\Bas::deleteBanner - */ - public function testDeleteBanner() - { - if (count(\collection::getPresentation(self::$DI['collection']->get_base_id())) === 0) { - $this->markTestSkipped('No Banner setted'); - } - - $this->setAdmin(true); - - $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$DI['collection']->get_base_id() . '/picture/banner/delete/'); - - $json = $this->getJson(self::$DI['client']->getResponse()); - $this->assertTrue($json->success); - } - /** * @covers Alchemy\Phrasea\Controller\Admin\Bas::getCollection */