diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index 606a1aa8..086f53af 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -381,6 +381,16 @@ public function requestAccountDeletion(): void ]); } + public function cancelRequestAccountDeletion(): void + { + $this->SQL->deleteAccountDeletionRequest($this->uid); + $this->MAILER->sendMail("admin", "account_deletion_request_cancelled_admin", [ + "user" => $this->uid, + "name" => $this->getFullname(), + "email" => $this->getMail(), + ]); + } + /** * Checks if the user has requested account deletion */ diff --git a/resources/mail/account_deletion_request_cancelled_admin.php b/resources/mail/account_deletion_request_cancelled_admin.php new file mode 100644 index 00000000..39f105fb --- /dev/null +++ b/resources/mail/account_deletion_request_cancelled_admin.php @@ -0,0 +1,15 @@ +Subject = "Account Deletion Request Cancelled"; ?> + +

Hello,

+ +

A user has cancelled their request for account deletion. User details are below:

+ +

+ Username +
+ Name +
+ Email +

diff --git a/test/functional/AccountDeletionRequestTest.php b/test/functional/AccountDeletionRequestTest.php index 8a590e3a..83177b25 100644 --- a/test/functional/AccountDeletionRequestTest.php +++ b/test/functional/AccountDeletionRequestTest.php @@ -69,4 +69,25 @@ public function testRequestAccountDeletionUserHasRequest() ensureUserNotInPIGroup($pi_group); } } + + public function testRequestAccountDeletionCancel() + { + global $USER; + switchUser(...getBlankUser()); + $this->assertEmpty($USER->getPIGroupGIDs()); + $this->assertNumberAccountDeletionRequests(0); + $this->assertNumberRequests(0); + try { + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "account_deletion_request", + ]); + $this->assertNumberAccountDeletionRequests(1); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "cancel_account_deletion_request", + ]); + $this->assertNumberAccountDeletionRequests(0); + } finally { + ensureUserNotRequestedAccountDeletion(); + } + } } diff --git a/test/phpunit-bootstrap.php b/test/phpunit-bootstrap.php index b7833676..862064b9 100644 --- a/test/phpunit-bootstrap.php +++ b/test/phpunit-bootstrap.php @@ -206,6 +206,14 @@ function ensureOrgGroupDoesNotExist() } } +function ensureUserNotRequestedAccountDeletion() +{ + global $USER, $SSO, $LDAP, $SQL, $MAILER, $WEBHOOK; + if ($SQL->accDeletionRequestExists($USER->uid)) { + $SQL->deleteAccountDeletionRequest($USER->uid); + } +} + function ensureUserNotInPIGroup(UnityGroup $pi_group) { global $USER; diff --git a/webroot/panel/account.php b/webroot/panel/account.php index 997d172a..8c2cf1a2 100644 --- a/webroot/panel/account.php +++ b/webroot/panel/account.php @@ -86,10 +86,17 @@ if ($hasGroups) { break; } + // FIXME send an error message if already exists if (!$SQL->accDeletionRequestExists($USER->uid)) { $USER->requestAccountDeletion(); } break; + case "cancel_account_deletion_request": + // FIXME send an error message if doesn't exist + if ($SQL->accDeletionRequestExists($USER->uid)) { + $USER->cancelRequestAccountDeletion(); + } + break; } } @@ -245,25 +252,34 @@ if ($hasGroups) { echo "

You cannot request to delete your account while you are in a PI group.

"; } else { - echo " -
- - "; if ($SQL->accDeletionRequestExists($USER->uid)) { - echo ""; echo " - +

Your request has been submitted and is currently pending.

+ + + +
"; } else { - echo ""; + echo " +
+ + +
+ "; } - echo ""; } ?>