Skip to content

Commit

Permalink
[User Management] Add default key bindings Endpoint (#561)
Browse files Browse the repository at this point in the history
* Add default Key Bindings

* Add Translation

* Add Tests

* Apply php-cs-fixer changes

* Add Docs.

* Add Docs.

* Update Link.

---------

Co-authored-by: martineiber <[email protected]>
  • Loading branch information
martineiber and martineiber authored Nov 20, 2024
1 parent 963d930 commit 04e5665
Show file tree
Hide file tree
Showing 16 changed files with 521 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Every description is translatable and can be found in the `studio_api_docs.en.ya
- [Grid](./doc/03_Grid.md)
- [Generic Execution Engine](doc/04_Generic_Execution_Engine.md)
- [Additional Attributes](./doc/05_Additional_Custom_Attributes.md)
- [Studio User](./doc/07_User.md)
1 change: 1 addition & 0 deletions config/pimcore/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ imports:
- { resource: firewall.yaml }
- { resource: execution_engine.yaml }
- { resource: doctrine.yaml }
- { resource: user_key_binding.yaml }

pimcore:
translations:
Expand Down
128 changes: 128 additions & 0 deletions config/pimcore/user_key_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
pimcore_studio_backend:
user:
default_key_bindings:
save:
key: 'S'
action: save
ctrl: true
publish:
key: 'P'
action: publish
ctrl: true
shift: true
unpublish:
key: 'U'
action: unpublish
ctrl: true
shift: true
rename:
key: 'R'
action: rename
alt: true
shift: true
refresh:
key: 't'
action: refresh
open_asset:
key: 'A'
action: openAsset
ctrl: true
shift: true
open_object:
key: 'O'
action: openObject
ctrl: true
shift: true
open_document:
key: 'D'
action: openDocument
ctrl: true
shift: true
open_class_editor:
key: 'C'
action: openClassEditor
ctrl: true
shift: true
open_in_tree:
key: 'L'
action: openInTree
ctrl: true
shift: true
show_meta_info:
key: 'I'
action: showMetaInfo
alt: true
search_document:
key: 'W'
action: searchDocument
alt: true
search_asset:
key: 'A'
action: searchAsset
alt: true
search_object:
key: 'O'
action: searchObject
alt: true
show_element_history:
key: 'H'
action: showElementHistory
alt: true
close_all_tabs:
key: 'T'
action: closeAllTabs
alt: true
search_and_replace_assignments:
key: 'S'
action: searchAndReplaceAssignments
alt: true
redirects:
key: 'R'
action: redirects
ctrl: false
alt: true
shared_translations:
key: 'T'
action: sharedTranslations
ctrl: true
alt: true
recycle_bin:
key: 'R'
action: recycleBin
ctrl: true
alt: true
notes_events:
key: 'N'
action: notesEvents
ctrl: true
alt: true
tag_manager:
key: 'H'
action: tagManager
ctrl: true
alt: true
tag_configuration:
key: 'N'
action: tagConfiguration
ctrl: true
alt: true
users:
key: 'U'
action: users
ctrl: true
alt: true
roles:
key: 'P'
action: roles
ctrl: true
alt: true
clear_all_caches:
key: 'Q'
action: clearAllCaches
ctrl: false
alt: true
clear_data_cache:
key: 'C'
action: clearDataCache
ctrl: false
alt: true
6 changes: 6 additions & 0 deletions config/users.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\User\Service\ObjectDependenciesServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\User\Service\ObjectDependenciesService

Pimcore\Bundle\StudioBackendBundle\User\Service\KeyBindingServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\User\Service\KeyBindingService


Pimcore\Bundle\StudioBackendBundle\User\Service\MailServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\User\Service\MailService
Expand Down Expand Up @@ -73,6 +76,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\User\Hydrator\DependencyHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\User\Hydrator\DependencyHydrator

Pimcore\Bundle\StudioBackendBundle\User\Hydrator\KeyBindingHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\User\Hydrator\KeyBindingHydrator


#
# Repositories
Expand Down
15 changes: 15 additions & 0 deletions doc/07_User.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Studio User
## Default Key Bindings
To change the default key bindings, you can add a synfony configuration file in your project.
The structure of the file should be like this:
```yaml
pimcore_studio_backend:
user:
default_key_bindings:
save:
key: 'S'
action: save
ctrl: true
```
You can find the predefined key bindings here `config/pimcore/user_key_binding.yaml` in the Studio Backend Bundle.
21 changes: 21 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function getConfigTreeBuilder(): TreeBuilder
$this->addGridConfiguration($rootNode);
$this->addNoteTypes($rootNode);
$this->addDataObjectAdapterMapping($rootNode);
$this->addUserNode($rootNode);

return $treeBuilder;
}
Expand Down Expand Up @@ -284,4 +285,24 @@ private function addDataObjectAdapterMapping(ArrayNodeDefinition $node): void
->end()
->end();
}

private function addUserNode(ArrayNodeDefinition $node): void
{
$node->children()
->arrayNode('user')
->addDefaultsIfNotSet()
->children()
->arrayNode('default_key_bindings')
->prototype('array')
->children()
->scalarNode('key')->isRequired()->end()
->scalarNode('action')->isRequired()->end()
->scalarNode('alt')->defaultFalse()->end()
->scalarNode('ctrl')->defaultFalse()->end()
->scalarNode('shift')->defaultFalse()->end()
->end()
->end()
->end()
->end();
}
}
4 changes: 4 additions & 0 deletions src/DependencyInjection/PimcoreStudioBackendExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Pimcore\Bundle\StudioBackendBundle\Mercure\Service\HubServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Note\Service\NoteServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Service\OpenApiServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\User\Service\KeyBindingServiceInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
Expand Down Expand Up @@ -104,6 +105,9 @@ public function load(array $configs, ContainerBuilder $container): void

$definition = $container->getDefinition(DataAdapterServiceInterface::class);
$definition->setArgument('$dataAdapters', $config['data_object_data_adapter_mapping']);

$definition = $container->getDefinition(KeyBindingServiceInterface::class);
$definition->setArgument('$defaultKeyBindings', $config['user']['default_key_bindings']);
}

public function prepend(ContainerBuilder $container): void
Expand Down
70 changes: 70 additions & 0 deletions src/User/Controller/GetDefaultKeyBindingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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\StudioBackendBundle\User\Controller;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\User\Schema\KeyBinding;
use Pimcore\Bundle\StudioBackendBundle\User\Service\KeyBindingServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;
use function count;

/**
* @internal
*/
final class GetDefaultKeyBindingsController extends AbstractApiController
{
use PaginatedResponseTrait;

public function __construct(
SerializerInterface $serializer,
private KeyBindingServiceInterface $keyBindingService
) {
parent::__construct($serializer);
}

#[Route('/users/default-key-bindings', name: 'pimcore_studio_api_users_default_key_bindings', methods: ['GET'])]
#[IsGranted(UserPermissions::USER_MANAGEMENT->value)]
#[Get(
path: self::PREFIX . '/users/default-key-bindings',
operationId: 'user_default_key_bindings',
description: 'user_default_key_bindings_description',
summary: 'user_default_key_bindings_summary',
tags: [Tags::User->value]
)]
#[SuccessResponse(
description: 'user_default_key_bindings_response',
content: new CollectionJson(new GenericCollection(KeyBinding::class))
)]
#[DefaultResponses]
public function getDefaultKeyBindings(): JsonResponse
{
$bindings = $this->keyBindingService->getDefaultKeyBindings();

return $this->getPaginatedCollection($this->serializer, $bindings, count($bindings));
}
}
41 changes: 41 additions & 0 deletions src/User/Hydrator/KeyBindingHydrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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\StudioBackendBundle\User\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\User\Schema\KeyBinding;

/**
* @internal
*/
final class KeyBindingHydrator implements KeyBindingHydratorInterface
{
public function hydrate(array $data): array
{
$keyBindings = [];
foreach ($data as $keyBinding) {
$keyBindings[] = new KeyBinding(
key: $keyBinding['key'],
action: $keyBinding['action'],
ctrl: $keyBinding['ctrl'],
alt: $keyBinding['alt'],
shift: $keyBinding['shift'],
);
}

return $keyBindings;
}
}
30 changes: 30 additions & 0 deletions src/User/Hydrator/KeyBindingHydratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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\StudioBackendBundle\User\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\User\Schema\KeyBinding;

/**
* @internal
*/
interface KeyBindingHydratorInterface
{
/**
* @return KeyBinding[]
*/
public function hydrate(array $data): array;
}
Loading

0 comments on commit 04e5665

Please sign in to comment.