diff --git a/tests/features/user/cancel.feature b/tests/features/user/cancel.feature index a7612e91b1..012310c1ed 100644 --- a/tests/features/user/cancel.feature +++ b/tests/features/user/cancel.feature @@ -30,11 +30,32 @@ Feature: And I check "Amelia Barker" And I select "Cancel the selected user account(s)" from "Action" And I press the "Apply to selected items" button - Then I should see the text "User Hazel Olson cannot be deleted as it is currently the sole owner of these collections:" + Then I should not see the following lines of text: + | This action cannot be undone. | + | When cancelling these accounts | + | Require email confirmation to cancel account | + | Notify user when account is canceled | + But I should see the text "User Hazel Olson cannot be deleted as it is currently the sole owner of these collections:" And I should see the text "User Amelia Barker cannot be deleted as it is currently the sole owner of these collections:" - And I should not see the text "This action cannot be undone." And I should see the link "Lugia was just released" And I should see the link "Articuno is hunted" + And I should see the link "Go back" + And I should not see the button "Cancel accounts" + + Scenario: Canceling a user directly from the profile when he is the sole owner of a collection, cannot be done. + When I am logged in as a moderator + And I click "People" + And I click "Hazel Olson" + And I click "Edit" in the "Header" region + And I press "Cancel account" + Then I should not see the following lines of text: + | This action cannot be undone. | + | When cancelling these accounts | + | Require email confirmation to cancel account | + | Notify user when account is canceled | + But I should see the text "User Hazel Olson cannot be deleted as it is currently the sole owner of these collections:" + And I should see the link "Go back" + And I should not see the button "Cancel account" @javascript Scenario: A moderator deletes a user. @@ -45,11 +66,12 @@ Feature: And I open the header local tasks menu And I click "Edit" in the "Header" region And I press "Cancel account" - And I press "Cancel account" + Then I should see the link "Go back" + When I press "Cancel account" And I wait for the batch job to finish And the following system email should have been sent: - | recipient_mail | AliciaPotter@example.com | - | subject | Your account has been deleted. | + | recipient_mail | AliciaPotter@example.com | + | subject | Your account has been deleted. | | body | Your account alicia__1997 has been deleted.This action has been done in the framework of moderation activities regularly conducted on the Joinup platform. If you believe that this action has been performed by mistake, please contact The Joinup Support Team at | @javascript diff --git a/web/modules/custom/joinup_user/joinup_user.module b/web/modules/custom/joinup_user/joinup_user.module index 79341fa397..1ae6ebc8f6 100644 --- a/web/modules/custom/joinup_user/joinup_user.module +++ b/web/modules/custom/joinup_user/joinup_user.module @@ -538,6 +538,7 @@ function joinup_user_form_user_cancel_form_alter(&$form, FormStateInterface $for $form['user_cancel_confirm']['#access'] = FALSE; $form['user_cancel_notify']['#default_value'] = TRUE; $form['user_cancel_notify']['#access'] = FALSE; + $form['actions']['cancel']['#title'] = t('Go back'); } /** diff --git a/web/profiles/joinup/src/Form/UserCancelForm.php b/web/profiles/joinup/src/Form/UserCancelForm.php index d1ccba1857..d9c4b04456 100644 --- a/web/profiles/joinup/src/Form/UserCancelForm.php +++ b/web/profiles/joinup/src/Form/UserCancelForm.php @@ -65,6 +65,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { $collections = $this->relationManager->getCollectionsWhereSoleOwner($this->entity); if (!empty($collections)) { + // No access to the 'Cancel' button should be given if the user is the + // sole owner of a collection. + $form['actions']['submit']['#access'] = FALSE; $form = [ 'collections' => [ '#theme' => 'item_list', diff --git a/web/profiles/joinup/src/Form/UserMultipleCancelConfirm.php b/web/profiles/joinup/src/Form/UserMultipleCancelConfirm.php index c4f378d92a..eb1a556956 100644 --- a/web/profiles/joinup/src/Form/UserMultipleCancelConfirm.php +++ b/web/profiles/joinup/src/Form/UserMultipleCancelConfirm.php @@ -69,6 +69,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { foreach (Element::children($form['accounts']) as $user_id) { /** @var \Drupal\user\Entity\User $account */ $account = $this->userStorage->load($user_id); + if (empty($account)) { + throw new \RuntimeException("User with id {$user_id} was not found."); + } $collections = $this->relationManager->getCollectionsWhereSoleOwner($account); if ($collections) { @@ -98,6 +101,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { // delete the user at this point. unset($form['description']); $form += $build; + // No access to the 'Cancel' button should be given if there is at least + // one user that is a sole owner of a collection. + $form['actions']['submit']['#access'] = FALSE; } return $form;