From 976ccbbe039a6d93eef062cfab6b4a1d5abc6a2f Mon Sep 17 00:00:00 2001 From: Divesh Pahuja Date: Mon, 24 Apr 2023 15:47:08 +0200 Subject: [PATCH] [Pimcore 11] Decouple AdminBundle from the Core (#14971) * [Pimcore 11] Decouple AdminBundle from the Core - follow up to https://github.com/pimcore/pimcore/pull/14918 * Fix Core Bundles & Security classes * require dev branch (temproray) of admin ui classic bundle * Make Core bundles implement PimcoreBundleAdminClassicInterface * Further decoupling * Fix tests * Further decoupling * Further decoupling * check disabling admin bundle * Fix stan issues * Move Admin Listeners to admin-classic.yaml * Add ignore again and void to method * Extend phpstand-baseline.neon and phpstan-parameters.neon * Revert unrelated changes * Refactor initializing system settings for tests * Adding void return type * Remove line from baseline.neon * Add interface * Extract AdminBundle tests from core. * extract testAddGridFeatureJoinsWithTwoFilters into AdminBundle. * Fix tests * Fix tests * Fix phpstan baseline - remove ignored errors * cleanup phpstan baseline * review changes * fix phpstan baseline * Fix docs related to bundle support interface & trait --------- Co-authored-by: mattamon Co-authored-by: Martin Eiber --- .github/ci/files/config/config.yaml | 7 - .../ci/files/config/packages/security.yaml | 33 +- .github/ci/files/src/Kernel.php | 1 - .../ci/scripts/setup-pimcore-environment.sh | 2 - .../Controller/AdminAbstractController.php | 46 --- .../config/authenticator_security.yaml | 3 - .../default.yaml => admin-classic.yaml} | 0 .../config/pimcore/config.yaml | 5 +- .../src/Controller/LogController.php | 35 +- .../PimcoreApplicationLoggerExtension.php | 16 +- .../src/PimcoreApplicationLoggerBundle.php | 8 +- bundles/CoreBundle/config/pimcore/config.yaml | 3 +- .../security.yaml} | 0 bundles/CoreBundle/config/routing.yaml | 6 +- bundles/CoreBundle/config/services.yaml | 13 +- .../src/Controller/WebDavController.php | 2 +- .../Compiler/SerializerPass.php | 2 +- .../default.yaml => admin-classic.yaml} | 11 + .../config/pimcore/config.yaml | 3 - .../CustomReportsBundle/config/services.yaml | 3 - .../Reports/CustomReportController.php | 40 ++- .../PimcoreCustomReportsExtension.php | 9 + .../src/PimcoreCustomReportsBundle.php | 8 +- .../GlossaryBundle/config/admin-classic.yaml | 8 + .../config/pimcore/default.yaml | 9 - .../src/Controller/SettingsController.php | 26 +- .../PimcoreGlossaryExtension.php | 15 +- .../src/PimcoreGlossaryBundle.php | 8 +- bundles/SeoBundle/config/admin-classic.yaml | 18 + bundles/SeoBundle/config/pimcore/default.yaml | 19 - .../Document/DocumentController.php | 23 +- .../src/Controller/MiscController.php | 11 +- .../src/Controller/RedirectsController.php | 34 +- .../src/Controller/SettingsController.php | 11 +- .../Traits/DocumentTreeConfigWrapperTrait.php | 41 +++ .../PimcoreSeoExtension.php | 15 +- bundles/SeoBundle/src/PimcoreSeoBundle.php | 8 +- .../config/admin-classic.yaml | 27 ++ .../config/pimcore/config.yaml | 2 +- .../config/pimcore/default.yaml | 11 +- .../config/services.yaml | 15 +- .../src/Controller/DataObjectController.php | 4 +- .../src/Controller/SearchController.php | 91 ++++- .../PimcoreSimpleBackendSearchExtension.php | 15 +- .../src/PimcoreSimpleBackendSearchBundle.php | 8 +- .../config/admin-classic.yaml | 11 + .../StaticRoutesBundle/config/services.yaml | 10 +- .../src/Controller/SettingsController.php | 17 +- .../PimcoreStaticRoutesExtension.php | 9 + .../src/PimcoreStaticRoutesBundle.php | 8 +- .../src/PimcoreTinymceBundle.php | 8 +- .../src/Controller/TranslationController.php | 15 +- .../src/PimcoreWordExportBundle.php | 8 +- .../Controller/XliffTranslationController.php | 15 +- .../XliffBundle/src/PimcoreXliffBundle.php | 8 +- .../05_Accessing_Assets_via_WebDAV.md | 2 +- .../07_Users_and_Roles.md | 2 +- .../09_Upgrade_Notes/README.md | 10 +- lib/Controller/Traits/JsonHelperTrait.php | 2 +- lib/Controller/UserAwareController.php | 49 +-- lib/Event/ElementEvents.php | 35 ++ .../AdminClassicBundleNotFoundException.php | 21 ++ lib/Extension/Bundle/PimcoreBundleManager.php | 2 +- .../BundleAdminClassicTrait.php} | 2 +- .../Handler/CleanupThumbnailsHandler.php | 1 + lib/Messenger/Handler/SanityCheckHandler.php | 1 + .../Hasher/PimcoreUserPasswordHasher.php | 2 +- .../User/TokenStorageUserResolver.php | 2 +- lib/Security/User/UserProvider.php | 42 +-- lib/Tool.php | 16 - lib/Twig/Extension/Templating/HeadScript.php | 11 +- .../Data/Classificationstore.php | 4 +- .../ClassDefinition/Data/Localizedfields.php | 2 +- .../ClassDefinition/Data/Objectbricks.php | 2 +- models/DataObject/Service.php | 6 +- models/Element/AbstractElement.php | 6 +- models/Element/Service.php | 21 -- phpstan-baseline.neon | 133 ++++++- phpstan-parameters.neon | 5 + .../ClassificationStore/GeneralTest.php | 88 ----- .../Permissions/ModelAssetPermissionsTest.php | 176 +--------- .../ModelDataObjectPermissionsTest.php | 328 +----------------- .../ModelDocumentPermissionsTest.php | 177 +--------- .../Helper/AbstractDefinitionHelper.php | 6 - tests/Support/Helper/Pimcore.php | 22 ++ tests/Unit.suite.dist.yml | 5 +- 86 files changed, 743 insertions(+), 1222 deletions(-) delete mode 100644 bundles/AdminBundle/Controller/AdminAbstractController.php delete mode 100644 bundles/AdminBundle/Resources/config/authenticator_security.yaml rename bundles/ApplicationLoggerBundle/config/{pimcore/default.yaml => admin-classic.yaml} (100%) rename bundles/CoreBundle/config/{authenticator_security.yaml => pimcore/security.yaml} (100%) rename bundles/CustomReportsBundle/config/{pimcore/default.yaml => admin-classic.yaml} (51%) create mode 100644 bundles/GlossaryBundle/config/admin-classic.yaml create mode 100644 bundles/SeoBundle/config/admin-classic.yaml create mode 100644 bundles/SeoBundle/src/Controller/Traits/DocumentTreeConfigWrapperTrait.php create mode 100644 bundles/SimpleBackendSearchBundle/config/admin-classic.yaml create mode 100644 bundles/StaticRoutesBundle/config/admin-classic.yaml create mode 100644 lib/Event/ElementEvents.php create mode 100644 lib/Extension/Bundle/Exception/AdminClassicBundleNotFoundException.php rename lib/Extension/Bundle/{BundleAdminClassicSupportTrait.php => Traits/BundleAdminClassicTrait.php} (94%) diff --git a/.github/ci/files/config/config.yaml b/.github/ci/files/config/config.yaml index 7ab5ae36fda..969863cb486 100644 --- a/.github/ci/files/config/config.yaml +++ b/.github/ci/files/config/config.yaml @@ -41,10 +41,3 @@ pimcore: type: 'settings-store' read_target: type: 'settings-store' -pimcore_admin: - config_location: - admin_system_settings: - write_target: - type: 'settings-store' - read_target: - type: 'settings-store' \ No newline at end of file diff --git a/.github/ci/files/config/packages/security.yaml b/.github/ci/files/config/packages/security.yaml index a34169bc2c1..7dea2c6ba00 100644 --- a/.github/ci/files/config/packages/security.yaml +++ b/.github/ci/files/config/packages/security.yaml @@ -11,40 +11,11 @@ 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\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) - access_control: # Pimcore admin ACl // DO NOT CHANGE! - { path: ^/admin/settings/display-custom-logo, roles: PUBLIC_ACCESS } diff --git a/.github/ci/files/src/Kernel.php b/.github/ci/files/src/Kernel.php index 5f58c5d7b11..22e0a8baee4 100644 --- a/.github/ci/files/src/Kernel.php +++ b/.github/ci/files/src/Kernel.php @@ -31,7 +31,6 @@ class Kernel extends BaseKernel public function registerBundlesToCollection(BundleCollection $collection): void { // pimcore bundles - $collection->addBundle(new PimcoreAdminBundle(), 60); } } diff --git a/.github/ci/scripts/setup-pimcore-environment.sh b/.github/ci/scripts/setup-pimcore-environment.sh index 11a35cb5c33..b319acb56d3 100755 --- a/.github/ci/scripts/setup-pimcore-environment.sh +++ b/.github/ci/scripts/setup-pimcore-environment.sh @@ -16,5 +16,3 @@ if [ ${PIMCORE_STORAGE:-local} = "minio" ]; then cp .github/ci/files/minio-flysystem.yaml config/local/ composer require -n --no-update league/flysystem-aws-s3-v3 fi - -composer require -n --no-update pimcore/admin-ui-classic-bundle:"@dev" diff --git a/bundles/AdminBundle/Controller/AdminAbstractController.php b/bundles/AdminBundle/Controller/AdminAbstractController.php deleted file mode 100644 index 2877eac5160..00000000000 --- a/bundles/AdminBundle/Controller/AdminAbstractController.php +++ /dev/null @@ -1,46 +0,0 @@ -jsonResponse($data, $status, $headers, $context, $useAdminSerializer); - } - - /** - * Get user from user proxy object which is registered on security component - */ - protected function getAdminUser(bool $proxyUser = false): UserProxy|User|null - { - return $this->getPimcoreUser($proxyUser); - } -} diff --git a/bundles/AdminBundle/Resources/config/authenticator_security.yaml b/bundles/AdminBundle/Resources/config/authenticator_security.yaml deleted file mode 100644 index b68dde96393..00000000000 --- a/bundles/AdminBundle/Resources/config/authenticator_security.yaml +++ /dev/null @@ -1,3 +0,0 @@ -scheb_two_factor: - security_tokens: - - Pimcore\Bundle\AdminBundle\Security\Authentication\Token\TwoFactorRequiredToken diff --git a/bundles/ApplicationLoggerBundle/config/pimcore/default.yaml b/bundles/ApplicationLoggerBundle/config/admin-classic.yaml similarity index 100% rename from bundles/ApplicationLoggerBundle/config/pimcore/default.yaml rename to bundles/ApplicationLoggerBundle/config/admin-classic.yaml diff --git a/bundles/ApplicationLoggerBundle/config/pimcore/config.yaml b/bundles/ApplicationLoggerBundle/config/pimcore/config.yaml index ddd36977a7a..54b93cddcde 100644 --- a/bundles/ApplicationLoggerBundle/config/pimcore/config.yaml +++ b/bundles/ApplicationLoggerBundle/config/pimcore/config.yaml @@ -1,6 +1,3 @@ -imports: - - { resource: default.yaml } - flysystem: storages: pimcore.application_log.storage: @@ -9,4 +6,4 @@ flysystem: visibility: private options: # TODO: revert default to `var/application-logger` when PIMCORE_LOG_FILEOBJECT_DIRECTORY is deprecated - directory: "%log.fileobject%" \ No newline at end of file + directory: "%log.fileobject%" diff --git a/bundles/ApplicationLoggerBundle/src/Controller/LogController.php b/bundles/ApplicationLoggerBundle/src/Controller/LogController.php index 6a3e0199428..416a12e44be 100644 --- a/bundles/ApplicationLoggerBundle/src/Controller/LogController.php +++ b/bundles/ApplicationLoggerBundle/src/Controller/LogController.php @@ -19,10 +19,10 @@ use Carbon\Carbon; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Types\Types; -use Pimcore\Bundle\AdminBundle\Controller\AdminAbstractController; -use Pimcore\Bundle\AdminBundle\Helper\QueryParams; use Pimcore\Bundle\ApplicationLoggerBundle\Handler\ApplicationLoggerDb; use Pimcore\Controller\KernelControllerEventInterface; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; use Pimcore\Tool\Storage; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -35,11 +35,13 @@ /** * @internal */ -class LogController extends AdminAbstractController implements KernelControllerEventInterface +class LogController extends UserAwareController implements KernelControllerEventInterface { + use JsonHelperTrait; + public function onKernelControllerEvent(ControllerEvent $event): void { - if (!$this->getAdminUser()->isAllowed('application_logging')) { + if (!$this->getPimcoreUser()->isAllowed('application_logging')) { throw new AccessDeniedHttpException("Permission denied, user needs 'application_logging' permission."); } } @@ -60,17 +62,20 @@ public function showAction(Request $request, Connection $db): JsonResponse ->setFirstResult($request->get('start', 0)) ->setMaxResults($request->get('limit', 50)); - $sortingSettings = QueryParams::extractSortingSettings(array_merge( - $request->request->all(), - $request->query->all() - )); + $qb->orderBy('id', 'DESC'); - if ($sortingSettings['orderKey']) { - $qb->orderBy($sortingSettings['orderKey'], $sortingSettings['order']); - } else { - $qb->orderBy('id', 'DESC'); + if (class_exists(\Pimcore\Bundle\AdminBundle\Helper\QueryParams::class)) { + $sortingSettings = \Pimcore\Bundle\AdminBundle\Helper\QueryParams::extractSortingSettings(array_merge( + $request->request->all(), + $request->query->all() + )); + + if ($sortingSettings['orderKey']) { + $qb->orderBy($sortingSettings['orderKey'], $sortingSettings['order']); + } } + $priority = $request->get('priority'); if ($priority !== '-1' && ($priority == '0' || $priority)) { $levels = []; @@ -149,7 +154,7 @@ public function showAction(Request $request, Connection $db): JsonResponse $logEntries[] = $logEntry; } - return $this->adminJson([ + return $this->jsonResponse([ 'p_totalCount' => $total, 'p_results' => $logEntries, ]); @@ -191,7 +196,7 @@ public function priorityJsonAction(Request $request): JsonResponse $priorities[] = ['key' => $key, 'value' => $p]; } - return $this->adminJson(['priorities' => $priorities]); + return $this->jsonResponse(['priorities' => $priorities]); } /** @@ -210,7 +215,7 @@ public function componentJsonAction(Request $request): JsonResponse $components[] = ['key' => $p, 'value' => $p]; } - return $this->adminJson(['components' => $components]); + return $this->jsonResponse(['components' => $components]); } /** diff --git a/bundles/ApplicationLoggerBundle/src/DependencyInjection/PimcoreApplicationLoggerExtension.php b/bundles/ApplicationLoggerBundle/src/DependencyInjection/PimcoreApplicationLoggerExtension.php index 3f926b1e9eb..14b5b455a1c 100644 --- a/bundles/ApplicationLoggerBundle/src/DependencyInjection/PimcoreApplicationLoggerExtension.php +++ b/bundles/ApplicationLoggerBundle/src/DependencyInjection/PimcoreApplicationLoggerExtension.php @@ -17,10 +17,12 @@ namespace Pimcore\Bundle\ApplicationLoggerBundle\DependencyInjection; use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -class PimcoreApplicationLoggerExtension extends Extension +class PimcoreApplicationLoggerExtension extends Extension implements PrependExtensionInterface { public function load(array $configs, \Symfony\Component\DependencyInjection\ContainerBuilder $container): void { @@ -31,4 +33,16 @@ public function load(array $configs, \Symfony\Component\DependencyInjection\Cont $loader->load('services.yaml'); } + + public function prepend(ContainerBuilder $container): void + { + if ($container->hasExtension('pimcore_admin')) { + $loader = new YamlFileLoader( + $container, + new FileLocator(__DIR__ . '/../../config') + ); + + $loader->load('admin-classic.yaml'); + } + } } diff --git a/bundles/ApplicationLoggerBundle/src/PimcoreApplicationLoggerBundle.php b/bundles/ApplicationLoggerBundle/src/PimcoreApplicationLoggerBundle.php index 9f5c53e58d8..1941dc6e7d3 100644 --- a/bundles/ApplicationLoggerBundle/src/PimcoreApplicationLoggerBundle.php +++ b/bundles/ApplicationLoggerBundle/src/PimcoreApplicationLoggerBundle.php @@ -16,14 +16,14 @@ namespace Pimcore\Bundle\ApplicationLoggerBundle; -use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait; -use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; +use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait; +use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; -class PimcoreApplicationLoggerBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminSupportInterface +class PimcoreApplicationLoggerBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface { - use BundleAdminSupportTrait; + use BundleAdminClassicTrait; use PackageVersionTrait; public function getCssPaths(): array diff --git a/bundles/CoreBundle/config/pimcore/config.yaml b/bundles/CoreBundle/config/pimcore/config.yaml index 2199fa3db65..a6e9b3b7e2c 100644 --- a/bundles/CoreBundle/config/pimcore/config.yaml +++ b/bundles/CoreBundle/config/pimcore/config.yaml @@ -1,4 +1,5 @@ imports: - { resource: default.yaml } - { resource: doctrine_migrations.yaml } - - { resource: flysystem.yaml } \ No newline at end of file + - { resource: flysystem.yaml } + - { resource: security.yaml } diff --git a/bundles/CoreBundle/config/authenticator_security.yaml b/bundles/CoreBundle/config/pimcore/security.yaml similarity index 100% rename from bundles/CoreBundle/config/authenticator_security.yaml rename to bundles/CoreBundle/config/pimcore/security.yaml diff --git a/bundles/CoreBundle/config/routing.yaml b/bundles/CoreBundle/config/routing.yaml index adf1fe0c733..536218c4cd6 100644 --- a/bundles/CoreBundle/config/routing.yaml +++ b/bundles/CoreBundle/config/routing.yaml @@ -32,8 +32,8 @@ _pimcore_bundle_auto: resource: . type: pimcore_bundle -pimcore_admin_webdav: - path: /admin/asset/webdav{path} +pimcore_webdav: + path: /asset/webdav{path} defaults: { _controller: Pimcore\Bundle\CoreBundle\Controller\WebDavController::webdavAction } requirements: - path: '.*' \ No newline at end of file + path: '.*' diff --git a/bundles/CoreBundle/config/services.yaml b/bundles/CoreBundle/config/services.yaml index 77ab4b90811..e08d8536fbc 100644 --- a/bundles/CoreBundle/config/services.yaml +++ b/bundles/CoreBundle/config/services.yaml @@ -153,7 +153,8 @@ services: # standard user provider returning admin users wrapped in a Pimcore\Security\User\User proxy object. # using this user provider allows implementations to authenticate against pimcore users on every desired firewall - Pimcore\Security\User\UserProvider: ~ + Pimcore\Security\User\UserProvider: + public: true Pimcore\Security\User\TokenStorageUserResolver: public: true @@ -170,3 +171,13 @@ services: # Pimcore\SystemSettingsConfig: public: true + + + # + # Notification Services + # + + Pimcore\Model\Notification\Service\NotificationService: + public: true + + Pimcore\Model\Notification\Service\UserService: ~ diff --git a/bundles/CoreBundle/src/Controller/WebDavController.php b/bundles/CoreBundle/src/Controller/WebDavController.php index 643a715d6bd..5a547b07119 100644 --- a/bundles/CoreBundle/src/Controller/WebDavController.php +++ b/bundles/CoreBundle/src/Controller/WebDavController.php @@ -32,7 +32,7 @@ public function webdavAction(): void $publicDir = new Asset\WebDAV\Folder($homeDir); $objectTree = new Asset\WebDAV\Tree($publicDir); $server = new \Sabre\DAV\Server($objectTree); - $server->setBaseUri($this->generateUrl('pimcore_admin_webdav', ['path' => '/'])); + $server->setBaseUri($this->generateUrl('pimcore_webdav', ['path' => '/'])); // lock plugin /** @var \PDO $pdo */ diff --git a/bundles/CoreBundle/src/DependencyInjection/Compiler/SerializerPass.php b/bundles/CoreBundle/src/DependencyInjection/Compiler/SerializerPass.php index b46ec850bea..31cad288648 100644 --- a/bundles/CoreBundle/src/DependencyInjection/Compiler/SerializerPass.php +++ b/bundles/CoreBundle/src/DependencyInjection/Compiler/SerializerPass.php @@ -35,7 +35,7 @@ final class SerializerPass implements CompilerPassInterface { use PriorityTaggedServiceTrait; - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->hasDefinition('Pimcore\\Serializer\\Serializer')) { return; diff --git a/bundles/CustomReportsBundle/config/pimcore/default.yaml b/bundles/CustomReportsBundle/config/admin-classic.yaml similarity index 51% rename from bundles/CustomReportsBundle/config/pimcore/default.yaml rename to bundles/CustomReportsBundle/config/admin-classic.yaml index ddf991d102a..5564d93afc9 100644 --- a/bundles/CustomReportsBundle/config/pimcore/default.yaml +++ b/bundles/CustomReportsBundle/config/admin-classic.yaml @@ -12,3 +12,14 @@ pimcore_admin: ctrl: true alt: true +services: + _defaults: + autowire: true + autoconfigure: true + + # + # Event Listeners + # + Pimcore\Bundle\CustomReportsBundle\EventListener\IndexSettingsListener: + tags: + - { name: kernel.event_listener, event: pimcore.admin.indexAction.settings, method: indexSettings } \ No newline at end of file diff --git a/bundles/CustomReportsBundle/config/pimcore/config.yaml b/bundles/CustomReportsBundle/config/pimcore/config.yaml index a7dc55849d3..5c51f978e8e 100644 --- a/bundles/CustomReportsBundle/config/pimcore/config.yaml +++ b/bundles/CustomReportsBundle/config/pimcore/config.yaml @@ -1,6 +1,3 @@ -imports: - - { resource: default.yaml } - pimcore_custom_reports: adapters: sql: pimcore.custom_report.adapter.factory.sql diff --git a/bundles/CustomReportsBundle/config/services.yaml b/bundles/CustomReportsBundle/config/services.yaml index 8dd00445ab4..5298cc36660 100644 --- a/bundles/CustomReportsBundle/config/services.yaml +++ b/bundles/CustomReportsBundle/config/services.yaml @@ -13,9 +13,6 @@ services: public: true tags: ['controller.service_arguments'] - Pimcore\Bundle\CustomReportsBundle\EventListener\IndexSettingsListener: - tags: - - { name: kernel.event_listener, event: pimcore.admin.indexAction.settings, method: indexSettings } pimcore.custom_report.adapter.factory.sql: class: Pimcore\Bundle\CustomReportsBundle\Tool\Adapter\DefaultCustomReportAdapterFactory diff --git a/bundles/CustomReportsBundle/src/Controller/Reports/CustomReportController.php b/bundles/CustomReportsBundle/src/Controller/Reports/CustomReportController.php index 9a7dfaaf624..6896068d616 100644 --- a/bundles/CustomReportsBundle/src/Controller/Reports/CustomReportController.php +++ b/bundles/CustomReportsBundle/src/Controller/Reports/CustomReportController.php @@ -16,8 +16,10 @@ namespace Pimcore\Bundle\CustomReportsBundle\Controller\Reports; -use Pimcore\Bundle\AdminBundle\Controller\AdminController; use Pimcore\Bundle\CustomReportsBundle\Tool; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; +use Pimcore\Extension\Bundle\Exception\AdminClassicBundleNotFoundException; use Pimcore\Model\Element\Service; use Pimcore\Model\Exception\ConfigWriteException; use Symfony\Component\Filesystem\Exception\FileNotFoundException; @@ -33,8 +35,10 @@ * * @internal */ -class CustomReportController extends AdminController +class CustomReportController extends UserAwareController { + use JsonHelperTrait; + /** * @Route("/tree", name="pimcore_bundle_customreports_customreport_tree", methods={"GET", "POST"}) * @@ -47,7 +51,7 @@ public function treeAction(Request $request): JsonResponse $this->checkPermission('reports_config'); $reports = Tool\Config::getReportsList(); - return $this->adminJson($reports); + return $this->jsonResponse($reports); } /** @@ -60,9 +64,9 @@ public function treeAction(Request $request): JsonResponse public function portletReportListAction(Request $request): JsonResponse { $this->checkPermission('reports'); - $reports = Tool\Config::getReportsList($this->getAdminUser()); + $reports = Tool\Config::getReportsList($this->getPimcoreUser()); - return $this->adminJson(['data' => $reports]); + return $this->jsonResponse(['data' => $reports]); } /** @@ -92,7 +96,7 @@ public function addAction(Request $request): JsonResponse $success = true; } - return $this->adminJson(['success' => $success, 'id' => $report->getName()]); + return $this->jsonResponse(['success' => $success, 'id' => $report->getName()]); } /** @@ -116,7 +120,7 @@ public function deleteAction(Request $request): JsonResponse $report->delete(); - return $this->adminJson(['success' => true]); + return $this->jsonResponse(['success' => true]); } /** @@ -155,7 +159,7 @@ public function cloneAction(Request $request): JsonResponse $report->save(); - return $this->adminJson(['success' => true]); + return $this->jsonResponse(['success' => true]); } /** @@ -176,7 +180,7 @@ public function getAction(Request $request): JsonResponse $data = $report->getObjectVars(); $data['writeable'] = $report->isWriteable(); - return $this->adminJson($data); + return $this->jsonResponse($data); } /** @@ -213,7 +217,7 @@ public function updateAction(Request $request): JsonResponse $report->save(); - return $this->adminJson(['success' => true]); + return $this->jsonResponse(['success' => true]); } /** @@ -267,7 +271,7 @@ public function columnConfigAction(Request $request): JsonResponse $errorMessage = $e->getMessage(); } - return $this->adminJson([ + return $this->jsonResponse([ 'success' => $success, 'columns' => $result, 'errorMessage' => $errorMessage, @@ -288,7 +292,7 @@ public function getReportConfigAction(Request $request): JsonResponse $reports = []; $list = new Tool\Config\Listing(); - $items = $list->getDao()->loadForGivenUser($this->getAdminUser()); + $items = $list->getDao()->loadForGivenUser($this->getPimcoreUser()); foreach ($items as $report) { $reports[] = [ @@ -302,7 +306,7 @@ public function getReportConfigAction(Request $request): JsonResponse ]; } - return $this->adminJson([ + return $this->jsonResponse([ 'success' => true, 'reports' => $reports, ]); @@ -319,6 +323,10 @@ public function dataAction(Request $request): JsonResponse { $this->checkPermission('reports'); + if (!class_exists(\Pimcore\Bundle\AdminBundle\Helper\QueryParams::class)) { + throw new AdminClassicBundleNotFoundException('This action requires package "pimcore/admin-ui-classic-bundle" to be installed.'); + } + $offset = (int) $request->get('start', 0); $limit = (int) $request->get('limit', 40); $sortingSettings = \Pimcore\Bundle\AdminBundle\Helper\QueryParams::extractSortingSettings(array_merge($request->request->all(), $request->query->all())); @@ -343,7 +351,7 @@ public function dataAction(Request $request): JsonResponse $result = $adapter->getData($filters, $sort, $dir, $offset, $limit, null, $drillDownFilters); - return $this->adminJson([ + return $this->jsonResponse([ 'success' => true, 'data' => $result['data'], 'total' => $result['total'], @@ -374,7 +382,7 @@ public function drillDownOptionsAction(Request $request): JsonResponse $adapter = Tool\Config::getAdapter($configuration, $config); $result = $adapter->getAvailableOptions($filters ?? [], $field ?? '', $drillDownFilters ?? []); - return $this->adminJson([ + return $this->jsonResponse([ 'success' => true, 'data' => $result['data'], ]); @@ -406,7 +414,7 @@ public function chartAction(Request $request): JsonResponse $adapter = Tool\Config::getAdapter($configuration, $config); $result = $adapter->getData($filters, $sort, $dir, null, null, null, $drillDownFilters); - return $this->adminJson([ + return $this->jsonResponse([ 'success' => true, 'data' => $result['data'], 'total' => $result['total'], diff --git a/bundles/CustomReportsBundle/src/DependencyInjection/PimcoreCustomReportsExtension.php b/bundles/CustomReportsBundle/src/DependencyInjection/PimcoreCustomReportsExtension.php index 1877feb136b..a6e0a6f3543 100644 --- a/bundles/CustomReportsBundle/src/DependencyInjection/PimcoreCustomReportsExtension.php +++ b/bundles/CustomReportsBundle/src/DependencyInjection/PimcoreCustomReportsExtension.php @@ -54,6 +54,15 @@ public function loadInternal(array $config, ContainerBuilder $container): void public function prepend(ContainerBuilder $container): void { + if ($container->hasExtension('pimcore_admin')) { + $loader = new YamlFileLoader( + $container, + new FileLocator(__DIR__ . '/../../config') + ); + + $loader->load('admin-classic.yaml'); + } + LocationAwareConfigRepository::loadSymfonyConfigFiles($container, 'pimcore_custom_reports', 'custom_reports'); } } diff --git a/bundles/CustomReportsBundle/src/PimcoreCustomReportsBundle.php b/bundles/CustomReportsBundle/src/PimcoreCustomReportsBundle.php index 0dfcec00f67..cba7b678d1c 100644 --- a/bundles/CustomReportsBundle/src/PimcoreCustomReportsBundle.php +++ b/bundles/CustomReportsBundle/src/PimcoreCustomReportsBundle.php @@ -16,14 +16,14 @@ namespace Pimcore\Bundle\CustomReportsBundle; -use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait; -use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; +use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait; +use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; -class PimcoreCustomReportsBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminSupportInterface +class PimcoreCustomReportsBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface { - use BundleAdminSupportTrait; + use BundleAdminClassicTrait; use PackageVersionTrait; public function getCssPaths(): array diff --git a/bundles/GlossaryBundle/config/admin-classic.yaml b/bundles/GlossaryBundle/config/admin-classic.yaml new file mode 100644 index 00000000000..c1d1311b0f4 --- /dev/null +++ b/bundles/GlossaryBundle/config/admin-classic.yaml @@ -0,0 +1,8 @@ +pimcore_admin: + user: + default_key_bindings: + glossary: + key: 'G' + action: glossary + alt: true + shift: true diff --git a/bundles/GlossaryBundle/config/pimcore/default.yaml b/bundles/GlossaryBundle/config/pimcore/default.yaml index 1c2c1d8160c..aba30ae4385 100644 --- a/bundles/GlossaryBundle/config/pimcore/default.yaml +++ b/bundles/GlossaryBundle/config/pimcore/default.yaml @@ -4,12 +4,3 @@ pimcore_glossary: 'a', 'script', 'style', 'code', 'pre', 'textarea', 'acronym', 'abbr', 'option', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ] - -pimcore_admin: - user: - default_key_bindings: - glossary: - key: 'G' - action: glossary - alt: true - shift: true \ No newline at end of file diff --git a/bundles/GlossaryBundle/src/Controller/SettingsController.php b/bundles/GlossaryBundle/src/Controller/SettingsController.php index 5d8b91b4e4b..73466dbd10e 100644 --- a/bundles/GlossaryBundle/src/Controller/SettingsController.php +++ b/bundles/GlossaryBundle/src/Controller/SettingsController.php @@ -16,9 +16,11 @@ namespace Pimcore\Bundle\GlossaryBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminController; use Pimcore\Bundle\GlossaryBundle\Model\Glossary; use Pimcore\Cache; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; +use Pimcore\Extension\Bundle\Exception\AdminClassicBundleNotFoundException; use Pimcore\Model\Document; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -29,8 +31,10 @@ * * @internal */ -class SettingsController extends AdminController +class SettingsController extends UserAwareController { + use JsonHelperTrait; + /** * @Route("/glossary", name="pimcore_bundle_glossary_settings_glossary", methods={"POST"}) * @@ -40,8 +44,10 @@ class SettingsController extends AdminController */ public function glossaryAction(Request $request): JsonResponse { + // check glossary permissions + $this->checkPermission('glossary'); + if ($request->get('data')) { - $this->checkPermission('glossary'); Cache::clearTag('glossary'); @@ -51,7 +57,7 @@ public function glossaryAction(Request $request): JsonResponse $glossary = Glossary::getById($id); $glossary->delete(); - return $this->adminJson(['success' => true, 'data' => []]); + return $this->jsonResponse(['success' => true, 'data' => []]); } elseif ($request->get('xaction') === 'update') { $data = $this->decodeJson($request->get('data')); @@ -76,7 +82,7 @@ public function glossaryAction(Request $request): JsonResponse } } - return $this->adminJson(['data' => $glossary, 'success' => true]); + return $this->jsonResponse(['data' => $glossary, 'success' => true]); } elseif ($request->get('xaction') == 'create') { $data = $this->decodeJson($request->get('data')); unset($data['id']); @@ -102,10 +108,12 @@ public function glossaryAction(Request $request): JsonResponse } } - return $this->adminJson(['data' => $glossary->getObjectVars(), 'success' => true]); + return $this->jsonResponse(['data' => $glossary->getObjectVars(), 'success' => true]); } } else { - // get list of glossaries + if (!class_exists(\Pimcore\Bundle\AdminBundle\Helper\QueryParams::class)) { + throw new AdminClassicBundleNotFoundException('This action requires package "pimcore/admin-ui-classic-bundle" to be installed.'); + } $list = new Glossary\Listing(); $list->setLimit((int) $request->get('limit', 50)); @@ -136,9 +144,9 @@ public function glossaryAction(Request $request): JsonResponse $glossaries[] = $glossary->getObjectVars(); } - return $this->adminJson(['data' => $glossaries, 'success' => true, 'total' => $list->getTotalCount()]); + return $this->jsonResponse(['data' => $glossaries, 'success' => true, 'total' => $list->getTotalCount()]); } - return $this->adminJson(['success' => false]); + return $this->jsonResponse(['success' => false]); } } diff --git a/bundles/GlossaryBundle/src/DependencyInjection/PimcoreGlossaryExtension.php b/bundles/GlossaryBundle/src/DependencyInjection/PimcoreGlossaryExtension.php index 16938b44c7d..06ff352bd51 100644 --- a/bundles/GlossaryBundle/src/DependencyInjection/PimcoreGlossaryExtension.php +++ b/bundles/GlossaryBundle/src/DependencyInjection/PimcoreGlossaryExtension.php @@ -18,10 +18,11 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; -final class PimcoreGlossaryExtension extends ConfigurableExtension +final class PimcoreGlossaryExtension extends ConfigurableExtension implements PrependExtensionInterface { public function loadInternal(array $config, ContainerBuilder $container): void { @@ -34,4 +35,16 @@ public function loadInternal(array $config, ContainerBuilder $container): void $container->setParameter('pimcore_glossary.blocked_tags', $config['blocked_tags']); } + + public function prepend(ContainerBuilder $container): void + { + if ($container->hasExtension('pimcore_admin')) { + $loader = new YamlFileLoader( + $container, + new FileLocator(__DIR__ . '/../../config') + ); + + $loader->load('admin-classic.yaml'); + } + } } diff --git a/bundles/GlossaryBundle/src/PimcoreGlossaryBundle.php b/bundles/GlossaryBundle/src/PimcoreGlossaryBundle.php index 94280f492a3..85daa688b6e 100644 --- a/bundles/GlossaryBundle/src/PimcoreGlossaryBundle.php +++ b/bundles/GlossaryBundle/src/PimcoreGlossaryBundle.php @@ -16,14 +16,14 @@ namespace Pimcore\Bundle\GlossaryBundle; -use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait; -use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; +use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait; +use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; -class PimcoreGlossaryBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminSupportInterface +class PimcoreGlossaryBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface { - use BundleAdminSupportTrait; + use BundleAdminClassicTrait; use PackageVersionTrait; public function getCssPaths(): array diff --git a/bundles/SeoBundle/config/admin-classic.yaml b/bundles/SeoBundle/config/admin-classic.yaml new file mode 100644 index 00000000000..cdbbd73579d --- /dev/null +++ b/bundles/SeoBundle/config/admin-classic.yaml @@ -0,0 +1,18 @@ +pimcore_admin: + user: + default_key_bindings: + seo_document_editor: + key: 'S' + action: seoDocumentEditor + ctrl: true + alt: true + robots: + key: 'J' + action: robots + ctrl: true + alt: true + http_error_log: + key: 'O' + action: httpErrorLog + ctrl: true + alt: true diff --git a/bundles/SeoBundle/config/pimcore/default.yaml b/bundles/SeoBundle/config/pimcore/default.yaml index bf26f5ec761..92d0aec61a2 100644 --- a/bundles/SeoBundle/config/pimcore/default.yaml +++ b/bundles/SeoBundle/config/pimcore/default.yaml @@ -1,22 +1,3 @@ -pimcore_admin: - user: - default_key_bindings: - seo_document_editor: - key: 'S' - action: seoDocumentEditor - ctrl: true - alt: true - robots: - key: 'J' - action: robots - ctrl: true - alt: true - http_error_log: - key: 'O' - action: httpErrorLog - ctrl: true - alt: true - pimcore_seo: sitemaps: generators: diff --git a/bundles/SeoBundle/src/Controller/Document/DocumentController.php b/bundles/SeoBundle/src/Controller/Document/DocumentController.php index 41801d95683..ce80380c37c 100644 --- a/bundles/SeoBundle/src/Controller/Document/DocumentController.php +++ b/bundles/SeoBundle/src/Controller/Document/DocumentController.php @@ -15,9 +15,11 @@ namespace Pimcore\Bundle\SeoBundle\Controller\Document; -use Pimcore\Bundle\AdminBundle\Controller\Admin\ElementControllerBase; -use Pimcore\Bundle\AdminBundle\Controller\Traits\DocumentTreeConfigTrait; use Pimcore\Bundle\AdminBundle\Event\AdminEvents; +use Pimcore\Bundle\SeoBundle\Controller\Traits\DocumentTreeConfigWrapperTrait; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; +use Pimcore\Extension\Bundle\Exception\AdminClassicBundleNotFoundException; use Pimcore\Model\Document; use Pimcore\Model\Document\Page; use Pimcore\Routing\Dynamic\DocumentRouteHandler; @@ -32,9 +34,10 @@ * * @internal */ -class DocumentController extends ElementControllerBase +class DocumentController extends UserAwareController { - use DocumentTreeConfigTrait; + use JsonHelperTrait; + use DocumentTreeConfigWrapperTrait; private const DOCUMENT_ROOT_ID = 1; @@ -57,7 +60,7 @@ public function seopanelTreeRootAction(DocumentRouteHandler $documentRouteHandle $nodeConfig = $this->getSeoNodeConfig($root); - return $this->adminJson($nodeConfig); + return $this->jsonResponse($nodeConfig); } throw $this->createAccessDeniedHttpException(); @@ -77,6 +80,12 @@ public function seopanelTreeAction( EventDispatcherInterface $eventDispatcher, DocumentRouteHandler $documentRouteHandler ): JsonResponse { + $this->checkPermission('seo_document_editor'); + + if (!class_exists(AdminEvents::class)) { + throw new AdminClassicBundleNotFoundException('This action requires package "pimcore/admin-ui-classic-bundle" to be installed.'); + } + $allParams = array_merge($request->request->all(), $request->query->all()); $filterPrepareEvent = new GenericEvent($this, [ @@ -86,8 +95,6 @@ public function seopanelTreeAction( $allParams = $filterPrepareEvent->getArgument('requestParams'); - $this->checkPermission('seo_document_editor'); - // make sure document routes are also built for unpublished documents $documentRouteHandler->setForceHandleUnpublishedDocuments(true); @@ -132,7 +139,7 @@ public function seopanelTreeAction( $eventDispatcher->dispatch($afterListLoadEvent, AdminEvents::DOCUMENT_LIST_AFTER_LIST_LOAD); $result = $afterListLoadEvent->getArgument('list'); - return $this->adminJson($result['data']); + return $this->jsonResponse($result['data']); } private function getSeoNodeConfig(Document $document): array diff --git a/bundles/SeoBundle/src/Controller/MiscController.php b/bundles/SeoBundle/src/Controller/MiscController.php index c0ce060c8f8..d713584b06a 100644 --- a/bundles/SeoBundle/src/Controller/MiscController.php +++ b/bundles/SeoBundle/src/Controller/MiscController.php @@ -15,7 +15,8 @@ namespace Pimcore\Bundle\SeoBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminController; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; use Pimcore\Db; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -23,8 +24,10 @@ use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\Routing\Annotation\Route; -class MiscController extends AdminController +class MiscController extends UserAwareController { + use JsonHelperTrait; + /** * @Route("/http-error-log", name="pimcore_bundle_seo_misc_httperrorlog", methods={"POST"}) * @@ -71,7 +74,7 @@ public function httpErrorLogAction(Request $request): JsonResponse $logs = $db->fetchAllAssociative('SELECT code,uri,`count`,date FROM http_error_log ' . $condition . ' ORDER BY ' . $sort . ' ' . $dir . ' LIMIT ' . $offset . ',' . $limit); $total = $db->fetchOne('SELECT count(*) FROM http_error_log ' . $condition); - return $this->adminJson([ + return $this->jsonResponse([ 'items' => $logs, 'total' => $total, 'success' => true, @@ -120,7 +123,7 @@ public function httpErrorLogFlushAction(Request $request): JsonResponse $db = Db::get(); $db->executeQuery('TRUNCATE TABLE http_error_log'); - return $this->adminJson([ + return $this->jsonResponse([ 'success' => true, ]); } diff --git a/bundles/SeoBundle/src/Controller/RedirectsController.php b/bundles/SeoBundle/src/Controller/RedirectsController.php index e797733b636..44b9ccc20c9 100644 --- a/bundles/SeoBundle/src/Controller/RedirectsController.php +++ b/bundles/SeoBundle/src/Controller/RedirectsController.php @@ -17,16 +17,18 @@ namespace Pimcore\Bundle\SeoBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminAbstractController; use Pimcore\Bundle\AdminBundle\Helper\QueryParams; -use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse; use Pimcore\Bundle\SeoBundle\Model\Redirect; use Pimcore\Bundle\SeoBundle\Redirect\Csv; use Pimcore\Bundle\SeoBundle\Redirect\RedirectHandler; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; +use Pimcore\Extension\Bundle\Exception\AdminClassicBundleNotFoundException; use Pimcore\Logger; use Pimcore\Model\Document; use Pimcore\Model\Site; use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; @@ -38,8 +40,10 @@ * * @internal */ -class RedirectsController extends AdminAbstractController +class RedirectsController extends UserAwareController { + use JsonHelperTrait; + /** * @Route("/list", name="pimcore_bundle_seo_redirects_redirects", methods={"POST"}) * @@ -63,7 +67,7 @@ public function redirectsAction(Request $request, RedirectHandler $redirectHandl $redirect?->delete(); } - return $this->adminJson(['success' => true, 'data' => []]); + return $this->jsonResponse(['success' => true, 'data' => []]); } if ($request->get('xaction') === 'update') { $data = $this->decodeJson($request->get('data')); @@ -72,7 +76,7 @@ public function redirectsAction(Request $request, RedirectHandler $redirectHandl $redirect = Redirect::getById($data['id']); if (!$redirect) { - return $this->adminJson(['success' => false]); + return $this->jsonResponse(['success' => false]); } if ($data['target']) { @@ -96,7 +100,7 @@ public function redirectsAction(Request $request, RedirectHandler $redirectHandl } } - return $this->adminJson(['data' => $redirect->getObjectVars(), 'success' => true]); + return $this->jsonResponse(['data' => $redirect->getObjectVars(), 'success' => true]); } if ($request->get('xaction') === 'create') { $data = $this->decodeJson($request->get('data')); @@ -126,9 +130,13 @@ public function redirectsAction(Request $request, RedirectHandler $redirectHandl } } - return $this->adminJson(['data' => $redirect->getObjectVars(), 'success' => true]); + return $this->jsonResponse(['data' => $redirect->getObjectVars(), 'success' => true]); } } else { + if (!class_exists(QueryParams::class)) { + throw new AdminClassicBundleNotFoundException('This action requires package "pimcore/admin-ui-classic-bundle" to be installed.'); + } + // get list of routes $list = new Redirect\Listing(); @@ -174,10 +182,10 @@ public function redirectsAction(Request $request, RedirectHandler $redirectHandl $redirects[] = $redirect->getObjectVars(); } - return $this->adminJson(['data' => $redirects, 'success' => true, 'total' => $list->getTotalCount()]); + return $this->jsonResponse(['data' => $redirects, 'success' => true, 'total' => $list->getTotalCount()]); } - return $this->adminJson(['success' => false]); + return $this->jsonResponse(['success' => false]); } /** @@ -232,7 +240,7 @@ public function csvImportAction(Request $request, Csv $csv): Response $result = $csv->import($file->getRealPath()); - return $this->adminJson([ + return $this->jsonResponse([ 'success' => true, 'data' => $result, ]); @@ -257,11 +265,11 @@ public function cleanupAction(): JsonResponse $expiredRedirect->delete(); } - return $this->adminJson(['success' => true]); + return $this->jsonResponse(['success' => true]); } catch (\Exception $e) { Logger::error($e->getMessage()); - return $this->adminJson(['success' => false]); + return $this->jsonResponse(['success' => false]); } } @@ -287,6 +295,6 @@ public function statusCodesAction(): JsonResponse ], ]; - return $this->adminJson($response); + return $this->jsonResponse($response); } } diff --git a/bundles/SeoBundle/src/Controller/SettingsController.php b/bundles/SeoBundle/src/Controller/SettingsController.php index 62693d1813a..63be3b56f82 100644 --- a/bundles/SeoBundle/src/Controller/SettingsController.php +++ b/bundles/SeoBundle/src/Controller/SettingsController.php @@ -16,15 +16,18 @@ namespace Pimcore\Bundle\SeoBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminController; use Pimcore\Bundle\SeoBundle\Config; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; use Pimcore\Model\Tool\SettingsStore; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; -class SettingsController extends AdminController +class SettingsController extends UserAwareController { + use JsonHelperTrait; + /** * @Route("/robots-txt", name="pimcore_bundle_seo_settings_robotstxtget", methods={"GET"}) * @@ -36,7 +39,7 @@ public function robotsTxtGetAction(): JsonResponse $config = Config::getRobotsConfig(); - return $this->adminJson([ + return $this->jsonResponse([ 'success' => true, 'data' => $config, 'onFileSystem' => file_exists(PIMCORE_WEB_ROOT . '/robots.txt'), @@ -63,7 +66,7 @@ public function robotsTxtPutAction(Request $request): JsonResponse SettingsStore::set('robots.txt-' . $siteId, $robotsContent, SettingsStore::TYPE_STRING, 'robots.txt'); } - return $this->adminJson([ + return $this->jsonResponse([ 'success' => true, ]); } diff --git a/bundles/SeoBundle/src/Controller/Traits/DocumentTreeConfigWrapperTrait.php b/bundles/SeoBundle/src/Controller/Traits/DocumentTreeConfigWrapperTrait.php new file mode 100644 index 00000000000..817a4fbac84 --- /dev/null +++ b/bundles/SeoBundle/src/Controller/Traits/DocumentTreeConfigWrapperTrait.php @@ -0,0 +1,41 @@ +setPublic(false); $listener->setArgument('$generators', $collection); } + + public function prepend(ContainerBuilder $container): void + { + if ($container->hasExtension('pimcore_admin')) { + $loader = new YamlFileLoader( + $container, + new FileLocator(__DIR__ . '/../../config') + ); + + $loader->load('admin-classic.yaml'); + } + } } diff --git a/bundles/SeoBundle/src/PimcoreSeoBundle.php b/bundles/SeoBundle/src/PimcoreSeoBundle.php index 33f987738c3..c07c1d9354f 100644 --- a/bundles/SeoBundle/src/PimcoreSeoBundle.php +++ b/bundles/SeoBundle/src/PimcoreSeoBundle.php @@ -16,17 +16,17 @@ namespace Pimcore\Bundle\SeoBundle; -use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait; -use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; +use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait; +use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; use Pimcore\HttpKernel\Bundle\DependentBundleInterface; use Pimcore\HttpKernel\BundleCollection\BundleCollection; use Presta\SitemapBundle\PrestaSitemapBundle; -class PimcoreSeoBundle extends AbstractPimcoreBundle implements DependentBundleInterface, PimcoreBundleAdminSupportInterface +class PimcoreSeoBundle extends AbstractPimcoreBundle implements DependentBundleInterface, PimcoreBundleAdminClassicInterface { - use BundleAdminSupportTrait; + use BundleAdminClassicTrait; use PackageVersionTrait; public function getCssPaths(): array diff --git a/bundles/SimpleBackendSearchBundle/config/admin-classic.yaml b/bundles/SimpleBackendSearchBundle/config/admin-classic.yaml new file mode 100644 index 00000000000..f6aac225d6f --- /dev/null +++ b/bundles/SimpleBackendSearchBundle/config/admin-classic.yaml @@ -0,0 +1,27 @@ +pimcore_admin: + user: + default_key_bindings: + quick_search: + key: 'F' + action: quickSearch + ctrl: true + shift: true + +services: + _defaults: + autowire: true + autoconfigure: true + + # + # Data Provider + # + + Pimcore\Bundle\AdminBundle\GDPR\DataProvider\Assets: + class: Pimcore\Bundle\SimpleBackendSearchBundle\DataProvider\GDPR\Assets + arguments: + $config: '%pimcore.gdpr-data-extrator.assets%' + + Pimcore\Bundle\AdminBundle\GDPR\DataProvider\DataObjects: + class: Pimcore\Bundle\SimpleBackendSearchBundle\DataProvider\GDPR\DataObjects + arguments: + $config: '%pimcore.gdpr-data-extrator.dataobjects%' diff --git a/bundles/SimpleBackendSearchBundle/config/pimcore/config.yaml b/bundles/SimpleBackendSearchBundle/config/pimcore/config.yaml index 74f488660fa..84157900cc8 100644 --- a/bundles/SimpleBackendSearchBundle/config/pimcore/config.yaml +++ b/bundles/SimpleBackendSearchBundle/config/pimcore/config.yaml @@ -1,2 +1,2 @@ imports: - - { resource: default.yaml } \ No newline at end of file + - { resource: default.yaml } diff --git a/bundles/SimpleBackendSearchBundle/config/pimcore/default.yaml b/bundles/SimpleBackendSearchBundle/config/pimcore/default.yaml index 77ceb60e992..13638aad2f1 100644 --- a/bundles/SimpleBackendSearchBundle/config/pimcore/default.yaml +++ b/bundles/SimpleBackendSearchBundle/config/pimcore/default.yaml @@ -1,15 +1,6 @@ -pimcore_admin: - user: - default_key_bindings: - quick_search: - key: 'F' - action: quickSearch - ctrl: true - shift: true - framework: messenger: transports: pimcore_search_backend_message: "doctrine://default?queue_name=pimcore_search_backend_message" routing: - Pimcore\Bundle\SimpleBackendSearchBundle\Message\SearchBackendMessage: pimcore_search_backend_message \ No newline at end of file + Pimcore\Bundle\SimpleBackendSearchBundle\Message\SearchBackendMessage: pimcore_search_backend_message diff --git a/bundles/SimpleBackendSearchBundle/config/services.yaml b/bundles/SimpleBackendSearchBundle/config/services.yaml index 7d246c3e779..87d078b7111 100644 --- a/bundles/SimpleBackendSearchBundle/config/services.yaml +++ b/bundles/SimpleBackendSearchBundle/config/services.yaml @@ -46,19 +46,6 @@ services: tags: - { name: messenger.message_handler } - # - # Data Provider - # - - Pimcore\Bundle\AdminBundle\GDPR\DataProvider\Assets: - class: Pimcore\Bundle\SimpleBackendSearchBundle\DataProvider\GDPR\Assets - arguments: - $config: '%pimcore.gdpr-data-extrator.assets%' - - Pimcore\Bundle\AdminBundle\GDPR\DataProvider\DataObjects: - class: Pimcore\Bundle\SimpleBackendSearchBundle\DataProvider\GDPR\DataObjects - arguments: - $config: '%pimcore.gdpr-data-extrator.dataobjects%' # # Maintenance Tasks @@ -66,4 +53,4 @@ services: Pimcore\Bundle\SimpleBackendSearchBundle\Task\Maintenance\FullTextIndexOptimizeTask: tags: - - { name: pimcore.maintenance.task, type: optimize_fulltext_indexes } \ No newline at end of file + - { name: pimcore.maintenance.task, type: optimize_fulltext_indexes } diff --git a/bundles/SimpleBackendSearchBundle/src/Controller/DataObjectController.php b/bundles/SimpleBackendSearchBundle/src/Controller/DataObjectController.php index 8b2b1ecaf2b..cc5c5dfbd35 100644 --- a/bundles/SimpleBackendSearchBundle/src/Controller/DataObjectController.php +++ b/bundles/SimpleBackendSearchBundle/src/Controller/DataObjectController.php @@ -16,13 +16,13 @@ namespace Pimcore\Bundle\SimpleBackendSearchBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminController; +use Pimcore\Controller\UserAwareController; use Pimcore\Model\DataObject; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; -class DataObjectController extends AdminController +class DataObjectController extends UserAwareController { /** * @Route("/relation-objects-list", name="pimcore_bundle_search_dataobject_relation_objects_list", methods={"GET"}) diff --git a/bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php b/bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php index da663ee9c6e..c870e0974f7 100644 --- a/bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php +++ b/bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php @@ -16,8 +16,6 @@ namespace Pimcore\Bundle\SimpleBackendSearchBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminAbstractController; -use Pimcore\Bundle\AdminBundle\Controller\Traits\AdminStyleTrait; use Pimcore\Bundle\AdminBundle\Event\AdminEvents; use Pimcore\Bundle\AdminBundle\Event\ElementAdminStyleEvent; use Pimcore\Bundle\AdminBundle\Helper\GridHelperService; @@ -25,11 +23,16 @@ use Pimcore\Bundle\SimpleBackendSearchBundle\Event\AdminSearchEvents; use Pimcore\Bundle\SimpleBackendSearchBundle\Model\Search\Backend\Data; use Pimcore\Config; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; use Pimcore\Db\Helper; +use Pimcore\Extension\Bundle\Exception\AdminClassicBundleNotFoundException; use Pimcore\Model\Asset; use Pimcore\Model\DataObject; use Pimcore\Model\Document; use Pimcore\Model\Element; +use Pimcore\Model\Element\AdminStyle; +use Pimcore\Model\Element\ElementInterface; use Symfony\Component\EventDispatcher\GenericEvent; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -41,9 +44,9 @@ * * @internal */ -class SearchController extends AdminAbstractController +class SearchController extends UserAwareController { - use AdminStyleTrait; + use JsonHelperTrait; /** * @Route("/find", name="pimcore_bundle_search_search_find", methods={"GET", "POST"}) @@ -243,8 +246,9 @@ public function findAction(Request $request, EventDispatcherInterface $eventDisp $searcherList->setOrderKey($queryCondition, false); $searcherList->setOrder('DESC'); - $sortingSettings = QueryParams::extractSortingSettings($allParams); - if ($sortingSettings['orderKey']) { + $sortingSettings = $this->extractSortingSettings($allParams); + + if ($sortingSettings['orderKey'] ?? false) { // Order by key column instead of filename $orderKeyQuote = true; if ($sortingSettings['orderKey'] === 'filename') { @@ -263,7 +267,8 @@ public function findAction(Request $request, EventDispatcherInterface $eventDisp } $searcherList->setOrderKey($sort, $orderKeyQuote); } - if ($sortingSettings['order']) { + + if ($sortingSettings['order'] ?? false) { $searcherList->setOrder($sortingSettings['order']); } @@ -281,12 +286,15 @@ public function findAction(Request $request, EventDispatcherInterface $eventDisp 'list' => $searcherList, 'context' => $allParams, ]); - $eventDispatcher->dispatch($beforeListLoadEvent, AdminEvents::ASSET_LIST_BEFORE_LIST_LOAD); - /** @var Data\Listing $searcherList */ - $searcherList = $beforeListLoadEvent->getArgument('list'); + + if (class_exists(AdminEvents::class)) { + $eventDispatcher->dispatch($beforeListLoadEvent, AdminEvents::ASSET_LIST_BEFORE_LIST_LOAD); + /** @var Data\Listing $searcherList */ + $searcherList = $beforeListLoadEvent->getArgument('list'); + } } - if (in_array('document', $types)) { + if (in_array('document', $types) && class_exists(AdminEvents::class)) { // Global document list event (same than the SEARCH_LIST_BEFORE_LIST_LOAD event, but this last one is global for search, list, tree) $beforeListLoadEvent = new GenericEvent($this, [ 'list' => $searcherList, @@ -303,9 +311,12 @@ public function findAction(Request $request, EventDispatcherInterface $eventDisp 'list' => $searcherList, 'context' => $allParams, ]); - $eventDispatcher->dispatch($beforeListLoadEvent, AdminEvents::OBJECT_LIST_BEFORE_LIST_LOAD); - /** @var Data\Listing $searcherList */ - $searcherList = $beforeListLoadEvent->getArgument('list'); + + if (class_exists(AdminEvents::class)) { + $eventDispatcher->dispatch($beforeListLoadEvent, AdminEvents::OBJECT_LIST_BEFORE_LIST_LOAD); + /** @var Data\Listing $searcherList */ + $searcherList = $beforeListLoadEvent->getArgument('list'); + } } $hits = $searcherList->load(); @@ -348,7 +359,19 @@ public function findAction(Request $request, EventDispatcherInterface $eventDisp $eventDispatcher->dispatch($afterListLoadEvent, AdminSearchEvents::SEARCH_LIST_AFTER_LIST_LOAD); $result = $afterListLoadEvent->getArgument('list'); - return $this->adminJson($result); + return $this->jsonResponse($result); + } + + /** + * @throws AdminClassicBundleNotFoundException + */ + protected function extractSortingSettings(array $params): array + { + if (!class_exists(QueryParams::class)) { + throw new AdminClassicBundleNotFoundException('This action requires package "pimcore/admin-ui-classic-bundle" to be installed.'); + } + + return QueryParams::extractSortingSettings($params); } /** @@ -360,7 +383,7 @@ public function findAction(Request $request, EventDispatcherInterface $eventDisp */ protected function getPermittedPaths(array $types = ['asset', 'document', 'object']): string { - $user = $this->getAdminUser(); + $user = $this->getPimcoreUser(); $db = \Pimcore\Db::get(); $allowedTypes = []; @@ -493,7 +516,9 @@ public function quickSearchAction(Request $request, EventDispatcherInterface $ev 'fullpathList' => htmlspecialchars($this->shortenPath($element->getRealFullPath())), ]; - $this->addAdminStyle($element, ElementAdminStyleEvent::CONTEXT_SEARCH, $data); + if (class_exists(ElementAdminStyleEvent::class)) { + $this->addAdminStyle($element, ElementAdminStyleEvent::CONTEXT_SEARCH, $data); + } $elements[] = $data; } @@ -508,7 +533,7 @@ public function quickSearchAction(Request $request, EventDispatcherInterface $ev $result = ['data' => $elements, 'success' => true]; - return $this->adminJson($result); + return $this->jsonResponse($result); } /** @@ -562,7 +587,7 @@ public function quickSearchByIdAction(Request $request, Config $config): JsonRes } } - return $this->adminJson($data); + return $this->jsonResponse($data); } protected function shortenPath(string $path): string @@ -584,4 +609,32 @@ protected function shortenPath(string $path): string return $shortPath; } + + /** + * @param ElementInterface $element + * @param int|null $context + * @param array $data + * + * @throws \Exception + */ + protected function addAdminStyle(ElementInterface $element, int $context = null, array &$data = []): void + { + $event = new ElementAdminStyleEvent($element, new AdminStyle($element), $context); + \Pimcore::getEventDispatcher()->dispatch($event, AdminEvents::RESOLVE_ELEMENT_ADMIN_STYLE); + $adminStyle = $event->getAdminStyle(); + + $data['iconCls'] = $adminStyle->getElementIconClass() !== false ? $adminStyle->getElementIconClass() : null; + if (!$data['iconCls']) { + $data['icon'] = $adminStyle->getElementIcon() !== false ? $adminStyle->getElementIcon() : null; + } else { + $data['icon'] = null; + } + if ($adminStyle->getElementCssClass() !== false) { + if (!isset($data['cls'])) { + $data['cls'] = ''; + } + $data['cls'] .= $adminStyle->getElementCssClass() . ' '; + } + $data['qtipCfg'] = $adminStyle->getElementQtipConfig(); + } } diff --git a/bundles/SimpleBackendSearchBundle/src/DependencyInjection/PimcoreSimpleBackendSearchExtension.php b/bundles/SimpleBackendSearchBundle/src/DependencyInjection/PimcoreSimpleBackendSearchExtension.php index 9a52ade81af..10a195b9288 100644 --- a/bundles/SimpleBackendSearchBundle/src/DependencyInjection/PimcoreSimpleBackendSearchExtension.php +++ b/bundles/SimpleBackendSearchBundle/src/DependencyInjection/PimcoreSimpleBackendSearchExtension.php @@ -19,9 +19,10 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -class PimcoreSimpleBackendSearchExtension extends Extension +class PimcoreSimpleBackendSearchExtension extends Extension implements PrependExtensionInterface { public function load(array $configs, ContainerBuilder $container): void { @@ -32,4 +33,16 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load('services.yaml'); } + + public function prepend(ContainerBuilder $container): void + { + if ($container->hasExtension('pimcore_admin')) { + $loader = new YamlFileLoader( + $container, + new FileLocator(__DIR__ . '/../../config') + ); + + $loader->load('admin-classic.yaml'); + } + } } diff --git a/bundles/SimpleBackendSearchBundle/src/PimcoreSimpleBackendSearchBundle.php b/bundles/SimpleBackendSearchBundle/src/PimcoreSimpleBackendSearchBundle.php index 07e087ffbd9..bf8cff13524 100644 --- a/bundles/SimpleBackendSearchBundle/src/PimcoreSimpleBackendSearchBundle.php +++ b/bundles/SimpleBackendSearchBundle/src/PimcoreSimpleBackendSearchBundle.php @@ -16,14 +16,14 @@ namespace Pimcore\Bundle\SimpleBackendSearchBundle; -use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait; -use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; +use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait; +use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; -class PimcoreSimpleBackendSearchBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminSupportInterface +class PimcoreSimpleBackendSearchBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface { - use BundleAdminSupportTrait; + use BundleAdminClassicTrait; use PackageVersionTrait; public function getJsPaths(): array diff --git a/bundles/StaticRoutesBundle/config/admin-classic.yaml b/bundles/StaticRoutesBundle/config/admin-classic.yaml new file mode 100644 index 00000000000..1787766aa56 --- /dev/null +++ b/bundles/StaticRoutesBundle/config/admin-classic.yaml @@ -0,0 +1,11 @@ +services: + _defaults: + autowire: true + autoconfigure: true + + # + # Event Listeners + # + Pimcore\Bundle\StaticRoutesBundle\EventListener\IndexSettingsListener: + tags: + - { name: kernel.event_listener, event: pimcore.admin.indexAction.settings, method: indexSettings } \ No newline at end of file diff --git a/bundles/StaticRoutesBundle/config/services.yaml b/bundles/StaticRoutesBundle/config/services.yaml index ffe4d889a81..88f30268854 100644 --- a/bundles/StaticRoutesBundle/config/services.yaml +++ b/bundles/StaticRoutesBundle/config/services.yaml @@ -31,12 +31,4 @@ services: - [ setLogger, [ '@logger' ] ] tags: - { name: router, priority: 100 } - - { name: monolog.logger, channel: routing } - - # - # Event Listeners - # - - Pimcore\Bundle\StaticRoutesBundle\EventListener\IndexSettingsListener: - tags: - - { name: kernel.event_listener, event: pimcore.admin.indexAction.settings, method: indexSettings } \ No newline at end of file + - { name: monolog.logger, channel: routing } \ No newline at end of file diff --git a/bundles/StaticRoutesBundle/src/Controller/SettingsController.php b/bundles/StaticRoutesBundle/src/Controller/SettingsController.php index db916cbfbfd..9733a52fdd0 100644 --- a/bundles/StaticRoutesBundle/src/Controller/SettingsController.php +++ b/bundles/StaticRoutesBundle/src/Controller/SettingsController.php @@ -16,15 +16,18 @@ namespace Pimcore\Bundle\StaticRoutesBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminController; use Pimcore\Bundle\StaticRoutesBundle\Model\Staticroute; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; use Pimcore\Model\Exception\ConfigWriteException; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; -class SettingsController extends AdminController +class SettingsController extends UserAwareController { + use JsonHelperTrait; + /** * @Route("/staticroutes", name="pimcore_bundle_staticroutes_settings_staticroutes", methods={"POST"}) * @@ -56,7 +59,7 @@ public function staticroutesAction(Request $request): JsonResponse } $route->delete(); - return $this->adminJson(['success' => true, 'data' => []]); + return $this->jsonResponse(['success' => true, 'data' => []]); } elseif ($request->get('xaction') == 'update') { // save routes $route = Staticroute::getById($data['id']); @@ -68,7 +71,7 @@ public function staticroutesAction(Request $request): JsonResponse $route->save(); - return $this->adminJson(['data' => $route->getObjectVars(), 'success' => true]); + return $this->jsonResponse(['data' => $route->getObjectVars(), 'success' => true]); } elseif ($request->get('xaction') == 'create') { if (!(new Staticroute())->isWriteable()) { throw new ConfigWriteException(); @@ -84,7 +87,7 @@ public function staticroutesAction(Request $request): JsonResponse $responseData = $route->getObjectVars(); $responseData['writeable'] = $route->isWriteable(); - return $this->adminJson(['data' => $responseData, 'success' => true]); + return $this->jsonResponse(['data' => $responseData, 'success' => true]); } } else { // get list of routes @@ -116,9 +119,9 @@ public function staticroutesAction(Request $request): JsonResponse $routes[] = $route; } - return $this->adminJson(['data' => $routes, 'success' => true, 'total' => $list->getTotalCount()]); + return $this->jsonResponse(['data' => $routes, 'success' => true, 'total' => $list->getTotalCount()]); } - return $this->adminJson(['success' => false]); + return $this->jsonResponse(['success' => false]); } } diff --git a/bundles/StaticRoutesBundle/src/DependencyInjection/PimcoreStaticRoutesExtension.php b/bundles/StaticRoutesBundle/src/DependencyInjection/PimcoreStaticRoutesExtension.php index 4156b3a7b30..1b8bcda4b08 100644 --- a/bundles/StaticRoutesBundle/src/DependencyInjection/PimcoreStaticRoutesExtension.php +++ b/bundles/StaticRoutesBundle/src/DependencyInjection/PimcoreStaticRoutesExtension.php @@ -40,6 +40,15 @@ public function loadInternal(array $config, ContainerBuilder $container): void public function prepend(ContainerBuilder $container): void { + if ($container->hasExtension('pimcore_admin')) { + $loader = new YamlFileLoader( + $container, + new FileLocator(__DIR__ . '/../../config') + ); + + $loader->load('admin-classic.yaml'); + } + LocationAwareConfigRepository::loadSymfonyConfigFiles($container, 'pimcore_static_routes', 'staticroutes'); } } diff --git a/bundles/StaticRoutesBundle/src/PimcoreStaticRoutesBundle.php b/bundles/StaticRoutesBundle/src/PimcoreStaticRoutesBundle.php index 78634b0e24c..27ca8b10a7a 100644 --- a/bundles/StaticRoutesBundle/src/PimcoreStaticRoutesBundle.php +++ b/bundles/StaticRoutesBundle/src/PimcoreStaticRoutesBundle.php @@ -16,14 +16,14 @@ namespace Pimcore\Bundle\StaticRoutesBundle; -use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait; -use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; +use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait; +use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; -class PimcoreStaticRoutesBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminSupportInterface +class PimcoreStaticRoutesBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface { - use BundleAdminSupportTrait; + use BundleAdminClassicTrait; use PackageVersionTrait; public function getCssPaths(): array diff --git a/bundles/TinymceBundle/src/PimcoreTinymceBundle.php b/bundles/TinymceBundle/src/PimcoreTinymceBundle.php index 26d44aa59f9..0b5a64f2085 100644 --- a/bundles/TinymceBundle/src/PimcoreTinymceBundle.php +++ b/bundles/TinymceBundle/src/PimcoreTinymceBundle.php @@ -16,15 +16,15 @@ namespace Pimcore\Bundle\TinymceBundle; -use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait; -use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; +use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait; +use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; use Pimcore\Helper\EncoreHelper; -class PimcoreTinymceBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminSupportInterface +class PimcoreTinymceBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface { - use BundleAdminSupportTrait; + use BundleAdminClassicTrait; use PackageVersionTrait; public function getCssPaths(): array diff --git a/bundles/WordExportBundle/src/Controller/TranslationController.php b/bundles/WordExportBundle/src/Controller/TranslationController.php index e138ab9df19..0bd7b5e0865 100644 --- a/bundles/WordExportBundle/src/Controller/TranslationController.php +++ b/bundles/WordExportBundle/src/Controller/TranslationController.php @@ -15,7 +15,8 @@ namespace Pimcore\Bundle\WordExportBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminController; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; use Pimcore\Logger; use Pimcore\Model\DataObject; use Pimcore\Model\Document\Page; @@ -34,8 +35,10 @@ * @Route("/translation") * */ -class TranslationController extends AdminController +class TranslationController extends UserAwareController { + use JsonHelperTrait; + private const PERMISSION = 'word_export'; /** @@ -241,11 +244,9 @@ public function wordExportAction(Request $request, Filesystem $filesystem): Json } } - return $this->adminJson( - [ - 'success' => true, - ] - ); + return new JsonResponse([ + 'success' => true, + ]); } /** diff --git a/bundles/WordExportBundle/src/PimcoreWordExportBundle.php b/bundles/WordExportBundle/src/PimcoreWordExportBundle.php index d38b6a81a25..bf783fe3d84 100644 --- a/bundles/WordExportBundle/src/PimcoreWordExportBundle.php +++ b/bundles/WordExportBundle/src/PimcoreWordExportBundle.php @@ -16,14 +16,14 @@ namespace Pimcore\Bundle\WordExportBundle; -use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait; -use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; +use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait; +use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; -class PimcoreWordExportBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminSupportInterface +class PimcoreWordExportBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface { - use BundleAdminSupportTrait; + use BundleAdminClassicTrait; use PackageVersionTrait; public function getCssPaths(): array diff --git a/bundles/XliffBundle/src/Controller/XliffTranslationController.php b/bundles/XliffBundle/src/Controller/XliffTranslationController.php index ac527a886d1..a71f3ed3d61 100644 --- a/bundles/XliffBundle/src/Controller/XliffTranslationController.php +++ b/bundles/XliffBundle/src/Controller/XliffTranslationController.php @@ -16,12 +16,13 @@ namespace Pimcore\Bundle\XliffBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminController; use Pimcore\Bundle\XliffBundle\ExportService\Exporter\ExporterInterface; use Pimcore\Bundle\XliffBundle\ExportService\ExportServiceInterface; use Pimcore\Bundle\XliffBundle\ImportDataExtractor\ImportDataExtractorInterface; use Pimcore\Bundle\XliffBundle\ImporterService\ImporterServiceInterface; use Pimcore\Bundle\XliffBundle\TranslationItemCollection\TranslationItemCollection; +use Pimcore\Controller\Traits\JsonHelperTrait; +use Pimcore\Controller\UserAwareController; use Pimcore\Logger; use Pimcore\Model\Element; use Symfony\Component\HttpFoundation\BinaryFileResponse; @@ -34,8 +35,10 @@ * @Route("/translation") * */ -class XliffTranslationController extends AdminController +class XliffTranslationController extends UserAwareController { + use JsonHelperTrait; + /** * @Route("/xliff-export", name="pimcore_bundle_xliff_translation_xliffexport", methods={"POST"}) * @@ -64,7 +67,7 @@ public function xliffExportAction(Request $request, ExportServiceInterface $expo $exportService->exportTranslationItems($translationItems, $source, [$target], $id); - return $this->adminJson([ + return $this->jsonResponse([ 'success' => true, ]); } @@ -121,7 +124,7 @@ public function xliffImportUploadAction(Request $request, ImportDataExtractorInt ]]; } - $response = $this->adminJson([ + $response = $this->jsonResponse([ 'success' => true, 'jobs' => $jobs, 'id' => $id, @@ -161,13 +164,13 @@ public function xliffImportElementAction(Request $request, ImportDataExtractorIn } catch (\Exception $e) { Logger::err($e->getMessage()); - return $this->adminJson([ + return $this->jsonResponse([ 'success' => false, 'message' => $e->getMessage(), ]); } - return $this->adminJson([ + return $this->jsonResponse([ 'success' => true, ]); } diff --git a/bundles/XliffBundle/src/PimcoreXliffBundle.php b/bundles/XliffBundle/src/PimcoreXliffBundle.php index f0cdb11b506..8ab6288a522 100644 --- a/bundles/XliffBundle/src/PimcoreXliffBundle.php +++ b/bundles/XliffBundle/src/PimcoreXliffBundle.php @@ -16,16 +16,16 @@ namespace Pimcore\Bundle\XliffBundle; -use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait; -use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface; use Pimcore\Bundle\XliffBundle\DependencyInjection\Compiler\TranslationServicesPass; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; +use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait; +use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; -class PimcoreXliffBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminSupportInterface +class PimcoreXliffBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface { - use BundleAdminSupportTrait; + use BundleAdminClassicTrait; use PackageVersionTrait; public function getJsPaths(): array diff --git a/doc/04_Assets/05_Accessing_Assets_via_WebDAV.md b/doc/04_Assets/05_Accessing_Assets_via_WebDAV.md index 7f0fc62d903..73eafb5c0b8 100644 --- a/doc/04_Assets/05_Accessing_Assets_via_WebDAV.md +++ b/doc/04_Assets/05_Accessing_Assets_via_WebDAV.md @@ -1,7 +1,7 @@ # Accessing Pimcore Assets via WebDAV Pimcore provides the option to access all assets via [WebDAV](https://en.wikipedia.org/wiki/WebDAV). To do so, -just open following URL via your browser or WebDAV client: https://YOUR-DOMAIN/admin/asset/webdav +just open following URL via your browser or WebDAV client: https://YOUR-DOMAIN/asset/webdav As user credentials use any Pimcore Backend user. Permissions for asset access are based on the users permissions. diff --git a/doc/22_Administration_of_Pimcore/07_Users_and_Roles.md b/doc/22_Administration_of_Pimcore/07_Users_and_Roles.md index 745f11239ed..1a110e9f7a8 100644 --- a/doc/22_Administration_of_Pimcore/07_Users_and_Roles.md +++ b/doc/22_Administration_of_Pimcore/07_Users_and_Roles.md @@ -109,7 +109,7 @@ custom layouts for the user. #### Dynamically control permissions on elements -By using the event `Pimcore\Bundle\AdminBundle\Event\AdminEvents::ELEMENT_PERMISSION_IS_ALLOWED` it is possible to dynamically manipulate +By using the event `Pimcore\Event\ElementEvents::ELEMENT_PERMISSION_IS_ALLOWED` it is possible to dynamically manipulate the permissions of a user on a specific element on request. Please note: When listing (tree view,search etc..), this event is fired afterwards on each element of the filtered result list, diff --git a/doc/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md b/doc/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md index e600d10ecc9..11daae0180f 100644 --- a/doc/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md +++ b/doc/23_Installation_and_Upgrade/09_Upgrade_Notes/README.md @@ -292,8 +292,8 @@ pimcore: - [Database] Removed `Pimcore\Db\Helper::insertOrUpdate()` method, please use `Pimcore\Db\Helper::upsert()` instead. - Removed methods `Pimcore\Tool\Admin::isExtJS6()`, `\Pimcore\Tool\Admin::getLanguageFile()`, `\Pimcore\Tool::exitWithError()`. - [DataObjects|Assets|Documents] Datetime values for scheduled tasks, application logger and notifications are now displayed in the local timezone. -- Moved implementation of `PimcoreBundleAdminSupportInterface` from `AbstractPimcoreBundle` to bundle classes. - Moved `getJsPaths`, `getCssPaths`, `getEditmodeJsPaths` and `getEditmodeCssPaths` from `AbstractPimcoreBundle` to `BundleAdminSupportTrait`. +- Moved implementation of `PimcoreBundleAdminClassicInterface` from `AbstractPimcoreBundle` to bundle classes. + Moved `getJsPaths`, `getCssPaths`, `getEditmodeJsPaths` and `getEditmodeCssPaths` from `AbstractPimcoreBundle` to `BundleAdminClassicTrait`. - [Cache] Responses containing a header `Cache-Control: no-cache`, `Cache-Control: private` or `Cache-Control: no-store` will no longer be cached by the full page cache. - [Events] Moved `SEARCH_LIST_BEFORE_FILTER_PREPARE`, `SEARCH_LIST_BEFORE_LIST_LOAD`, `SEARCH_LIST_AFTER_LIST_LOAD`, `QUICKSEARCH_LIST_BEFORE_LIST_LOAD` and `QUICKSEARCH_LIST_AFTER_LIST_LOAD` events from `Pimcore\Bundle\AdminBundle\Event\AdminEvents` to `Pimcore\Bundle\SimpleBackendSearchBundle\Event\AdminSearchEvents`. - [Sites] Calling absolute path from a site is not possible anymore. If the absolute path is called, a 404 error will be returned instead. @@ -331,6 +331,8 @@ pimcore: - Removed AdminSessionHandler and AdminSessionListener. The session is now handled by Symfony. - Methods `Pimcore\Navigation::setDefaultPageType`, `Pimcore\Navigation::getDefaultPageType`, `Pimcore\Navigation\Container::_sort() and `Pimcore\Navigation\Page::_normalizePropertyName()` have been marked as internal. - [Configuration] Moved `hide_edit_image` & `disable_tree_preview` configs from `pimcore` to `pimcore_admin` section. +- [WebDAV] WebDAV url has been changed from `https://YOUR-DOMAIN/admin/asset/webdav` to `https://YOUR-DOMAIN/asset/webdav` +- [Events] `AdminEvents::ELEMENT_PERMISSION_IS_ALLOWED` has been renamed to `Pimcore\Event\ElementEvents::ELEMENT_PERMISSION_IS_ALLOWED`. ## 10.6.0 @@ -372,11 +374,11 @@ pimcore: - [Thumbnails] Using Callable in Asset thumbnail transformations is deprecated and will not work in Pimcore 11. - [Thumbnails] Deprecated the usage of `$thumbnail->getPath(false)` by passing boolean parameters, use `$thumbnail->getPath(["deferredAllowed" => false]);` and pass an array instead. Added the possibility to get the frontend path by adding `frontend => true` into the array, useful in console commands. - Marked `Pimcore\Model\User\AbstractUser` and `Pimcore\Model\User\UserRole` classes as abstract via php doc. It will be natively abstract in Pimcore 11. -- [Bundles] Deprecated `getJsPaths`, `getCssPaths`, `getEditmodeJsPaths` and `getEditmodeCssPaths` in the `PimcoreBundleInterface`. These methods will be provided by the new `PimcoreBundleAdminSupportInterface`. +- [Bundles] Deprecated `getJsPaths`, `getCssPaths`, `getEditmodeJsPaths` and `getEditmodeCssPaths` in the `PimcoreBundleInterface`. These methods will be provided by the new `PimcoreBundleAdminClassicInterface`. - [Web2print] Deprecated `HeadlessChrome` processor, it will be removed and replaced by `Chromium` processor (which doesn't require NodeJS to work) in Pimcore 11. - [Database] Deprecated `Pimcore\Db\Helper::insertOrUpdate()` method, please use `Pimcore\Db\Helper::upsert()` instead. - [Events] The `SEARCH_LIST_BEFORE_FILTER_PREPARE`, `SEARCH_LIST_BEFORE_LIST_LOAD`, `SEARCH_LIST_AFTER_LIST_LOAD`, `QUICKSEARCH_LIST_BEFORE_LIST_LOAD` and `QUICKSEARCH_LIST_AFTER_LIST_LOAD` events from `Pimcore\Bundle\AdminBundle\Event\AdminEvents` are deprecated and wont't work in Pimcore 11. Please use `Pimcore\Bundle\SimpleBackendSearchBundle\Event\AdminSearchEvents` in Pimcore 11. -- Deprecated `getJsPaths`, `getCssPaths`, `getEditmodeJsPaths` and `getEditmodeCssPaths` in `AbstractPimcoreBundle`. Please use the `PimcoreBundleAdminSupportInterface` and the `BundleAdminSupportTrait` instead. +- Deprecated `getJsPaths`, `getCssPaths`, `getEditmodeJsPaths` and `getEditmodeCssPaths` in `AbstractPimcoreBundle`. Please use the `PimcoreBundleAdminClassicInterface` and the `BundleAdminClassicTrait` instead. - [Events] Deprecated Admin Event classes (below), please use these classes from AdminBundle instead. - `Pimcore\Event\AdminEvents` - `Pimcore\Event\Admin\AdminStyleEvent` diff --git a/lib/Controller/Traits/JsonHelperTrait.php b/lib/Controller/Traits/JsonHelperTrait.php index 51444646db6..6c6fe0d7c2f 100644 --- a/lib/Controller/Traits/JsonHelperTrait.php +++ b/lib/Controller/Traits/JsonHelperTrait.php @@ -15,9 +15,9 @@ namespace Pimcore\Controller\Traits; -use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse; use Pimcore\Serializer\Serializer as PimcoreSerializer; use Psr\Container\ContainerInterface; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Serializer\SerializerInterface; /** diff --git a/lib/Controller/UserAwareController.php b/lib/Controller/UserAwareController.php index c2c9c27f65b..36e103a3c28 100644 --- a/lib/Controller/UserAwareController.php +++ b/lib/Controller/UserAwareController.php @@ -25,10 +25,7 @@ abstract class UserAwareController extends Controller { - /** - * @var TokenStorageUserResolver|TokenStorageUserResolver - */ - protected $tokenResolver; + protected TokenStorageUserResolver $tokenResolver; #[Required] public function setTokenResolver(TokenStorageUserResolver $tokenResolver): void @@ -36,25 +33,10 @@ public function setTokenResolver(TokenStorageUserResolver $tokenResolver): void $this->tokenResolver = $tokenResolver; } - /** - * @return string[] - */ - public static function getSubscribedServices(): array - { - $services = parent::getSubscribedServices(); - $services[TokenStorageUserResolver::class] = TokenStorageUserResolver::class; - - return $services; - } - /** * Get user from user proxy object which is registered on security component - * - * @param bool $proxyUser Return the proxy user (UserInterface) instead of the pimcore model - * - * @return UserProxy|User|null */ - protected function getPimcoreUser($proxyUser = false) + protected function getPimcoreUser(bool $proxyUser = false): UserProxy|User|null { if ($proxyUser) { return $this->tokenResolver->getUserProxy(); @@ -66,11 +48,9 @@ protected function getPimcoreUser($proxyUser = false) /** * Check user permission * - * @param string $permission - * * @throws AccessDeniedHttpException */ - protected function checkPermission($permission) + protected function checkPermission(string $permission): void { if (!$this->getPimcoreUser() || !$this->getPimcoreUser()->isAllowed($permission)) { Logger::error( @@ -85,15 +65,12 @@ protected function checkPermission($permission) } } - /** - * @param string $message - * @param \Throwable|null $previous - * @param int $code - * @param array $headers - * - * @return AccessDeniedHttpException - */ - protected function createAccessDeniedHttpException(string $message = 'Access Denied.', \Throwable $previous = null, int $code = 0, array $headers = []): AccessDeniedHttpException + protected function createAccessDeniedHttpException( + string $message = 'Access Denied.', + \Throwable $previous = null, + int $code = 0, + array $headers = [] + ): AccessDeniedHttpException { // $headers parameter not supported by Symfony 3.4 return new AccessDeniedHttpException($message, $previous, $code, $headers); @@ -102,7 +79,7 @@ protected function createAccessDeniedHttpException(string $message = 'Access Den /** * @param string[] $permissions */ - protected function checkPermissionsHasOneOf(array $permissions) + protected function checkPermissionsHasOneOf(array $permissions): void { $allowed = false; $permission = null; @@ -129,12 +106,8 @@ protected function checkPermissionsHasOneOf(array $permissions) /** * Check permission against all controller actions. Can optionally exclude a list of actions. - * - * @param ControllerEvent $event - * @param string $permission - * @param array $unrestrictedActions */ - protected function checkActionPermission(ControllerEvent $event, string $permission, array $unrestrictedActions = []) + protected function checkActionPermission(ControllerEvent $event, string $permission, array $unrestrictedActions = []): void { $actionName = null; $controller = $event->getController(); diff --git a/lib/Event/ElementEvents.php b/lib/Event/ElementEvents.php new file mode 100644 index 00000000000..3c9e74edefd --- /dev/null +++ b/lib/Event/ElementEvents.php @@ -0,0 +1,35 @@ +getActiveBundles() as $bundle) { - if ($bundle instanceof PimcoreBundleAdminSupportInterface) { + if ($bundle instanceof PimcoreBundleAdminClassicInterface) { $paths = $bundle->$getter(); foreach ($paths as $path) { diff --git a/lib/Extension/Bundle/BundleAdminClassicSupportTrait.php b/lib/Extension/Bundle/Traits/BundleAdminClassicTrait.php similarity index 94% rename from lib/Extension/Bundle/BundleAdminClassicSupportTrait.php rename to lib/Extension/Bundle/Traits/BundleAdminClassicTrait.php index b4c5e5dfcb5..d02f658c60a 100644 --- a/lib/Extension/Bundle/BundleAdminClassicSupportTrait.php +++ b/lib/Extension/Bundle/Traits/BundleAdminClassicTrait.php @@ -13,7 +13,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Extension\Bundle; +namespace Pimcore\Extension\Bundle\Traits; trait BundleAdminClassicTrait { diff --git a/lib/Messenger/Handler/CleanupThumbnailsHandler.php b/lib/Messenger/Handler/CleanupThumbnailsHandler.php index 6f5973d818b..65cbeb44f12 100644 --- a/lib/Messenger/Handler/CleanupThumbnailsHandler.php +++ b/lib/Messenger/Handler/CleanupThumbnailsHandler.php @@ -35,6 +35,7 @@ public function __invoke(CleanupThumbnailsMessage $message, Acknowledger $ack = return $this->handle($message, $ack); } + // @phpstan-ignore-next-line private function process(array $jobs): void { $jobs = $this->filterUnique($jobs, static function (CleanupThumbnailsMessage $message) { diff --git a/lib/Messenger/Handler/SanityCheckHandler.php b/lib/Messenger/Handler/SanityCheckHandler.php index 5378122ac97..b1619d65967 100644 --- a/lib/Messenger/Handler/SanityCheckHandler.php +++ b/lib/Messenger/Handler/SanityCheckHandler.php @@ -39,6 +39,7 @@ public function __invoke(SanityCheckMessage $message, Acknowledger $ack = null): return $this->handle($message, $ack); } + // @phpstan-ignore-next-line private function process(array $jobs): void { $jobs = $this->filterUnique($jobs, static function (SanityCheckMessage $message) { diff --git a/lib/Security/Hasher/PimcoreUserPasswordHasher.php b/lib/Security/Hasher/PimcoreUserPasswordHasher.php index 8b6e09dfb25..eee94299205 100644 --- a/lib/Security/Hasher/PimcoreUserPasswordHasher.php +++ b/lib/Security/Hasher/PimcoreUserPasswordHasher.php @@ -41,7 +41,7 @@ public function hash(string $plainPassword, string $salt = null): string throw new BadCredentialsException(sprintf('Password exceeds a maximum of %d characters', static::MAX_PASSWORD_LENGTH)); } - return Authentication::getPasswordHash($this->getUser()->getUsername(), $plainPassword); + return Authentication::getPasswordHash($this->getUser()->getUserIdentifier(), $plainPassword); } /** diff --git a/lib/Security/User/TokenStorageUserResolver.php b/lib/Security/User/TokenStorageUserResolver.php index 00a5311c778..e690e61ca37 100644 --- a/lib/Security/User/TokenStorageUserResolver.php +++ b/lib/Security/User/TokenStorageUserResolver.php @@ -43,7 +43,7 @@ public function getUser(): ?User /** * Taken and adapted from framework base controller. * - * The proxy is the wrapping Pimcore\Bundle\AdminBundle\Security\User\User object implementing UserInterface. + * The proxy is the wrapping Pimcore\Security\User\User object implementing UserInterface. * * @return UserProxy|null */ diff --git a/lib/Security/User/UserProvider.php b/lib/Security/User/UserProvider.php index 9037682952f..481e063e0f7 100644 --- a/lib/Security/User/UserProvider.php +++ b/lib/Security/User/UserProvider.php @@ -23,38 +23,18 @@ class UserProvider implements UserProviderInterface { - /** - * {@inheritdoc} - */ - public function loadUserByIdentifier(string $username): UserInterface + public function loadUserByIdentifier(string $identifier): UserInterface { - $pimcoreUser = PimcoreUser::getByName($username); + $pimcoreUser = PimcoreUser::getByName($identifier); if ($pimcoreUser) { return new User($pimcoreUser); } - throw new UserNotFoundException(sprintf('User %s was not found', $username)); + throw new UserNotFoundException(sprintf('User %s was not found', $identifier)); } - /** - * {@inheritdoc} - * - * @deprecated use loadUserByIdentifier() instead. - */ - public function loadUserByUsername($identifier) - { - return $this->loadUserByIdentifier($identifier); - } - - /** - * {@inheritdoc} - * - * @param UserInterface $user - * - * @return UserInterface - */ - public function refreshUser(UserInterface $user)//: UserInterface + public function refreshUser(UserInterface $user): UserInterface { if (!$user instanceof User) { // user is not supported - we only support pimcore users @@ -67,22 +47,12 @@ public function refreshUser(UserInterface $user)//: UserInterface return $this->buildUser($refreshedPimcoreUser); } - /** - * @param PimcoreUser $pimcoreUser - * - * @return User - */ - protected function buildUser(PimcoreUser $pimcoreUser) + protected function buildUser(PimcoreUser $pimcoreUser): User { return new User($pimcoreUser); } - /** - * {@inheritdoc} - * - * @return bool - */ - public function supportsClass($class)//: bool + public function supportsClass(string $class): bool { return $class === User::class; } diff --git a/lib/Tool.php b/lib/Tool.php index 0acadf2870b..dbc3b7437e8 100644 --- a/lib/Tool.php +++ b/lib/Tool.php @@ -17,7 +17,6 @@ namespace Pimcore; use GuzzleHttp\RequestOptions; -use Pimcore\Bundle\AdminBundle\Tool as AdminTool; use Pimcore\Http\RequestHelper; use Pimcore\Localization\LocaleServiceInterface; use Pimcore\Model\Element; @@ -107,21 +106,6 @@ public static function getValidLanguages(): array return self::$validLanguages; } - /** - * @param string $language - * @param bool $absolutePath - * - * @return string - * - * @internal - * - * @TODO for bundles to be supported on Pimcore 10 & 11 - */ - public static function getLanguageFlagFile(string $language, bool $absolutePath = true): string - { - return AdminTool::getLanguageFlagFile($language, $absolutePath); - } - /** * @return string[] * diff --git a/lib/Twig/Extension/Templating/HeadScript.php b/lib/Twig/Extension/Templating/HeadScript.php index da7ae7fdc8a..2a2ff981bc4 100644 --- a/lib/Twig/Extension/Templating/HeadScript.php +++ b/lib/Twig/Extension/Templating/HeadScript.php @@ -39,7 +39,6 @@ namespace Pimcore\Twig\Extension\Templating; -use Pimcore\Bundle\AdminBundle\Security\ContentSecurityPolicyHandler; use Pimcore\Event\FrontendEvents; use Pimcore\Twig\Extension\Templating\Placeholder\CacheBusterAware; use Pimcore\Twig\Extension\Templating\Placeholder\Container; @@ -483,9 +482,13 @@ public function itemToString(\stdClass $item, string $indent, string $escapeStar } } - /** @var ContentSecurityPolicyHandler $cspHandler */ - $cspHandler = \Pimcore::getContainer()->get(ContentSecurityPolicyHandler::class); - $attrString .= $cspHandler->getNonceHtmlAttribute(); + $container = \Pimcore::getContainer(); + //@phpstan-ignore-next-line + if ($container->has('pimcore.admin.security.content_security_policy')) { + $cspHandler = $container->get('pimcore.admin.security.content_security_policy'); + $attrString .= $cspHandler->getNonceHtmlAttribute(); + } + $addScriptEscape = !(isset($item->attributes['noescape']) && filter_var($item->attributes['noescape'], FILTER_VALIDATE_BOOLEAN)); $html = ''; diff --git a/models/DataObject/ClassDefinition/Data/Classificationstore.php b/models/DataObject/ClassDefinition/Data/Classificationstore.php index e355a5aa4d8..457cc60d203 100644 --- a/models/DataObject/ClassDefinition/Data/Classificationstore.php +++ b/models/DataObject/ClassDefinition/Data/Classificationstore.php @@ -400,7 +400,7 @@ public function getDataForGrid(mixed $data, Concrete $object = null, array $para public function getVersionPreview(mixed $data, DataObject\Concrete $object = null, array $params = []): string { // this is handled directly in the template - // /bundles/AdminBundle/templates/admin/data_object/data_object/preview_version.html.twig + // https://github.com/pimcore/admin-ui-classic-bundle/blob/1.x/templates/admin/data_object/data_object/preview_version.html.twig return 'CLASSIFICATIONSTORE'; } @@ -917,7 +917,7 @@ public function enrichLayoutDefinition(?Concrete $object, array $context = []): } $definition = DataObject\Classificationstore\Service::getFieldDefinitionFromKeyConfig($keyGroupRelation); - // changes here also have an effect here: "bundles/AdminBundle/public/js/pimcore/object/tags/classificationstore.js" + // changes here also have an effect here: "https://github.com/pimcore/admin-ui-classic-bundle/blob/1.x/public/js/pimcore/object/tags/classificationstore.js" $fallbackTooltip = $definition->getName(); if (!empty($keyGroupRelation->getDescription())) { $fallbackTooltip .= ' - ' . $keyGroupRelation->getDescription(); diff --git a/models/DataObject/ClassDefinition/Data/Localizedfields.php b/models/DataObject/ClassDefinition/Data/Localizedfields.php index 67e764b72a7..fc0d9448a8f 100644 --- a/models/DataObject/ClassDefinition/Data/Localizedfields.php +++ b/models/DataObject/ClassDefinition/Data/Localizedfields.php @@ -336,7 +336,7 @@ public function getDataForGrid(?Localizedfield $data, Concrete $object = null, a public function getVersionPreview(mixed $data, DataObject\Concrete $object = null, array $params = []): string { // this is handled directly in the template - // /bundles/AdminBundle/templates/admin/data_object/data_object/preview_version.html.twig + // https://github.com/pimcore/admin-ui-classic-bundle/blob/1.x/templates/admin/data_object/data_object/preview_version.html.twig return 'LOCALIZED FIELDS'; } diff --git a/models/DataObject/ClassDefinition/Data/Objectbricks.php b/models/DataObject/ClassDefinition/Data/Objectbricks.php index 91db7f21fa7..0803332e9b2 100644 --- a/models/DataObject/ClassDefinition/Data/Objectbricks.php +++ b/models/DataObject/ClassDefinition/Data/Objectbricks.php @@ -314,7 +314,7 @@ public function getDataFromEditmode(mixed $data, DataObject\Concrete $object = n public function getVersionPreview(mixed $data, DataObject\Concrete $object = null, array $params = []): string { // this is handled directly in the template - // /bundles/AdminBundle/templates/admin/data_object/data_object/preview_version.html.twig + // https://github.com/pimcore/admin-ui-classic-bundle/blob/1.x/templates/admin/data_object/data_object/preview_version.html.twig return 'BRICKS'; } diff --git a/models/DataObject/Service.php b/models/DataObject/Service.php index c686a348901..897a874da45 100644 --- a/models/DataObject/Service.php +++ b/models/DataObject/Service.php @@ -25,6 +25,7 @@ use Pimcore\Db; use Pimcore\Event\DataObjectEvents; use Pimcore\Event\Model\DataObjectEvent; +use Pimcore\Extension\Bundle\Exception\AdminClassicBundleNotFoundException; use Pimcore\Localization\LocaleServiceInterface; use Pimcore\Logger; use Pimcore\Model; @@ -487,7 +488,7 @@ public static function gridObjectData(AbstractObject $object, array $fields = nu public static function expandGridColumnForExport(array $helperDefinitions, string $key): ?array { $config = self::getConfigForHelperDefinition($helperDefinitions, $key); - if ($config instanceof AbstractOperator && $config->expandLocales()) { + if (class_exists(AbstractOperator::class) && $config instanceof AbstractOperator && $config->expandLocales()) { return $config->getValidLanguages(); } @@ -517,6 +518,9 @@ public static function getConfigForHelperDefinition(array $helperDefinitions, st // TODO refactor how the service is accessed into something non-static and inject the service there $service = \Pimcore::getContainer()->get(GridColumnConfigService::class); + if (!$service) { + throw new AdminClassicBundleNotFoundException('Admin Bundle not found. Please install the package pimcore/admin-ui-classic-bundle.'); + } $config = $service->buildOutputDataConfig([$attributes], $context); if (!$config) { diff --git a/models/Element/AbstractElement.php b/models/Element/AbstractElement.php index b4bc258d83f..e76fe77f705 100644 --- a/models/Element/AbstractElement.php +++ b/models/Element/AbstractElement.php @@ -16,9 +16,9 @@ namespace Pimcore\Model\Element; -use Pimcore\Bundle\AdminBundle\Event\AdminEvents; use Pimcore\Cache; use Pimcore\Cache\RuntimeCache; +use Pimcore\Event\ElementEvents; use Pimcore\Event\Model\ElementEvent; use Pimcore\Event\Traits\RecursionBlockingEventDispatchHelperTrait; use Pimcore\Model; @@ -468,7 +468,7 @@ public function getUserPermissions(?User $user = null): array foreach ($permissions as $type => $isAllowed) { $event = new ElementEvent($this, ['isAllowed' => $isAllowed, 'permissionType' => $type, 'user' => $user]); - \Pimcore::getEventDispatcher()->dispatch($event, AdminEvents::ELEMENT_PERMISSION_IS_ALLOWED); + \Pimcore::getEventDispatcher()->dispatch($event, ElementEvents::ELEMENT_PERMISSION_IS_ALLOWED); $permissions[$type] = $event->getArgument('isAllowed'); } @@ -504,7 +504,7 @@ public function isAllowed(string $type, ?User $user = null): bool $isAllowed = $this->getDao()->isAllowed($type, $user); $event = new ElementEvent($this, ['isAllowed' => $isAllowed, 'permissionType' => $type, 'user' => $user]); - \Pimcore::getEventDispatcher()->dispatch($event, AdminEvents::ELEMENT_PERMISSION_IS_ALLOWED); + \Pimcore::getEventDispatcher()->dispatch($event, ElementEvents::ELEMENT_PERMISSION_IS_ALLOWED); return (bool) $event->getArgument('isAllowed'); } diff --git a/models/Element/Service.php b/models/Element/Service.php index 4507443361c..e1f5c9d517e 100644 --- a/models/Element/Service.php +++ b/models/Element/Service.php @@ -973,27 +973,6 @@ public static function addTreeFilterJoins(array $cv, Asset\Listing|DataObject\Li } } - /** - * @param string $id - * - * @return array|null - * - * @internal - */ - public static function getCustomViewById(string $id): ?array - { - $customViews = Config::get(); - if ($customViews) { - foreach ($customViews as $customView) { - if ($customView['id'] == $id) { - return $customView; - } - } - } - - return null; - } - public static function getValidKey(string $key, string $type): string { $event = new GenericEvent(null, [ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7c3f37a5709..9a752d304d0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5,6 +5,101 @@ parameters: count: 2 path: bundles/CoreBundle/src/DependencyInjection/PimcoreCoreExtension.php + - + message: "#^Call to method addSetting\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\Event\\\\IndexActionSettingsEvent\\.$#" + count: 1 + path: bundles/CustomReportsBundle/src/EventListener/IndexSettingsListener.php + + - + message: "#^Parameter \\$settingsEvent of method Pimcore\\\\Bundle\\\\CustomReportsBundle\\\\EventListener\\\\IndexSettingsListener\\:\\:indexSettings\\(\\) has invalid type Pimcore\\\\Bundle\\\\AdminBundle\\\\Event\\\\IndexActionSettingsEvent\\.$#" + count: 1 + path: bundles/CustomReportsBundle/src/EventListener/IndexSettingsListener.php + + - + message: "#^Call to an undefined method Pimcore\\\\Bundle\\\\SeoBundle\\\\Controller\\\\Document\\\\DocumentController\\:\\:getTreeNodeConfig\\(\\)\\.$#" + count: 1 + path: bundles/SeoBundle/src/Controller/Document/DocumentController.php + + - + message: "#^Access to constant CONTEXT_SEARCH on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\Event\\\\ElementAdminStyleEvent\\.$#" + count: 1 + path: bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php + + - + message: "#^Access to constant RESOLVE_ELEMENT_ADMIN_STYLE on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\Event\\\\AdminEvents\\.$#" + count: 1 + path: bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php + + - + message: "#^Call to method getAdminStyle\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\Event\\\\ElementAdminStyleEvent\\.$#" + count: 1 + path: bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php + + - + message: "#^Call to method getFilterCondition\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\Helper\\\\GridHelperService\\.$#" + count: 2 + path: bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php + + - + message: "#^Instantiated class Pimcore\\\\Bundle\\\\AdminBundle\\\\Event\\\\ElementAdminStyleEvent not found\\.$#" + count: 1 + path: bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php + + - + message: "#^Parameter \\$gridHelperService of method Pimcore\\\\Bundle\\\\SimpleBackendSearchBundle\\\\Controller\\\\SearchController\\:\\:findAction\\(\\) has invalid type Pimcore\\\\Bundle\\\\AdminBundle\\\\Helper\\\\GridHelperService\\.$#" + count: 1 + path: bundles/SimpleBackendSearchBundle/src/Controller/SearchController.php + + - + message: "#^Access to an undefined property Pimcore\\\\Bundle\\\\SimpleBackendSearchBundle\\\\DataProvider\\\\GDPR\\\\Assets\\:\\:\\$config\\.$#" + count: 2 + path: bundles/SimpleBackendSearchBundle/src/DataProvider/GDPR/Assets.php + + - + message: "#^Call to an undefined method Pimcore\\\\Bundle\\\\SimpleBackendSearchBundle\\\\DataProvider\\\\GDPR\\\\Assets\\:\\:prepareQueryString\\(\\)\\.$#" + count: 3 + path: bundles/SimpleBackendSearchBundle/src/DataProvider/GDPR/Assets.php + + - + message: "#^Call to static method extractSortingSettings\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\Helper\\\\QueryParams\\.$#" + count: 1 + path: bundles/SimpleBackendSearchBundle/src/DataProvider/GDPR/Assets.php + + - + message: "#^Access to an undefined property Pimcore\\\\Bundle\\\\SimpleBackendSearchBundle\\\\DataProvider\\\\GDPR\\\\DataObjects\\:\\:\\$config\\.$#" + count: 2 + path: bundles/SimpleBackendSearchBundle/src/DataProvider/GDPR/DataObjects.php + + - + message: "#^Call to an undefined method Pimcore\\\\Bundle\\\\SimpleBackendSearchBundle\\\\DataProvider\\\\GDPR\\\\DataObjects\\:\\:prepareQueryString\\(\\)\\.$#" + count: 3 + path: bundles/SimpleBackendSearchBundle/src/DataProvider/GDPR/DataObjects.php + + - + message: "#^Call to static method extractSortingSettings\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\Helper\\\\QueryParams\\.$#" + count: 1 + path: bundles/SimpleBackendSearchBundle/src/DataProvider/GDPR/DataObjects.php + + - + message: "#^Method Pimcore\\\\Bundle\\\\SimpleBackendSearchBundle\\\\MessageHandler\\\\SearchBackendHandler\\:\\:process\\(\\) is unused\\.$#" + count: 1 + path: bundles/SimpleBackendSearchBundle/src/MessageHandler/SearchBackendHandler.php + + - + message: "#^Method Pimcore\\\\Bundle\\\\SimpleBackendSearchBundle\\\\MessageHandler\\\\SearchBackendHandler\\:\\:shouldFlush\\(\\) is unused\\.$#" + count: 1 + path: bundles/SimpleBackendSearchBundle/src/MessageHandler/SearchBackendHandler.php + + - + message: "#^Call to method addSetting\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\Event\\\\IndexActionSettingsEvent\\.$#" + count: 1 + path: bundles/StaticRoutesBundle/src/EventListener/IndexSettingsListener.php + + - + message: "#^Parameter \\$settingsEvent of method Pimcore\\\\Bundle\\\\StaticRoutesBundle\\\\EventListener\\\\IndexSettingsListener\\:\\:indexSettings\\(\\) has invalid type Pimcore\\\\Bundle\\\\AdminBundle\\\\Event\\\\IndexActionSettingsEvent\\.$#" + count: 1 + path: bundles/StaticRoutesBundle/src/EventListener/IndexSettingsListener.php + - message: "#^Negated boolean expression is always false\\.$#" count: 1 @@ -14,7 +109,6 @@ parameters: message: "#^Result of \\|\\| is always true\\.$#" count: 2 path: lib/Mail.php - - message: "#^Call to an undefined method COM\\:\\:Run\\(\\)\\.$#" count: 1 @@ -29,25 +123,36 @@ parameters: message: "#^Negated boolean expression is always true\\.$#" count: 1 path: models/Asset/Video/ImageThumbnail.php + - - message: "#^Method Pimcore\\\\Messenger\\\\Handler\\\\CleanupThumbnailsHandler\\:\\:process\\(\\) is unused\\.$#" + message: "#^Call to method expandLocales\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\DataObject\\\\GridColumnConfig\\\\ConfigElementInterface\\.$#" count: 1 - path: lib/Messenger/Handler/CleanupThumbnailsHandler.php + path: models/DataObject/Service.php - - message: "#^Method Pimcore\\\\Messenger\\\\Handler\\\\SanityCheckHandler\\:\\:process\\(\\) is unused\\.$#" + message: "#^Call to method getLabeledValue\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\DataObject\\\\GridColumnConfig\\\\ConfigElementInterface\\.$#" count: 1 - path: lib/Messenger/Handler/SanityCheckHandler.php + path: models/DataObject/Service.php - - message: "#^Method Pimcore\\\\Bundle\\\\SimpleBackendSearchBundle\\\\MessageHandler\\\\SearchBackendHandler\\:\\:process\\(\\) is unused\\.$#" + message: "#^Call to method getRenderer\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\DataObject\\\\GridColumnConfig\\\\ConfigElementInterface\\.$#" + count: 2 + path: models/DataObject/Service.php + + - + message: "#^Call to method getValidLanguages\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\DataObject\\\\GridColumnConfig\\\\ConfigElementInterface\\.$#" count: 1 - path: bundles/SimpleBackendSearchBundle/src/MessageHandler/SearchBackendHandler.php + path: models/DataObject/Service.php - - message: "#^Method Pimcore\\\\Bundle\\\\SimpleBackendSearchBundle\\\\MessageHandler\\\\SearchBackendHandler\\:\\:shouldFlush\\(\\) is unused\\.$#" + message: "#^Class Pimcore\\\\Bundle\\\\AdminBundle\\\\DataObject\\\\GridColumnConfig\\\\Service not found\\.$#" count: 1 - path: bundles/SimpleBackendSearchBundle/src/MessageHandler/SearchBackendHandler.php + path: models/DataObject/Service.php + + - + message: "#^Method Pimcore\\\\Model\\\\DataObject\\\\Service\\:\\:getConfigForHelperDefinition\\(\\) has invalid return type Pimcore\\\\Bundle\\\\AdminBundle\\\\DataObject\\\\GridColumnConfig\\\\ConfigElementInterface\\.$#" + count: 2 + path: models/DataObject/Service.php - message: "#^Class Pimcore\\\\Bundle\\\\PersonalizationBundle\\\\Model\\\\Document\\\\Targeting\\\\TargetingDocumentInterface not found\\.$#" @@ -63,3 +168,13 @@ parameters: message: "#^Class Pimcore\\\\Bundle\\\\PersonalizationBundle\\\\Targeting\\\\Document\\\\DocumentTargetingConfigurator not found\\.$#" count: 1 path: models/Document/Editable/Snippet.php + + - + message: "#^Call to static method get\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\Perspective\\\\Config\\.$#" + count: 1 + path: models/User.php + + - + message: "#^Call to static method getAvailablePerspectives\\(\\) on an unknown class Pimcore\\\\Bundle\\\\AdminBundle\\\\Perspective\\\\Config\\.$#" + count: 1 + path: models/User.php diff --git a/phpstan-parameters.neon b/phpstan-parameters.neon index 7f579aed3c3..2bb5ef3fff3 100644 --- a/phpstan-parameters.neon +++ b/phpstan-parameters.neon @@ -9,6 +9,11 @@ parameters: bootstrapFiles: - phpstan-bootstrap.php + excludePaths: + - bundles/SeoBundle/src/Controller/Traits/DocumentTreeConfigWrapperTrait.php + - bundles/SimpleBackendSearchBundle/src/DataProvider/GDPR/Assets.php + - bundles/SimpleBackendSearchBundle/src/DataProvider/GDPR/DataObjects.php + symfony: container_xml_path: var/cache/test/App_KernelTestDebugContainer.xml diff --git a/tests/Model/DataType/ClassificationStore/GeneralTest.php b/tests/Model/DataType/ClassificationStore/GeneralTest.php index 17cf1ada54d..10536b58ea4 100644 --- a/tests/Model/DataType/ClassificationStore/GeneralTest.php +++ b/tests/Model/DataType/ClassificationStore/GeneralTest.php @@ -17,10 +17,7 @@ namespace Pimcore\Tests\Model\DataType\ClassificationStore; use Carbon\Carbon; -use Pimcore\Bundle\AdminBundle\Helper\GridHelperService; use Pimcore\Cache; -use Pimcore\Db; -use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\DataObject\ClassDefinition\Data\Input; use Pimcore\Model\DataObject\Classificationstore; use Pimcore\Model\DataObject\Data\EncryptedField; @@ -672,89 +669,4 @@ public function testWysiwyg(): void $newValue = $o->getCsstore()->getLocalizedKeyValue($groupConfig->getId(), $keyConfig->getId()); $this->assertEquals($originalValue, $newValue); } - - public function testAddGridFeatureJoinsWithTwoFilters(): void - { - $name = 'inheritance'; - $class = ClassDefinition::getByName($name); - - $list = new \Pimcore\Model\DataObject\Inheritance\Listing(); - - $list->setCondition("(`path` = '/tmp' OR `path` like '/tmp/%') AND 1 = 1"); - $list->setLimit(25); - $list->setOffset(0); - $list->setGroupBy('oo_id'); - $list->setOrder('ASC'); - - $featureJoins = []; - $featureJoins[0] = [ - 'fieldname' => 'teststore', - 'groupId' => 1, - 'keyId' => 1, - 'language' => 'default', - ]; - $featureJoins[1] = [ - 'fieldname' => 'teststore', - 'groupId' => 1, - 'keyId' => 2, - 'language' => 'default', - ]; - - $featureConditions = [ - 'cskey_teststore_1_1' => "`cskey_teststore_1_1` LIKE '%t%'", - 'cskey_teststore_1_2' => "`cskey_teststore_1_2` LIKE '%t77%'", - ]; - - $featureAndSlugFilters = [ - 'featureJoins' => $featureJoins, - 'slugJoins' => [], - 'featureConditions' => $featureConditions, - 'slugConditions' => [], - ]; - - $queryBuilder = Db::get()->createQueryBuilder(); - - $gridHelperService = new GridHelperService(); - $gridHelperService->addGridFeatureJoins($list, $featureJoins, $class, $featureAndSlugFilters); - - $dao = $list->getDao(); - - $method = $this->getPrivateMethod($dao, 'applyListingParametersToQueryBuilder'); - $method->invokeArgs($dao, [$queryBuilder]); - - $expectedJoin0 = [ - 'joinType' => 'left', - 'joinTable' => 'object_classificationstore_data_inheritance', - 'joinAlias' => 'cskey_teststore_1_1', - 'joinCondition' => "(cskey_teststore_1_1.id = object_localized_inheritance_en.id and cskey_teststore_1_1.fieldname = 'teststore' and cskey_teststore_1_1.groupId=1 and cskey_teststore_1_1.keyId=1 and cskey_teststore_1_1.language = 'default')", - ]; - - $expectedJoin1 = [ - 'joinType' => 'left', - 'joinTable' => 'object_classificationstore_data_inheritance', - 'joinAlias' => 'cskey_teststore_1_2', - 'joinCondition' => "(cskey_teststore_1_2.id = object_localized_inheritance_en.id and cskey_teststore_1_2.fieldname = 'teststore' and cskey_teststore_1_2.groupId=1 and cskey_teststore_1_2.keyId=2 and cskey_teststore_1_2.language = 'default')", - ]; - - $selectParts = $queryBuilder->getQueryPart('select'); - - $this->assertTrue(in_array('cskey_teststore_1_1.value AS cskey_teststore_1_1', $selectParts)); - $this->assertTrue(in_array('cskey_teststore_1_2.value AS cskey_teststore_1_2', $selectParts)); - - $joins = $queryBuilder->getQueryPart('join')['object_localized_inheritance_en']; - - $this->assertEquals($expectedJoin0, $joins[0]); - $this->assertEquals($expectedJoin1, $joins[1]); - - $this->assertEquals("`cskey_teststore_1_1` LIKE '%t%' AND `cskey_teststore_1_2` LIKE '%t77%'", $queryBuilder->getQueryPart('having')->__toString()); - } - - public function getPrivateMethod(mixed $className, string $methodName): \ReflectionMethod - { - $reflector = new \ReflectionClass($className); - $method = $reflector->getMethod($methodName); - $method->setAccessible(true); - - return $method; - } } diff --git a/tests/Model/Permissions/ModelAssetPermissionsTest.php b/tests/Model/Permissions/ModelAssetPermissionsTest.php index 6940e8df37f..0a59abbc3d4 100644 --- a/tests/Model/Permissions/ModelAssetPermissionsTest.php +++ b/tests/Model/Permissions/ModelAssetPermissionsTest.php @@ -17,8 +17,6 @@ namespace Pimcore\Tests\Model\Element; use Codeception\Stub; -use Pimcore\Bundle\AdminBundle\Helper\GridHelperService; -use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse; use Pimcore\Bundle\SimpleBackendSearchBundle\Model\Search; use Pimcore\Model\Asset; use Pimcore\Model\Property; @@ -423,186 +421,23 @@ public function testAreAllowed(): void protected function buildController(string $classname, User $user): mixed { $AssetController = Stub::construct($classname, [], [ - 'getAdminUser' => function () use ($user) { - return $user; - }, 'getPimcoreUser' => function () use ($user) { return $user; }, - 'adminJson' => function ($data) { + 'jsonResponse' => function ($data) { return new JsonResponse($data); }, 'getThumbnailUrl' => function ($asset) { return ''; }, + 'extractSortingSettings' => function ($params) { + return $params; + } ]); return $AssetController; } - protected function doTestTreeGetChildrenById(Asset $element, User $user, array $expectedChildren): void - { - $controller = $this->buildController('\\Pimcore\\Bundle\\AdminBundle\\Controller\\Admin\\Asset\\AssetController', $user); - - $request = new Request([ - 'node' => $element->getId(), - 'limit' => 100, - 'view' => 0, - ]); - $eventDispatcher = new EventDispatcher(); - - $responseData = $controller->treeGetChildrenByIdAction( - $request, - $eventDispatcher - ); - - $responseData = json_decode($responseData->getContent(), true); - $responsePaths = []; - $responseData = json_decode($responseData->getContent(), true); - foreach ($responseData['nodes'] as $node) { - $responsePaths[] = $node['path']; - } - - $this->assertCount( - $responseData['total'], - $responseData['nodes'], - 'Assert total count of response matches count of nodes array for `' . $element->getFullpath() . '` for user `' . $user->getName() . '`' - ); - - $this->assertCount( - count($expectedChildren), - $responseData['nodes'], - 'Assert number of expected result matches count of nodes array for `' . $element->getFullpath() . '` for user `' . $user->getName() . '` (' . print_r($responsePaths, true) . ')' - ); - - foreach ($expectedChildren as $path) { - $this->assertContains( - $path, - $responsePaths, - 'Children of `' . $element->getFullpath() . '` do to not contain `' . $path . '` for user `' . $user->getName() . '`' - ); - } - } - - public function testTreeGetChildrenById(): void - { - $admin = User::getByName('admin'); - - // test /permissionfoo - $this->doTestTreeGetChildrenById( - $this->permissionfoo, - $admin, - [$this->bars->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( //did not work before (count vs. total) - $this->permissionfoo, - $this->userPermissionTest1, - [$this->bars->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( //did not work before - $this->permissionfoo, - $this->userPermissionTest2, - [$this->bars->getFullpath()] - ); - - // test /permissionfoo/bars - $this->doTestTreeGetChildrenById( - $this->bars, - $admin, - [$this->hugo->getFullpath(), $this->userfolder->getFullpath(), $this->groupfolder->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->bars, - $this->userPermissionTest1, - [$this->userfolder->getFullpath(), $this->groupfolder->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( //did not work before (count vs. total) - $this->bars, - $this->userPermissionTest2, - [$this->userfolder->getFullpath()] - ); - - // test /permissionfoo/bars/userfolder - $this->doTestTreeGetChildrenById( - $this->userfolder, - $admin, - [$this->usertestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->userfolder, - $this->userPermissionTest1, - [$this->usertestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->userfolder, - $this->userPermissionTest2, - [$this->usertestobject->getFullpath()] - ); - - // test /permissionfoo/bars/groupfolder - $this->doTestTreeGetChildrenById( - $this->groupfolder, - $admin, - [$this->grouptestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->groupfolder, - $this->userPermissionTest1, - [$this->grouptestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( //did not work before (count vs. total) - $this->groupfolder, - $this->userPermissionTest2, - [] - ); - - // test /permissionbar - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $admin, - [$this->foo->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $this->userPermissionTest1, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $this->userPermissionTest2, - [] - ); - - // test /permissionbar/foo - $this->doTestTreeGetChildrenById( - $this->foo, - $admin, - [$this->hiddenobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->foo, - $this->userPermissionTest1, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->foo, - $this->userPermissionTest2, - [] - ); - } - protected function doTestSearch(string $searchText, User $user, array $expectedResultPaths, int $limit = 100): void { $controller = $this->buildController('\\Pimcore\\Bundle\\SimpleBackendSearchBundle\\Controller\\SearchController', $user); @@ -617,10 +452,9 @@ protected function doTestSearch(string $searchText, User $user, array $expectedR $responseData = $controller->findAction( $request, new EventDispatcher(), - new GridHelperService() + $this->getMockBuilder('\Pimcore\Bundle\AdminBundle\Helper\GridHelperService')->getMock() //this is not used in the test ); - $responseData = json_decode($responseData->getContent(), true); $responsePaths = []; $responseData = json_decode($responseData->getContent(), true); foreach ($responseData['data'] as $node) { diff --git a/tests/Model/Permissions/ModelDataObjectPermissionsTest.php b/tests/Model/Permissions/ModelDataObjectPermissionsTest.php index 55cfe6baf80..86db269fb4d 100644 --- a/tests/Model/Permissions/ModelDataObjectPermissionsTest.php +++ b/tests/Model/Permissions/ModelDataObjectPermissionsTest.php @@ -17,8 +17,6 @@ namespace Pimcore\Tests\Model\Element; use Codeception\Stub; -use Pimcore\Bundle\AdminBundle\Helper\GridHelperService; -use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse; use Pimcore\Bundle\SimpleBackendSearchBundle\Controller\SearchController; use Pimcore\Bundle\SimpleBackendSearchBundle\Model\Search; use Pimcore\Model\Asset; @@ -29,7 +27,6 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; class ModelDataObjectPermissionsTest extends ModelTestCase { @@ -562,333 +559,20 @@ public function testAreAllowed(): void protected function buildController(string $classname, User $user): mixed { $dataObjectController = Stub::construct($classname, [], [ - 'getAdminUser' => function () use ($user) { - return $user; - }, 'getPimcoreUser' => function () use ($user) { return $user; }, - 'adminJson' => function ($data) { + 'jsonResponse' => function ($data) { return new JsonResponse($data); }, + 'extractSortingSettings' => function ($params) { + return $params; + } ]); return $dataObjectController; } - /** - * @param DataObject\AbstractObject $element - * @param User $user - * @param array|null $expectedChildren When null,the main permission is disabled - * - * @throws \ReflectionException - */ - protected function doTestTreeGetChildrenById(DataObject\AbstractObject $element, User $user, ?array $expectedChildren): void - { - $controller = $this->buildController('\\Pimcore\\Bundle\\AdminBundle\\Controller\\Admin\\DataObject\\DataObjectController', $user); - - $request = new Request([ - 'node' => $element->getId(), - ]); - $eventDispatcher = new EventDispatcher(); - - try { - TestHelper::callMethod($controller, 'checkPermission', ['objects']); - $responseData = $controller->treeGetChildrenByIdAction( - $request, - $eventDispatcher - ); - } catch (\Exception $e) { - if (is_null($expectedChildren)) { - $this->assertInstanceOf(AccessDeniedHttpException::class, $e, 'Assert main object permission'); - - return; - } - } - - $responsePaths = []; - $responseData = json_decode($responseData->getContent(), true); - foreach ($responseData['nodes'] as $node) { - $responsePaths[] = $node['path']; - } - - $this->assertCount( - $responseData['total'], - $responseData['nodes'], - 'Assert total count of response matches count of nodes array for `' . $element->getFullpath() . '` for user `' . $user->getName() . '`' - ); - - $this->assertCount( - count($expectedChildren), - $responseData['nodes'], - 'Assert number of expected result matches count of nodes array for `' . $element->getFullpath() . '` for user `' . $user->getName() . '` (' . print_r($responsePaths, true) . ')' - ); - - foreach ($expectedChildren as $path) { - $this->assertContains( - $path, - $responsePaths, - 'Children of `' . $element->getFullpath() . '` do to not contain `' . $path . '` for user `' . $user->getName() . '`' - ); - } - } - - public function testTreeGetChildrenById(): void - { - $admin = User::getByName('admin'); - - // test /permissionfoo - $this->doTestTreeGetChildrenById( - $this->permissionfoo, - $admin, - [$this->bars->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionfoo, - $this->userPermissionTest1, - [$this->bars->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionfoo, - $this->userPermissionTest2, - [$this->bars->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionfoo, - $this->userPermissionTest3, - [$this->bars->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionfoo, - $this->userPermissionTest4, - [$this->bars->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionfoo, - $this->userPermissionTest5, - [$this->bars->getFullpath()] - ); - - // test /permissionfoo/bars - $this->doTestTreeGetChildrenById( - $this->bars, - $admin, - [$this->hugo->getFullpath(), $this->userfolder->getFullpath(), $this->groupfolder->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->bars, - $this->userPermissionTest1, - [$this->userfolder->getFullpath(), $this->groupfolder->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->bars, - $this->userPermissionTest2, - [$this->userfolder->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->bars, - $this->userPermissionTest3, - [$this->userfolder->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->bars, - $this->userPermissionTest4, - [$this->groupfolder->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->bars, - $this->userPermissionTest5, - [$this->userfolder->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->bars, - $this->userPermissionTest6, - null - ); - - // test /permissionfoo/bars/userfolder - $this->doTestTreeGetChildrenById( - $this->userfolder, - $admin, - [$this->usertestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->userfolder, - $this->userPermissionTest1, - [$this->usertestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->userfolder, - $this->userPermissionTest2, - [$this->usertestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->userfolder, - $this->userPermissionTest3, - [$this->usertestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->userfolder, - $this->userPermissionTest4, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->userfolder, - $this->userPermissionTest5, - [$this->usertestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->userfolder, - $this->userPermissionTest6, - null - ); - - // test /permissionfoo/bars/groupfolder - $this->doTestTreeGetChildrenById( - $this->groupfolder, - $admin, - [$this->grouptestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->groupfolder, - $this->userPermissionTest1, - [$this->grouptestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->groupfolder, - $this->userPermissionTest2, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->groupfolder, - $this->userPermissionTest3, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->groupfolder, - $this->userPermissionTest4, - [$this->grouptestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->groupfolder, - $this->userPermissionTest5, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->groupfolder, - $this->userPermissionTest6, - null - ); - - // test /permissionbar - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $admin, - [$this->foo->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $this->userPermissionTest1, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $this->userPermissionTest2, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $this->userPermissionTest3, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $this->userPermissionTest4, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $this->userPermissionTest5, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $this->userPermissionTest6, - null - ); - // test /permissionbar/foo - $this->doTestTreeGetChildrenById( - $this->foo, - $admin, - [$this->hiddenobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->foo, - $this->userPermissionTest1, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->foo, - $this->userPermissionTest2, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->foo, - $this->userPermissionTest3, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->foo, - $this->userPermissionTest4, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->foo, - $this->userPermissionTest5, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->foo, - $this->userPermissionTest6, - null - ); - } - protected function doTestSearch(string $searchText, User $user, array $expectedResultPaths, int $limit = 100): void { /** @@ -906,10 +590,9 @@ protected function doTestSearch(string $searchText, User $user, array $expectedR $responseData = $controller->findAction( $request, new EventDispatcher(), - new GridHelperService() + $this->getMockBuilder('\Pimcore\Bundle\AdminBundle\Helper\GridHelperService')->getMock() //this is not used in the test ); - $responseData = json_decode($responseData->getContent(), true); $responsePaths = []; $responseData = json_decode($responseData->getContent(), true); foreach ($responseData['data'] as $node) { @@ -1065,7 +748,6 @@ protected function doTestQuickSearch(string $searchText, User $user, array $expe new EventDispatcher(), ); - $responseData = json_decode($responseData->getContent(), true); $responsePaths = []; $responseData = json_decode($responseData->getContent(), true); foreach ($responseData['data'] as $node) { diff --git a/tests/Model/Permissions/ModelDocumentPermissionsTest.php b/tests/Model/Permissions/ModelDocumentPermissionsTest.php index 105c1c9569e..8b9565d0394 100644 --- a/tests/Model/Permissions/ModelDocumentPermissionsTest.php +++ b/tests/Model/Permissions/ModelDocumentPermissionsTest.php @@ -17,12 +17,11 @@ namespace Pimcore\Tests\Model\Element; use Codeception\Stub; -use Pimcore\Bundle\AdminBundle\Helper\GridHelperService; -use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse; use Pimcore\Bundle\SimpleBackendSearchBundle\Model\Search; use Pimcore\Model\Document; use Pimcore\Model\Document\Page; use Pimcore\Model\User; +use Pimcore\Security\User\TokenStorageUserResolver; use Pimcore\Tests\Support\Test\ModelTestCase; use Pimcore\Tests\Support\Util\TestHelper; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -416,183 +415,20 @@ public function testAreAllowed(): void protected function buildController(string $classname, User $user): mixed { $DocumentController = Stub::construct($classname, [], [ - 'getAdminUser' => function () use ($user) { - return $user; - }, 'getPimcoreUser' => function () use ($user) { return $user; }, - 'adminJson' => function ($data) { + 'jsonResponse' => function ($data) { return new JsonResponse($data); }, + 'extractSortingSettings' => function ($params) { + return $params; + } ]); return $DocumentController; } - protected function doTestTreeGetChildrenById(Document $element, User $user, array $expectedChildren): void - { - $controller = $this->buildController('\\Pimcore\\Bundle\\AdminBundle\\Controller\\Admin\\Document\\DocumentController', $user); - - $request = new Request([ - 'node' => $element->getId(), - 'limit' => 100, - 'view' => 0, - ]); - $eventDispatcher = new EventDispatcher(); - - $responseData = $controller->treeGetChildrenByIdAction( - $request, - $eventDispatcher - ); - - $responseData = json_decode($responseData->getContent(), true); - $responsePaths = []; - $responseData = json_decode($responseData->getContent(), true); - foreach ($responseData['nodes'] as $node) { - $responsePaths[] = $node['path']; - } - - $this->assertCount( - $responseData['total'], - $responseData['nodes'], - 'Assert total count of response matches count of nodes array for `' . $element->getFullpath() . '` for user `' . $user->getName() . '`' - ); - - $this->assertCount( - count($expectedChildren), - $responseData['nodes'], - 'Assert number of expected result matches count of nodes array for `' . $element->getFullpath() . '` for user `' . $user->getName() . '` (' . print_r($responsePaths, true) . ')' - ); - - foreach ($expectedChildren as $path) { - $this->assertContains( - $path, - $responsePaths, - 'Children of `' . $element->getFullpath() . '` do to not contain `' . $path . '` for user `' . $user->getName() . '`' - ); - } - } - - public function testTreeGetChildrenById(): void - { - $admin = User::getByName('admin'); - - // test /permissionfoo - $this->doTestTreeGetChildrenById( - $this->permissionfoo, - $admin, - [$this->bars->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( //did not work before (count vs. total) - $this->permissionfoo, - $this->userPermissionTest1, - [$this->bars->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( //did not work before - $this->permissionfoo, - $this->userPermissionTest2, - [$this->bars->getFullpath()] - ); - - // test /permissionfoo/bars - $this->doTestTreeGetChildrenById( - $this->bars, - $admin, - [$this->hugo->getFullpath(), $this->userfolder->getFullpath(), $this->groupfolder->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->bars, - $this->userPermissionTest1, - [$this->userfolder->getFullpath(), $this->groupfolder->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( //did not work before (count vs. total) - $this->bars, - $this->userPermissionTest2, - [$this->userfolder->getFullpath()] - ); - - // test /permissionfoo/bars/userfolder - $this->doTestTreeGetChildrenById( - $this->userfolder, - $admin, - [$this->usertestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->userfolder, - $this->userPermissionTest1, - [$this->usertestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->userfolder, - $this->userPermissionTest2, - [$this->usertestobject->getFullpath()] - ); - - // test /permissionfoo/bars/groupfolder - $this->doTestTreeGetChildrenById( - $this->groupfolder, - $admin, - [$this->grouptestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->groupfolder, - $this->userPermissionTest1, - [$this->grouptestobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( //did not work before (count vs. total) - $this->groupfolder, - $this->userPermissionTest2, - [] - ); - - // test /permissionbar - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $admin, - [$this->foo->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $this->userPermissionTest1, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->permissionbar, - $this->userPermissionTest2, - [] - ); - - // test /permissionbar/foo - $this->doTestTreeGetChildrenById( - $this->foo, - $admin, - [$this->hiddenobject->getFullpath()] - ); - - $this->doTestTreeGetChildrenById( - $this->foo, - $this->userPermissionTest1, - [] - ); - - $this->doTestTreeGetChildrenById( - $this->foo, - $this->userPermissionTest2, - [] - ); - } - protected function doTestSearch(string $searchText, User $user, array $expectedResultPaths, int $limit = 100): void { $controller = $this->buildController('\\Pimcore\\Bundle\\SimpleBackendSearchBundle\\Controller\\SearchController', $user); @@ -607,10 +443,9 @@ protected function doTestSearch(string $searchText, User $user, array $expectedR $responseData = $controller->findAction( $request, new EventDispatcher(), - new GridHelperService() + $this->getMockBuilder('\Pimcore\Bundle\AdminBundle\Helper\GridHelperService')->getMock() //this is not used in the test ); - $responseData = json_decode($responseData->getContent(), true); $responsePaths = []; $responseData = json_decode($responseData->getContent(), true); foreach ($responseData['data'] as $node) { diff --git a/tests/Support/Helper/AbstractDefinitionHelper.php b/tests/Support/Helper/AbstractDefinitionHelper.php index 1bd35e3602b..67adb3b19f0 100644 --- a/tests/Support/Helper/AbstractDefinitionHelper.php +++ b/tests/Support/Helper/AbstractDefinitionHelper.php @@ -37,12 +37,6 @@ public function _beforeSuite(array $settings = []): void { if ($this->config['initialize_definitions']) { if (TestHelper::supportsDbTests()) { - $path = TestHelper::resolveFilePath('system_settings.json'); - if (!file_exists($path)) { - throw new \RuntimeException(sprintf('System settings file in %s was not found', $path)); - } - $data = file_get_contents($path); - SettingsStore::set('system_settings', $data, 'string', 'pimcore_system_settings'); $this->initializeDefinitions(); } else { $this->debug(sprintf( diff --git a/tests/Support/Helper/Pimcore.php b/tests/Support/Helper/Pimcore.php index 1b38fe43a18..a10342aa864 100644 --- a/tests/Support/Helper/Pimcore.php +++ b/tests/Support/Helper/Pimcore.php @@ -28,6 +28,8 @@ use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\ClassDefinition\ClassDefinitionManager; use Pimcore\Model\Document; +use Pimcore\Model\Tool\SettingsStore; +use Pimcore\Tests\Support\Util\TestHelper; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\GenericEvent; use Symfony\Component\Filesystem\Filesystem; @@ -90,6 +92,9 @@ public function _initialize(): void // connect and initialize DB $this->setupDbConnection(); + // initialize system settings + $this->initializeSystemSettings(); + // disable cache Cache::disable(); } @@ -214,6 +219,23 @@ protected function initializeDb(Connection $connection): bool return true; } + /** + * @throws \Exception + */ + protected function initializeSystemSettings(): void + { + if (SettingsStore::get('system_settings')) { + return; + } + + $path = TestHelper::resolveFilePath('system_settings.json'); + if (!file_exists($path)) { + throw new \RuntimeException(sprintf('System settings file in %s was not found', $path)); + } + $data = file_get_contents($path); + SettingsStore::set('system_settings', $data, 'string', 'pimcore_system_settings'); + } + /** * Drop and re-create the DB * diff --git a/tests/Unit.suite.dist.yml b/tests/Unit.suite.dist.yml index 226a12353c5..cd947135917 100644 --- a/tests/Unit.suite.dist.yml +++ b/tests/Unit.suite.dist.yml @@ -1,5 +1,8 @@ actor: UnitTester modules: enabled: - - \Pimcore\Tests\Support\Helper\Pimcore + - \Pimcore\Tests\Support\Helper\Pimcore: + connect_db: true - \Pimcore\Tests\Support\Helper\Unit + - \Pimcore\Tests\Support\Helper\ClassManager + - \Pimcore\Tests\Support\Helper\Model