Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions resources/lib/UnitySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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",
Expand Down Expand Up @@ -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);
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 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, 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");
}
Expand Down
3 changes: 2 additions & 1 deletion webroot/admin/pi-mgmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -62,7 +63,7 @@
</tr>

<?php
$requests = $SQL->getRequests();
$requests = $SQL->getRequests(UnitySQL::REQUEST_BECOME_PI);

foreach ($requests as $request) {
$uid = $request["uid"];
Expand Down
7 changes: 4 additions & 3 deletions webroot/panel/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -165,7 +166,7 @@
</label>
";
} 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 "<input type='submit' value='Cancel PI Account Request' onclick='$onclick'/>";
echo "
Expand Down
Loading