Skip to content

Commit

Permalink
[Task]: Improve permission check (#149)
Browse files Browse the repository at this point in the history
* add permission check

* add permission check

* add permission check

* replace with UserAwareController

* remov eextra break line
  • Loading branch information
kingjia90 authored Jan 8, 2024
1 parent 3912853 commit 997a097
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/Controller/AdminOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function __construct(protected TranslatorInterface $translator)

public function onKernelControllerEvent(ControllerEvent $event): void
{
$this->checkPermission('bundle_ecommerce_back-office_order');

// set language
$user = $this->tokenResolver->getUser();

Expand Down
9 changes: 8 additions & 1 deletion src/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

namespace Pimcore\Bundle\EcommerceFrameworkBundle\Controller;

use Pimcore\Controller\KernelControllerEventInterface;
use Pimcore\Controller\UserAwareController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;

Expand All @@ -28,7 +30,7 @@
*
* @internal
*/
class ConfigController extends UserAwareController
class ConfigController extends UserAwareController implements KernelControllerEventInterface
{
/**
* ConfigController constructor.
Expand All @@ -40,6 +42,11 @@ public function __construct(private RouterInterface $router)
$this->router = $router;
}

public function onKernelControllerEvent(ControllerEvent $event): void
{
$this->checkPermission('bundle_ecommerce_back-office_order');
}

/**
* @Route("/js-config", name="pimcore_ecommerceframework_config_jsconfig", methods={"GET"})
*
Expand Down
11 changes: 9 additions & 2 deletions src/Controller/FindologicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

namespace Pimcore\Bundle\EcommerceFrameworkBundle\Controller;

use Pimcore\Controller\FrontendController;
use Pimcore\Controller\KernelControllerEventInterface;
use Pimcore\Controller\UserAwareController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ControllerEvent;

/**
* Class FindologicController
Expand All @@ -27,8 +29,13 @@
*
* @internal
*/
class FindologicController extends FrontendController
class FindologicController extends UserAwareController implements KernelControllerEventInterface
{
public function onKernelControllerEvent(ControllerEvent $event): void
{
$this->checkPermission('bundle_ecommerce_back-office_order');
}

/**
* create xml output for findologic
*/
Expand Down
9 changes: 8 additions & 1 deletion src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
use Pimcore\Bundle\EcommerceFrameworkBundle\Event\AdminEvents;
use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ProductListInterface;
use Pimcore\Controller\KernelControllerEventInterface;
use Pimcore\Controller\Traits\JsonHelperTrait;
use Pimcore\Controller\UserAwareController;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
Expand All @@ -35,10 +37,15 @@
*
* @internal
*/
class IndexController extends UserAwareController
class IndexController extends UserAwareController implements KernelControllerEventInterface
{
use JsonHelperTrait;

public function onKernelControllerEvent(ControllerEvent $event): void
{
$this->checkPermission('bundle_ecommerce_back-office_order');
}

/**
* @Route("/get-filter-groups", name="pimcore_ecommerceframework_index_getfiltergroups", methods={"GET"})
*
Expand Down
5 changes: 1 addition & 4 deletions src/Controller/PricingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ class PricingController extends UserAwareController implements KernelControllerE
public function onKernelControllerEvent(ControllerEvent $event): void
{
// permission check
$access = $this->getPimcoreUser()->isAllowed('bundle_ecommerce_pricing_rules');
if (!$access) {
throw new \Exception('this function requires "bundle_ecommerce_pricing_rules" permission!');
}
$this->checkPermission('bundle_ecommerce_pricing_rules');
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Controller/VoucherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
namespace Pimcore\Bundle\EcommerceFrameworkBundle\Controller;

use Pimcore\Bundle\EcommerceFrameworkBundle\VoucherService\TokenManager\ExportableTokenManagerInterface;
use Pimcore\Controller\FrontendController;
use Pimcore\Controller\KernelControllerEventInterface;
use Pimcore\Controller\UserAwareController;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\Localizedfield;
use Pimcore\Model\DataObject\OnlineShopVoucherSeries;
Expand All @@ -37,7 +37,7 @@
*
* @internal
*/
class VoucherController extends FrontendController implements KernelControllerEventInterface
class VoucherController extends UserAwareController implements KernelControllerEventInterface
{
protected TokenStorageUserResolver $tokenResolver;

Expand All @@ -55,6 +55,8 @@ public function __construct(TokenStorageUserResolver $tokenStorageUserResolver,

public function onKernelControllerEvent(ControllerEvent $event): void
{
$this->checkPermission('bundle_ecommerce_pricing_rules');

// set language
$user = $this->tokenResolver->getUser();

Expand Down

0 comments on commit 997a097

Please sign in to comment.