diff options
5 files changed, 37 insertions, 0 deletions
diff --git a/app/config/config.yml b/app/config/config.yml index 4f4fb900..451809d6 100644 --- a/app/config/config.yml +++ b/app/config/config.yml | |||
@@ -55,6 +55,7 @@ wallabag_core: | |||
55 | list_mode: 0 | 55 | list_mode: 0 |
56 | fetching_error_message: | | 56 | fetching_error_message: | |
57 | wallabag can't retrieve contents for this article. Please <a href="http://doc.wallabag.org/en/master/user/errors_during_fetching.html#how-can-i-help-to-fix-that">troubleshoot this issue</a>. | 57 | wallabag can't retrieve contents for this article. Please <a href="http://doc.wallabag.org/en/master/user/errors_during_fetching.html#how-can-i-help-to-fix-that">troubleshoot this issue</a>. |
58 | api_limit_mass_actions: 10 | ||
58 | 59 | ||
59 | wallabag_user: | 60 | wallabag_user: |
60 | registration_enabled: "%fosuser_registration%" | 61 | registration_enabled: "%fosuser_registration%" |
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index ae6f0e3f..7c3e778e 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -5,6 +5,7 @@ namespace Wallabag\ApiBundle\Controller; | |||
5 | use Hateoas\Configuration\Route; | 5 | use Hateoas\Configuration\Route; |
6 | use Hateoas\Representation\Factory\PagerfantaFactory; | 6 | use Hateoas\Representation\Factory\PagerfantaFactory; |
7 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | 7 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
8 | use Symfony\Component\Config\Definition\Exception\Exception; | ||
8 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
9 | use Symfony\Component\HttpFoundation\JsonResponse; | 10 | use Symfony\Component\HttpFoundation\JsonResponse; |
10 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 11 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
@@ -229,6 +230,8 @@ class EntryRestController extends WallabagRestController | |||
229 | * ) | 230 | * ) |
230 | * | 231 | * |
231 | * @return JsonResponse | 232 | * @return JsonResponse |
233 | * | ||
234 | * @throws Symfony\Component\Config\Definition\Exception\Exception When limit is reached | ||
232 | */ | 235 | */ |
233 | public function postEntriesListAction(Request $request) | 236 | public function postEntriesListAction(Request $request) |
234 | { | 237 | { |
@@ -237,6 +240,12 @@ class EntryRestController extends WallabagRestController | |||
237 | $urls = json_decode($request->query->get('urls', [])); | 240 | $urls = json_decode($request->query->get('urls', [])); |
238 | $results = []; | 241 | $results = []; |
239 | 242 | ||
243 | $limit = $this->container->getParameter('wallabag_core.api_limit_mass_actions'); | ||
244 | |||
245 | if (count($urls) > $limit) { | ||
246 | throw new Exception('API limit reached'); | ||
247 | } | ||
248 | |||
240 | // handle multiple urls | 249 | // handle multiple urls |
241 | if (!empty($urls)) { | 250 | if (!empty($urls)) { |
242 | foreach ($urls as $key => $url) { | 251 | foreach ($urls as $key => $url) { |
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php index 006a18c3..75b37729 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php | |||
@@ -47,6 +47,9 @@ class Configuration implements ConfigurationInterface | |||
47 | ->scalarNode('list_mode') | 47 | ->scalarNode('list_mode') |
48 | ->defaultValue(1) | 48 | ->defaultValue(1) |
49 | ->end() | 49 | ->end() |
50 | ->scalarNode('api_limit_mass_actions') | ||
51 | ->defaultValue(10) | ||
52 | ->end() | ||
50 | ->end() | 53 | ->end() |
51 | ; | 54 | ; |
52 | 55 | ||
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php index aa9ee339..c075c19f 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php | |||
@@ -26,6 +26,7 @@ class WallabagCoreExtension extends Extension | |||
26 | $container->setParameter('wallabag_core.action_mark_as_read', $config['action_mark_as_read']); | 26 | $container->setParameter('wallabag_core.action_mark_as_read', $config['action_mark_as_read']); |
27 | $container->setParameter('wallabag_core.list_mode', $config['list_mode']); | 27 | $container->setParameter('wallabag_core.list_mode', $config['list_mode']); |
28 | $container->setParameter('wallabag_core.fetching_error_message', $config['fetching_error_message']); | 28 | $container->setParameter('wallabag_core.fetching_error_message', $config['fetching_error_message']); |
29 | $container->setParameter('wallabag_core.api_limit_mass_actions', $config['api_limit_mass_actions']); | ||
29 | 30 | ||
30 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | 31 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
31 | $loader->load('services.yml'); | 32 | $loader->load('services.yml'); |
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 88a5be93..8594ad0b 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -809,4 +809,27 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
809 | $this->assertFalse($content[1]['entry']); | 809 | $this->assertFalse($content[1]['entry']); |
810 | $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']); | 810 | $this->assertEquals('http://0.0.0.0/entry3', $content[1]['url']); |
811 | } | 811 | } |
812 | |||
813 | /** | ||
814 | * @expectedException Symfony\Component\Config\Definition\Exception\Exception | ||
815 | * @expectedExceptionMessage API limit reached | ||
816 | */ | ||
817 | public function testLimitBulkAction() | ||
818 | { | ||
819 | $list = [ | ||
820 | 'http://0.0.0.0/entry1', | ||
821 | 'http://0.0.0.0/entry1', | ||
822 | 'http://0.0.0.0/entry1', | ||
823 | 'http://0.0.0.0/entry1', | ||
824 | 'http://0.0.0.0/entry1', | ||
825 | 'http://0.0.0.0/entry1', | ||
826 | 'http://0.0.0.0/entry1', | ||
827 | 'http://0.0.0.0/entry1', | ||
828 | 'http://0.0.0.0/entry1', | ||
829 | 'http://0.0.0.0/entry1', | ||
830 | 'http://0.0.0.0/entry1', | ||
831 | ]; | ||
832 | |||
833 | $this->client->request('POST', '/api/entries/lists?urls='.json_encode($list)); | ||
834 | } | ||
812 | } | 835 | } |