From eff78d2ab8cd6f8a818402bd06890e1ab543e82e Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Thu, 4 Jan 2024 16:40:19 -0600 Subject: [PATCH 1/2] VACMS-15901: Removes facilities not in user's sections --- .../custom/va_gov_backend/va_gov_backend.module | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docroot/modules/custom/va_gov_backend/va_gov_backend.module b/docroot/modules/custom/va_gov_backend/va_gov_backend.module index 5983862374..c6a4af772e 100644 --- a/docroot/modules/custom/va_gov_backend/va_gov_backend.module +++ b/docroot/modules/custom/va_gov_backend/va_gov_backend.module @@ -419,12 +419,12 @@ function va_gov_backend_form_alter(&$form, FormStateInterface $form_state, $form // Only run when on a node. // Additionally, reduce the number of times called when editing a paragraph, // which will have a triggering_element set. - if (isset($form['#entity_type']) - && $form['#entity_type'] === 'node' - && (!$form_state->getTriggeringElement())) { + $base_form_id = $form_state->getBuildInfo()['base_form_id'] ?? ''; + if ((!$form_state->getTriggeringElement()) && ($base_form_id === "node_form")) { $targets = [ 'field_office', 'field_listing', + 'field_facility_location', ]; _va_gov_backend_dropdown_field_access($form, $targets); } @@ -1045,6 +1045,13 @@ function _va_gov_backend_dropdown_field_access(array &$form, array $targets) { } } } + elseif (!empty($option_header)) { + // If not an array, it's just an option. + // If not in the allowed items array, take it out. + if (!in_array($header_key, $allowed_options)) { + unset($form[$target]['widget']['#options'][$header_key]); + } + } } } } From a79355d0c2f2c17f975381ea4878339c65da061a Mon Sep 17 00:00:00 2001 From: Christian Burk Date: Mon, 8 Jan 2024 16:14:52 -0600 Subject: [PATCH 2/2] Adds cypress tests --- .../content_type/vba_facility_service.feature | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/cypress/integration/features/content_type/vba_facility_service.feature diff --git a/tests/cypress/integration/features/content_type/vba_facility_service.feature b/tests/cypress/integration/features/content_type/vba_facility_service.feature new file mode 100644 index 0000000000..5955137998 --- /dev/null +++ b/tests/cypress/integration/features/content_type/vba_facility_service.feature @@ -0,0 +1,21 @@ +@content_type__vba_facility_service +Feature: CMS User may effectively interact with the VBA Facility service form + In order to confirm that cms user have access to the necessary functionality + As anyone involved in the project + I need to have certain functionality available + + Scenario: Log in and try to create a VBA Facility service as a VBA editor + When I am logged in as a user with the roles "content_creator_vba, content_publisher" + And my workbench access sections are set to "1065" + And I am at "/node/add/vba_facility_service" + Then I should see an option with the text "Columbia VA Regional Benefit Office" from dropdown with selector "#edit-field-office" + And I should not see an option with the text "Cheyenne VA Regional Benefit Office" from dropdown with selector "#edit-field-office" + +Scenario: Log in and try to create a VBA Facility service as a VBA editor with 2 sections + When I am logged in as a user with the roles "content_creator_vba, content_publisher" + And my workbench access sections are set to "1065,1104" + And I am at "/node/add/vba_facility_service" + Then I should see an option with the text "Cheyenne VA Regional Benefit Office" from dropdown with selector "#edit-field-office" + And I should see an option with the text "Columbia VA Regional Benefit Office" from dropdown with selector "#edit-field-office" + And I should not see an option with the text "Denver VA Regional Benefit Office" from dropdown with selector "#edit-field-office" +