File tree Expand file tree Collapse file tree 5 files changed +84
-14
lines changed
Expand file tree Collapse file tree 5 files changed +84
-14
lines changed Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff line change 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>
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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+
209217function ensureUserNotInPIGroup (UnityGroup $ pi_group )
210218{
211219 global $ USER ;
Original file line number Diff line number Diff line change 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
245252if ($ 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?>
You can’t perform that action at this time.
0 commit comments