Skip to content

Commit dca4c46

Browse files
authored
removed the constant REQUEST_BECOME_PI from UnitySQL (#370)
1 parent 917f216 commit dca4c46

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

resources/lib/UnityGroup.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function requestGroup(bool $send_mail_to_admins, bool $send_mail = true):
7676
"name" => $this->getOwner()->getFullName(),
7777
"email" => $this->getOwner()->getMail(),
7878
];
79-
$this->SQL->addRequest($this->getOwner()->uid);
79+
$this->SQL->addRequest($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI);
8080
if ($send_mail) {
8181
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_request");
8282
$this->WEBHOOK->sendWebhook("group_request_admin", $context);
@@ -99,7 +99,7 @@ public function approveGroup(?UnityUser $operator = null, bool $send_mail = true
9999
}
100100
\ensure($this->getOwner()->exists());
101101
$this->init();
102-
$this->SQL->removeRequest($this->getOwner()->uid);
102+
$this->SQL->removeRequest($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI);
103103
$operator = is_null($operator) ? $this->getOwner()->uid : $operator->uid;
104104
$this->SQL->addLog(
105105
$operator,
@@ -137,10 +137,10 @@ public function denyGroup(?UnityUser $operator = null, bool $send_mail = true):
137137

138138
public function cancelGroupRequest(bool $send_mail = true): void
139139
{
140-
if (!$this->SQL->requestExists($this->getOwner()->uid)) {
140+
if (!$this->SQL->requestExists($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI)) {
141141
return;
142142
}
143-
$this->SQL->removeRequest($this->getOwner()->uid);
143+
$this->SQL->removeRequest($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI);
144144
if ($send_mail) {
145145
$this->MAILER->sendMail("admin", "group_request_cancelled", [
146146
"uid" => $this->getOwner()->uid,

resources/lib/UnitySQL.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getConn(): PDO
3434
//
3535
// requests table methods
3636
//
37-
public function addRequest(string $requestor, string $dest = self::REQUEST_BECOME_PI): void
37+
public function addRequest(string $requestor, string $dest): void
3838
{
3939
if ($this->requestExists($requestor, $dest)) {
4040
return;
@@ -48,7 +48,7 @@ public function addRequest(string $requestor, string $dest = self::REQUEST_BECOM
4848
$stmt->execute();
4949
}
5050

51-
public function removeRequest($requestor, string $dest = self::REQUEST_BECOME_PI): void
51+
public function removeRequest($requestor, string $dest): void
5252
{
5353
if (!$this->requestExists($requestor, $dest)) {
5454
return;
@@ -63,7 +63,7 @@ public function removeRequest($requestor, string $dest = self::REQUEST_BECOME_PI
6363
$stmt->execute();
6464
}
6565

66-
public function removeRequests(string $dest = self::REQUEST_BECOME_PI): void
66+
public function removeRequests(string $dest): void
6767
{
6868
$stmt = $this->conn->prepare(
6969
"DELETE FROM " . self::TABLE_REQS . " WHERE request_for=:request_for",
@@ -91,7 +91,7 @@ public function getRequest(string $user, string $dest): array
9191
return $result[0];
9292
}
9393

94-
public function requestExists(string $requestor, string $dest = self::REQUEST_BECOME_PI): bool
94+
public function requestExists(string $requestor, string $dest): bool
9595
{
9696
try {
9797
$this->getRequest($requestor, $dest);
@@ -109,7 +109,7 @@ public function getAllRequests(): array
109109
return $stmt->fetchAll();
110110
}
111111

112-
public function getRequests(string $dest = self::REQUEST_BECOME_PI): array
112+
public function getRequests(string $dest): array
113113
{
114114
$stmt = $this->conn->prepare(
115115
"SELECT * FROM " . self::TABLE_REQS . " WHERE request_for=:request_for",

test/functional/PiBecomeRequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ private function assertNumberPiBecomeRequests(int $x)
99
{
1010
global $USER, $SQL;
1111
if ($x == 0) {
12-
$this->assertFalse($SQL->requestExists($USER->uid));
12+
$this->assertFalse($SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI));
1313
} elseif ($x > 0) {
14-
$this->assertTrue($SQL->requestExists($USER->uid));
14+
$this->assertTrue($SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI));
1515
} else {
1616
throw new RuntimeException("x must not be negative");
1717
}

webroot/admin/pi-mgmt.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use UnityWebPortal\lib\UnityUser;
66
use UnityWebPortal\lib\UnityGroup;
77
use UnityWebPortal\lib\UnityHTTPD;
8+
use UnityWebPortal\lib\UnitySQL;
89

910
if (!$USER->isAdmin()) {
1011
UnityHTTPD::forbidden("not an admin");
@@ -62,7 +63,7 @@
6263
</tr>
6364

6465
<?php
65-
$requests = $SQL->getRequests();
66+
$requests = $SQL->getRequests(UnitySQL::REQUEST_BECOME_PI);
6667

6768
foreach ($requests as $request) {
6869
$uid = $request["uid"];

webroot/panel/account.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use UnityWebPortal\lib\UnityHTTPD;
66
use UnityWebPortal\lib\exceptions\EncodingUnknownException;
77
use UnityWebPortal\lib\exceptions\EncodingConversionException;
8+
use UnityWebPortal\lib\UnitySQL;
89

910
$hasGroups = count($USER->getPIGroupGIDs()) > 0;
1011

@@ -70,13 +71,13 @@
7071
if ($USER->isPI()) {
7172
UnityHTTPD::badRequest("already a PI");
7273
}
73-
if ($SQL->requestExists($USER->uid)) {
74+
if ($SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI)) {
7475
UnityHTTPD::badRequest("already requested to be PI");
7576
}
7677
if (!isset($_POST["tos"]) || $_POST["tos"] != "agree") {
7778
UnityHTTPD::badRequest("user did not agree to terms of service");
7879
}
79-
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS);
80+
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS, UnitySQL::REQUEST_BECOME_PI);
8081
break;
8182
case "cancel_pi_request":
8283
$USER->getPIGroup()->cancelGroupRequest();
@@ -165,7 +166,7 @@
165166
</label>
166167
";
167168
} else {
168-
if ($SQL->requestExists($USER->uid)) {
169+
if ($SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI)) {
169170
$onclick = "return confirm(\"Are you sure you want to cancel this request?\")";
170171
echo "<input type='submit' value='Cancel PI Account Request' onclick='$onclick'/>";
171172
echo "

0 commit comments

Comments
 (0)