Skip to content

Commit

Permalink
[Pimcore 11] Decouple AdminBundle from the Core (pimcore#14971)
Browse files Browse the repository at this point in the history
* [Pimcore 11] Decouple AdminBundle from the Core - follow up to pimcore#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 <[email protected]>
Co-authored-by: Martin Eiber <[email protected]>
  • Loading branch information
3 people authored Apr 24, 2023
1 parent 9c76a27 commit 976ccbb
Show file tree
Hide file tree
Showing 86 changed files with 743 additions and 1,222 deletions.
7 changes: 0 additions & 7 deletions .github/ci/files/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
33 changes: 2 additions & 31 deletions .github/ci/files/config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 0 additions & 1 deletion .github/ci/files/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Kernel extends BaseKernel
public function registerBundlesToCollection(BundleCollection $collection): void
{
// pimcore bundles
$collection->addBundle(new PimcoreAdminBundle(), 60);
}

}
2 changes: 0 additions & 2 deletions .github/ci/scripts/setup-pimcore-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
46 changes: 0 additions & 46 deletions bundles/AdminBundle/Controller/AdminAbstractController.php

This file was deleted.

This file was deleted.

5 changes: 1 addition & 4 deletions bundles/ApplicationLoggerBundle/config/pimcore/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
imports:
- { resource: default.yaml }

flysystem:
storages:
pimcore.application_log.storage:
Expand All @@ -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%"
directory: "%log.fileobject%"
35 changes: 20 additions & 15 deletions bundles/ApplicationLoggerBundle/src/Controller/LogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.");
}
}
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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,
]);
Expand Down Expand Up @@ -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]);
}

/**
Expand All @@ -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]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion bundles/CoreBundle/config/pimcore/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
imports:
- { resource: default.yaml }
- { resource: doctrine_migrations.yaml }
- { resource: flysystem.yaml }
- { resource: flysystem.yaml }
- { resource: security.yaml }
6 changes: 3 additions & 3 deletions bundles/CoreBundle/config/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '.*'
path: '.*'
13 changes: 12 additions & 1 deletion bundles/CoreBundle/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -170,3 +171,13 @@ services:
#
Pimcore\SystemSettingsConfig:
public: true


#
# Notification Services
#

Pimcore\Model\Notification\Service\NotificationService:
public: true

Pimcore\Model\Notification\Service\UserService: ~
2 changes: 1 addition & 1 deletion bundles/CoreBundle/src/Controller/WebDavController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
3 changes: 0 additions & 3 deletions bundles/CustomReportsBundle/config/pimcore/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
imports:
- { resource: default.yaml }

pimcore_custom_reports:
adapters:
sql: pimcore.custom_report.adapter.factory.sql
Expand Down
3 changes: 0 additions & 3 deletions bundles/CustomReportsBundle/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 976ccbb

Please sign in to comment.