From 33a1404e8a921d955344a8990e9d4af41ac4e78e Mon Sep 17 00:00:00 2001 From: Divesh Pahuja Date: Mon, 24 Apr 2023 16:35:58 +0200 Subject: [PATCH] Adapt admin bundle refactorings (#87) * Adapt admin bundle refactorings - related to https://github.com/pimcore/pimcore/pull/14971 * DI translator service * Update composer.json * add conflict for alpha & beta --- .../ci/files/config/packages/security.yaml | 37 ++---------- composer.json | 3 + src/Controller/AdminController.php | 60 +++++++++++-------- src/Controller/ClassController.php | 10 +++- src/OutputDataConfigToolkitBundle.php | 8 +-- 5 files changed, 55 insertions(+), 63 deletions(-) diff --git a/.github/ci/files/config/packages/security.yaml b/.github/ci/files/config/packages/security.yaml index e99bd82..3923c52 100644 --- a/.github/ci/files/config/packages/security.yaml +++ b/.github/ci/files/config/packages/security.yaml @@ -3,7 +3,7 @@ security: providers: pimcore_admin: - id: Pimcore\Bundle\AdminBundle\Security\User\UserProvider + id: Pimcore\Security\User\UserProvider firewalls: dev: @@ -11,39 +11,13 @@ security: 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! @@ -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! diff --git a/composer.json b/composer.json index ac7661b..96ab537 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,9 @@ "symfony/templating": "^6.2", "pimcore/ecommerce-framework-bundle": "^1.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" + }, "require-dev": { "phpstan/phpstan": "^1.10.5", "phpstan/phpstan-symfony": "^1.2.20" diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index d452e70..f64ed2b 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -20,22 +20,32 @@ use OutputDataConfigToolkitBundle\Event\SaveConfigEvent; use OutputDataConfigToolkitBundle\OutputDefinition; use OutputDataConfigToolkitBundle\Service; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; use Pimcore\Logger; use Pimcore\Model\DataObject\AbstractObject; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\DataObject\Classificationstore\KeyConfig; use Pimcore\Model\DataObject\Objectbrick\Definition; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Contracts\Translation\TranslatorInterface; /** * Class AdminController * * @Route("/admin") */ -class AdminController extends \Pimcore\Bundle\AdminBundle\Controller\AdminController +class AdminController extends UserAwareController { + use JsonHelperTrait; + + public function __construct(protected TranslatorInterface $translator) + { + } + /* @var string[] $defaultGridClasses */ private $defaultGridClasses = []; @@ -45,7 +55,7 @@ class AdminController extends \Pimcore\Bundle\AdminBundle\Controller\AdminContro /** * @param Request $request * - * @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse + * @return JsonResponse * * @Route("/initialize") */ @@ -55,7 +65,7 @@ public function initializeAction(Request $request, EventDispatcherInterface $eve $object = AbstractObject::getById($objectId); if (!$object) { - $this->adminJson(['error' => true, 'object' => (object)[]]); + $this->jsonResponse(['error' => true, 'object' => (object)[]]); } $event = new InitializeEvent($object); @@ -63,18 +73,18 @@ public function initializeAction(Request $request, EventDispatcherInterface $eve if ($event->getHideConfigTab()) { // do not show output config tab - return $this->adminJson(['success' => true, 'object' => false]); + return $this->jsonResponse(['success' => true, 'object' => false]); } $data = ['id' => $event->getObject()->getId()]; - return $this->adminJson(['success' => true, 'object' => $data]); + return $this->jsonResponse(['success' => true, 'object' => $data]); } /** * @param Request $request * - * @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse + * @return JsonResponse * * @Route("/get-output-configs") */ @@ -109,7 +119,7 @@ public function getOutputConfigsAction(Request $request) } } - return $this->adminJson(['success' => true, 'data' => $outputDefinitions]); + return $this->jsonResponse(['success' => true, 'data' => $outputDefinitions]); } /** @@ -135,7 +145,7 @@ private function getOutputDefinitionForObjectAndChannel($object, $classId, $chan /** * @param Request $request * - * @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse + * @return JsonResponse * * @Route("/reset-output-config") */ @@ -145,18 +155,18 @@ public function resetOutputConfigAction(Request $request) $config = OutputDefinition::getByID($request->get('config_id')); $config->delete(); - return $this->adminJson(['success' => true]); + return $this->jsonResponse(['success' => true]); } catch (\Exception $e) { Logger::err($e->getMessage()); - return $this->adminJson(['success' => false, 'message' => $e->getMessage()]); + return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]); } } /** * @param Request $request * - * @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse + * @return JsonResponse * * @Route("/get-output-config") */ @@ -171,18 +181,18 @@ public function getOutputConfigAction(Request $request) $config->setConfiguration($configuration); - return $this->adminJson(['success' => true, 'outputConfig' => $config]); + return $this->jsonResponse(['success' => true, 'outputConfig' => $config]); } catch (\Exception $e) { Logger::err($e); - return $this->adminJson(['success' => false, 'message' => $e->getMessage()]); + return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]); } } /** * @param Request $request * - * @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse + * @return JsonResponse * * @Route("/get-or-create-output-config") */ @@ -210,7 +220,7 @@ public function getOrCreateOutputConfigAction(Request $request) $configuration = $this->doGetAttributeLabels($configuration, $objectClass); $config->setConfiguration($configuration); - return $this->adminJson(['success' => true, 'outputConfig' => $config]); + return $this->jsonResponse(['success' => true, 'outputConfig' => $config]); } else { $config = new OutputDefinition(); $config->setChannel($request->get('channel')); @@ -218,12 +228,12 @@ public function getOrCreateOutputConfigAction(Request $request) $config->setObjectId($request->get('o_id')); $config->save(); - return $this->adminJson(['success' => true, 'outputConfig' => $config]); + return $this->jsonResponse(['success' => true, 'outputConfig' => $config]); } } catch (\Exception $e) { Logger::err($e->getMessage()); - return $this->adminJson(['success' => false, 'message' => $e->getMessage()]); + return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]); } } @@ -284,7 +294,7 @@ private function sortAttributes(array &$attributes) /** * @param Request $request * - * @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse + * @return JsonResponse * * @Route("/get-attribute-labels") */ @@ -295,7 +305,7 @@ public function getAttributeLabelsAction(Request $request) $configration = $this->doGetAttributeLabels($configration, $class); - return $this->adminJson(['configuration' => $configration]); + return $this->jsonResponse(['configuration' => $configration]); } /** @@ -374,7 +384,7 @@ private function getFieldDefinition($attributeName, $objectClass) * @param Request $request * @Route("/get-field-definition") * - * @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse + * @return JsonResponse */ public function getFieldDefinitionAction(Request $request) { @@ -382,11 +392,11 @@ public function getFieldDefinitionAction(Request $request) $objectClass = ClassDefinition::getById($request->get('class_id')); $def = $this->getFieldDefinition($request->get('key'), $objectClass); - return $this->adminJson(['success' => true, 'fieldDefinition' => $def]); + return $this->jsonResponse(['success' => true, 'fieldDefinition' => $def]); } catch (\Exception $e) { Logger::err($e->getMessage()); - return $this->adminJson(['success' => false, 'message' => $e->getMessage()]); + return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]); } } @@ -394,7 +404,7 @@ public function getFieldDefinitionAction(Request $request) * @param Request $request * @Route("/save-output-config") * - * @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse + * @return JsonResponse */ public function saveOutputConfigAction(Request $request, EventDispatcherInterface $eventDispatcher) { @@ -428,11 +438,11 @@ public function saveOutputConfigAction(Request $request, EventDispatcherInterfac } $config->save(); - return $this->adminJson(['success' => true]); + return $this->jsonResponse(['success' => true]); } catch (\Exception $e) { Logger::err($e->getMessage()); - return $this->adminJson(['success' => false, 'message' => $e->getMessage()]); + return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]); } } diff --git a/src/Controller/ClassController.php b/src/Controller/ClassController.php index d42f766..ec4a299 100644 --- a/src/Controller/ClassController.php +++ b/src/Controller/ClassController.php @@ -17,10 +17,12 @@ use Doctrine\DBAL\Exception\TableNotFoundException; use OutputDataConfigToolkitBundle\Constant\ColumnConfigDisplayMode; -use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; use Pimcore\Db; use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\Classificationstore; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; @@ -30,8 +32,10 @@ * @package OutputDataConfigToolkitBundle\Controller * */ -class ClassController extends \Pimcore\Bundle\AdminBundle\Controller\AdminController +class ClassController extends UserAwareController { + use JsonHelperTrait; + /* @var string $classificationDisplayMode */ protected $classificationDisplayMode; @@ -101,7 +105,7 @@ public function getClassDefinitionForColumnConfigAction(Request $request) $this->considerClassificationStoreForColumnConfig($request, $class, $fieldDefinitions, $result); - return $this->adminJson($result); + return $this->jsonResponse($result); } /** diff --git a/src/OutputDataConfigToolkitBundle.php b/src/OutputDataConfigToolkitBundle.php index 61f70fe..5250988 100644 --- a/src/OutputDataConfigToolkitBundle.php +++ b/src/OutputDataConfigToolkitBundle.php @@ -16,14 +16,14 @@ namespace OutputDataConfigToolkitBundle; use OutputDataConfigToolkitBundle\Tools\Installer; -use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait; -use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; +use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface; +use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; -class OutputDataConfigToolkitBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminSupportInterface +class OutputDataConfigToolkitBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface { - use BundleAdminSupportTrait; + use BundleAdminClassicTrait; use PackageVersionTrait; protected function getComposerPackageName(): string