diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index bc057410..688d7106 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -76,7 +76,7 @@ public function requestGroup(bool $send_mail_to_admins, bool $send_mail = true): "name" => $this->getOwner()->getFullName(), "email" => $this->getOwner()->getMail(), ]; - $this->SQL->addRequest($this->getOwner()->uid); + $this->SQL->addRequest($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI); if ($send_mail) { $this->MAILER->sendMail($this->getOwner()->getMail(), "group_request"); $this->WEBHOOK->sendWebhook("group_request_admin", $context); @@ -99,7 +99,7 @@ public function approveGroup(?UnityUser $operator = null, bool $send_mail = true } \ensure($this->getOwner()->exists()); $this->init(); - $this->SQL->removeRequest($this->getOwner()->uid); + $this->SQL->removeRequest($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI); $operator = is_null($operator) ? $this->getOwner()->uid : $operator->uid; $this->SQL->addLog( $operator, @@ -137,10 +137,10 @@ public function denyGroup(?UnityUser $operator = null, bool $send_mail = true): public function cancelGroupRequest(bool $send_mail = true): void { - if (!$this->SQL->requestExists($this->getOwner()->uid)) { + if (!$this->SQL->requestExists($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI)) { return; } - $this->SQL->removeRequest($this->getOwner()->uid); + $this->SQL->removeRequest($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI); if ($send_mail) { $this->MAILER->sendMail("admin", "group_request_cancelled", [ "uid" => $this->getOwner()->uid, diff --git a/resources/lib/UnitySQL.php b/resources/lib/UnitySQL.php index 5d4c7803..2d9d8e5b 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -34,7 +34,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; @@ -48,7 +48,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; @@ -63,7 +63,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", @@ -91,7 +91,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); @@ -109,7 +109,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", diff --git a/test/functional/PiBecomeRequestTest.php b/test/functional/PiBecomeRequestTest.php index 5714a6b9..0ac80e3f 100644 --- a/test/functional/PiBecomeRequestTest.php +++ b/test/functional/PiBecomeRequestTest.php @@ -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, UnitySQL::REQUEST_BECOME_PI)); } elseif ($x > 0) { - $this->assertTrue($SQL->requestExists($USER->uid)); + $this->assertTrue($SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI)); } else { throw new RuntimeException("x must not be negative"); } diff --git a/webroot/admin/pi-mgmt.php b/webroot/admin/pi-mgmt.php index 3fdd28fc..7b161a4b 100644 --- a/webroot/admin/pi-mgmt.php +++ b/webroot/admin/pi-mgmt.php @@ -5,6 +5,7 @@ use UnityWebPortal\lib\UnityUser; use UnityWebPortal\lib\UnityGroup; use UnityWebPortal\lib\UnityHTTPD; +use UnityWebPortal\lib\UnitySQL; if (!$USER->isAdmin()) { UnityHTTPD::forbidden("not an admin"); @@ -62,7 +63,7 @@ getRequests(); + $requests = $SQL->getRequests(UnitySQL::REQUEST_BECOME_PI); foreach ($requests as $request) { $uid = $request["uid"]; diff --git a/webroot/panel/account.php b/webroot/panel/account.php index 7167a122..eaff0d55 100644 --- a/webroot/panel/account.php +++ b/webroot/panel/account.php @@ -5,6 +5,7 @@ use UnityWebPortal\lib\UnityHTTPD; use UnityWebPortal\lib\exceptions\EncodingUnknownException; use UnityWebPortal\lib\exceptions\EncodingConversionException; +use UnityWebPortal\lib\UnitySQL; $hasGroups = count($USER->getPIGroupGIDs()) > 0; @@ -70,13 +71,13 @@ if ($USER->isPI()) { UnityHTTPD::badRequest("already a PI"); } - if ($SQL->requestExists($USER->uid)) { + if ($SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI)) { 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, UnitySQL::REQUEST_BECOME_PI); break; case "cancel_pi_request": $USER->getPIGroup()->cancelGroupRequest(); @@ -165,7 +166,7 @@ "; } else { - if ($SQL->requestExists($USER->uid)) { + if ($SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI)) { $onclick = "return confirm(\"Are you sure you want to cancel this request?\")"; echo ""; echo "