diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index ab2c7270..8b0f2143 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -218,10 +218,10 @@ public function cancelGroupRequest($send_mail = true) $this->SQL->removeRequest($this->getOwner()->getUID()); if ($send_mail) { - // send email to requestor $this->MAILER->sendMail( "admin", - "group_request_cancelled" + "group_request_cancelled", + ["uid" => $this->getOwner()->getUID()], ); } } @@ -239,7 +239,7 @@ public function cancelGroupJoinRequest($user, $send_mail = true) $this->MAILER->sendMail( $this->getOwner()->getMail(), "group_join_request_cancelled", - ["group" => $this->pi_uid] + ["uid" => $user->getUID()] ); } } diff --git a/resources/mail/group_join_request_cancelled.php b/resources/mail/group_join_request_cancelled.php index 7fb02df1..3421f198 100644 --- a/resources/mail/group_join_request_cancelled.php +++ b/resources/mail/group_join_request_cancelled.php @@ -1,11 +1,5 @@ Subject = "Unity Account Request Cancelled"; +$this->Subject = "Unity PI Membership Request Cancelled: '" . $data["uid"] . "'"; ?> -
Hello,
- -Your request to join group '' on the Unity Cluster has been cancelled per your request. -
- +The user '' has cancelled their request to join your PI group.
diff --git a/resources/mail/group_request_cancelled.php b/resources/mail/group_request_cancelled.php index e143d1d0..73995b56 100644 --- a/resources/mail/group_request_cancelled.php +++ b/resources/mail/group_request_cancelled.php @@ -1,10 +1,5 @@ Subject = "Unity PI Account Request Cancelled"; +$this->Subject = "PI Request Cancelled: '" . $data["uid"] . "'"; ?> -Hello,
- -Your request for a PI account on the Unity Cluster has been cancelled per your request.
- +The user '' has cancelled their request to become a PI.
diff --git a/test/functional/PIMemberRequestTest.php b/test/functional/PIMemberRequestTest.php new file mode 100644 index 00000000..ec4cff71 --- /dev/null +++ b/test/functional/PIMemberRequestTest.php @@ -0,0 +1,54 @@ + "addPIform", "pi" => $gid], + ); + } + + private function cancelRequest(string $gid) + { + http_post( + __DIR__ . "/../../webroot/panel/groups.php", + ["form_type" => "cancelPIForm", "pi" => $gid], + ); + } + + public function testRequestMembership() + { + global $USER, $SQL; + switchUser(...getUserIsPIHasNoMembersNoMemberRequests()); + $pi = $USER; + $pi_group = $USER->getPIGroup(); + $gid = $pi_group->getPIUID(); + $this->assertTrue($USER->isPI()); + $this->assertTrue($pi_group->exists()); + $this->assertTrue(arraysAreEqualUnOrdered([$pi], $pi_group->getGroupMembers())); + $this->assertEquals([], $SQL->getRequests($gid)); + switchUser(...getUserNotPiNotRequestedBecomePi()); + $uid = $USER->getUID(); + $this->assertFalse($USER->isPI()); + $this->assertFalse($SQL->requestExists($uid, UnitySQL::REQUEST_BECOME_PI)); + $this->assertFalse($pi_group->userExists($USER)); + try { + $this->requestMembership($gid); + $this->assertTrue($SQL->requestExists($uid, $gid)); + $this->cancelRequest($gid); + $this->assertFalse($SQL->requestExists($uid, $gid)); + $this->requestMembership($gid); + $this->assertTrue($SQL->requestExists($uid, $gid)); + } finally { + if ($SQL->requestExists($uid, $gid)) { + $SQL->removeRequest($uid, $gid); + } + } + } +} diff --git a/test/functional/PiBecomeRequestTest.php b/test/functional/PiBecomeRequestTest.php index d0c1edd2..686b02a3 100644 --- a/test/functional/PiBecomeRequestTest.php +++ b/test/functional/PiBecomeRequestTest.php @@ -38,6 +38,16 @@ public function testRequestBecomePi() $this->assertFalse($USER->isPI()); $this->assertNumberPiBecomeRequests(0); try { + http_post( + __DIR__ . "/../../webroot/panel/account.php", + ["form_type" => "pi_request"] + ); + $this->assertNumberPiBecomeRequests(1); + http_post( + __DIR__ . "/../../webroot/panel/account.php", + ["form_type" => "cancel_pi_request"] + ); + $this->assertNumberPiBecomeRequests(0); http_post( __DIR__ . "/../../webroot/panel/account.php", ["form_type" => "pi_request"] diff --git a/webroot/panel/account.php b/webroot/panel/account.php index 14047f3f..79090ecd 100644 --- a/webroot/panel/account.php +++ b/webroot/panel/account.php @@ -60,6 +60,9 @@ } } break; + case "cancel_pi_request": + $USER->getPIGroup()->cancelGroupRequest(); + break; case "account_deletion_request": $hasGroups = count($USER->getGroups()) > 0; if ($hasGroups) { @@ -126,9 +129,7 @@ action='' method='POST' id='piReq' - onsubmit='return confirm(\"Are you sure you want to request a PI account?\")' > - "; if ($SQL->accDeletionRequestExists($USER->getUID())) { echo ""; @@ -137,15 +138,21 @@ You cannot request PI Account while you have requested account deletion. "; - } elseif ($SQL->requestExists($USER->getUID())) { - echo ""; - echo " - - "; } else { - echo ""; + if ($SQL->requestExists($USER->getUID())) { + $prompt = "onclick='return confirm(\"Are you sure you want to cancel this request?\")"; + echo ""; + echo " + + + "; + } else { + echo ""; + $prompt = "onclick='return confirm(\"Are you sure you want to request a PI account?\")"; + echo ""; + } } echo ""; } diff --git a/webroot/panel/groups.php b/webroot/panel/groups.php index 916acb9e..c51dfede 100644 --- a/webroot/panel/groups.php +++ b/webroot/panel/groups.php @@ -40,6 +40,10 @@ // Remove PI form $pi_account->removeUser($USER); break; + case "cancelPIForm": + // cancel Group Join + $pi_account->cancelGroupJoinRequest($USER); + break; } } } @@ -74,7 +78,13 @@ echo "