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
21 changes: 20 additions & 1 deletion resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public function equals($other_group)
return $this->getPIUID() == $other_group->getPIUID();
}

public function __toString()
{
return $this->getPIUID();
}

/**
* Returns this group's PI UID
*
Expand Down Expand Up @@ -133,6 +138,12 @@ public function requestGroup($send_mail_to_admins, $send_mail = true)
*/
public function approveGroup($operator = null, $send_mail = true)
{
if (!$this->SQL->requestExists($this->getOwner()->getUID())) {
throw new Exception(
"attempt to approve nonexistent request for group='{$this->getPIUID()}' uid='$new_user'"
);
}

// check for edge cases...
if ($this->exists()) {
return;
Expand Down Expand Up @@ -277,6 +288,12 @@ public function cancelGroupJoinRequest($user, $send_mail = true)
*/
public function approveUser($new_user, $send_mail = true)
{
if (!$this->requestExists($new_user)) {
throw new Exception(
"attempt to approve nonexistent request for group='{$this->getPIUID()}' uid='$new_user'"
);
}

// check if user exists
if (!$new_user->exists()) {
$new_user->init();
Expand Down Expand Up @@ -382,15 +399,17 @@ public function removeUser($new_user, $send_mail = true)
public function newUserRequest($new_user, $send_mail = true)
{
if ($this->userExists($new_user)) {
UnitySite::errorLog("warning", "user '$new_user' already in group");
return;
}

if ($this->requestExists($new_user)) {
UnitySite::errorLog("warning", "user '$new_user' already requested group membership");
return;
}

// check if account deletion request already exists
if ($this->SQL->accDeletionRequestExists($new_user->getUID())) {
throw new Exception("user '$new_user' requested account deletion");
return;
}

Expand Down
5 changes: 5 additions & 0 deletions resources/lib/UnityUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public function equals($other_user)
return $this->getUID() == $other_user->getUID();
}

public function __toString()
{
return $this->uid;
}

/**
* This is the method that is run when a new account is created
*
Expand Down
7 changes: 4 additions & 3 deletions test/functional/PiMemberApproveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ public function testApproveNonexistentRequest()
$this->assertEmpty($piGroup->getRequests());

try {
$this->expectException(Exception::class);
$piGroup->approveUser($notRequestedUser);
$this->assertEquals([$pi->getUID()], $piGroup->getGroupMemberUIDs());
$this->assertFalse($piGroup->userExists($notRequestedUser));
} finally {
$piGroup->removeUser($notRequestedUser);
if ($piGroup->userExists($notRequestedUser)) {
$piGroup->removeUser($notRequestedUser);
}
}
}
}
3 changes: 3 additions & 0 deletions test/functional/PiRemoveUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public function testRemoveUser()
foreach ($memberUIDs as $uid) {
if ($uid != $piUid) {
$memberToDelete = new UnityUser($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
if ($memberToDelete->hasRequestedAccountDeletion()) {
continue;
}
break;
}
}
Expand Down