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
6 changes: 3 additions & 3 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
);
}
}
Expand All @@ -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()]
);
}
}
Expand Down
10 changes: 2 additions & 8 deletions resources/mail/group_join_request_cancelled.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?php

// This template is sent to the user cancelling the request
$this->Subject = "Unity Account Request Cancelled";
$this->Subject = "Unity PI Membership Request Cancelled: '" . $data["uid"] . "'";
?>

<p>Hello,</p>

<p>Your request to join group '<?php echo $data["group"]; ?>' on the Unity Cluster has been cancelled per your request.
</p>

<p>The user '<?php echo $data["uid"]; ?>' has cancelled their request to join your PI group.</p>
9 changes: 2 additions & 7 deletions resources/mail/group_request_cancelled.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?php

// This template is sent to the user cancelling the request
$this->Subject = "Unity PI Account Request Cancelled";
$this->Subject = "PI Request Cancelled: '" . $data["uid"] . "'";
?>

<p>Hello,</p>

<p>Your request for a PI account on the Unity Cluster has been cancelled per your request.</p>

<p>The user '<?php echo $data["uid"] ?>' has cancelled their request to become a PI.</p>
54 changes: 54 additions & 0 deletions test/functional/PIMemberRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

use PHPUnit\Framework\TestCase;
use UnityWebPortal\lib\UnitySQL;

class PiMemberRequestTest extends TestCase
{

private function requestMembership(string $gid)
{
http_post(
__DIR__ . "/../../webroot/panel/groups.php",
["form_type" => "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);
}
}
}
}
10 changes: 10 additions & 0 deletions test/functional/PiBecomeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
27 changes: 17 additions & 10 deletions webroot/panel/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
}
}
break;
case "cancel_pi_request":
$USER->getPIGroup()->cancelGroupRequest();
break;
case "account_deletion_request":
$hasGroups = count($USER->getGroups()) > 0;
if ($hasGroups) {
Expand Down Expand Up @@ -126,9 +129,7 @@
action=''
method='POST'
id='piReq'
onsubmit='return confirm(\"Are you sure you want to request a PI account?\")'
>
<input type='hidden' name='form_type' value='pi_request'/>
";
if ($SQL->accDeletionRequestExists($USER->getUID())) {
echo "<input type='submit' value='Request PI Account' disabled />";
Expand All @@ -137,15 +138,21 @@
You cannot request PI Account while you have requested account deletion.
</label>
";
} elseif ($SQL->requestExists($USER->getUID())) {
echo "<input type='submit' value='Request PI Account' disabled />";
echo "
<label style='margin-left: 10px'>
Your request has been submitted and is currently pending
</label>
";
} else {
echo "<input type='submit' value='Request PI Account'/>";
if ($SQL->requestExists($USER->getUID())) {
$prompt = "onclick='return confirm(\"Are you sure you want to cancel this request?\")";
echo "<input type='submit' value='Cancel PI Account Request' $prompt'/>";
echo "
<label style='margin-left: 10px'>
Your request has been submitted and is currently pending
</label>
<input type='hidden' name='form_type' value='cancel_pi_request'/>
";
} else {
echo "<input type='hidden' name='form_type' value='pi_request'/>";
$prompt = "onclick='return confirm(\"Are you sure you want to request a PI account?\")";
echo "<input type='submit' value='Request PI Account' $prompt'/>";
}
}
echo "</form>";
}
Expand Down
12 changes: 11 additions & 1 deletion webroot/panel/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
// Remove PI form
$pi_account->removeUser($USER);
break;
case "cancelPIForm":
// cancel Group Join
$pi_account->cancelGroupJoinRequest($USER);
break;
}
}
}
Expand Down Expand Up @@ -74,7 +78,13 @@
echo "<td>" . $requested_account->getPIUID() . "</td>";
echo "<td><a href='mailto:" . $requested_owner->getMail() . "'>" . $requested_owner->getMail() . "</a></td>";
echo "<td>" . date("jS F, Y", strtotime($request['timestamp'])) . "</td>";
echo "<td></td>";
echo "<td>";
echo "<form action='' method='POST' id='cancelPI'>
<input type='hidden' name='pi' value='{$requested_account->getPIUID()}'>
<input type='hidden' name='form_type' value='cancelPIForm'>
<input name='cancel' style='margin-top: 10px;' type='submit' value='Cancel Request'/>
</form>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
Expand Down