Skip to content

Commit

Permalink
[Task]: Remove system/admin settings remnants (#37)
Browse files Browse the repository at this point in the history
* fix: create separate service for default key bindings

* fix: service name

* Remove legacy code and implement fallback in helper

* Set default user to null

---------

Co-authored-by: mattamon <matthias.schuhmayer@pimcore.com>
  • Loading branch information
lukmzig and mattamon authored Apr 21, 2023
1 parent 0448842 commit f3d6556
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
5 changes: 5 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ services:

Pimcore\Bundle\AdminBundle\Helper\GridHelperService: ~

#
# User Helper Service
#

Pimcore\Bundle\AdminBundle\Helper\User: ~

#
# Default Preview Generator
Expand Down
8 changes: 3 additions & 5 deletions src/Controller/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse;
use Pimcore\Bundle\AdminBundle\Helper\User as UserHelper;
use Pimcore\Controller\KernelControllerEventInterface;
use Pimcore\Logger;
use Pimcore\Model\Asset;
Expand Down Expand Up @@ -367,7 +368,6 @@ public function updateAction(Request $request): JsonResponse
$tmpArray[] = json_decode($item, true);
}
$tmpArray = array_values(array_filter($tmpArray));
$tmpArray = User::strictKeybinds($tmpArray);
$tmpArray = json_encode($tmpArray);

$user->setKeyBindings($tmpArray);
Expand Down Expand Up @@ -637,7 +637,7 @@ public function getCurrentUserAction(Request $request): Response
$userData = $user->getObjectVars();
$contentLanguages = Tool\Admin::reorderWebsiteLanguages($user, Tool::getValidLanguages());
$userData['contentLanguages'] = $contentLanguages;
$userData['keyBindings'] = $user->getKeyBindings();
$userData['keyBindings'] = UserHelper::getDefaultKeyBindings($user);

unset($userData['password']);
$userData['twoFactorAuthentication'] = $user->getTwoFactorAuthentication();
Expand Down Expand Up @@ -1120,9 +1120,7 @@ public function getRolesAction(Request $request): JsonResponse
*/
public function getDefaultKeyBindingsAction(Request $request): JsonResponse
{
$data = User::getDefaultKeyBindings();

return $this->adminJson(['success' => true, 'data' => $data]);
return $this->adminJson(['success' => true, 'data' => UserHelper::getDefaultKeyBindings()]);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/PimcoreAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setParameter('pimcore_admin.admin_languages', $config['admin_languages']);
$container->setParameter('pimcore_admin.custom_admin_path_identifier', $config['custom_admin_path_identifier']);
$container->setParameter('pimcore_admin.custom_admin_route_name', $config['custom_admin_route_name']);
$container->setParameter('pimcore_admin.user', $config['user']);

$container->setParameter('pimcore_admin.config', $config);

Expand Down
62 changes: 62 additions & 0 deletions src/Helper/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\AdminBundle\Helper;

use Pimcore;
use Pimcore\Bundle\AdminBundle\Security\User\User as UserProxy;

/**
* @internal
*/
final class User
{
protected const DEFAULT_KEY_BINDINGS = 'default_key_bindings';

/**
* @internal
*
* @return string
*/
public static function getDefaultKeyBindings(Pimcore\Model\User|UserProxy|null $user = null): string
{
if(method_exists($user, 'getKeyBindings') && $user->getKeyBindings()) {
return $user->getKeyBindings();
}

$defaultKeyBindings = [];
$container = Pimcore::getContainer();
$userConfig = $container->getParameter('pimcore_admin.user');
// make sure the default key binding node is in the config
if (is_array($userConfig) && array_key_exists(self::DEFAULT_KEY_BINDINGS, $userConfig)) {
$defaultKeyBindingsConfig = $userConfig[self::DEFAULT_KEY_BINDINGS];
if (!empty($defaultKeyBindingsConfig)) {
foreach ($defaultKeyBindingsConfig as $keys) {
$defaultKeyBinding = [];
// we do not check if the keys are empty because key is required
foreach ($keys as $index => $value) {
if ($index === 'key') {
$value = ord($value);
}
$defaultKeyBinding[$index] = $value;
}
$defaultKeyBindings[] = $defaultKeyBinding;
}
}
}
return json_encode($defaultKeyBindings);
}
}

0 comments on commit f3d6556

Please sign in to comment.