From 104ed6c132ad90167446cc4ed121c36b8d7449f2 Mon Sep 17 00:00:00 2001 From: mcop1 <89011527+mcop1@users.noreply.github.com> Date: Wed, 26 Apr 2023 11:59:38 +0200 Subject: [PATCH] [Task] Adapting changes for decoupling admin bundle (#131) * Adapting changes for decoupling admin bundle * Apply php-cs-fixer changes * Activated require admin bundle check * Copy security.yaml based on version * Fix phpstan * Apply php-cs-fixer changes * Fixed typo * Small refactorings * Added namespace * Adjusted composer require command for admin ui bundle * Adapted requirement in composer * Moved registerDependentBundles * Apply php-cs-fixer changes --------- Co-authored-by: mcop1 --- .github/ci/files/config/bundles.php | 4 +-- .../ci/files/config/packages/security.yaml | 35 +++---------------- .github/ci/files/config/system.yml | 11 ------ .github/ci/files/security.yaml | 31 ++++++++++++++++ .../ci/scripts/setup-pimcore-environment.sh | 8 +++++ .github/workflows/codeception.yml | 8 +++-- .github/workflows/static-analysis.yml | 8 +++-- composer.json | 11 ++++-- doc/01_Installation.md | 10 +++++- src/Controller/PerspectiveController.php | 17 +++++---- src/PimcorePerspectiveEditorBundle.php | 16 ++++++--- 11 files changed, 96 insertions(+), 63 deletions(-) create mode 100644 .github/ci/files/security.yaml diff --git a/.github/ci/files/config/bundles.php b/.github/ci/files/config/bundles.php index 261196e..5bf02ff 100644 --- a/.github/ci/files/config/bundles.php +++ b/.github/ci/files/config/bundles.php @@ -1,6 +1,6 @@ ['all' => false], - 'Pimcore\\Bundle\\PerspectiveEditorBundle\\PimcorePerspectiveEditorBundle' => ['all' => true], + \Pimcore\Bundle\AdminBundle\PimcoreAdminBundle::class => ['all' => true], + \Pimcore\Bundle\PerspectiveEditorBundle\PimcorePerspectiveEditorBundle::class => ['all' => true] ]; diff --git a/.github/ci/files/config/packages/security.yaml b/.github/ci/files/config/packages/security.yaml index e99bd82..d9ff588 100644 --- a/.github/ci/files/config/packages/security.yaml +++ b/.github/ci/files/config/packages/security.yaml @@ -3,7 +3,7 @@ security: providers: pimcore_admin: - id: Pimcore\Bundle\AdminBundle\Security\User\UserProvider + id: Pimcore\Security\User\UserProvider firewalls: dev: @@ -11,39 +11,12 @@ security: security: false # Pimcore WebDAV HTTP basic // DO NOT CHANGE! - pimcore_admin_webdav: - pattern: ^/admin/asset/webdav + pimcore_webdav: + pattern: ^/asset/webdav provider: pimcore_admin http_basic: ~ - # Pimcore admin form login // DO NOT CHANGE! - pimcore_admin: - pattern: ^/admin(/.*)?$ - user_checker: Pimcore\Bundle\AdminBundle\Security\User\UserChecker - provider: pimcore_admin - login_throttling: - max_attempts: 3 - interval: '5 minutes' - logout: - path: pimcore_admin_logout - target: pimcore_admin_login - form_login: - default_target_path: pimcore_admin_index - always_use_default_target_path: true - login_path: pimcore_admin_login - check_path: pimcore_admin_login_check - username_parameter: username - password_parameter: password - custom_authenticators: - - Pimcore\Bundle\AdminBundle\Security\Authenticator\AdminTokenAuthenticator - two_factor: - auth_form_path: /admin/login/2fa # Path or route name of the two-factor form - check_path: /admin/login/2fa-verify # Path or route name of the two-factor code check - default_target_path: /admin # Where to redirect by default after successful authentication - always_use_default_target_path: false # If it should always redirect to default_target_path - auth_code_parameter_name: _auth_code # Name of the parameter for the two-factor authentication code - trusted_parameter_name: _trusted # Name of the parameter for the trusted device option - multi_factor: false # If ALL active two-factor methods need to be fulfilled (multi-factor authentication) + pimcore_admin: '%pimcore_admin_bundle.firewall_settings%' access_control: # Pimcore admin ACl // DO NOT CHANGE! diff --git a/.github/ci/files/config/system.yml b/.github/ci/files/config/system.yml index 8bda27b..47b5a0b 100644 --- a/.github/ci/files/config/system.yml +++ b/.github/ci/files/config/system.yml @@ -29,8 +29,6 @@ pimcore: steps: 10 icc_rgb_profile: '' icc_cmyk_profile: '' - hide_edit_image: false - disable_tree_preview: false full_page_cache: enabled: false lifetime: null @@ -51,15 +49,6 @@ pimcore: email: pimcore@example.com debug: email_addresses: '' - newsletter: - sender: - name: '' - email: '' - return: - name: '' - email: '' - debug: null - use_specific: true applicationlog: mail_notification: send_log_summary: false diff --git a/.github/ci/files/security.yaml b/.github/ci/files/security.yaml new file mode 100644 index 0000000..7dea2c6 --- /dev/null +++ b/.github/ci/files/security.yaml @@ -0,0 +1,31 @@ +security: + enable_authenticator_manager: true + + providers: + pimcore_admin: + id: Pimcore\Security\User\UserProvider + + firewalls: + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + + # Pimcore WebDAV HTTP basic // DO NOT CHANGE! + pimcore_webdav: + pattern: ^/asset/webdav + provider: pimcore_admin + http_basic: ~ + + access_control: + # Pimcore admin ACl // DO NOT CHANGE! + - { path: ^/admin/settings/display-custom-logo, roles: PUBLIC_ACCESS } + - { path: ^/admin/login/2fa-verify, roles: IS_AUTHENTICATED_2FA_IN_PROGRESS } + - { path: ^/admin/login/2fa-setup, roles: ROLE_PIMCORE_USER } + - { path: ^/admin/login/2fa, roles: IS_AUTHENTICATED_2FA_IN_PROGRESS } + - { path: ^/admin/login$, roles: PUBLIC_ACCESS } + - { path: ^/admin/login/(login|lostpassword|deeplink|csrf-token)$, roles: PUBLIC_ACCESS } + - { path: ^/admin, roles: ROLE_PIMCORE_USER } + + role_hierarchy: + # Pimcore admin // DO NOT CHANGE! + ROLE_PIMCORE_ADMIN: [ROLE_PIMCORE_USER] diff --git a/.github/ci/scripts/setup-pimcore-environment.sh b/.github/ci/scripts/setup-pimcore-environment.sh index b8f7369..e76ac93 100755 --- a/.github/ci/scripts/setup-pimcore-environment.sh +++ b/.github/ci/scripts/setup-pimcore-environment.sh @@ -14,3 +14,11 @@ cp -r .github/ci/files/bin/console bin/console chmod 755 bin/console cp -r .github/ci/files/kernel/. kernel cp -r .github/ci/files/public/. public + +if [ ${REQUIRE_ADMIN_BUNDLE} = true ]; then + composer require -n --no-update pimcore/admin-ui-classic-bundle:^1.0 +else + ## Todo Remove when dropping support for Pimcore 10 + rm config/packages/security.yaml + cp .github/ci/files/security.yaml config/packages +fi diff --git a/.github/workflows/codeception.yml b/.github/workflows/codeception.yml index d72aeea..ccc7d98 100644 --- a/.github/workflows/codeception.yml +++ b/.github/workflows/codeception.yml @@ -27,9 +27,9 @@ jobs: strategy: matrix: include: - - { php-version: 8.0, database: "mariadb:10.7", pimcore_version: "", dependencies: lowest, experimental: false } - - { php-version: 8.1, database: "mariadb:10.7", pimcore_version: "", dependencies: highest, experimental: false } - - { php-version: 8.1, database: "mariadb:10.7", pimcore_version: "11.x-dev as 11.0.0", dependencies: highest, experimental: true } + - { php-version: 8.0, database: "mariadb:10.7", pimcore_version: "", dependencies: lowest, experimental: false, require_admin_bundle: false } + - { php-version: 8.1, database: "mariadb:10.7", pimcore_version: "", dependencies: highest, experimental: false, require_admin_bundle: true } + - { php-version: 8.1, database: "mariadb:10.7", pimcore_version: "11.x-dev as 11.0.0", dependencies: highest, experimental: true, require_admin_bundle: true } services: mariadb: image: "${{ matrix.database }}" @@ -58,6 +58,8 @@ jobs: done - name: "Setup Pimcore environment" + env: + REQUIRE_ADMIN_BUNDLE: "${{ matrix.require_admin_bundle }}" run: | mysql -e "CREATE DATABASE pimcore_test CHARSET=utf8mb4;" chmod 755 .github/ci/scripts/setup-pimcore-environment.sh diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 4c008a5..8f6d1e6 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -20,9 +20,9 @@ jobs: strategy: matrix: include: - - { php-version: "8.0", dependencies: "highest", pimcore_version: "", phpstan_args: "", experimental: false } - - { php-version: "8.1", dependencies: "highest", pimcore_version: "", phpstan_args: "", experimental: false } - - { php-version: "8.1", dependencies: "highest", pimcore_version: "11.x-dev as 11.0.0", phpstan_args: "", experimental: true } + - { php-version: "8.0", dependencies: "lowest", pimcore_version: "", phpstan_args: "", experimental: false, require_admin_bundle: false } + - { php-version: "8.1", dependencies: "highest", pimcore_version: "", phpstan_args: "", experimental: false, require_admin_bundle: true } + - { php-version: "8.1", dependencies: "highest", pimcore_version: "11.x-dev as 11.0.0", phpstan_args: "", experimental: true, require_admin_bundle: true } steps: - name: "Checkout code" uses: "actions/checkout@v2" @@ -34,6 +34,8 @@ jobs: php-version: "${{ matrix.php-version }}" - name: "Setup Pimcore environment" + env: + REQUIRE_ADMIN_BUNDLE: "${{ matrix.require_admin_bundle }}" run: | .github/ci/scripts/setup-pimcore-environment.sh diff --git a/composer.json b/composer.json index bb42bb5..a2941d5 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ "prefer-stable": true, "minimum-stability": "dev", "require": { - "pimcore/pimcore": "^10.6 || ^11.0", - "pimcore/compatibility-bridge-v10": "1.x-dev" + "pimcore/compatibility-bridge-v10": "^1.0", + "pimcore/pimcore": "^10.6 || ^11.0" }, "require-dev": { "phpstan/phpstan": "^1.2", @@ -24,6 +24,13 @@ "codeception/phpunit-wrapper": "^9", "codeception/module-asserts": "^2" }, + "conflict": { + "pimcore/pimcore": "v11.0.0-BETA1 || v11.0.0-ALPHA8 || v11.0.0-ALPHA7 || v11.0.0-ALPHA6 || v11.0.0-ALPHA5 || v11.0.0-ALPHA4 || v11.0.0-ALPHA3 || v11.0.0-ALPHA2 || v11.0.0-ALPHA1", + "pimcore/admin-ui-classic-bundle": "v1.0.0-BETA1" + }, + "suggest": { + "pimcore/admin-ui-classic-bundle": "Required for Pimcore 11" + }, "autoload": { "psr-4": { "Pimcore\\Bundle\\PerspectiveEditorBundle\\": "src/" diff --git a/doc/01_Installation.md b/doc/01_Installation.md index a48b80c..1a1dcf1 100644 --- a/doc/01_Installation.md +++ b/doc/01_Installation.md @@ -1,6 +1,6 @@ # Installation ## Bundle Installation -### For Pimcore >= 10.5 +### For Pimcore >= 10.5 & <= 10.6 To install Pimcore Perspective Editor for Pimcore 10.5 or higher, follow the three steps below: 1. Install the required dependencies: @@ -27,6 +27,14 @@ return [ bin/console pimcore:bundle:install PimcorePerspectiveEditorBundle ``` +### For Pimcore 11 + +You need to follow the steps mentioned above and additionally run the following command: + +```bash +composer require pimcore/admin-ui-classic-bundle +``` + ### For Older Versions To install the Perspective Editor bundle for older versions of Pimcore, please run the following commands instead: diff --git a/src/Controller/PerspectiveController.php b/src/Controller/PerspectiveController.php index 9f219c9..c724c12 100644 --- a/src/Controller/PerspectiveController.php +++ b/src/Controller/PerspectiveController.php @@ -15,25 +15,30 @@ namespace Pimcore\Bundle\PerspectiveEditorBundle\Controller; -use Pimcore\Bundle\AdminBundle\Controller\AdminController; use Pimcore\Bundle\AdminBundle\Security\CsrfProtectionHandler; use Pimcore\Bundle\PerspectiveEditorBundle\PimcorePerspectiveEditorBundle; use Pimcore\Bundle\PerspectiveEditorBundle\Services\PerspectiveAccessor; use Pimcore\Bundle\PerspectiveEditorBundle\Services\TreeHelper; use Pimcore\Bundle\PerspectiveEditorBundle\Services\ViewAccessor; +use Pimcore\Controller\UserAwareController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Contracts\Translation\TranslatorInterface; /** * Class PerspectiveController * * @package Pimcore\Bundle\PerspectiveEditorBundle\Controller\Admin */ -class PerspectiveController extends AdminController +class PerspectiveController extends UserAwareController { protected $disabledCssClass = 'pimcore_tree_node_disabled'; + public function __construct(protected TranslatorInterface $translator) + { + } + /** * @Route("/perspective/get-tree", name="get-perspective-tree") * @@ -205,7 +210,7 @@ protected function createPerspectiveEntry(TreeHelper $treeHelper, $perspectiveNa ], [ 'id' => $treeHelper->createUuid(), - 'text' => $this->trans('plugin_pimcore_perspectiveeditor_elementTreeLeft', [], 'admin'), + 'text' => $this->translator->trans('plugin_pimcore_perspectiveeditor_elementTreeLeft', [], 'admin'), 'type' => 'elementTree', 'leaf' => false, 'expanded' => !empty($leftElementTrees), @@ -217,7 +222,7 @@ protected function createPerspectiveEntry(TreeHelper $treeHelper, $perspectiveNa 'children' => $leftElementTrees, ], [ 'id' => $treeHelper->createUuid(), - 'text' => $this->trans('plugin_pimcore_perspectiveeditor_elementTreeRight', [], 'admin'), + 'text' => $this->translator->trans('plugin_pimcore_perspectiveeditor_elementTreeRight', [], 'admin'), 'type' => 'elementTreeRight', 'leaf' => false, 'expanded' => !empty($rightElementTrees), @@ -230,7 +235,7 @@ protected function createPerspectiveEntry(TreeHelper $treeHelper, $perspectiveNa ], [ 'id' => $treeHelper->createUuid(), - 'text' => $this->trans('plugin_pimcore_perspectiveeditor_dashboard', [], 'admin'), + 'text' => $this->translator->trans('plugin_pimcore_perspectiveeditor_dashboard', [], 'admin'), 'type' => 'dashboard', 'leaf' => empty(array_diff(array_keys($perspectiveConfig['dashboards'] ?? []), ['disabledPortlets'])), 'expanded' => !empty(array_diff(array_keys($perspectiveConfig['dashboards'] ?? []), ['disabledPortlets'])), @@ -244,7 +249,7 @@ protected function createPerspectiveEntry(TreeHelper $treeHelper, $perspectiveNa ], [ 'id' => $treeHelper->createUuid(), - 'text' => $this->trans('plugin_pimcore_perspectiveeditor_toolbar', [], 'admin'), + 'text' => $this->translator->trans('plugin_pimcore_perspectiveeditor_toolbar', [], 'admin'), 'type' => 'toolbar', 'leaf' => true, 'icon' => '/bundles/pimcoreadmin/img/flat-color-icons/support.svg', diff --git a/src/PimcorePerspectiveEditorBundle.php b/src/PimcorePerspectiveEditorBundle.php index af92822..de0dd91 100644 --- a/src/PimcorePerspectiveEditorBundle.php +++ b/src/PimcorePerspectiveEditorBundle.php @@ -15,20 +15,28 @@ namespace Pimcore\Bundle\PerspectiveEditorBundle; -use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait; -use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface; +use Pimcore\Bundle\AdminBundle\PimcoreAdminBundle; use Pimcore\Extension\Bundle\AbstractPimcoreBundle; use Pimcore\Extension\Bundle\Installer\InstallerInterface; +use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface; +use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait; use Pimcore\Extension\Bundle\Traits\PackageVersionTrait; +use Pimcore\HttpKernel\Bundle\DependentBundleInterface; +use Pimcore\HttpKernel\BundleCollection\BundleCollection; -class PimcorePerspectiveEditorBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminSupportInterface +class PimcorePerspectiveEditorBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface, DependentBundleInterface { - use BundleAdminSupportTrait; + use BundleAdminClassicTrait; use PackageVersionTrait; const PERMISSION_PERSPECTIVE_EDITOR = 'perspective_editor'; const PERMISSION_PERSPECTIVE_EDITOR_VIEW_EDIT = 'perspective_editor_view_edit'; + public static function registerDependentBundles(BundleCollection $collection): void + { + $collection->addBundle(new PimcoreAdminBundle(), 60); + } + public function getJsPaths(): array { return [