Skip to content

Commit eb4fbb2

Browse files
authored
replace "request account deletion" with "disable" (#612)
1 parent 8c28d42 commit eb4fbb2

19 files changed

Lines changed: 138 additions & 420 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ rm "$prod" && ln -s "$old" "$prod"
156156
- `disable_warning_days`: list of day numbers when a user will get an email warning that their account will be disabled
157157
- `disable_day`: day number when a user will be disabled
158158
- a "day number" starts counting from the last day that a user logged in, so on day 5, the user last logged in 5 days ago
159+
- drop the `account_deletion_requests` table
159160

160161
### 1.5 -> 1.6
161162

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ parameters:
5353
- '#If condition is always false\.#'
5454
paths:
5555
- test/functional/PIBecomeDenyTest.php
56+
- test/functional/UserDisableTest.php
5657
- webroot/panel/pi.php
5758
# $Subject is written by mail templates
5859
- messages:

resources/lib/UnityGroup.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ public function requestGroup(?bool $send_mail_to_admins = null, bool $send_mail
4343
if ($this->exists() && !$this->getIsDisabled()) {
4444
return;
4545
}
46-
if ($this->SQL->accDeletionRequestExists($this->getOwner()->uid)) {
47-
return;
48-
}
4946
$context = [
5047
"user" => $this->getOwner()->uid,
5148
"org" => $this->getOwner()->getOrg(),
@@ -289,9 +286,6 @@ public function newUserRequest(UnityUser $new_user, bool $send_mail = true): voi
289286
UnityHTTPD::errorLog("warning", "user '$new_user' already requested group membership");
290287
return;
291288
}
292-
if ($this->SQL->accDeletionRequestExists($new_user->uid)) {
293-
throw new Exception("user '$new_user' requested account deletion");
294-
}
295289
$this->addRequest($new_user->uid);
296290
if ($send_mail) {
297291
$this->MAILER->sendMail($new_user->getMail(), "group_user_request", [

resources/lib/UnitySQL.php

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
use PDO;
66

77
/**
8-
* @phpstan-type account_deletion_request array{timestamp: string, uid: string}
98
* @phpstan-type user_last_login array{operator: string, last_login: string}
109
* @phpstan-type request array{request_for: string, uid: string, timestamp: string}
1110
*/
1211
class UnitySQL
1312
{
1413
private const string TABLE_REQS = "requests";
1514
private const string TABLE_AUDIT_LOG = "audit_log";
16-
private const string TABLE_ACCOUNT_DELETION_REQUESTS = "account_deletion_requests";
1715
private const string TABLE_USER_LAST_LOGINS = "user_last_logins";
1816
// FIXME this string should be changed to something more intuitive, requires production change
1917
public const string REQUEST_BECOME_PI = "admin";
@@ -157,45 +155,6 @@ public function addLog(string $action_type, string $recipient): void
157155
$stmt->execute();
158156
}
159157

160-
public function addAccountDeletionRequest(string $uid): void
161-
{
162-
$stmt = $this->conn->prepare(
163-
"INSERT INTO " . self::TABLE_ACCOUNT_DELETION_REQUESTS . " (uid) VALUE (:uid)",
164-
);
165-
$stmt->bindParam(":uid", $uid);
166-
$stmt->execute();
167-
}
168-
169-
public function accDeletionRequestExists(string $uid): bool
170-
{
171-
$stmt = $this->conn->prepare(
172-
"SELECT * FROM " . self::TABLE_ACCOUNT_DELETION_REQUESTS . " WHERE uid=:uid",
173-
);
174-
$stmt->bindParam(":uid", $uid);
175-
$stmt->execute();
176-
return count($stmt->fetchAll()) > 0;
177-
}
178-
179-
public function deleteAccountDeletionRequest(string $uid): void
180-
{
181-
if (!$this->accDeletionRequestExists($uid)) {
182-
return;
183-
}
184-
$stmt = $this->conn->prepare(
185-
"DELETE FROM " . self::TABLE_ACCOUNT_DELETION_REQUESTS . " WHERE uid=:uid",
186-
);
187-
$stmt->bindParam(":uid", $uid);
188-
$stmt->execute();
189-
}
190-
191-
/** @return account_deletion_request[] */
192-
public function getAllAccountDeletionRequests(): array
193-
{
194-
$stmt = $this->conn->prepare("SELECT * FROM " . self::TABLE_ACCOUNT_DELETION_REQUESTS);
195-
$stmt->execute();
196-
return $stmt->fetchAll();
197-
}
198-
199158
/** @return user_last_login[] */
200159
public function getAllUserLastLogins(): array
201160
{

resources/lib/UnityUser.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -377,39 +377,6 @@ public function getPIGroupGIDs(): array
377377
return $this->LDAP->getNonDisabledPIGroupGIDsWithMemberUID($this->uid);
378378
}
379379

380-
/**
381-
* Sends an email to admins about account deletion request
382-
* and also adds it to a table in the database
383-
*/
384-
public function requestAccountDeletion(): void
385-
{
386-
$this->SQL->deleteRequestsByUser($this->uid);
387-
$this->SQL->addAccountDeletionRequest($this->uid);
388-
$this->MAILER->sendMail("admin", "account_deletion_request_admin", [
389-
"user" => $this->uid,
390-
"name" => $this->getFullname(),
391-
"email" => $this->getMail(),
392-
]);
393-
}
394-
395-
public function cancelRequestAccountDeletion(): void
396-
{
397-
$this->SQL->deleteAccountDeletionRequest($this->uid);
398-
$this->MAILER->sendMail("admin", "account_deletion_request_cancelled_admin", [
399-
"user" => $this->uid,
400-
"name" => $this->getFullname(),
401-
"email" => $this->getMail(),
402-
]);
403-
}
404-
405-
/**
406-
* Checks if the user has requested account deletion
407-
*/
408-
public function hasRequestedAccountDeletion(): bool
409-
{
410-
return $this->SQL->accDeletionRequestExists($this->uid);
411-
}
412-
413380
/**
414381
* Checks whether a user is in a group or not
415382
*/

resources/mail/account_deletion_request_admin.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

resources/mail/account_deletion_request_cancelled_admin.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/functional/AccountDeletionRequestTest.php

Lines changed: 0 additions & 85 deletions
This file was deleted.

test/functional/PIBecomeRequestTest.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,4 @@ public function testRequestBecomePi()
3838
}
3939
}
4040
}
41-
42-
public function testRequestBecomePiUserRequestedAccountDeletion()
43-
{
44-
global $USER, $SQL;
45-
$this->switchUser("Blank");
46-
$this->assertNumberPiBecomeRequests(0);
47-
try {
48-
$USER->requestAccountDeletion();
49-
http_post(__DIR__ . "/../../webroot/panel/account.php", [
50-
"form_type" => "pi_request",
51-
"tos" => "agree",
52-
"account_policy" => "agree",
53-
]);
54-
$this->assertNumberPiBecomeRequests(0);
55-
} finally {
56-
if ($SQL->requestExists($USER, UnitySQL::REQUEST_BECOME_PI)) {
57-
$SQL->removeRequest($USER->uid, UnitySQL::REQUEST_BECOME_PI);
58-
}
59-
if ($SQL->accDeletionRequestExists($USER->uid)) {
60-
$SQL->deleteAccountDeletionRequest($USER->uid);
61-
}
62-
}
63-
}
6441
}

test/functional/PIRemoveUserTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ public function testRemoveUser($methodName)
5353
foreach ($memberUIDs as $uid) {
5454
if ($uid != $piUid) {
5555
$memberToDelete = new UnityUser($uid, $LDAP, $SQL, $MAILER, $WEBHOOK);
56-
if ($memberToDelete->hasRequestedAccountDeletion()) {
57-
continue;
58-
}
5956
break;
6057
}
6158
}

0 commit comments

Comments
 (0)