diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index 5d75c66df..d1d709f5b 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -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, @@ -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(); @@ -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) { @@ -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); @@ -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); @@ -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) { @@ -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"); diff --git a/test/functional/PiBecomeRequestTest.php b/test/functional/PiBecomeRequestTest.php index 34933c777..133da5762 100644 --- a/test/functional/PiBecomeRequestTest.php +++ b/test/functional/PiBecomeRequestTest.php @@ -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);