Skip to content

Commit

Permalink
Adapt admin bundle refactorings (#87)
Browse files Browse the repository at this point in the history
* Adapt admin bundle refactorings - related to pimcore/pimcore#14971

* DI translator service

* Update composer.json

* add conflict for alpha & beta
  • Loading branch information
dvesh3 authored Apr 24, 2023
1 parent b64a1c5 commit 33a1404
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 63 deletions.
37 changes: 6 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,21 @@ 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 Bundle firewall
pimcore_admin: '%pimcore_admin_bundle.firewall_settings%'

access_control:
# Pimcore admin ACl // DO NOT CHANGE!
Expand All @@ -54,6 +28,7 @@ security:
- { path: ^/admin/login$, roles: PUBLIC_ACCESS }
- { path: ^/admin/login/(login|lostpassword|deeplink|csrf-token)$, roles: PUBLIC_ACCESS }
- { path: ^/admin, roles: ROLE_PIMCORE_USER }
- { path: ^/asset/webdav, roles: ROLE_PIMCORE_USER }

role_hierarchy:
# Pimcore admin // DO NOT CHANGE!
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"symfony/templating": "^6.2",
"pimcore/ecommerce-framework-bundle": "^1.0"
},
"conflict": {
"pimcore/pimcore": "v11.0.0-ALPHA1 || v11.0.0-ALPHA2 || v11.0.0-ALPHA3 || v11.0.0-ALPHA4 || v11.0.0-ALPHA5 || v11.0.0-ALPHA6 || v11.0.0-ALPHA7 || v11.0.0-ALPHA8 || v11.0.0-BETA1"
},
"require-dev": {
"phpstan/phpstan": "^1.10.5",
"phpstan/phpstan-symfony": "^1.2.20"
Expand Down
60 changes: 35 additions & 25 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,32 @@
use OutputDataConfigToolkitBundle\Event\SaveConfigEvent;
use OutputDataConfigToolkitBundle\OutputDefinition;
use OutputDataConfigToolkitBundle\Service;
use Pimcore\Controller\Traits\JsonHelperTrait;
use Pimcore\Controller\UserAwareController;
use Pimcore\Logger;
use Pimcore\Model\DataObject\AbstractObject;
use Pimcore\Model\DataObject\ClassDefinition;
use Pimcore\Model\DataObject\Classificationstore\KeyConfig;
use Pimcore\Model\DataObject\Objectbrick\Definition;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Class AdminController
*
* @Route("/admin")
*/
class AdminController extends \Pimcore\Bundle\AdminBundle\Controller\AdminController
class AdminController extends UserAwareController
{
use JsonHelperTrait;

public function __construct(protected TranslatorInterface $translator)
{
}

/* @var string[] $defaultGridClasses */
private $defaultGridClasses = [];

Expand All @@ -45,7 +55,7 @@ class AdminController extends \Pimcore\Bundle\AdminBundle\Controller\AdminContro
/**
* @param Request $request
*
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @return JsonResponse
*
* @Route("/initialize")
*/
Expand All @@ -55,26 +65,26 @@ public function initializeAction(Request $request, EventDispatcherInterface $eve
$object = AbstractObject::getById($objectId);

if (!$object) {
$this->adminJson(['error' => true, 'object' => (object)[]]);
$this->jsonResponse(['error' => true, 'object' => (object)[]]);
}

$event = new InitializeEvent($object);
$eventDispatcher->dispatch($event, OutputDataConfigToolkitEvents::INITIALIZE);

if ($event->getHideConfigTab()) {
// do not show output config tab
return $this->adminJson(['success' => true, 'object' => false]);
return $this->jsonResponse(['success' => true, 'object' => false]);
}

$data = ['id' => $event->getObject()->getId()];

return $this->adminJson(['success' => true, 'object' => $data]);
return $this->jsonResponse(['success' => true, 'object' => $data]);
}

/**
* @param Request $request
*
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @return JsonResponse
*
* @Route("/get-output-configs")
*/
Expand Down Expand Up @@ -109,7 +119,7 @@ public function getOutputConfigsAction(Request $request)
}
}

return $this->adminJson(['success' => true, 'data' => $outputDefinitions]);
return $this->jsonResponse(['success' => true, 'data' => $outputDefinitions]);
}

/**
Expand All @@ -135,7 +145,7 @@ private function getOutputDefinitionForObjectAndChannel($object, $classId, $chan
/**
* @param Request $request
*
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @return JsonResponse
*
* @Route("/reset-output-config")
*/
Expand All @@ -145,18 +155,18 @@ public function resetOutputConfigAction(Request $request)
$config = OutputDefinition::getByID($request->get('config_id'));
$config->delete();

return $this->adminJson(['success' => true]);
return $this->jsonResponse(['success' => true]);
} catch (\Exception $e) {
Logger::err($e->getMessage());

return $this->adminJson(['success' => false, 'message' => $e->getMessage()]);
return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]);
}
}

/**
* @param Request $request
*
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @return JsonResponse
*
* @Route("/get-output-config")
*/
Expand All @@ -171,18 +181,18 @@ public function getOutputConfigAction(Request $request)

