1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-04-12 21:14:06 +00:00

Add IsGranted to import controllers

This commit is contained in:
Yassine Guedidi 2025-03-11 00:54:02 +01:00
parent e3dc63f739
commit 9499b062d0
20 changed files with 71 additions and 17 deletions

View file

@ -2,6 +2,7 @@
namespace Wallabag\Controller\Import;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -14,6 +15,7 @@ abstract class BrowserController extends AbstractController
{
/**
* @Route("/import/browser", name="import_browser", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*
* @return Response
*/

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -27,6 +28,7 @@ class ChromeController extends BrowserController
/**
* @Route("/import/chrome", name="import_chrome", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, TranslatorInterface $translator)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -25,6 +26,7 @@ class DeliciousController extends AbstractController
/**
* @Route("/import/delicious", name="import_delicious", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, DeliciousImport $delicious, Config $craueConfig, TranslatorInterface $translator)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -27,6 +28,7 @@ class ElcuratorController extends WallabagController
/**
* @Route("/import/elcurator", name="import_elcurator", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, TranslatorInterface $translator)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -27,6 +28,7 @@ class FirefoxController extends BrowserController
/**
* @Route("/import/firefox", name="import_firefox", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, TranslatorInterface $translator)
{

View file

@ -2,6 +2,7 @@
namespace Wallabag\Controller\Import;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -14,6 +15,7 @@ abstract class HtmlController extends AbstractController
{
/**
* @Route("/import/html", name="import_html", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*
* @return Response
*/

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use Predis\Client;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Wallabag\Consumer\RabbitMQConsumerTotalProxy;
@ -21,6 +22,7 @@ class ImportController extends AbstractController
/**
* @Route("/import/", name="import", methods={"GET"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function importAction(ImportChain $importChain)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -25,6 +26,7 @@ class InstapaperController extends AbstractController
/**
* @Route("/import/instapaper", name="import_instapaper", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, InstapaperImport $instapaper, Config $craueConfig, TranslatorInterface $translator)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -25,6 +26,7 @@ class OmnivoreController extends AbstractController
/**
* @Route("/import/omnivore", name="import_omnivore", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, OmnivoreImport $omnivore, Config $craueConfig, TranslatorInterface $translator)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -25,6 +26,7 @@ class PinboardController extends AbstractController
/**
* @Route("/import/pinboard", name="import_pinboard", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, PinboardImport $pinboard, Config $craueConfig, TranslatorInterface $translator)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
@ -31,6 +32,7 @@ class PocketController extends AbstractController
/**
* @Route("/import/pocket", name="import_pocket", methods={"GET"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(PocketImport $pocketImport)
{
@ -52,6 +54,7 @@ class PocketController extends AbstractController
/**
* @Route("/import/pocket/auth", name="import_pocket_auth", methods={"POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function authAction(Request $request, PocketImport $pocketImport)
{
@ -82,6 +85,7 @@ class PocketController extends AbstractController
/**
* @Route("/import/pocket/callback", name="import_pocket_callback", methods={"GET"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function callbackAction(PocketImport $pocketImport, TranslatorInterface $translator)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -27,6 +28,7 @@ class PocketHtmlController extends HtmlController
/**
* @Route("/import/pocket_html", name="import_pocket_html", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, TranslatorInterface $translator)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -25,6 +26,7 @@ class ReadabilityController extends AbstractController
/**
* @Route("/import/readability", name="import_readability", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, ReadabilityImport $readability, Config $craueConfig, TranslatorInterface $translator)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -27,6 +28,7 @@ class ShaarliController extends HtmlController
/**
* @Route("/import/shaarli", name="import_shaarli", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, TranslatorInterface $translator)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -27,6 +28,7 @@ class WallabagV1Controller extends WallabagController
/**
* @Route("/import/wallabag-v1", name="import_wallabag_v1", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, TranslatorInterface $translator)
{

View file

@ -4,6 +4,7 @@ namespace Wallabag\Controller\Import;
use Craue\ConfigBundle\Util\Config;
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -27,6 +28,7 @@ class WallabagV2Controller extends WallabagController
/**
* @Route("/import/wallabag-v2", name="import_wallabag_v2", methods={"GET", "POST"})
* @IsGranted("IMPORT_ENTRIES")
*/
public function indexAction(Request $request, TranslatorInterface $translator)
{

View file

@ -12,6 +12,7 @@ class MainVoter extends Voter
public const CREATE_ENTRIES = 'CREATE_ENTRIES';
public const EDIT_ENTRIES = 'EDIT_ENTRIES';
public const EXPORT_ENTRIES = 'EXPORT_ENTRIES';
public const IMPORT_ENTRIES = 'IMPORT_ENTRIES';
public const LIST_SITE_CREDENTIALS = 'LIST_SITE_CREDENTIALS';
public const CREATE_SITE_CREDENTIALS = 'CREATE_SITE_CREDENTIALS';
@ -28,7 +29,7 @@ class MainVoter extends Voter
return false;
}
if (!\in_array($attribute, [self::LIST_ENTRIES, self::CREATE_ENTRIES, self::EDIT_ENTRIES, self::EXPORT_ENTRIES, self::LIST_SITE_CREDENTIALS, self::CREATE_SITE_CREDENTIALS], true)) {
if (!\in_array($attribute, [self::LIST_ENTRIES, self::CREATE_ENTRIES, self::EDIT_ENTRIES, self::EXPORT_ENTRIES, self::IMPORT_ENTRIES, self::LIST_SITE_CREDENTIALS, self::CREATE_SITE_CREDENTIALS], true)) {
return false;
}
@ -42,6 +43,7 @@ class MainVoter extends Voter
case self::CREATE_ENTRIES:
case self::EDIT_ENTRIES:
case self::EXPORT_ENTRIES:
case self::IMPORT_ENTRIES:
case self::LIST_SITE_CREDENTIALS:
case self::CREATE_SITE_CREDENTIALS:
return $this->security->isGranted('ROLE_USER');

View file

@ -45,22 +45,24 @@
</div>
</li>
<li class="col l4 m6 s12">
<div class="card light-green darken-1">
<div class="card-content white-text">
<span class="card-title white-text">{{ 'quickstart.migrate.title'|trans }}</span>
<p>{{ 'quickstart.migrate.description'|trans }}</p>
{% if is_granted('IMPORT_ENTRIES') %}
<li class="col l4 m6 s12">
<div class="card light-green darken-1">
<div class="card-content white-text">
<span class="card-title white-text">{{ 'quickstart.migrate.title'|trans }}</span>
<p>{{ 'quickstart.migrate.description'|trans }}</p>
</div>
<div class="card-action">
<ul>
<li><a href="{{ path('import_pocket') }}">{{ 'quickstart.migrate.pocket'|trans }}</a></li>
<li><a href="{{ path('import_readability') }}">{{ 'quickstart.migrate.readability'|trans }}</a></li>
<li><a href="{{ path('import_instapaper') }}">{{ 'quickstart.migrate.instapaper'|trans }}</a></li>
<li><a href="{{ path('import') }}">{{ 'quickstart.more'|trans }}</a></li>
</ul>
</div>
</div>
<div class="card-action">
<ul>
<li><a href="{{ path('import_pocket') }}">{{ 'quickstart.migrate.pocket'|trans }}</a></li>
<li><a href="{{ path('import_readability') }}">{{ 'quickstart.migrate.readability'|trans }}</a></li>
<li><a href="{{ path('import_instapaper') }}">{{ 'quickstart.migrate.instapaper'|trans }}</a></li>
<li><a href="{{ path('import') }}">{{ 'quickstart.more'|trans }}</a></li>
</ul>
</div>
</div>
</li>
</li>
{% endif %}
<li class="col l4 m6 s12">
<div class="card blue darken-1">

View file

@ -123,7 +123,9 @@
<ul id="dropdown-account" class="dropdown-content">
<li><a href="{{ path('config') }}"><i class="material-icons">settings</i> {{ 'menu.left.config'|trans }}</a></li>
<li><a href="{{ path('developer') }}"><i class="material-icons">smartphone</i> {{ 'menu.left.developer'|trans }}</a></li>
<li><a href="{{ path('import') }}"><i class="material-icons">import_export</i> {{ 'menu.left.import'|trans }}</a></li>
{% if is_granted('IMPORT_ENTRIES') %}
<li><a href="{{ path('import') }}"><i class="material-icons">import_export</i> {{ 'menu.left.import'|trans }}</a></li>
{% endif %}
{% if craue_setting('restricted_access') and is_granted('LIST_SITE_CREDENTIALS') %}
<li><a href="{{ path('site_credentials_index') }}"><i class="material-icons">vpn_key</i> {{ 'menu.left.site_credentials'|trans }}</a></li>
{% endif %}

View file

@ -98,6 +98,20 @@ class MainVoterTest extends TestCase
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->mainVoter->vote($this->token, null, [MainVoter::EXPORT_ENTRIES]));
}
public function testVoteReturnsDeniedForNonUserImportEntries(): void
{
$this->security->method('isGranted')->with('ROLE_USER')->willReturn(false);
$this->assertSame(VoterInterface::ACCESS_DENIED, $this->mainVoter->vote($this->token, null, [MainVoter::IMPORT_ENTRIES]));
}
public function testVoteReturnsGrantedForUserImportEntries(): void
{
$this->security->method('isGranted')->with('ROLE_USER')->willReturn(true);
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->mainVoter->vote($this->token, null, [MainVoter::IMPORT_ENTRIES]));
}
public function testVoteReturnsDeniedForNonUserListSiteCredentials(): void
{
$this->security->method('isGranted')->with('ROLE_USER')->willReturn(false);