Skip to content

Commit

Permalink
[Pimcore 11] Exclude AdminBundle (#51)
Browse files Browse the repository at this point in the history
* Adapt decoupling admin bundle

* Change return values and getAdminUser to getPimcoreUser

* Remove Admin from bundles

* Add more conflicting bundles

* Apply CR changes

* Add google-marketing-bundle to conflicting

* Readd firewall, and adding admin to trans

* re-enable admin bundle for tests

---------

Co-authored-by: Divesh Pahuja <[email protected]>
  • Loading branch information
mattamon and dvesh3 authored Apr 26, 2023
1 parent fa4c987 commit 70ceb47
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 85 deletions.
37 changes: 6 additions & 31 deletions .github/ci/files/config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,21 @@ security:

providers:
pimcore_admin:
id: Pimcore\Bundle\AdminBundle\Security\User\UserProvider
id: Pimcore\Security\User\UserProvider

firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false

# Pimcore WebDAV HTTP basic // DO NOT CHANGE!
pimcore_admin_webdav:
pattern: ^/admin/asset/webdav
pimcore_webdav:
pattern: ^/asset/webdav
provider: pimcore_admin
http_basic: ~

# Pimcore admin form login // DO NOT CHANGE!
pimcore_admin:
pattern: ^/admin(/.*)?$
user_checker: Pimcore\Bundle\AdminBundle\Security\User\UserChecker
provider: pimcore_admin
login_throttling:
max_attempts: 3
interval: '5 minutes'
logout:
path: pimcore_admin_logout
target: pimcore_admin_login
form_login:
default_target_path: pimcore_admin_index
always_use_default_target_path: true
login_path: pimcore_admin_login
check_path: pimcore_admin_login_check
username_parameter: username
password_parameter: password
custom_authenticators:
- Pimcore\Bundle\AdminBundle\Security\Authenticator\AdminTokenAuthenticator
two_factor:
auth_form_path: /admin/login/2fa # Path or route name of the two-factor form
check_path: /admin/login/2fa-verify # Path or route name of the two-factor code check
default_target_path: /admin # Where to redirect by default after successful authentication
always_use_default_target_path: false # If it should always redirect to default_target_path
auth_code_parameter_name: _auth_code # Name of the parameter for the two-factor authentication code
trusted_parameter_name: _trusted # Name of the parameter for the trusted device option
multi_factor: false # If ALL active two-factor methods need to be fulfilled (multi-factor authentication)
# Pimcore Admin Bundle firewall
pimcore_admin: '%pimcore_admin_bundle.firewall_settings%'

access_control:
# Pimcore admin ACl // DO NOT CHANGE!
Expand All @@ -54,6 +28,7 @@ security:
- { path: ^/admin/login$, roles: PUBLIC_ACCESS }
- { path: ^/admin/login/(login|lostpassword|deeplink|csrf-token)$, roles: PUBLIC_ACCESS }
- { path: ^/admin, roles: ROLE_PIMCORE_USER }
- { path: ^/asset/webdav, roles: ROLE_PIMCORE_USER }

role_hierarchy:
# Pimcore admin // DO NOT CHANGE!
Expand Down
7 changes: 1 addition & 6 deletions .github/ci/files/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,4 @@ pimcore:
filter_priority: null
mail_receiver: ''
archive_treshold: '30'
archive_alternative_database: ''
pimcore_admin:
branding:
color_login_screen: ''
color_admin_interface: ''
login_screen_custom_image: ''
archive_alternative_database: ''
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"require": {
"php": "~8.1.0 || ~8.2.0",
"pimcore/pimcore": "^11.0",
"pimcore/admin-ui-classic-bundle": "^1.0",
"pimcore/personalization-bundle": "^1.0",
"pimcore/google-marketing-bundle": "^1.0",
"knplabs/knp-paginator-bundle": "^6.0.0",
Expand All @@ -35,6 +34,13 @@
"elasticsearch/elasticsearch": "^8.0",
"pimcore/elasticsearch-client": "^1.0.0"
},
"conflict": {
"pimcore/pimcore": "v11.0.0-ALPHA1 || v11.0.0-ALPHA2 || v11.0.0-ALPHA3 || v11.0.0-ALPHA4 || v11.0.0-ALPHA5 || v11.0.0-ALPHA6 || v11.0.0-ALPHA7 || v11.0.0-ALPHA8 || v11.0.0-BETA1",
"pimcore/admin-ui-classic-bundle": "v1.0.0-BETA1",
"pimcore/personalization-bundle": "v1.0.0-BETA1",
"pimcore/google-marketing-bundle": "v1.0.0-BETA1",
"pimcore/newsletter-bundle": "v1.0.0-BETA1"
},
"suggest": {
"elasticsearch/elasticsearch": "Required for Elastic Search service",
"webmozarts/console-parallelization": "Required for parallelization of console commands"
Expand Down
9 changes: 7 additions & 2 deletions src/Controller/AdminOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use GuzzleHttp\ClientInterface;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Pimcore\Bundle\AdminBundle\Security\CsrfProtectionHandler;
use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Bundle\EcommerceFrameworkBundle\Model\AbstractOrder;
Expand All @@ -32,6 +31,7 @@
use Pimcore\Bundle\EcommerceFrameworkBundle\PaymentManager\PaymentManagerInterface;
use Pimcore\Cache;
use Pimcore\Controller\KernelControllerEventInterface;
use Pimcore\Controller\UserAwareController;
use Pimcore\Localization\IntlFormatter;
use Pimcore\Localization\LocaleServiceInterface;
use Pimcore\Model\DataObject;
Expand All @@ -46,6 +46,7 @@
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\LocaleAwareInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Class AdminOrderController
Expand All @@ -55,12 +56,16 @@
* @Route("/admin-order")
*
*/
class AdminOrderController extends AdminController implements KernelControllerEventInterface
class AdminOrderController extends UserAwareController implements KernelControllerEventInterface
{
protected OrderManagerInterface $orderManager;

protected PaymentManagerInterface $paymentManager;

public function __construct(protected TranslatorInterface $translator)
{
}

public function onKernelControllerEvent(ControllerEvent $event): void
{
// set language
Expand Down
8 changes: 3 additions & 5 deletions src/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Pimcore\Bundle\EcommerceFrameworkBundle\Controller;

use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Pimcore\Controller\UserAwareController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
Expand All @@ -28,16 +28,14 @@
*
* @internal
*/
class ConfigController extends AdminController
class ConfigController extends UserAwareController
{
private RouterInterface $router;

/**
* ConfigController constructor.
*
* @param RouterInterface $router
*/
public function __construct(RouterInterface $router)
public function __construct(private RouterInterface $router)
{
$this->router = $router;
}
Expand Down
44 changes: 25 additions & 19 deletions src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

namespace Pimcore\Bundle\EcommerceFrameworkBundle\Controller;

use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Pimcore\Bundle\EcommerceFrameworkBundle\Event\AdminEvents;
use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\ProductList\ProductListInterface;
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\Routing\Annotation\Route;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Class IndexController
Expand All @@ -32,14 +35,16 @@
*
* @internal
*/
class IndexController extends AdminController
class IndexController extends UserAwareController
{
use JsonHelperTrait;

/**
* @Route("/get-filter-groups", name="pimcore_ecommerceframework_index_getfiltergroups", methods={"GET"})
*
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @return JsonResponse
*/
public function getFilterGroupsAction(): \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
public function getFilterGroupsAction(): JsonResponse
{
$indexService = Factory::getInstance()->getIndexService();
$tenants = Factory::getInstance()->getAllTenants();
Expand All @@ -59,13 +64,13 @@ public function getFilterGroupsAction(): \Pimcore\Bundle\AdminBundle\HttpFoundat
}
}

return $this->adminJson(['data' => array_values($data)]);
return $this->jsonResponse(['data' => array_values($data)]);
}

/**
* @Route("/get-values-for-filter-field", name="pimcore_ecommerceframework_index_getvaluesforfilterfield", methods={"GET"})
*/
public function getValuesForFilterFieldAction(Request $request, EventDispatcherInterface $eventDispatcher): \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
public function getValuesForFilterFieldAction(Request $request, EventDispatcherInterface $eventDispatcher): JsonResponse
{
try {
$data = [];
Expand Down Expand Up @@ -102,9 +107,9 @@ public function getValuesForFilterFieldAction(Request $request, EventDispatcherI
$eventDispatcher->dispatch($event, AdminEvents::GET_VALUES_FOR_FILTER_FIELD_PRE_SEND_DATA);
$data = $event->getArgument('data');

return $this->adminJson(['data' => array_values($data)]);
return $this->jsonResponse(['data' => array_values($data)]);
} catch (\Exception $e) {
return $this->adminJson(['message' => $e->getMessage()]);
return $this->jsonResponse(['message' => $e->getMessage()]);
}
}

Expand All @@ -113,10 +118,10 @@ public function getValuesForFilterFieldAction(Request $request, EventDispatcherI
*
* @param Request $request
* @param EventDispatcherInterface $eventDispatcher
*
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @param TranslatorInterface $translator
* @return JsonResponse
*/
public function getFieldsAction(Request $request, EventDispatcherInterface $eventDispatcher): \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
public function getFieldsAction(Request $request, EventDispatcherInterface $eventDispatcher, TranslatorInterface $translator): JsonResponse
{
$indexService = Factory::getInstance()->getIndexService();

Expand All @@ -142,17 +147,17 @@ public function getFieldsAction(Request $request, EventDispatcherInterface $even
$fields = [];

if ($request->get('add_empty') == 'true') {
$fields[' '] = ['key' => '', 'name' => '(' . $this->trans('empty', [], 'messages') . ')'];
$fields[' '] = ['key' => '', 'name' => '(' . $translator->trans('empty', [], 'messages') . ')'];
}

foreach ($indexColumns as $c) {
$fields[$c] = ['key' => $c, 'name' => $this->trans($c)];
$fields[$c] = ['key' => $c, 'name' => $translator->trans($c, [], 'admin')];
}

if ($request->get('specific_price_field') == 'true') {
$fields[ProductListInterface::ORDERKEY_PRICE] = [
'key' => ProductListInterface::ORDERKEY_PRICE,
'name' => $this->trans(ProductListInterface::ORDERKEY_PRICE),
'name' => $translator->trans(ProductListInterface::ORDERKEY_PRICE, [], 'admin'),
];
}

Expand All @@ -162,25 +167,26 @@ public function getFieldsAction(Request $request, EventDispatcherInterface $even
$eventDispatcher->dispatch($event, AdminEvents::GET_INDEX_FIELD_NAMES_PRE_SEND_DATA);
$data = $event->getArgument('data');

return $this->adminJson(['data' => array_values($data)]);
return $this->jsonResponse(['data' => array_values($data)]);
}

/**
* @Route("/get-all-tenants", name="pimcore_ecommerceframework_index_getalltenants", methods={"GET"})
*
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @param TranslatorInterface $translator
* @return JsonResponse
*/
public function getAllTenantsAction(): \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
public function getAllTenantsAction(TranslatorInterface $translator): JsonResponse
{
$tenants = Factory::getInstance()->getAllTenants();
$data = [];

if ($tenants) {
foreach ($tenants as $tenant) {
$data[] = ['key' => $tenant, 'name' => $this->trans($tenant)];
$data[] = ['key' => $tenant, 'name' => $translator->trans($tenant, [], 'admin')];
}
}

return $this->adminJson(['data' => $data]);
return $this->jsonResponse(['data' => $data]);
}
}
Loading

0 comments on commit 70ceb47

Please sign in to comment.