Skip to content

Commit bd30167

Browse files
committed
removed the constant from UnitySQL
1 parent c726b86 commit bd30167

File tree

7 files changed

+22
-26
lines changed

7 files changed

+22
-26
lines changed

resources/lib/UnityGroup.php

Lines changed: 5 additions & 5 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, "admin");
8080
if ($send_mail) {
8181
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_request");
8282
$this->WEBHOOK->sendWebhook("group_request_admin", $context);
@@ -93,13 +93,13 @@ public function requestGroup(bool $send_mail_to_admins, bool $send_mail = true):
9393
public function approveGroup(?UnityUser $operator = null, bool $send_mail = true): void
9494
{
9595
$uid = $this->getOwner()->uid;
96-
$request = $this->SQL->getRequest($uid, UnitySQL::REQUEST_BECOME_PI);
96+
$request = $this->SQL->getRequest($uid, "admin");
9797
if ($this->exists()) {
9898
return;
9999
}
100100
\ensure($this->getOwner()->exists());
101101
$this->init();
102-
$this->SQL->removeRequest($this->getOwner()->uid);
102+
$this->SQL->removeRequest($this->getOwner()->uid, "admin");
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, "admin")) {
141141
return;
142142
}
143-
$this->SQL->removeRequest($this->getOwner()->uid);
143+
$this->SQL->removeRequest($this->getOwner()->uid, "admin");
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class UnitySQL
1212
private const string TABLE_AUDIT_LOG = "audit_log";
1313
private const string TABLE_ACCOUNT_DELETION_REQUESTS = "account_deletion_requests";
1414
// FIXME this string should be changed to something more intuitive, requires production change
15-
public const string REQUEST_BECOME_PI = "admin";
1615

1716
private $conn;
1817

@@ -34,7 +33,7 @@ public function getConn(): PDO
3433
//
3534
// requests table methods
3635
//
37-
public function addRequest(string $requestor, string $dest = self::REQUEST_BECOME_PI): void
36+
public function addRequest(string $requestor, string $dest): void
3837
{
3938
if ($this->requestExists($requestor, $dest)) {
4039
return;
@@ -48,7 +47,7 @@ public function addRequest(string $requestor, string $dest = self::REQUEST_BECOM
4847
$stmt->execute();
4948
}
5049

51-
public function removeRequest($requestor, string $dest = self::REQUEST_BECOME_PI): void
50+
public function removeRequest($requestor, string $dest): void
5251
{
5352
if (!$this->requestExists($requestor, $dest)) {
5453
return;
@@ -63,7 +62,7 @@ public function removeRequest($requestor, string $dest = self::REQUEST_BECOME_PI
6362
$stmt->execute();
6463
}
6564

66-
public function removeRequests(string $dest = self::REQUEST_BECOME_PI): void
65+
public function removeRequests(string $dest): void
6766
{
6867
$stmt = $this->conn->prepare(
6968
"DELETE FROM " . self::TABLE_REQS . " WHERE request_for=:request_for",
@@ -91,7 +90,7 @@ public function getRequest(string $user, string $dest): array
9190
return $result[0];
9291
}
9392

94-
public function requestExists(string $requestor, string $dest = self::REQUEST_BECOME_PI): bool
93+
public function requestExists(string $requestor, string $dest): bool
9594
{
9695
try {
9796
$this->getRequest($requestor, $dest);
@@ -109,7 +108,7 @@ public function getAllRequests(): array
109108
return $stmt->fetchAll();
110109
}
111110

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

test/functional/PIBecomeApproveTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ class PIBecomeApproveTest extends TestCase
99
private function assertRequestedPIGroup(bool $expected)
1010
{
1111
global $USER, $SQL;
12-
$this->assertEquals(
13-
$expected,
14-
$SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI),
15-
);
12+
$this->assertEquals($expected, $SQL->requestExists($USER->uid, "admin"));
1613
}
1714

1815
private function requestGroupCreation()

test/functional/PIMemberRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testRequestMembership()
3636
switchUser(...getUserNotPiNotRequestedBecomePi());
3737
$uid = $USER->uid;
3838
$this->assertFalse($USER->isPI());
39-
$this->assertFalse($SQL->requestExists($uid, UnitySQL::REQUEST_BECOME_PI));
39+
$this->assertFalse($SQL->requestExists($uid, "admin"));
4040
$this->assertFalse($pi_group->memberExists($USER));
4141
try {
4242
$this->requestMembership($gid);

test/functional/PiBecomeRequestTest.php

Lines changed: 6 additions & 6 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, "admin"));
1313
} elseif ($x > 0) {
14-
$this->assertTrue($SQL->requestExists($USER->uid));
14+
$this->assertTrue($SQL->requestExists($USER->uid, "admin"));
1515
} else {
1616
throw new RuntimeException("x must not be negative");
1717
}
@@ -62,8 +62,8 @@ public function testRequestBecomePi()
6262
]);
6363
$this->assertNumberPiBecomeRequests(1);
6464
} finally {
65-
if ($SQL->requestExists($USER, UnitySQL::REQUEST_BECOME_PI)) {
66-
$SQL->removeRequest($USER->uid, UnitySQL::REQUEST_BECOME_PI);
65+
if ($SQL->requestExists($USER, "admin")) {
66+
$SQL->removeRequest($USER->uid, "admin");
6767
}
6868
}
6969
}
@@ -83,8 +83,8 @@ public function testRequestBecomePiUserRequestedAccountDeletion()
8383
]);
8484
$this->assertNumberPiBecomeRequests(0);
8585
} finally {
86-
if ($SQL->requestExists($USER, UnitySQL::REQUEST_BECOME_PI)) {
87-
$SQL->removeRequest($USER->uid, UnitySQL::REQUEST_BECOME_PI);
86+
if ($SQL->requestExists($USER, "admin")) {
87+
$SQL->removeRequest($USER->uid, "admin");
8888
}
8989
}
9090
}

webroot/admin/pi-mgmt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</tr>
6363

6464
<?php
65-
$requests = $SQL->getRequests();
65+
$requests = $SQL->getRequests("admin");
6666

6767
foreach ($requests as $request) {
6868
$uid = $request["uid"];

webroot/panel/account.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@
7070
if ($USER->isPI()) {
7171
UnityHTTPD::badRequest("already a PI");
7272
}
73-
if ($SQL->requestExists($USER->uid)) {
73+
if ($SQL->requestExists($USER->uid, "admin")) {
7474
UnityHTTPD::badRequest("already requested to be PI");
7575
}
7676
if (!isset($_POST["tos"]) || $_POST["tos"] != "agree") {
7777
UnityHTTPD::badRequest("user did not agree to terms of service");
7878
}
79-
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS);
79+
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS, "admin");
8080
break;
8181
case "cancel_pi_request":
8282
$USER->getPIGroup()->cancelGroupRequest();
@@ -165,7 +165,7 @@
165165
</label>
166166
";
167167
} else {
168-
if ($SQL->requestExists($USER->uid)) {
168+
if ($SQL->requestExists($USER->uid, "admin")) {
169169
$onclick = "return confirm(\"Are you sure you want to cancel this request?\")";
170170
echo "<input type='submit' value='Cancel PI Account Request' onclick='$onclick'/>";
171171
echo "

0 commit comments

Comments
 (0)