Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Task]: Remove system/admin settings remnants #37

Merged
merged 4 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 4 additions & 3 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,7 @@ public function updateAction(Request $request): JsonResponse
$tmpArray[] = json_decode($item, true);
}
$tmpArray = array_values(array_filter($tmpArray));
$tmpArray = User::strictKeybinds($tmpArray);
$tmpArray = UserHelper::strictKeybinds($tmpArray);
$tmpArray = json_encode($tmpArray);

$user->setKeyBindings($tmpArray);
Expand Down Expand Up @@ -637,7 +638,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'] = $user->getKeyBindings() ?? UserHelper::getDefaultKeyBindings();
dvesh3 marked this conversation as resolved.
Show resolved Hide resolved

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

return $this->adminJson(['success' => true, 'data' => $data]);
}
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
268 changes: 268 additions & 0 deletions src/Helper/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
<?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;

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

/**
* @internal
*
* @return string
*/
public static function getDefaultKeyBindings(): string
{
$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];
$defaultKeyBindings = [];
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;
}
}
}

if (!empty($defaultKeyBindings)) {
return json_encode($defaultKeyBindings);
}

// keep for legacy reasons

$bindings = [
[
'action' => 'save',
'key' => ord('S'),
'ctrl' => true,
],
[
'action' => 'publish',
'key' => ord('P'),
'ctrl' => true,
'shift' => true,
],
[
'action' => 'unpublish',
'key' => ord('U'),
'ctrl' => true,
'shift' => true,
],
[
'action' => 'rename',
'key' => ord('R'),
'alt' => true,
'shift' => true,
],
[
'action' => 'refresh',
'key' => 116,
],
[
'action' => 'openAsset',
'key' => ord('A'),
'ctrl' => true,
'shift' => true,
],
[
'action' => 'openObject',
'key' => ord('O'),
'ctrl' => true,
'shift' => true,
],
[
'action' => 'openDocument',
'key' => ord('D'),
'ctrl' => true,
'shift' => true,
],
[
'action' => 'openClassEditor',
'key' => ord('C'),
'ctrl' => true,
'shift' => true,

],
[
'action' => 'openInTree',
'key' => ord('L'),
'ctrl' => true,
'shift' => true,

],
[
'action' => 'showMetaInfo',
'key' => ord('I'),
'alt' => true,
],
[
'action' => 'searchDocument',
'key' => ord('W'),
'alt' => true,
],
[
'action' => 'searchAsset',
'key' => ord('A'),
'alt' => true,
],
[
'action' => 'searchObject',
'key' => ord('O'),
'alt' => true,
],
[
'action' => 'showElementHistory',
'key' => ord('H'),
'alt' => true,
],
[
'action' => 'closeAllTabs',
'key' => ord('T'),
'alt' => true,
],
[
'action' => 'searchAndReplaceAssignments',
'key' => ord('S'),
'alt' => true,
],
[
'action' => 'redirects',
'key' => ord('R'),
'ctrl' => false,
'alt' => true,
],
[
'action' => 'sharedTranslations',
'key' => ord('T'),
'ctrl' => true,
'alt' => true,
],
[
'action' => 'recycleBin',
'key' => ord('R'),
'ctrl' => true,
'alt' => true,
],
[
'action' => 'notesEvents',
'key' => ord('N'),
'ctrl' => true,
'alt' => true,
],
[
'action' => 'applicationLogger',
'key' => ord('L'),
'ctrl' => true,
'alt' => true,
],
[
'action' => 'tagManager',
'key' => ord('H'),
'ctrl' => true,
'alt' => true,
],
[
'action' => 'seoDocumentEditor',
'key' => ord('S'),
'ctrl' => true,
'alt' => true,
],
[
'action' => 'robots',
'key' => ord('J'),
'ctrl' => true,
'alt' => true,
],
[
'action' => 'httpErrorLog',
'key' => ord('O'),
'ctrl' => true,
'alt' => true,
],
[
'action' => 'tagConfiguration',
'key' => ord('N'),
'ctrl' => true,
'alt' => true,
],
[
'action' => 'users',
'key' => ord('U'),
'ctrl' => true,
'alt' => true,
],
[
'action' => 'roles',
'key' => ord('P'),
'ctrl' => true,
'alt' => true,
],
[
'action' => 'clearAllCaches',
'key' => ord('Q'),
'ctrl' => false,
'alt' => true,
],
[
'action' => 'clearDataCache',
'key' => ord('C'),
'ctrl' => false,
'alt' => true,
],
[
'action' => 'quickSearch',
'key' => ord('F'),
'ctrl' => true,
'shift' => true,
],
];

return json_encode(self::strictKeybinds($bindings));
}


/**
* @param list<array{action: string, key: int, alt?: bool, ctrl?: bool, shift?: bool}> $bindings
*
* @return list<array{action: string, key: int, alt: bool, ctrl: bool, shift: bool}>
*/
public static function strictKeybinds(array $bindings): array
{
foreach ($bindings as $ind => $binding) {
$bindings[$ind]['ctrl'] ??= false;
$bindings[$ind]['alt'] ??= false;
$bindings[$ind]['shift'] ??= false;
}

return $bindings;
}
}