Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"name" => $this->getOwner()->getFullName(),
"email" => $this->getOwner()->getMail(),
];
$this->SQL->addRequest($this->getOwner()->uid);
$this->SQL->addRequest($this->getOwner()->uid, "admin");
if ($send_mail) {
$this->MAILER->sendMail($this->getOwner()->getMail(), "group_request");
$this->WEBHOOK->sendWebhook("group_request_admin", $context);
Expand All @@ -93,13 +93,13 @@
public function approveGroup(?UnityUser $operator = null, bool $send_mail = true): void
{
$uid = $this->getOwner()->uid;
$request = $this->SQL->getRequest($uid, UnitySQL::REQUEST_BECOME_PI);
$request = $this->SQL->getRequest($uid, "admin");
if ($this->exists()) {
return;
}
\ensure($this->getOwner()->exists());
$this->init();
$this->SQL->removeRequest($this->getOwner()->uid);
$this->SQL->removeRequest($this->getOwner()->uid, "admin");
$operator = is_null($operator) ? $this->getOwner()->uid : $operator->uid;
$this->SQL->addLog(
$operator,
Expand All @@ -118,7 +118,7 @@
*/
public function denyGroup(?UnityUser $operator = null, bool $send_mail = true): void
{
$request = $this->SQL->getRequest($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI);

Check failure on line 121 in resources/lib/UnityGroup.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to undefined constant UnityWebPortal\lib\UnitySQL::REQUEST_BECOME_PI.
$this->SQL->removeRequest($this->getOwner()->uid);
if ($this->exists()) {
return;
Expand All @@ -137,10 +137,10 @@

public function cancelGroupRequest(bool $send_mail = true): void
{
if (!$this->SQL->requestExists($this->getOwner()->uid)) {
if (!$this->SQL->requestExists($this->getOwner()->uid, "admin")) {
return;
}
$this->SQL->removeRequest($this->getOwner()->uid);
$this->SQL->removeRequest($this->getOwner()->uid, "admin");
if ($send_mail) {
$this->MAILER->sendMail("admin", "group_request_cancelled", [
"uid" => $this->getOwner()->uid,
Expand Down
11 changes: 5 additions & 6 deletions resources/lib/UnitySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class UnitySQL
private const string TABLE_AUDIT_LOG = "audit_log";
private const string TABLE_ACCOUNT_DELETION_REQUESTS = "account_deletion_requests";
// FIXME this string should be changed to something more intuitive, requires production change
public const string REQUEST_BECOME_PI = "admin";

private $conn;

Expand All @@ -34,7 +33,7 @@ public function getConn(): PDO
//
// requests table methods
//
public function addRequest(string $requestor, string $dest = self::REQUEST_BECOME_PI): void
public function addRequest(string $requestor, string $dest): void
{
if ($this->requestExists($requestor, $dest)) {
return;
Expand All @@ -48,7 +47,7 @@ public function addRequest(string $requestor, string $dest = self::REQUEST_BECOM
$stmt->execute();
}

public function removeRequest($requestor, string $dest = self::REQUEST_BECOME_PI): void
public function removeRequest($requestor, string $dest): void
{
if (!$this->requestExists($requestor, $dest)) {
return;
Expand All @@ -63,7 +62,7 @@ public function removeRequest($requestor, string $dest = self::REQUEST_BECOME_PI
$stmt->execute();
}

public function removeRequests(string $dest = self::REQUEST_BECOME_PI): void
public function removeRequests(string $dest): void
{
$stmt = $this->conn->prepare(
"DELETE FROM " . self::TABLE_REQS . " WHERE request_for=:request_for",
Expand Down Expand Up @@ -91,7 +90,7 @@ public function getRequest(string $user, string $dest): array
return $result[0];
}

public function requestExists(string $requestor, string $dest = self::REQUEST_BECOME_PI): bool
public function requestExists(string $requestor, string $dest): bool
{
try {
$this->getRequest($requestor, $dest);
Expand All @@ -109,7 +108,7 @@ public function getAllRequests(): array
return $stmt->fetchAll();
}

public function getRequests(string $dest = self::REQUEST_BECOME_PI): array
public function getRequests(string $dest): array
{
$stmt = $this->conn->prepare(
"SELECT * FROM " . self::TABLE_REQS . " WHERE request_for=:request_for",
Expand Down
5 changes: 1 addition & 4 deletions test/functional/PIBecomeApproveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ class PIBecomeApproveTest extends TestCase
private function assertRequestedPIGroup(bool $expected)
{
global $USER, $SQL;
$this->assertEquals(
$expected,
$SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI),
);
$this->assertEquals($expected, $SQL->requestExists($USER->uid, "admin"));
}

private function requestGroupCreation()
Expand Down
2 changes: 1 addition & 1 deletion test/functional/PIMemberRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testRequestMembership()
switchUser(...getUserNotPiNotRequestedBecomePi());
$uid = $USER->uid;
$this->assertFalse($USER->isPI());
$this->assertFalse($SQL->requestExists($uid, UnitySQL::REQUEST_BECOME_PI));
$this->assertFalse($SQL->requestExists($uid, "admin"));
$this->assertFalse($pi_group->memberExists($USER));
try {
$this->requestMembership($gid);
Expand Down
12 changes: 6 additions & 6 deletions test/functional/PiBecomeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ private function assertNumberPiBecomeRequests(int $x)
{
global $USER, $SQL;
if ($x == 0) {
$this->assertFalse($SQL->requestExists($USER->uid));
$this->assertFalse($SQL->requestExists($USER->uid, "admin"));
} elseif ($x > 0) {
$this->assertTrue($SQL->requestExists($USER->uid));
$this->assertTrue($SQL->requestExists($USER->uid, "admin"));
} else {
throw new RuntimeException("x must not be negative");
}
Expand Down Expand Up @@ -62,8 +62,8 @@ public function testRequestBecomePi()
]);
$this->assertNumberPiBecomeRequests(1);
} finally {
if ($SQL->requestExists($USER, UnitySQL::REQUEST_BECOME_PI)) {
$SQL->removeRequest($USER->uid, UnitySQL::REQUEST_BECOME_PI);
if ($SQL->requestExists($USER, "admin")) {
$SQL->removeRequest($USER->uid, "admin");
}
}
}
Expand All @@ -83,8 +83,8 @@ public function testRequestBecomePiUserRequestedAccountDeletion()
]);
$this->assertNumberPiBecomeRequests(0);
} finally {
if ($SQL->requestExists($USER, UnitySQL::REQUEST_BECOME_PI)) {
$SQL->removeRequest($USER->uid, UnitySQL::REQUEST_BECOME_PI);
if ($SQL->requestExists($USER, "admin")) {
$SQL->removeRequest($USER->uid, "admin");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion webroot/admin/pi-mgmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</tr>

<?php
$requests = $SQL->getRequests();
$requests = $SQL->getRequests("admin");

foreach ($requests as $request) {
$uid = $request["uid"];
Expand Down
6 changes: 3 additions & 3 deletions webroot/panel/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@
if ($USER->isPI()) {
UnityHTTPD::badRequest("already a PI");
}
if ($SQL->requestExists($USER->uid)) {
if ($SQL->requestExists($USER->uid, "admin")) {
UnityHTTPD::badRequest("already requested to be PI");
}
if (!isset($_POST["tos"]) || $_POST["tos"] != "agree") {
UnityHTTPD::badRequest("user did not agree to terms of service");
}
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS);
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS, "admin");
break;
case "cancel_pi_request":
$USER->getPIGroup()->cancelGroupRequest();
Expand Down Expand Up @@ -165,7 +165,7 @@
</label>
";
} else {
if ($SQL->requestExists($USER->uid)) {
if ($SQL->requestExists($USER->uid, "admin")) {
$onclick = "return confirm(\"Are you sure you want to cancel this request?\")";
echo "<input type='submit' value='Cancel PI Account Request' onclick='$onclick'/>";
echo "
Expand Down
Loading