Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
50 changes: 50 additions & 0 deletions src/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Pimcore\Bundle\StudioBackendBundle\Entity\Grid\GridConfigurationShare;
use Pimcore\Bundle\StudioBackendBundle\Entity\Perspective\UserPerspectiveData;
use Pimcore\Bundle\StudioBackendBundle\Translation\Service\TranslatorService;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Pimcore\Extension\Bundle\Installer\Exception\InstallationException;
use Pimcore\Extension\Bundle\Installer\SettingsStoreAwareInstaller;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
Expand All @@ -36,6 +37,11 @@
*/
final class Installer extends SettingsStoreAwareInstaller
{
private const array PERSPECTIVE_PERMISSIONS = [
UserPermissions::PERSPECTIVE_EDITOR->value,
UserPermissions::WIDGET_EDITOR->value,
];

public function __construct(
private readonly Connection $db,
BundleInterface $bundle,
Expand All @@ -55,6 +61,7 @@ public function install(): void
$this->createGridConfigurationSharesTable($schema);
$this->createGridConfigurationFavoritesTable($schema);
$this->createUserPerspectivesTable($schema);
$this->addUserPermission($schema);
$this->executeDiffSql($schema);

parent::install();
Expand Down Expand Up @@ -83,6 +90,7 @@ public function uninstall(): void
if ($schema->hasTable(UserPerspectiveData::TABLE_NAME)) {
$schema->dropTable(UserPerspectiveData::TABLE_NAME);
}
$this->removeUserPermission($schema);

$this->executeDiffSql($schema);

Expand Down Expand Up @@ -334,6 +342,48 @@ public function createUserPerspectivesTable(Schema $schema): void
$table->setPrimaryKey(['user'], 'pk_' . UserPerspectiveData::TABLE_NAME);
}

/**
* @throws Exception
*/
private function addUserPermission(Schema $schema): void
{
if ($schema->hasTable(UserPermissions::DEFINITIONS_TABLE->value)) {
foreach (self::PERSPECTIVE_PERMISSIONS as $permission) {
$queryBuilder = $this->db->createQueryBuilder();
$queryBuilder
->insert(UserPermissions::DEFINITIONS_TABLE->value)
->values([
$this->db->quoteIdentifier('key') => ':key',
$this->db->quoteIdentifier('category') => ':category',
])
->setParameters([
'key' => $permission,
'category' => UserPermissions::PERMISSIONS_CATEGORY->value,
]);

$queryBuilder->executeStatement();
}
}
}

/**
* @throws Exception
*/
private function removeUserPermission(Schema $schema): void
{
if ($schema->hasTable(UserPermissions::DEFINITIONS_TABLE->value)) {
foreach (self::PERSPECTIVE_PERMISSIONS as $permission) {
$queryBuilder = $this->db->createQueryBuilder();
$queryBuilder
->delete(UserPermissions::DEFINITIONS_TABLE->value)
->where($this->db->quoteIdentifier('key') . ' = :key')
->setParameter('key', $permission);

$queryBuilder->executeStatement();
}
}
}

/**
* @throws Exception
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Perspective/Controller/Widget/AddController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(
name: 'pimcore_studio_api_create_perspectives_widgets_config',
methods: ['POST']
)]
#[IsGranted(UserPermissions::WIDGET_EDIT->value)]
#[IsGranted(UserPermissions::WIDGET_EDITOR->value)]
#[Post(
path: self::PREFIX . self::ROUTE,
operationId: 'perspective_widget_create',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(
* @throws InvalidArgumentException|NotFoundException
*/
#[Route(self::ROUTE, name: 'pimcore_studio_api_get_perspectives_widgets_configurations_list', methods: ['GET'])]
#[IsGranted(UserPermissions::WIDGET_EDIT->value)]
#[IsGranted(UserPermissions::WIDGET_EDITOR->value)]
#[Get(
path: self::PREFIX . self::ROUTE,
operationId: 'perspective_widget_get_config_collection',
Expand Down
2 changes: 1 addition & 1 deletion src/Perspective/Controller/Widget/DeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(
* @throws InvalidArgumentException|NotFoundException|NotWriteableException
*/
#[Route(self::ROUTE, name: 'pimcore_studio_api_delete_perspectives_widgets_config', methods: ['DELETE'])]
#[IsGranted(UserPermissions::WIDGET_EDIT->value)]
#[IsGranted(UserPermissions::WIDGET_EDITOR->value)]
#[Delete(
path: self::PREFIX . self::ROUTE,
operationId: 'perspective_widget_delete',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(
requirements: ['id' => '\d+'],
methods: ['GET']
)]
#[IsGranted(UserPermissions::WIDGET_EDIT->value)]
#[IsGranted(UserPermissions::WIDGET_EDITOR->value)]
#[Get(
path: self::PREFIX . self::ROUTE,
operationId: 'perspective_widget_get_config_by_id',
Expand Down
2 changes: 1 addition & 1 deletion src/Perspective/Controller/Widget/TypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(
}

#[Route(self::ROUTE, name: 'pimcore_studio_api_get_perspectives_widgets_types', methods: ['GET'])]
#[IsGranted(UserPermissions::WIDGET_EDIT->value)]
#[IsGranted(UserPermissions::WIDGET_EDITOR->value)]
#[Get(
path: self::PREFIX . self::ROUTE,
operationId: 'perspective_widget_get_type_collection',
Expand Down
2 changes: 1 addition & 1 deletion src/Perspective/Controller/Widget/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(
name: 'pimcore_studio_api_update_perspectives_widgets_config',
methods: ['PUT']
)]
#[IsGranted(UserPermissions::WIDGET_EDIT->value)]
#[IsGranted(UserPermissions::WIDGET_EDITOR->value)]
#[Put(
path: self::PREFIX . self::ROUTE,
operationId: 'perspective_widget_update_config_by_id',
Expand Down
4 changes: 3 additions & 1 deletion src/Util/Constant/UserPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
enum UserPermissions: string
{
case PERMISSIONS_CATEGORY = 'Pimcore Studio Backend Bundle';
case DEFINITIONS_TABLE = 'users_permission_definitions';
case ASSETS = 'assets';
case DATA_OBJECTS = 'objects';
case DOCUMENTS = 'documents';
Expand All @@ -40,5 +42,5 @@ enum UserPermissions: string
case TAGS_SEARCH = 'tags_search';
case THUMBNAILS = 'thumbnails';
case USER_MANAGEMENT = 'users';
case WIDGET_EDIT = 'perspective_editor_view_edit';
case WIDGET_EDITOR = 'perspective_widget_editor';
}
2 changes: 2 additions & 0 deletions translations/admin.en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
perspective_editor: Perspective Editor
perspective_widget_editor: Widget Editor
Loading