Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Isaicp 4392: Change the 'Cancel account' button label on the user cancel form #1215

Merged
merged 4 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions tests/features/user/cancel.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 | [email protected] |
| subject | Your account has been deleted. |
| recipient_mail | [email protected] |
| 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
Expand Down
1 change: 1 addition & 0 deletions web/modules/custom/joinup_user/joinup_user.module
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
3 changes: 3 additions & 0 deletions web/profiles/joinup/src/Form/UserCancelForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

@pfrenssen pfrenssen Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this but shouldn't we solve this differently? I would suggest to show a greyed out version of the button with a tooltip "This user cannot be deleted since it is the owner of a collection".

This is out of scope for this ticket so I made a followup for it: ISAICP-4555

$form = [
'collections' => [
'#theme' => 'item_list',
Expand Down
6 changes: 6 additions & 0 deletions web/profiles/joinup/src/Form/UserMultipleCancelConfirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down