From 20195675f36947666582266415feb4b117f771e6 Mon Sep 17 00:00:00 2001 From: Christia Troyer Date: Fri, 15 Sep 2023 11:06:48 -0700 Subject: [PATCH 1/2] VACMS-15222: Unlock benefit taxononmy fields to content admins --- .../EventSubscriber/BenefitsSubscriber.php | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/docroot/modules/custom/va_gov_benefits/src/EventSubscriber/BenefitsSubscriber.php b/docroot/modules/custom/va_gov_benefits/src/EventSubscriber/BenefitsSubscriber.php index 157ab4c533..cba3eefcb2 100644 --- a/docroot/modules/custom/va_gov_benefits/src/EventSubscriber/BenefitsSubscriber.php +++ b/docroot/modules/custom/va_gov_benefits/src/EventSubscriber/BenefitsSubscriber.php @@ -2,12 +2,12 @@ namespace Drupal\va_gov_benefits\EventSubscriber; -use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent; -use Drupal\core_event_dispatcher\FormHookEvents; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Form\FormStateInterface; -use Drupal\va_gov_user\Service\UserPermsService; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent; +use Drupal\core_event_dispatcher\FormHookEvents; +use Drupal\va_gov_user\Service\UserPermsService; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -65,14 +65,19 @@ public function formAlter(FormAlterEvent $event): void { */ public function protectSelectFields(array &$form, FormStateInterface $form_state): void { $form_object = $form_state->getFormObject(); - if ($form_object instanceof ContentEntityForm) { - $bundle = $form_object->getEntity()->bundle(); - if (!$this->userPermsService->hasAdminRole(TRUE) && $bundle === 'va_benefits_taxonomy') { - // Disable Official Benefit name field from non-editors. + if ($form_object instanceof ContentEntityForm + && $form_object->getEntity()->bundle() === 'va_benefits_taxonomy') { + // Distinguish between admins and lock down accordingly. + $is_admin = $this->userPermsService->hasAdminRole(); + $is_administrator_only = $this->userPermsService->hasAdminRole(TRUE); + if (!$is_admin) { + // Disable Official Benefit name field from non-admins. $form['name']['#disabled'] = TRUE; - // Hide API ID field from non-editors. - $form['field_va_benefit_api_id']['#access'] = FALSE; - // Hide taxonomy Relations field from non-editors. + // Disable API ID field from non-admins. + $form['field_va_benefit_api_id']['#disabled'] = TRUE; + } + if (!$is_administrator_only) { + // Hide taxonomy Relations field. $form['relations']['#access'] = FALSE; } } From fd4a6d9007bfef25cbfaf33b1bf4606697bf8dc0 Mon Sep 17 00:00:00 2001 From: Christia Troyer Date: Fri, 15 Sep 2023 12:27:14 -0700 Subject: [PATCH 2/2] VACMS-15222: Update cypress test to accommodate unlocking field access --- .../features/taxonomy_type/va_benefit_taxonomy.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cypress/integration/features/taxonomy_type/va_benefit_taxonomy.feature b/tests/cypress/integration/features/taxonomy_type/va_benefit_taxonomy.feature index 273337fff9..939c03f369 100644 --- a/tests/cypress/integration/features/taxonomy_type/va_benefit_taxonomy.feature +++ b/tests/cypress/integration/features/taxonomy_type/va_benefit_taxonomy.feature @@ -6,8 +6,8 @@ Feature: Taxonomy: VA Benefits When I am at "admin/structure/taxonomy/manage/va_benefits_taxonomy/add" Then I should see "Official Benefit name" And I should see "The full name of the benefit." - And an element with the selector "#edit-name-0-value" should be disabled - And an element with the selector "#edit-field-va-benefit-api-id-0-value" should not exist + And an element with the selector "#edit-name-0-value" should not be disabled + And an element with the selector "#edit-field-va-benefit-api-id-0-value" should exist And an element with the selector "#edit-relations" should not exist Scenario: Log in and create a va benefit.