mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
PHRAS-260 Remove collection banner
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -226,15 +226,6 @@
|
||||
</button>
|
||||
</form>
|
||||
{% endif%}
|
||||
{% elseif app['authentication'].getUser().ACL.has_right_on_base(bas_id, 'manage') %}
|
||||
<span>{% trans 'admin::base:collection: aucun fichier (minilogo, watermark ...)' %}</span>
|
||||
<form class="fileupload no-ajax" enctype="multipart/form-data" method="post" action="{{ path('admin_collection_submit_banner', { 'bas_id' : bas_id }) }}" style="margin:0;">
|
||||
<span class="btn btn-success fileinput-button">
|
||||
<i class="icon-plus icon-white"></i>
|
||||
<span>{% trans %}Select files...{% endtrans %}</span>
|
||||
<input name="newBanner" type="file" accept="image/*" />
|
||||
</span>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user