2727use Pimcore \Bundle \StudioBackendBundle \Entity \Grid \GridConfigurationShare ;
2828use Pimcore \Bundle \StudioBackendBundle \Entity \Perspective \UserPerspectiveData ;
2929use Pimcore \Bundle \StudioBackendBundle \Translation \Service \TranslatorService ;
30+ use Pimcore \Bundle \StudioBackendBundle \Util \Constant \UserPermissions ;
3031use Pimcore \Extension \Bundle \Installer \Exception \InstallationException ;
3132use Pimcore \Extension \Bundle \Installer \SettingsStoreAwareInstaller ;
3233use Symfony \Component \HttpKernel \Bundle \BundleInterface ;
3637 */
3738final class Installer extends SettingsStoreAwareInstaller
3839{
40+ private const array PERSPECTIVE_PERMISSIONS = [
41+ UserPermissions::PERSPECTIVE_EDITOR ->value ,
42+ UserPermissions::WIDGET_EDITOR ->value ,
43+ ];
44+
3945 public function __construct (
4046 private readonly Connection $ db ,
4147 BundleInterface $ bundle ,
@@ -55,6 +61,7 @@ public function install(): void
5561 $ this ->createGridConfigurationSharesTable ($ schema );
5662 $ this ->createGridConfigurationFavoritesTable ($ schema );
5763 $ this ->createUserPerspectivesTable ($ schema );
64+ $ this ->addUserPermission ($ schema );
5865 $ this ->executeDiffSql ($ schema );
5966
6067 parent ::install ();
@@ -83,6 +90,7 @@ public function uninstall(): void
8390 if ($ schema ->hasTable (UserPerspectiveData::TABLE_NAME )) {
8491 $ schema ->dropTable (UserPerspectiveData::TABLE_NAME );
8592 }
93+ $ this ->removeUserPermission ($ schema );
8694
8795 $ this ->executeDiffSql ($ schema );
8896
@@ -334,6 +342,48 @@ public function createUserPerspectivesTable(Schema $schema): void
334342 $ table ->setPrimaryKey (['user ' ], 'pk_ ' . UserPerspectiveData::TABLE_NAME );
335343 }
336344
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+
337387 /**
338388 * @throws Exception
339389 */
0 commit comments