$config->setConfiguration($configuration);

return $this->adminJson(['success' => true, 'outputConfig' => $config]);
return $this->jsonResponse(['success' => true, 'outputConfig' => $config]);
} catch (\Exception $e) {
Logger::err($e);

return $this->adminJson(['success' => false, 'message' => $e->getMessage()]);
return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]);
}
}

/**
* @param Request $request
*
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @return JsonResponse
*
* @Route("/get-or-create-output-config")
*/
Expand Down Expand Up @@ -210,20 +220,20 @@ public function getOrCreateOutputConfigAction(Request $request)
$configuration = $this->doGetAttributeLabels($configuration, $objectClass);
$config->setConfiguration($configuration);

return $this->adminJson(['success' => true, 'outputConfig' => $config]);
return $this->jsonResponse(['success' => true, 'outputConfig' => $config]);
} else {
$config = new OutputDefinition();
$config->setChannel($request->get('channel'));
$config->setClassId($class->getId());
$config->setObjectId($request->get('o_id'));
$config->save();

return $this->adminJson(['success' => true, 'outputConfig' => $config]);
return $this->jsonResponse(['success' => true, 'outputConfig' => $config]);
}
} catch (\Exception $e) {
Logger::err($e->getMessage());

return $this->adminJson(['success' => false, 'message' => $e->getMessage()]);
return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]);
}
}

Expand Down Expand Up @@ -284,7 +294,7 @@ private function sortAttributes(array &$attributes)
/**
* @param Request $request
*
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @return JsonResponse
*
* @Route("/get-attribute-labels")
*/
Expand All @@ -295,7 +305,7 @@ public function getAttributeLabelsAction(Request $request)

$configration = $this->doGetAttributeLabels($configration, $class);

return $this->adminJson(['configuration' => $configration]);
return $this->jsonResponse(['configuration' => $configration]);
}

/**
Expand Down Expand Up @@ -374,27 +384,27 @@ private function getFieldDefinition($attributeName, $objectClass)
* @param Request $request
* @Route("/get-field-definition")
*
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @return JsonResponse
*/
public function getFieldDefinitionAction(Request $request)
{
try {
$objectClass = ClassDefinition::getById($request->get('class_id'));
$def = $this->getFieldDefinition($request->get('key'), $objectClass);

return $this->adminJson(['success' => true, 'fieldDefinition' => $def]);
return $this->jsonResponse(['success' => true, 'fieldDefinition' => $def]);
} catch (\Exception $e) {
Logger::err($e->getMessage());

return $this->adminJson(['success' => false, 'message' => $e->getMessage()]);
return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]);
}
}

/**
* @param Request $request
* @Route("/save-output-config")
*
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @return JsonResponse
*/
public function saveOutputConfigAction(Request $request, EventDispatcherInterface $eventDispatcher)
{
Expand Down Expand Up @@ -428,11 +438,11 @@ public function saveOutputConfigAction(Request $request, EventDispatcherInterfac
}
$config->save();

return $this->adminJson(['success' => true]);
return $this->jsonResponse(['success' => true]);
} catch (\Exception $e) {
Logger::err($e->getMessage());

return $this->adminJson(['success' => false, 'message' => $e->getMessage()]);
return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]);
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/Controller/ClassController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

use Doctrine\DBAL\Exception\TableNotFoundException;
use OutputDataConfigToolkitBundle\Constant\ColumnConfigDisplayMode;
use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse;
use Pimcore\Controller\Traits\JsonHelperTrait;
use Pimcore\Controller\UserAwareController;
use Pimcore\Db;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\Classificationstore;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

Expand All @@ -30,8 +32,10 @@
* @package OutputDataConfigToolkitBundle\Controller
*
*/
class ClassController extends \Pimcore\Bundle\AdminBundle\Controller\AdminController
class ClassController extends UserAwareController
{
use JsonHelperTrait;

/* @var string $classificationDisplayMode */
protected $classificationDisplayMode;

Expand Down Expand Up @@ -101,7 +105,7 @@ public function getClassDefinitionForColumnConfigAction(Request $request)

$this->considerClassificationStoreForColumnConfig($request, $class, $fieldDefinitions, $result);

return $this->adminJson($result);
return $this->jsonResponse($result);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/OutputDataConfigToolkitBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
namespace OutputDataConfigToolkitBundle;

use OutputDataConfigToolkitBundle\Tools\Installer;
use Pimcore\Bundle\AdminBundle\Support\BundleAdminSupportTrait;
use Pimcore\Bundle\AdminBundle\Support\PimcoreBundleAdminSupportInterface;
use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface;
use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait;
use Pimcore\Extension\Bundle\Traits\PackageVersionTrait;

class OutputDataConfigToolkitBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminSupportInterface
class OutputDataConfigToolkitBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface
{
use BundleAdminSupportTrait;
use BundleAdminClassicTrait;
use PackageVersionTrait;

protected function getComposerPackageName(): string
Expand Down

0 comments on commit 33a1404

Please sign in to comment.