Skip to content

Commit

Permalink
VACMS-17676: prevent removal required services (#18318)
Browse files Browse the repository at this point in the history
* VACMS-17676: Required or optional box showing

* VACMS-17676: archived option not showing for non-admins

* VACMS-17676: Updates cypress tests

* VACMS-17676: Updating Cypress to avoid reuse
  • Loading branch information
omahane authored Jun 14, 2024
1 parent 9d29d6d commit 42b5458
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,84 @@ public function alterVetCenterServiceNodeForm(FormIdAlterEvent $event): void {
$is_admin = $this->userPermsService->hasAdminRole(TRUE);
if (!$is_admin) {
$this->disableFacilityServiceChange($form, $form_state);
$this->disableArchivingRequiredServicesNonAdmins($form, $form_state);
}
$this->showServiceAsRequiredOrOptional($form, $form_state);

}

/**
* Disable the Archived moderation state on required services for non-admins.
*
* @param array $form
* The node form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
public function disableArchivingRequiredServicesNonAdmins(array &$form, FormStateInterface $form_state) {
$required_services = $this->requiredServices->getRequiredServices();
$form_object = $form_state->getFormObject();
$node = $form_object->getEntity();
$service_id = $node->field_service_name_and_descripti->target_id;
foreach ($required_services as $required_service) {
$required_service_id = $required_service->id();
if ($service_id == $required_service_id) {
if ($form['moderation_state']['widget'][0]['state']['#options']['archived']) {
unset($form['moderation_state']['widget'][0]['state']['#options']['archived']);
}
}
}
}

/**
* Show service as required or optional.
*
* @param array $form
* The node form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
public function showServiceAsRequiredOrOptional(array &$form, FormStateInterface $form_state) {
$required_services = $this->requiredServices->getRequiredServices();
$form_object = $form_state->getFormObject();
$node = $form_object->getEntity();
$service_id = $node->field_service_name_and_descripti->target_id;
$service_name = $node->field_service_name_and_descripti->entity->getName();
foreach ($required_services as $required_service) {
$required_service_id = $required_service->id();
if ($service_id == $required_service_id) {
// This is a required service.
$service_required_or_optional = $this->t('a required');
$can_or_cannot = $this->t('cannot');
$service_required_or_optional_capitalized = $this->t('Required');
break;
}
else {
// This is an optional service.
$service_required_or_optional = $this->t('an optional');
$can_or_cannot = $this->t('can');
$service_required_or_optional_capitalized = $this->t('Optional');
}
}

$required_or_optional_markup = new FormattableMarkup(
'<div class="field-group-tooltip not-editable centralized field-group-html-element tooltip-layout">
<p><strong>:service_required_or_optional_capitalized Service</strong>
<br />:service_name is :required_or_optional service. :service_required_or_optional_capitalized services :can_or_cannot be archived. Learn more in the <a href="https://prod.cms.va.gov/help/vet-centers/how-to-edit-a-vet-center-service" target="_blank">Knowledge Base article about Vet Center Services (opens in a new window).</a></p>
</div>',
[
':service_required_or_optional_capitalized' => $service_required_or_optional_capitalized,
':required_or_optional' => $service_required_or_optional,
':service_name' => $service_name,
':can_or_cannot' => $can_or_cannot,
]
);
$form['service_optional_or_required'] = [
'#type' => 'markup',
'#markup' => $this->t('@markup', ['@markup' => $required_or_optional_markup]),
'#weight' => 5,
];

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,40 @@ Scenario: Editors should not be able to rename a Vet Center - Facility Service
And I click the "Unlock" link
And I click the "Confirm break lock" button

Scenario: Editors should be able to archive an optional Vet Center - Facility Service
Given I am logged in as a user with the roles "content_creator_vet_center, content_publisher, content_editor"
# Escanaba Vet Center
And my workbench access sections are set to "392"
# Escanaba Vet Center - Workshops and Classes
When I am at "node/19570/edit"
And I scroll to element "select#edit-moderation-state-0-state"
Then an option with the text "Archived" from dropdown with selector "select#edit-moderation-state-0-state" should be visible
Then I scroll to position "bottom"
And I click the "Unlock" link
And I click the "Confirm break lock" button

Scenario: Editors should be not able to archive a required Vet Center - Facility Service
Given I am logged in as a user with the roles "content_creator_vet_center, content_publisher, content_editor"
# Escanaba Vet Center
And my workbench access sections are set to "392"
# Escanaba Vet Center - Addiction
When I am at "node/17597/edit"
And I scroll to element "select#edit-moderation-state-0-state"
Then an option with the text "Archived" from dropdown with selector "select#edit-moderation-state-0-state" should not be visible
Then I scroll to position "bottom"
And I click the "Unlock" link
And I click the "Confirm break lock" button

Scenario: Admins should be able to archive a required Vet Center - Facility Service
Given I am logged in as a user with the "administrator" role
# Escanaba Vet Center - Suicide prevention
When I am at "node/17926/edit"
And I scroll to element "select#edit-moderation-state-0-state"
Then an option with the text "Archived" from dropdown with selector "select#edit-moderation-state-0-state" should be visible
Then I scroll to position "bottom"
And I click the "Unlock" link
And I click the "Confirm break lock" button

Scenario: Administrators should be able to rename a Vet Center - Facility Service
Given I am logged in as a user with the "administrator" role
# Escanaba Vet Center - Telehealth
Expand Down

0 comments on commit 42b5458

Please sign in to comment.