Skip to content
Draft
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
32 changes: 24 additions & 8 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public function __toString(): string
public function requestGroup(bool $send_mail_to_admins, bool $send_mail = true): void
{
if ($this->exists()) {
return;
throw new Exception("requested to create group '$this' that already exists!");
}
if ($this->SQL->accDeletionRequestExists($this->getOwner()->uid)) {
return;
throw new Exception("group owner '$this' requested account deletion");
}
$context = [
"user" => $this->getOwner()->uid,
Expand All @@ -70,7 +70,11 @@ public function approveGroup(bool $send_mail = true): void
$uid = $this->getOwner()->uid;
$request = $this->SQL->getRequest($uid, UnitySQL::REQUEST_BECOME_PI);
if ($this->exists()) {
return;
throw new Exception("group '$this' exists");
}
$owner_uid = $this->getOwner()->uid;
if ($this->SQL->accDeletionRequestExists($owner_uid)) {
throw new Exception("group owner '$owner_uid' requested account deletion");
}
\ensure($this->getOwner()->exists());
$this->init();
Expand All @@ -91,7 +95,9 @@ public function denyGroup(bool $send_mail = true): void
$request = $this->SQL->getRequest($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI);
$this->SQL->removeRequest($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI);
if ($this->exists()) {
return;
throw new Exception(
"group '$this' creation request cannot be denied, it already exists!",
);
}
$this->SQL->addLog("denied_group", $this->getOwner()->uid);
if ($send_mail) {
Expand All @@ -102,6 +108,10 @@ public function denyGroup(bool $send_mail = true): void
public function cancelGroupRequest(bool $send_mail = true): void
{
if (!$this->SQL->requestExists($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI)) {
UnityHTTPD::errorLog(
"warning",
"attempt to cancel nonexistent group creation request ($this)",
);
return;
}
$this->SQL->removeRequest($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI);
Expand All @@ -115,6 +125,10 @@ public function cancelGroupRequest(bool $send_mail = true): void
public function cancelGroupJoinRequest(UnityUser $user, bool $send_mail = true): void
{
if (!$this->requestExists($user)) {
UnityHTTPD::errorLog(
"warning",
"attempt to cancel nonexistent group join request ($this)",
);
return;
}
$this->SQL->removeRequest($user->uid, $this->gid);
Expand Down Expand Up @@ -217,6 +231,10 @@ public function denyUser(UnityUser $new_user, bool $send_mail = true): void
public function removeUser(UnityUser $new_user, bool $send_mail = true): void
{
if (!$this->memberUIDExists($new_user->uid)) {
UnityHTTPD::errorLog(
"warning",
"attempted to delete absent user '$new_user' from group '$this'",
);
return;
}
if ($new_user->uid == $this->getOwner()->uid) {
Expand Down Expand Up @@ -245,12 +263,10 @@ public function removeUser(UnityUser $new_user, bool $send_mail = true): void
public function newUserRequest(UnityUser $new_user, bool $send_mail = true): void
{
if ($this->memberUIDExists($new_user->uid)) {
UnityHTTPD::errorLog("warning", "user '$new_user' already in group");
return;
throw new Exception("user '$new_user' already in group");
}
if ($this->requestExists($new_user)) {
UnityHTTPD::errorLog("warning", "user '$new_user' already requested group membership");
return;
throw new Exception("user '$new_user' already requested group membership");
}
if ($this->SQL->accDeletionRequestExists($new_user->uid)) {
throw new Exception("user '$new_user' requested account deletion");
Expand Down
3 changes: 1 addition & 2 deletions test/functional/PiBecomeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ public function testRequestBecomePiUserRequestedAccountDeletion()
{
global $USER, $SQL;
$this->switchUser("Blank");
$this->assertNumberPiBecomeRequests(0);
try {
$USER->requestAccountDeletion();
$this->expectException(Exception::class);
http_post(__DIR__ . "/../../webroot/panel/account.php", [
"form_type" => "pi_request",
"tos" => "agree",
"account_policy" => "agree",
]);
$this->assertNumberPiBecomeRequests(0);
} finally {
if ($SQL->requestExists($USER, UnitySQL::REQUEST_BECOME_PI)) {
$SQL->removeRequest($USER->uid, UnitySQL::REQUEST_BECOME_PI);
Expand Down