Skip to content

Commit b0253ac

Browse files
cancel request account deletion (#376)
Co-authored-by: bryank-cs <[email protected]>
1 parent df4cf1a commit b0253ac

File tree

5 files changed

+84
-14
lines changed

5 files changed

+84
-14
lines changed

resources/lib/UnityUser.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,16 @@ public function requestAccountDeletion(): void
381381
]);
382382
}
383383

384+
public function cancelRequestAccountDeletion(): void
385+
{
386+
$this->SQL->deleteAccountDeletionRequest($this->uid);
387+
$this->MAILER->sendMail("admin", "account_deletion_request_cancelled_admin", [
388+
"user" => $this->uid,
389+
"name" => $this->getFullname(),
390+
"email" => $this->getMail(),
391+
]);
392+
}
393+
384394
/**
385395
* Checks if the user has requested account deletion
386396
*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$this->Subject = "Account Deletion Request Cancelled"; ?>
4+
5+
<p>Hello,</p>
6+
7+
<p>A user has cancelled their request for account deletion. User details are below:</p>
8+
9+
<p>
10+
<strong>Username</strong> <?php echo $data["user"]; ?>
11+
<br>
12+
<strong>Name</strong> <?php echo $data["name"]; ?>
13+
<br>
14+
<strong>Email</strong> <?php echo $data["email"]; ?>
15+
</p>

test/functional/AccountDeletionRequestTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,25 @@ public function testRequestAccountDeletionUserHasRequest()
6969
ensureUserNotInPIGroup($pi_group);
7070
}
7171
}
72+
73+
public function testRequestAccountDeletionCancel()
74+
{
75+
global $USER;
76+
switchUser(...getBlankUser());
77+
$this->assertEmpty($USER->getPIGroupGIDs());
78+
$this->assertNumberAccountDeletionRequests(0);
79+
$this->assertNumberRequests(0);
80+
try {
81+
http_post(__DIR__ . "/../../webroot/panel/account.php", [
82+
"form_type" => "account_deletion_request",
83+
]);
84+
$this->assertNumberAccountDeletionRequests(1);
85+
http_post(__DIR__ . "/../../webroot/panel/account.php", [
86+
"form_type" => "cancel_account_deletion_request",
87+
]);
88+
$this->assertNumberAccountDeletionRequests(0);
89+
} finally {
90+
ensureUserNotRequestedAccountDeletion();
91+
}
92+
}
7293
}

test/phpunit-bootstrap.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ function ensureOrgGroupDoesNotExist()
206206
}
207207
}
208208

209+
function ensureUserNotRequestedAccountDeletion()
210+
{
211+
global $USER, $SQL;
212+
if ($SQL->accDeletionRequestExists($USER->uid)) {
213+
$SQL->deleteAccountDeletionRequest($USER->uid);
214+
}
215+
}
216+
209217
function ensureUserNotInPIGroup(UnityGroup $pi_group)
210218
{
211219
global $USER;

webroot/panel/account.php

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,17 @@
8686
if ($hasGroups) {
8787
break;
8888
}
89+
// FIXME send an error message if already exists
8990
if (!$SQL->accDeletionRequestExists($USER->uid)) {
9091
$USER->requestAccountDeletion();
9192
}
9293
break;
94+
case "cancel_account_deletion_request":
95+
// FIXME send an error message if doesn't exist
96+
if ($SQL->accDeletionRequestExists($USER->uid)) {
97+
$USER->cancelRequestAccountDeletion();
98+
}
99+
break;
93100
}
94101
}
95102

@@ -245,25 +252,34 @@
245252
if ($hasGroups) {
246253
echo "<p>You cannot request to delete your account while you are in a PI group.</p>";
247254
} else {
248-
echo "
249-
<form
250-
action=''
251-
method='POST'
252-
id='accDel'
253-
onsubmit='return confirm(\"Are you sure you want to request an account deletion?\")'
254-
>
255-
<input type='hidden' name='form_type' value='account_deletion_request' />
256-
";
257255
if ($SQL->accDeletionRequestExists($USER->uid)) {
258-
echo "<input type='submit' value='Request Account Deletion' disabled />";
259256
echo "
260-
<label style='margin-left: 10px'>
261-
Your request has been submitted and is currently pending</label>
257+
<p>Your request has been submitted and is currently pending.</p>
258+
<form
259+
action=''
260+
method='POST'
261+
onsubmit='
262+
return confirm(
263+
\"Are you sure you want to cancel your request for account deletion?\"
264+
)
265+
'
266+
>
267+
<input type='hidden' name='form_type' value='cancel_account_deletion_request' />
268+
<input type='submit' value='Cancel Account Deletion Request' />
269+
</form>
262270
";
263271
} else {
264-
echo "<input type='submit' value='Request Account Deletion' />";
272+
echo "
273+
<form
274+
action=''
275+
method='POST'
276+
onsubmit='return confirm(\"Are you sure you want to request an account deletion?\")'
277+
>
278+
<input type='hidden' name='form_type' value='account_deletion_request' />
279+
<input type='submit' value='Request Account Deletion' />
280+
</form>
281+
";
265282
}
266-
echo "</form>";
267283
}
268284

269285
?>

0 commit comments

Comments
 (0)