From 033a89683376325e30116e1c62dbe85f5698b995 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Thu, 26 Dec 2024 14:17:40 +0530 Subject: [PATCH] ACMS-4373: Refactore code and add toolbar test in CI. --- .github/workflows/acquia_cms_ci.workflow.yml | 1 + .github/workflows/acquia_cms_cron.yml | 1 + .../acquia_cms_toolbar.module | 28 ++----------------- .../EntityOperations/PermissionManager.php | 2 +- .../acquia_cms_tour/acquia_cms_tour.module | 7 ++--- 5 files changed, 9 insertions(+), 30 deletions(-) diff --git a/.github/workflows/acquia_cms_ci.workflow.yml b/.github/workflows/acquia_cms_ci.workflow.yml index cde428f6c..84a694c9d 100644 --- a/.github/workflows/acquia_cms_ci.workflow.yml +++ b/.github/workflows/acquia_cms_ci.workflow.yml @@ -240,6 +240,7 @@ jobs: - acquia_cms_place - acquia_cms_search - acquia_cms_site_studio + - acquia_cms_toolbar - acquia_cms_tour - acquia_cms_video steps: diff --git a/.github/workflows/acquia_cms_cron.yml b/.github/workflows/acquia_cms_cron.yml index c405d6458..6f52ab32e 100644 --- a/.github/workflows/acquia_cms_cron.yml +++ b/.github/workflows/acquia_cms_cron.yml @@ -383,6 +383,7 @@ jobs: - acquia_cms_place - acquia_cms_search - acquia_cms_site_studio + - acquia_cms_toolbar - acquia_cms_tour - acquia_cms_video steps: diff --git a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module index 0b2316d18..aafd15256 100644 --- a/modules/acquia_cms_toolbar/acquia_cms_toolbar.module +++ b/modules/acquia_cms_toolbar/acquia_cms_toolbar.module @@ -106,32 +106,10 @@ function _acquia_cms_toolbar_get_environment_indicator_color_config(): array { /** * Implements hook_entity_insert(). */ -function acquia_cms_toolbar_entity_insert(EntityInterface $entity) { - if($entity instanceof RoleInterface && !$entity->isSyncing()) { +function acquia_cms_toolbar_user_role_insert(RoleInterface $role) { + if(!$role->isSyncing()) { $class_resolver = \Drupal::service('class_resolver'); $class_resolver->getInstanceFromDefinition(PermissionManager::class) - ->grantPermissionToRoles([$entity->id()]); - } -} - -/** - * Update role permission handler. - * - * @param array|null $role_ids - * - * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException - * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException - */ -function update_toolbar_role_permission(array $role_ids = NULL): void { - $roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple($role_ids ?? [ - 'content_administrator', - 'content_author', - 'content_editor', - 'developer', - 'site_builder', - 'user_administrator', - ]); - foreach ($roles as $role) { - $role->grantPermission('access toolbar')->trustData()->save(); + ->grantPermissionToRoles([$role->id()]); } } diff --git a/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php b/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php index 0e7d3be58..cdf2bc7be 100644 --- a/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php +++ b/modules/acquia_cms_toolbar/src/EntityOperations/PermissionManager.php @@ -36,7 +36,7 @@ public static function create(ContainerInterface $container) { * {@inheritdoc} */ public function grantPermissionToRoles(array $role_ids = NULL): void { - $roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple($role_ids ?? [ + $roles = $this->entityTypeManager->getStorage('user_role')->loadMultiple($role_ids ?? [ 'content_administrator', 'content_author', 'content_editor', diff --git a/modules/acquia_cms_tour/acquia_cms_tour.module b/modules/acquia_cms_tour/acquia_cms_tour.module index 7aae2390a..e0a9808ef 100644 --- a/modules/acquia_cms_tour/acquia_cms_tour.module +++ b/modules/acquia_cms_tour/acquia_cms_tour.module @@ -60,10 +60,9 @@ function acquia_cms_tour_modules_uninstalled(array $modules) { /** * Implements hook_cms_tour_entity_insert(). */ -function acquia_cms_tour_entity_insert(EntityInterface $entity) { - if($entity instanceof RoleInterface && - !$entity->isSyncing() && - $entity->id() == 'content_administrator' +function acquia_cms_tour_user_role_insert(RoleInterface $role) { + if(!$role->isSyncing() && + $role->id() == 'content_administrator' ) { $role = \Drupal::entityTypeManager()->getStorage('user_role')->load('content_administrator'); $role->grantPermission('access acquia cms tour dashboard')->trustData()->save();