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 @@ -312,7 +312,7 @@ public function denyUser($new_user, $send_mail = true)

public function removeUser($new_user, $send_mail = true)
{
if (!$this->userExists($new_user)) {
if (!$this->memberExists($new_user)) {
return;
}
if ($new_user->uid == $this->getOwner()->uid) {
Expand Down Expand Up @@ -348,7 +348,7 @@ public function newUserRequest(
$org,
$send_mail = true
) {
if ($this->userExists($new_user)) {
if ($this->memberExists($new_user)) {
UnityHTTPD::errorLog("warning", "user '$new_user' already in group");
return;
}
Expand Down Expand Up @@ -490,7 +490,7 @@ private function removeUserFromGroup($old_user)
$this->REDIS->removeCacheArray($old_user->uid, "groups", $this->gid);
}

public function userExists($user)
public function memberExists($user)
{
return in_array($user->uid, $this->getGroupMemberUIDs());
}
Expand Down
18 changes: 9 additions & 9 deletions test/functional/NewUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ private function ensureOrgGroupDoesNotExist()
private function ensureUserNotInPIGroup(UnityGroup $pi_group)
{
global $USER, $REDIS;
if ($pi_group->userExists($USER)) {
if ($pi_group->memberExists($USER)) {
$pi_group->removeUser($USER);
assert(!$pi_group->userExists($USER));
assert(!$pi_group->memberExists($USER));
}
$REDIS->removeCacheArray($pi_group->gid, "members", $USER->uid);
}
Expand Down Expand Up @@ -177,7 +177,7 @@ public function testCreateUserByJoinGoupByPI($user_to_create_args, $expected_uid
$newOrg = new UnityOrg($SSO["org"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
$this->assertTrue(!$newOrg->exists());
$this->assertTrue($pi_group->exists());
$this->assertTrue(!$pi_group->userExists($USER));
$this->assertTrue(!$pi_group->memberExists($USER));
$this->assertRequestedMembership(false, $gid);
try {
$this->requestGroupMembership($pi_group->gid);
Expand Down Expand Up @@ -208,7 +208,7 @@ public function testCreateUserByJoinGoupByPI($user_to_create_args, $expected_uid

$this->assertTrue(!$pi_group->requestExists($USER));
$this->assertRequestedMembership(false, $gid);
$this->assertTrue($pi_group->userExists($USER));
$this->assertTrue($pi_group->memberExists($USER));
$this->assertTrue($USER->exists());
$this->assertTrue($newOrg->exists());

Expand Down Expand Up @@ -247,18 +247,18 @@ public function testCreateMultipleUsersByJoinGoupByPI()
foreach ($users_to_create_args as $user_to_create_args) {
switchUser(...$user_to_create_args);
$this->assertTrue(!$USER->exists());
$this->assertTrue(!$pi_group->userExists($USER));
$this->assertTrue(!$pi_group->memberExists($USER));
$this->assertRequestedMembership(false, $gid);
$this->requestGroupMembership($pi_group->gid);
$this->assertRequestedMembership(true, $gid);
$approve_uid = $USER->uid;
switchUser(...$pi_user_args);
// $this->assertTrue(!$pi_group->userExists($USER));
// $this->assertTrue(!$pi_group->memberExists($USER));
$this->approveUserByPI($approve_uid);
switchUser(...$user_to_create_args);
$this->assertTrue(!$pi_group->requestExists($USER));
$this->assertRequestedMembership(false, $gid);
$this->assertTrue($pi_group->userExists($USER));
$this->assertTrue($pi_group->memberExists($USER));
$this->assertTrue($USER->exists());
}
} finally {
Expand All @@ -282,7 +282,7 @@ public function testCreateUserByJoinGoupByAdmin($user_to_create_args, $expected_
$newOrg = new UnityOrg($SSO["org"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
$this->assertTrue(!$newOrg->exists());
$this->assertTrue($pi_group->exists());
$this->assertTrue(!$pi_group->userExists($USER));
$this->assertTrue(!$pi_group->memberExists($USER));
$this->assertRequestedMembership(false, $gid);
try {
$this->requestGroupMembership($pi_group->gid);
Expand Down Expand Up @@ -313,7 +313,7 @@ public function testCreateUserByJoinGoupByAdmin($user_to_create_args, $expected_

$this->assertTrue(!$pi_group->requestExists($USER));
$this->assertRequestedMembership(false, $gid);
$this->assertTrue($pi_group->userExists($USER));
$this->assertTrue($pi_group->memberExists($USER));
$this->assertTrue($USER->exists());
$this->assertTrue($newOrg->exists());

Expand Down
2 changes: 1 addition & 1 deletion test/functional/PIMemberRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testRequestMembership()
$uid = $USER->uid;
$this->assertFalse($USER->isPI());
$this->assertFalse($SQL->requestExists($uid, UnitySQL::REQUEST_BECOME_PI));
$this->assertFalse($pi_group->userExists($USER));
$this->assertFalse($pi_group->memberExists($USER));
try {
$this->requestMembership($gid);
$this->assertTrue($SQL->requestExists($uid, $gid));
Expand Down
10 changes: 5 additions & 5 deletions test/functional/PiMemberApproveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ public function testApproveRequest()
try {
switchUser(...$userSwitchArgs);
$this->requestJoinPI($piGroup->gid);
$this->assertFalse($piGroup->userExists($user));
$this->assertFalse($piGroup->memberExists($user));

switchUser(...$piSwitchArgs);
$this->approveUser($uid);
$this->assertTrue(!$piGroup->requestExists($user));
$this->assertEmpty($piGroup->getRequests());
$this->assertGroupMembers($piGroup, [$piUID, $uid]);
$this->assertTrue($piGroup->userExists($user));
$this->assertTrue($piGroup->memberExists($user));
} finally {
if ($piGroup->userExists($user)) {
if ($piGroup->memberExists($user)) {
$piGroup->removeUser($user);
}
if ($piGroup->requestExists($user)) {
Expand All @@ -94,13 +94,13 @@ public function testApproveNonexistentRequest()
$this->assertTrue($piGroup->exists());
$this->assertGroupMembers($piGroup, [$piUID]);
$this->assertEmpty($piGroup->getRequests());
$this->assertFalse($piGroup->userExists($user));
$this->assertFalse($piGroup->memberExists($user));
$this->assertEmpty($piGroup->getRequests());
try {
$this->expectException(Exception::class);
$piGroup->approveUser($user);
} finally {
if ($piGroup->userExists($user)) {
if ($piGroup->memberExists($user)) {
$piGroup->removeUser($user);
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/functional/PiMemberDenyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testDenyRequest()
$requestedUser->getMail(),
$requestedUser->getOrg(),
);
$this->assertFalse($piGroup->userExists($requestedUser));
$this->assertFalse($piGroup->memberExists($requestedUser));

$piGroup->denyUser($requestedUser);
$this->assertEmpty($piGroup->getRequests());
Expand All @@ -54,7 +54,7 @@ public function testDenyRequest()
$piGroup->getGroupMemberUIDs()
)
);
$this->assertFalse($piGroup->userExists($requestedUser));
$this->assertFalse($piGroup->memberExists($requestedUser));
} finally {
$SQL->removeRequest(self::$requestUid, $piGroup->gid);
}
Expand Down
12 changes: 6 additions & 6 deletions test/functional/PiRemoveUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public function testRemoveUser()
}
}
$this->assertNotEquals($pi->uid, $memberToDelete->uid);
$this->assertTrue($piGroup->userExists($memberToDelete));
$this->assertTrue($piGroup->memberExists($memberToDelete));
try {
$this->removeUser($memberToDelete->uid);
$this->assertFalse($piGroup->userExists($memberToDelete));
$this->assertFalse($piGroup->memberExists($memberToDelete));
} finally {
if (!$piGroup->userExists($memberToDelete)) {
if (!$piGroup->memberExists($memberToDelete)) {
$piGroup->newUserRequest(
$memberToDelete,
$memberToDelete->getFirstname(),
Expand All @@ -62,13 +62,13 @@ public function testRemovePIFromTheirOwnGroup()
$pi = $USER;
$piGroup = $USER->getPIGroup();
$this->assertTrue($piGroup->exists());
$this->assertTrue($piGroup->userExists($pi));
$this->assertTrue($piGroup->memberExists($pi));
$this->expectException(Exception::class);
try {
$this->removeUser($pi->uid);
$this->assertTrue($piGroup->userExists($pi));
$this->assertTrue($piGroup->memberExists($pi));
} finally {
if (!$piGroup->userExists($pi)) {
if (!$piGroup->memberExists($pi)) {
$piGroup->newUserRequest(
$pi,
$pi->getFirstname(),
Expand Down
2 changes: 1 addition & 1 deletion webroot/panel/ajax/get_group_members.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}

$group = new UnityGroup($_GET["gid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
if (!$group->userExists($USER)) {
if (!$group->memberExists($USER)) {
UnityHTTPD::forbidden("not a group member");
}
$members = $group->getGroupMembers();
Expand Down
2 changes: 1 addition & 1 deletion webroot/panel/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
if ($pi_account->requestExists($USER)) {
array_push($modalErrors, "You\'ve already requested this");
}
if ($pi_account->userExists($USER)) {
if ($pi_account->memberExists($USER)) {
array_push($modalErrors, "You\'re already in this PI group");
}
if ($USER->uid != $SSO["user"]) {
Expand Down
2 changes: 1 addition & 1 deletion workers/remove-users-from-group.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function _die($msg) {
while (($line = fgets($handle)) !== false) {
$uid = trim($line);
$user = new UnityUser($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
if (!$group->userExists($user)) {
if (!$group->memberExists($user)) {
print("Skipping '$uid' who doesn't appear to be in '$gid'\n");
continue;
}
Expand Down