27
27
use Pimcore \Bundle \StudioBackendBundle \Entity \Grid \GridConfigurationShare ;
28
28
use Pimcore \Bundle \StudioBackendBundle \Entity \Perspective \UserPerspectiveData ;
29
29
use Pimcore \Bundle \StudioBackendBundle \Translation \Service \TranslatorService ;
30
+ use Pimcore \Bundle \StudioBackendBundle \Util \Constant \UserPermissions ;
30
31
use Pimcore \Extension \Bundle \Installer \Exception \InstallationException ;
31
32
use Pimcore \Extension \Bundle \Installer \SettingsStoreAwareInstaller ;
32
33
use Symfony \Component \HttpKernel \Bundle \BundleInterface ;
36
37
*/
37
38
final class Installer extends SettingsStoreAwareInstaller
38
39
{
40
+ private const array PERSPECTIVE_PERMISSIONS = [
41
+ UserPermissions::PERSPECTIVE_EDITOR ->value ,
42
+ UserPermissions::WIDGET_EDITOR ->value ,
43
+ ];
44
+
39
45
public function __construct (
40
46
private readonly Connection $ db ,
41
47
BundleInterface $ bundle ,
@@ -55,6 +61,7 @@ public function install(): void
55
61
$ this ->createGridConfigurationSharesTable ($ schema );
56
62
$ this ->createGridConfigurationFavoritesTable ($ schema );
57
63
$ this ->createUserPerspectivesTable ($ schema );
64
+ $ this ->addUserPermission ($ schema );
58
65
$ this ->executeDiffSql ($ schema );
59
66
60
67
parent ::install ();
@@ -83,6 +90,7 @@ public function uninstall(): void
83
90
if ($ schema ->hasTable (UserPerspectiveData::TABLE_NAME )) {
84
91
$ schema ->dropTable (UserPerspectiveData::TABLE_NAME );
85
92
}
93
+ $ this ->removeUserPermission ($ schema );
86
94
87
95
$ this ->executeDiffSql ($ schema );
88
96
@@ -334,6 +342,48 @@ public function createUserPerspectivesTable(Schema $schema): void
334
342
$ table ->setPrimaryKey (['user ' ], 'pk_ ' . UserPerspectiveData::TABLE_NAME );
335
343
}
336
344
345
+ /**
346
+ * @throws Exception
347
+ */
348
+ private function addUserPermission (Schema $ schema ): void
349
+ {
350
+ if ($ schema ->hasTable (UserPermissions::DEFINITIONS_TABLE ->value )) {
351
+ foreach (self ::PERSPECTIVE_PERMISSIONS as $ permission ) {
352
+ $ queryBuilder = $ this ->db ->createQueryBuilder ();
353
+ $ queryBuilder
354
+ ->insert (UserPermissions::DEFINITIONS_TABLE ->value )
355
+ ->values ([
356
+ $ this ->db ->quoteIdentifier ('key ' ) => ':key ' ,
357
+ $ this ->db ->quoteIdentifier ('category ' ) => ':category ' ,
358
+ ])
359
+ ->setParameters ([
360
+ 'key ' => $ permission ,
361
+ 'category ' => UserPermissions::PERMISSIONS_CATEGORY ->value ,
362
+ ]);
363
+
364
+ $ queryBuilder ->executeStatement ();
365
+ }
366
+ }
367
+ }
368
+
369
+ /**
370
+ * @throws Exception
371
+ */
372
+ private function removeUserPermission (Schema $ schema ): void
373
+ {
374
+ if ($ schema ->hasTable (UserPermissions::DEFINITIONS_TABLE ->value )) {
375
+ foreach (self ::PERSPECTIVE_PERMISSIONS as $ permission ) {
376
+ $ queryBuilder = $ this ->db ->createQueryBuilder ();
377
+ $ queryBuilder
378
+ ->delete (UserPermissions::DEFINITIONS_TABLE ->value )
379
+ ->where ($ this ->db ->quoteIdentifier ('key ' ) . ' = :key ' )
380
+ ->setParameter ('key ' , $ permission );
381
+
382
+ $ queryBuilder ->executeStatement ();
383
+ }
384
+ }
385
+ }
386
+
337
387
/**
338
388
* @throws Exception
339
389
*/
0 commit comments