Skip to content

Commit

Permalink
[Task] Adapting changes for decoupling admin bundle (#131)
Browse files Browse the repository at this point in the history
* 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 <mcop1@users.noreply.github.com>
  • Loading branch information
mcop1 and mcop1 committed Apr 26, 2023
1 parent 4052600 commit 104ed6c
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 63 deletions.
4 changes: 2 additions & 2 deletions .github/ci/files/config/bundles.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

return [
'Pimcore\\Bundle\\EcommerceFrameworkBundle\\PimcoreEcommerceFrameworkBundle' => ['all' => false],
'Pimcore\\Bundle\\PerspectiveEditorBundle\\PimcorePerspectiveEditorBundle' => ['all' => true],
\Pimcore\Bundle\AdminBundle\PimcoreAdminBundle::class => ['all' => true],
\Pimcore\Bundle\PerspectiveEditorBundle\PimcorePerspectiveEditorBundle::class => ['all' => true]
];
35 changes: 4 additions & 31 deletions .github/ci/files/config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,20 @@ security:

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

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

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

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

access_control:
# Pimcore admin ACl // DO NOT CHANGE!
Expand Down
11 changes: 0 additions & 11 deletions .github/ci/files/config/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions .github/ci/files/security.yaml
Original file line number Diff line number Diff line change
@@ -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]
8 changes: 8 additions & 0 deletions .github/ci/scripts/setup-pimcore-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions .github/workflows/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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/"
Expand Down
10 changes: 9 additions & 1 deletion doc/01_Installation.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:

Expand Down
17 changes: 11 additions & 6 deletions src/Controller/PerspectiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")
*
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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'])),
Expand All @@ -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',
Expand Down
16 changes: 12 additions & 4 deletions src/PimcorePerspectiveEditorBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit 104ed6c

Please sign in to comment.