diff --git a/resources/autoload.php b/resources/autoload.php index 5c0c25c2..7f3e7f5e 100644 --- a/resources/autoload.php +++ b/resources/autoload.php @@ -12,6 +12,9 @@ require_once __DIR__ . "/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPConn.php"; // load libs +require_once __DIR__ . "/lib/ObjectClass.php"; +require_once __DIR__ . "/lib/ObjectClassUser.php"; +require_once __DIR__ . "/lib/ObjectClassGroup.php"; require_once __DIR__ . "/lib/UnityLDAP.php"; require_once __DIR__ . "/lib/UnityUser.php"; require_once __DIR__ . "/lib/UnityGroup.php"; diff --git a/resources/init.php b/resources/init.php index b34df57a..6bc098de 100644 --- a/resources/init.php +++ b/resources/init.php @@ -119,10 +119,10 @@ $SEND_PIMESG_TO_ADMINS = $CONFIG["mail"]["send_pimesg_to_admins"]; $SQL->addLog( - $OPERATOR->getUID(), + $OPERATOR->uid, $_SERVER['REMOTE_ADDR'], "user_login", - $OPERATOR->getUID() + $OPERATOR->uid ); if (!$_SESSION["user_exists"]) { diff --git a/resources/lib/ObjectClass.php b/resources/lib/ObjectClass.php new file mode 100644 index 00000000..6fa0d3bd --- /dev/null +++ b/resources/lib/ObjectClass.php @@ -0,0 +1,69 @@ +entry->getAttribute($x) or $this->entry->getAttribute($x)[0] + * $attributes_array is a list of LDAP attribute names (lowercase only!) that should be an array + * $attributes_non_array is a list of LDAP attribute names (lowercase only!) that should be a single + * value instead of an array + * $entry is a PHPOpenLDAPer\LDAPEntry + * @since 8.3.0 + */ +class ObjectClass +{ + private ?LDAPEntry $entry = null; // define in constructor of child class + protected static array $attributes_array = []; + protected static array $attributes_non_array = []; + private $validated = false; + + private function ensureAttributeListsValidated() + { + if ($this->validated) { + return; + } + assert( + array_reduce( + array_merge(static::$attributes_array, static::$attributes_non_array), + fn($carry, $x) => $carry && is_string($x) && $x === strtolower($x), + true + ), + "attributes_array and attributes_non_array must be only lowercase strings" + ); + $this->validated = true; + } + + public function __get(string $property): mixed + { + assert(!is_null($this->entry)); + $this->ensureAttributeListsValidated(); + $property = strtolower($property); + if (in_array($property, static::$attributes_array, true)) { + return $this->entry->getAttribute($property); + } + if (in_array($property, static::$attributes_non_array, true)) { + $attribute = $this->entry->getAttribute($property); + if (empty($attribute)) { + throw new AttributeNotFound($property); + } + return $attribute[0]; + } + throw new Exception("Unknown property '$property'"); + } + + public function __isset(string $property): bool + { + $this->ensureAttributeListsValidated(); + $property = strtolower($property); + assert(!is_null($this->entry)); + $this->assert_attribute_lists_are_lowercase(); + if (in_array($property, static::$attributes_array, true) + || in_array($property, static::$attributes_non_array, true) + ) { + return (!empty($this->getAttribute($property))); + } + return false; + } +} diff --git a/resources/lib/ObjectClassGroup.php b/resources/lib/ObjectClassGroup.php new file mode 100644 index 00000000..0439ab98 --- /dev/null +++ b/resources/lib/ObjectClassGroup.php @@ -0,0 +1,28 @@ + $this->getAttribute("cn")[0] +// } +// public int $gidNumber { +// get => $this->getAttribute("gidNumber")[0] +// } +// public array $memberUid { +// get => $this->getAttribute("memberUid") +// } +// public array $objectClass { +// get => $this->getAttribute("objectClass") +// } +// } +// $LDAP->getUserGroupEntry,getOrgGroupEntry,getPIGroupEntry will also have to be +// updated to use LDAPConn::getEntryOfObjectClass diff --git a/resources/lib/ObjectClassUser.php b/resources/lib/ObjectClassUser.php new file mode 100644 index 00000000..d39a4f5b --- /dev/null +++ b/resources/lib/ObjectClassUser.php @@ -0,0 +1,67 @@ + $this->getAttribute("cn")[0] +// } +// public string $gecos { +// get => $this->getAttribute("gecos")[0] +// } +// public int $gidNumber { +// get => $this->getAttribute("gidNumber")[0] +// } +// public string $givenName { +// get => $this->getAttribute("givenName")[0] +// } +// public string $homeDirectory { +// get => $this->getAttribute("homeDirectory")[0] +// } +// public string $loginShell { +// get => $this->getAttribute("loginShell")[0] +// } +// public string $mail { +// get => $this->getAttribute("mail")[0] +// } +// public string $o { +// get => $this->getAttribute("o")[0] +// } +// public array $objectClass { +// get => $this->getAttribute("objectClass") +// } +// public string $sn { +// get => $this->getAttribute("sn")[0] +// } +// public array $sshPublicKey { +// get => $this->getAttribute("sshPublicKey") +// } +// public string $uid { +// get => $this->getAttribute("uid")[0] +// } +// public int $uidNumber { +// get => $this->getAttribute("uidNumber")[0] +// } +// } +// $LDAP->getUserEntry will also have to be updated to use LDAPConn::getEntryOfObjectClass diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index 9fac0191..3d784b74 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -7,11 +7,12 @@ /** * Class that represents a single PI group in the Unity Cluster. */ -class UnityGroup +class UnityGroup extends ObjectClassGroup { public const PI_PREFIX = "pi_"; private $pi_uid; + private $entry; // Services private $LDAP; @@ -30,6 +31,7 @@ class UnityGroup public function __construct($pi_uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK) { $this->pi_uid = $pi_uid; + $this->entry = $LDAP->getPIGroupEntry($pi_uid); $this->LDAP = $LDAP; $this->SQL = $SQL; @@ -69,7 +71,7 @@ public function getPIUID() */ public function exists() { - return $this->getLDAPPiGroup()->exists(); + return $this->entry->exists(); } // @@ -84,11 +86,11 @@ public function requestGroup($firstname, $lastname, $email, $org, $send_mail_to_ } // check if account deletion request already exists - if ($this->SQL->accDeletionRequestExists($this->getOwner()->getUID())) { + if ($this->SQL->accDeletionRequestExists($this->getOwner()->uid)) { return; } - $this->SQL->addRequest($this->getOwner()->getUID(), $firstname, $lastname, $email, $org); + $this->SQL->addRequest($this->getOwner()->uid, $firstname, $lastname, $email, $org); if ($send_mail) { // send email to requestor @@ -100,7 +102,7 @@ public function requestGroup($firstname, $lastname, $email, $org, $send_mail_to_ $this->WEBHOOK->sendWebhook( "group_request_admin", array( - "user" => $this->getOwner()->getUID(), + "user" => $this->getOwner()->uid, "org" => $org, "name" => "$firstname $lastname", "email" => $email @@ -112,7 +114,7 @@ public function requestGroup($firstname, $lastname, $email, $org, $send_mail_to_ "admin", "group_request_admin", array( - "user" => $this->getOwner()->getUID(), + "user" => $this->getOwner()->uid, "org" => $org, "name" => "$firstname $lastname", "email" => $email @@ -124,7 +126,7 @@ public function requestGroup($firstname, $lastname, $email, $org, $send_mail_to_ "pi_approve", "group_request_admin", array( - "user" => $this->getOwner()->getUID(), + "user" => $this->getOwner()->uid, "org" => $org, "name" => "$firstname $lastname", "email" => $email @@ -138,7 +140,7 @@ public function requestGroup($firstname, $lastname, $email, $org, $send_mail_to_ */ public function approveGroup($operator = null, $send_mail = true) { - $uid = $this->getOwner()->getUID(); + $uid = $this->getOwner()->uid; $request = $this->SQL->getRequest($uid, UnitySQL::REQUEST_BECOME_PI); // check for edge cases... @@ -162,15 +164,15 @@ public function approveGroup($operator = null, $send_mail = true) // remove the request from the sql table // this will silently fail if the request doesn't exist - $this->SQL->removeRequest($this->getOwner()->getUID()); + $this->SQL->removeRequest($this->getOwner()->uid); - $operator = is_null($operator) ? $this->getOwner()->getUID() : $operator->getUID(); + $operator = is_null($operator) ? $this->getOwner()->uid : $operator->uid; $this->SQL->addLog( $operator, $_SERVER['REMOTE_ADDR'], "approved_group", - $this->getOwner()->getUID() + $this->getOwner()->uid ); // send email to the newly approved PI @@ -188,19 +190,19 @@ public function approveGroup($operator = null, $send_mail = true) public function denyGroup($operator = null, $send_mail = true) { // remove request - this will fail silently if the request doesn't exist - $this->SQL->removeRequest($this->getOwner()->getUID()); + $this->SQL->removeRequest($this->getOwner()->uid); if ($this->exists()) { return; } - $operator = is_null($operator) ? $this->getOwner()->getUID() : $operator->getUID(); + $operator = is_null($operator) ? $this->getOwner()->uid : $operator->uid; $this->SQL->addLog( $operator, $_SERVER['REMOTE_ADDR'], "denied_group", - $this->getOwner()->getUID() + $this->getOwner()->uid ); // send email to the requestor @@ -214,17 +216,17 @@ public function denyGroup($operator = null, $send_mail = true) public function cancelGroupRequest($send_mail = true) { - if (!$this->SQL->requestExists($this->getOwner()->getUID())) { + if (!$this->SQL->requestExists($this->getOwner()->uid)) { return; } - $this->SQL->removeRequest($this->getOwner()->getUID()); + $this->SQL->removeRequest($this->getOwner()->uid); if ($send_mail) { $this->MAILER->sendMail( "admin", "group_request_cancelled", - ["uid" => $this->getOwner()->getUID()], + ["uid" => $this->getOwner()->uid], ); } } @@ -235,14 +237,14 @@ public function cancelGroupJoinRequest($user, $send_mail = true) return; } - $this->SQL->removeRequest($user->getUID(), $this->pi_uid); + $this->SQL->removeRequest($user->uid, $this->pi_uid); if ($send_mail) { // send email to requestor $this->MAILER->sendMail( $this->getOwner()->getMail(), "group_join_request_cancelled", - ["uid" => $user->getUID()] + ["uid" => $user->uid] ); } } @@ -265,12 +267,11 @@ public function cancelGroupJoinRequest($user, $send_mail = true) // $users = $this->getGroupMembers(); // // now we delete the ldap entry - // $ldapPiGroupEntry = $this->getLDAPPiGroup(); - // if ($ldapPiGroupEntry->exists()) { - // $ldapPiGroupEntry->delete(); + // if ($this->entry->exists()) { + // $this->entry->delete(); // $this->REDIS->removeCacheArray("sorted_groups", "", $this->getPIUID()); // foreach ($users as $user) { - // $this->REDIS->removeCacheArray($user->getUID(), "groups", $this->getPIUID()); + // $this->REDIS->removeCacheArray($user->uid, "groups", $this->getPIUID()); // } // } @@ -291,7 +292,7 @@ public function cancelGroupJoinRequest($user, $send_mail = true) */ public function approveUser($new_user, $send_mail = true) { - $uid = $new_user->getUID(); + $uid = $new_user->uid; $gid = $this->getPIUID(); $request = $this->SQL->getRequest($uid, $gid); // check if user exists @@ -307,7 +308,7 @@ public function approveUser($new_user, $send_mail = true) // add user to the LDAP object $this->addUserToGroup($new_user); - $this->SQL->removeRequest($new_user->getUID(), $this->pi_uid); + $this->SQL->removeRequest($new_user->uid, $this->pi_uid); // send email to the requestor if ($send_mail) { @@ -323,7 +324,7 @@ public function approveUser($new_user, $send_mail = true) "group_user_added_owner", array( "group" => $this->pi_uid, - "user" => $new_user->getUID(), + "user" => $new_user->uid, "name" => $request["firstname"] . " " . $request["lastname"], "email" => $request["email"], "org" => $request["org"], @@ -334,12 +335,12 @@ public function approveUser($new_user, $send_mail = true) public function denyUser($new_user, $send_mail = true) { - $uid = $new_user->getUID(); + $uid = $new_user->uid; $gid = $this->getPIUID(); $request = $this->SQL->getRequest($uid, $gid); // remove request, this will fail silently if the request doesn't exist - $this->SQL->removeRequest($new_user->getUID(), $this->pi_uid); + $this->SQL->removeRequest($new_user->uid, $this->pi_uid); if ($send_mail) { // send email to the user @@ -355,7 +356,7 @@ public function denyUser($new_user, $send_mail = true) "group_user_denied_owner", array( "group" => $this->pi_uid, - "user" => $new_user->getUID(), + "user" => $new_user->uid, "name" => $new_user->getFullName(), "email" => $new_user->getMail(), "org" => $new_user->getOrg() @@ -370,7 +371,7 @@ public function removeUser($new_user, $send_mail = true) return; } - if ($new_user->getUID() == $this->getOwner()->getUID()) { + if ($new_user->uid == $this->getOwner()->uid) { throw new Exception("Cannot delete group owner from group. Disband group instead"); } @@ -391,7 +392,7 @@ public function removeUser($new_user, $send_mail = true) "group_user_removed_owner", array( "group" => $this->pi_uid, - "user" => $new_user->getUID(), + "user" => $new_user->uid, "name" => $new_user->getFullName(), "email" => $new_user->getMail(), "org" => $new_user->getOrg() @@ -412,12 +413,12 @@ public function newUserRequest($new_user, $firstname, $lastname, $email, $org, $ return; } - if ($this->SQL->accDeletionRequestExists($new_user->getUID())) { + if ($this->SQL->accDeletionRequestExists($new_user->uid)) { throw new Exception("user '$new_user' requested account deletion"); return; } - $this->addRequest($new_user->getUID(), $firstname, $lastname, $email, $org); + $this->addRequest($new_user->uid, $firstname, $lastname, $email, $org); if ($send_mail) { // send email to user @@ -433,7 +434,7 @@ public function newUserRequest($new_user, $firstname, $lastname, $email, $org, $ "group_user_request_owner", array( "group" => $this->pi_uid, - "user" => $new_user->getUID(), + "user" => $new_user->uid, "name" => "$firstname $lastname", "email" => $email, "org" => $org, @@ -476,7 +477,7 @@ public function getGroupMembers($ignorecache = false) { $members = $this->getGroupMemberUIDs($ignorecache); $out = array(); - $owner_uid = $this->getOwner()->getUID(); + $owner_uid = $this->getOwner()->uid; foreach ($members as $member) { $user_obj = new UnityUser( $member, @@ -501,8 +502,7 @@ public function getGroupMemberUIDs($ignorecache = false) } $updatecache = false; if (!isset($members)) { - $pi_group = $this->getLDAPPiGroup(); - $members = $pi_group->getAttribute("memberuid"); + $members = $this->entry->getAttribute("memberuid"); $updatecache = true; } if (!$ignorecache && $updatecache) { @@ -517,7 +517,7 @@ public function requestExists($user) $requesters = $this->getRequests(); if (count($requesters) > 0) { foreach ($requesters as $requester) { - if ($requester[0]->getUID() == $user->getUID()) { + if ($requester[0]->uid == $user->uid) { return true; } } @@ -535,16 +535,13 @@ private function init() // make this user a PI $owner = $this->getOwner(); - // (1) Create LDAP PI group - $ldapPiGroupEntry = $this->getLDAPPiGroup(); - - if (!$ldapPiGroupEntry->exists()) { + if (!$this->entry->exists()) { $nextGID = $this->LDAP->getNextPiGIDNumber($this->SQL); - $ldapPiGroupEntry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS); - $ldapPiGroupEntry->setAttribute("gidnumber", strval($nextGID)); - $ldapPiGroupEntry->setAttribute("memberuid", array($owner->getUID())); - $ldapPiGroupEntry->write(); + $this->entry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS); + $this->entry->setAttribute("gidnumber", strval($nextGID)); + $this->entry->setAttribute("memberuid", array($owner->uid)); + $this->entry->write(); } $this->REDIS->appendCacheArray("sorted_groups", "", $this->getPIUID()); @@ -555,26 +552,24 @@ private function init() private function addUserToGroup($new_user) { // Add to LDAP Group - $pi_group = $this->getLDAPPiGroup(); - $pi_group->appendAttribute("memberuid", $new_user->getUID()); - $pi_group->write(); - $this->REDIS->appendCacheArray($this->getPIUID(), "members", $new_user->getUID()); - $this->REDIS->appendCacheArray($new_user->getUID(), "groups", $this->getPIUID()); + $this->entry->appendAttribute("memberuid", $new_user->uid); + $this->entry->write(); + $this->REDIS->appendCacheArray($this->getPIUID(), "members", $new_user->uid); + $this->REDIS->appendCacheArray($new_user->uid, "groups", $this->getPIUID()); } private function removeUserFromGroup($old_user) { // Remove from LDAP Group - $pi_group = $this->getLDAPPiGroup(); - $pi_group->removeAttributeEntryByValue("memberuid", $old_user->getUID()); - $pi_group->write(); - $this->REDIS->removeCacheArray($this->getPIUID(), "members", $old_user->getUID()); - $this->REDIS->removeCacheArray($old_user->getUID(), "groups", $this->getPIUID()); + $this->entry->removeAttributeEntryByValue("memberuid", $old_user->uid); + $this->entry->write(); + $this->REDIS->removeCacheArray($this->getPIUID(), "members", $old_user->uid); + $this->REDIS->removeCacheArray($old_user->uid, "groups", $this->getPIUID()); } public function userExists($user) { - return in_array($user->getUID(), $this->getGroupMemberUIDs()); + return in_array($user->uid, $this->getGroupMemberUIDs()); } private function addRequest($uid, $firstname, $lastname, $email, $org) @@ -598,11 +593,6 @@ public function getOwner() ); } - public function getLDAPPiGroup() - { - return $this->LDAP->getPIGroupEntry($this->pi_uid); - } - public static function getPIUIDfromUID($uid) { return self::PI_PREFIX . $uid; diff --git a/resources/lib/UnityOrg.php b/resources/lib/UnityOrg.php index c965d628..b9b5ad46 100644 --- a/resources/lib/UnityOrg.php +++ b/resources/lib/UnityOrg.php @@ -4,7 +4,7 @@ use Exception; -class UnityOrg +class UnityOrg extends ObjectClassGroup { private $orgid; @@ -57,14 +57,14 @@ public function getOrgID() public function inOrg($user, $ignorecache = false) { - return in_array($user->getUID(), $this->getOrgMemberUIDs($ignorecache)); + return in_array($user->uid, $this->getOrgMemberUIDs($ignorecache)); } public function getOrgMembers($ignorecache = false) { $members = $this->getGroupMemberUIDs($ignorecache); $out = array(); - $owner_uid = $this->getOwner()->getUID(); + $owner_uid = $this->getOwner()->uid; foreach ($members as $member) { $user_obj = new UnityUser( $member, @@ -103,16 +103,16 @@ public function getOrgMemberUIDs($ignorecache = false) public function addUser($user) { $org_group = $this->getLDAPOrgGroup(); - $org_group->appendAttribute("memberuid", $user->getUID()); + $org_group->appendAttribute("memberuid", $user->uid); $org_group->write(); - $this->REDIS->appendCacheArray($this->getOrgID(), "members", $user->getUID()); + $this->REDIS->appendCacheArray($this->getOrgID(), "members", $user->uid); } public function removeUser($user) { $org_group = $this->getLDAPOrgGroup(); - $org_group->removeAttributeEntryByValue("memberuid", $user->getUID()); + $org_group->removeAttributeEntryByValue("memberuid", $user->uid); $org_group->write(); - $this->REDIS->removeCacheArray($this->getOrgID(), "members", $user->getUID()); + $this->REDIS->removeCacheArray($this->getOrgID(), "members", $user->uid); } } diff --git a/resources/lib/UnitySQL.php b/resources/lib/UnitySQL.php index 26721a6c..fcd409ca 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -165,7 +165,7 @@ public function addNotice($title, $date, $content, $operator) $stmt->execute(); - $operator = $operator->getUID(); + $operator = $operator->uid; $this->addLog( $operator, @@ -252,7 +252,7 @@ public function editPage($id, $content, $operator) $stmt->execute(); - $operator = $operator->getUID(); + $operator = $operator->uid; $this->addLog( $operator, diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index 983e2a5f..2ef076b3 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -5,11 +5,12 @@ use PHPOpenLDAPer\LDAPEntry; use Exception; -class UnityUser +class UnityUser extends ObjectClassUser { private const HOME_DIR = "/home/"; - private $uid; + public $uid; + private $entry; // service stack private $LDAP; @@ -21,6 +22,7 @@ class UnityUser public function __construct($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK) { $this->uid = $uid; + $this->entry = $LDAP->getUserEntry($uid); $this->LDAP = $LDAP; $this->SQL = $SQL; @@ -35,7 +37,7 @@ public function equals($other_user) throw new Exception("Unable to check equality because the parameter is not a " . self::class . " object"); } - return $this->getUID() == $other_user->getUID(); + return $this->uid == $other_user->uid; } public function __toString() @@ -59,7 +61,7 @@ public function init($firstname, $lastname, $email, $org, $send_mail = true) // Create LDAP group // $ldapGroupEntry = $this->getLDAPGroup(); - $id = $this->LDAP->getUnassignedID($this->getUID(), $this->SQL); + $id = $this->LDAP->getUnassignedID($this->uid, $this->SQL); if (!$ldapGroupEntry->exists()) { $ldapGroupEntry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS); @@ -70,24 +72,22 @@ public function init($firstname, $lastname, $email, $org, $send_mail = true) // // Create LDAP user // - $ldapUserEntry = $this->getLDAPUser(); - - if (!$ldapUserEntry->exists()) { - $ldapUserEntry->setAttribute("objectclass", UnityLDAP::POSIX_ACCOUNT_CLASS); - $ldapUserEntry->setAttribute("uid", $this->uid); - $ldapUserEntry->setAttribute("givenname", $firstname); - $ldapUserEntry->setAttribute("sn", $lastname); - $ldapUserEntry->setAttribute( + if (!$this->entry->exists()) { + $this->entry->setAttribute("objectclass", UnityLDAP::POSIX_ACCOUNT_CLASS); + $this->entry->setAttribute("uid", $this->uid); + $this->entry->setAttribute("givenname", $firstname); + $this->entry->setAttribute("sn", $lastname); + $this->entry->setAttribute( "gecos", \transliterator_transliterate("Latin-ASCII", "$firstname $lastname") ); - $ldapUserEntry->setAttribute("mail", $email); - $ldapUserEntry->setAttribute("o", $org); - $ldapUserEntry->setAttribute("homedirectory", self::HOME_DIR . $this->uid); - $ldapUserEntry->setAttribute("loginshell", $this->LDAP->getDefUserShell()); - $ldapUserEntry->setAttribute("uidnumber", strval($id)); - $ldapUserEntry->setAttribute("gidnumber", strval($id)); - $ldapUserEntry->write(); + $this->entry->setAttribute("mail", $email); + $this->entry->setAttribute("o", $org); + $this->entry->setAttribute("homedirectory", self::HOME_DIR . $this->uid); + $this->entry->setAttribute("loginshell", $this->LDAP->getDefUserShell()); + $this->entry->setAttribute("uidnumber", strval($id)); + $this->entry->setAttribute("gidnumber", strval($id)); + $this->entry->write(); } // update cache @@ -113,20 +113,20 @@ public function init($firstname, $lastname, $email, $org, $send_mail = true) } // add to user group as well as user OU - $this->LDAP->getUserGroup()->appendAttribute("memberuid", $this->getUID()); + $this->LDAP->getUserGroup()->appendAttribute("memberuid", $this->uid); $this->LDAP->getUserGroup()->write(); // add user to cache - $this->REDIS->appendCacheArray("sorted_users", "", $this->getUID()); + $this->REDIS->appendCacheArray("sorted_users", "", $this->uid); // // add to audit log // $this->SQL->addLog( - $this->getUID(), + $this->uid, $_SERVER['REMOTE_ADDR'], "user_added", - $this->getUID() + $this->uid ); // @@ -141,16 +141,6 @@ public function init($firstname, $lastname, $email, $org, $send_mail = true) } } - /** - * Returns the ldap account entry corresponding to the user - * - * @return ldapEntry posix account - */ - public function getLDAPUser() - { - return $this->LDAP->getUserEntry($this->uid); - } - /** * Returns the ldap group entry corresponding to the user * @@ -163,28 +153,17 @@ public function getLDAPGroup() public function exists() { - return $this->getLDAPUser()->exists() && $this->getLDAPGroup()->exists(); + return $this->entry->exists() && $this->getLDAPGroup()->exists(); } // // User Attribute Functions // - /** - * Get method for NetID - * - * @return string Net ID of user - */ - public function getUID() - { - return $this->uid; - } - public function setOrg($org) { - $ldap_user = $this->getLDAPUser(); - $ldap_user->setAttribute("o", $org); - $ldap_user->write(); + $this->entry->setAttribute("o", $org); + $this->entry->write(); $this->REDIS->setCache($this->uid, "org", $org); } @@ -192,20 +171,20 @@ public function getOrg($ignorecache = false) { assert($this->exists()); if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->getUID(), "org"); + $cached_val = $this->REDIS->getCache($this->uid, "org"); if (!is_null($cached_val)) { return $cached_val; } } if ($this->exists()) { - $org = $this->getLDAPUser()->getAttribute("o")[0]; + $org = $this->entry->getAttribute("o")[0]; if (!$ignorecache) { - $this->REDIS->setCache($this->getUID(), "org", $org); + $this->REDIS->setCache($this->uid, "org", $org); } - return $this->getLDAPUser()->getAttribute("o")[0]; + return $this->entry->getAttribute("o")[0]; } return null; @@ -218,18 +197,17 @@ public function getOrg($ignorecache = false) */ public function setFirstname($firstname, $operator = null) { - $ldap_user = $this->getLDAPUser(); - $ldap_user->setAttribute("givenname", $firstname); - $operator = is_null($operator) ? $this->getUID() : $operator->getUID(); + $this->entry->setAttribute("givenname", $firstname); + $operator = is_null($operator) ? $this->uid : $operator->uid; $this->SQL->addLog( $operator, $_SERVER['REMOTE_ADDR'], "firstname_changed", - $this->getUID() + $this->uid ); - $ldap_user->write(); + $this->entry->write(); $this->REDIS->setCache($this->uid, "firstname", $firstname); } @@ -242,17 +220,17 @@ public function getFirstname($ignorecache = false) { assert($this->exists()); if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->getUID(), "firstname"); + $cached_val = $this->REDIS->getCache($this->uid, "firstname"); if (!is_null($cached_val)) { return $cached_val; } } if ($this->exists()) { - $firstname = $this->getLDAPUser()->getAttribute("givenname")[0]; + $firstname = $this->entry->getAttribute("givenname")[0]; if (!$ignorecache) { - $this->REDIS->setCache($this->getUID(), "firstname", $firstname); + $this->REDIS->setCache($this->uid, "firstname", $firstname); } return $firstname; @@ -268,18 +246,17 @@ public function getFirstname($ignorecache = false) */ public function setLastname($lastname, $operator = null) { - $ldap_user = $this->getLDAPUser(); - $ldap_user->setAttribute("sn", $lastname); - $operator = is_null($operator) ? $this->getUID() : $operator->getUID(); + $this->entry->setAttribute("sn", $lastname); + $operator = is_null($operator) ? $this->uid : $operator->uid; $this->SQL->addLog( $operator, $_SERVER['REMOTE_ADDR'], "lastname_changed", - $this->getUID() + $this->uid ); - $this->getLDAPUser()->write(); + $this->entry->write(); $this->REDIS->setCache($this->uid, "lastname", $lastname); } @@ -292,17 +269,17 @@ public function getLastname($ignorecache = false) { assert($this->exists()); if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->getUID(), "lastname"); + $cached_val = $this->REDIS->getCache($this->uid, "lastname"); if (!is_null($cached_val)) { return $cached_val; } } if ($this->exists()) { - $lastname = $this->getLDAPUser()->getAttribute("sn")[0]; + $lastname = $this->entry->getAttribute("sn")[0]; if (!$ignorecache) { - $this->REDIS->setCache($this->getUID(), "lastname", $lastname); + $this->REDIS->setCache($this->uid, "lastname", $lastname); } return $lastname; @@ -324,18 +301,17 @@ public function getFullname() */ public function setMail($email, $operator = null) { - $ldap_user = $this->getLDAPUser(); - $ldap_user->setAttribute("mail", $email); - $operator = is_null($operator) ? $this->getUID() : $operator->getUID(); + $this->entry->setAttribute("mail", $email); + $operator = is_null($operator) ? $this->uid : $operator->uid; $this->SQL->addLog( $operator, $_SERVER['REMOTE_ADDR'], "email_changed", - $this->getUID() + $this->uid ); - $this->getLDAPUser()->write(); + $this->entry->write(); $this->REDIS->setCache($this->uid, "mail", $email); } @@ -348,17 +324,17 @@ public function getMail($ignorecache = false) { assert($this->exists()); if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->getUID(), "mail"); + $cached_val = $this->REDIS->getCache($this->uid, "mail"); if (!is_null($cached_val)) { return $cached_val; } } if ($this->exists()) { - $mail = $this->getLDAPUser()->getAttribute("mail")[0]; + $mail = $this->entry->getAttribute("mail")[0]; if (!$ignorecache) { - $this->REDIS->setCache($this->getUID(), "mail", $mail); + $this->REDIS->setCache($this->uid, "mail", $mail); } return $mail; @@ -374,12 +350,11 @@ public function getMail($ignorecache = false) */ public function setSSHKeys($keys, $operator = null, $send_mail = true) { - $ldapUser = $this->getLDAPUser(); - $operator = is_null($operator) ? $this->getUID() : $operator->getUID(); + $operator = is_null($operator) ? $this->uid : $operator->uid; $keys_filt = array_values(array_unique($keys)); - if ($ldapUser->exists()) { - $ldapUser->setAttribute("sshpublickey", $keys_filt); - $ldapUser->write(); + if ($this->entry->exists()) { + $this->entry->setAttribute("sshpublickey", $keys_filt); + $this->entry->write(); } $this->REDIS->setCache($this->uid, "sshkeys", $keys_filt); @@ -391,7 +366,7 @@ public function setSSHKeys($keys, $operator = null, $send_mail = true) $operator, $_SERVER['REMOTE_ADDR'], "sshkey_modify", - $this->getUID() + $this->uid ); if ($send_mail) { @@ -412,15 +387,14 @@ public function getSSHKeys($ignorecache = false) { assert($this->exists()); if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->getUID(), "sshkeys"); + $cached_val = $this->REDIS->getCache($this->uid, "sshkeys"); if (!is_null($cached_val)) { return $cached_val; } } if ($this->exists()) { - $ldapUser = $this->getLDAPUser(); - $result = $ldapUser->getAttribute("sshpublickey"); + $result = $this->entry->getAttribute("sshpublickey"); if (is_null($result)) { $keys = array(); } else { @@ -428,7 +402,7 @@ public function getSSHKeys($ignorecache = false) } if (!$ignorecache) { - $this->REDIS->setCache($this->getUID(), "sshkeys", $keys); + $this->REDIS->setCache($this->uid, "sshkeys", $keys); } return $keys; @@ -454,19 +428,18 @@ public function setLoginShell($shell, $operator = null, $send_mail = true) if (empty($shell)) { throw new Exception("login shell must not be empty!"); } - $ldapUser = $this->getLDAPUser(); - if ($ldapUser->exists()) { - $ldapUser->setAttribute("loginshell", $shell); - $ldapUser->write(); + if ($this->entry->exists()) { + $this->entry->setAttribute("loginshell", $shell); + $this->entry->write(); } - $operator = is_null($operator) ? $this->getUID() : $operator->getUID(); + $operator = is_null($operator) ? $this->uid : $operator->uid; $this->SQL->addLog( $operator, $_SERVER['REMOTE_ADDR'], "loginshell_changed", - $this->getUID() + $this->uid ); $this->REDIS->setCache($this->uid, "loginshell", $shell); @@ -489,19 +462,17 @@ public function getLoginShell($ignorecache = false) { assert($this->exists()); if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->getUID(), "loginshell"); + $cached_val = $this->REDIS->getCache($this->uid, "loginshell"); if (!is_null($cached_val)) { return $cached_val; } } if ($this->exists()) { - $ldapUser = $this->getLDAPUser(); - - $loginshell = $ldapUser->getAttribute("loginshell")[0]; + $loginshell = $this->entry->getAttribute("loginshell")[0]; if (!$ignorecache) { - $this->REDIS->setCache($this->getUID(), "loginshell", $loginshell); + $this->REDIS->setCache($this->uid, "loginshell", $loginshell); } return $loginshell; @@ -512,17 +483,16 @@ public function getLoginShell($ignorecache = false) public function setHomeDir($home, $operator = null) { - $ldapUser = $this->getLDAPUser(); - if ($ldapUser->exists()) { - $ldapUser->setAttribute("homedirectory", $home); - $ldapUser->write(); - $operator = is_null($operator) ? $this->getUID() : $operator->getUID(); + if ($this->entry->exists()) { + $this->entry->setAttribute("homedirectory", $home); + $this->entry->write(); + $operator = is_null($operator) ? $this->uid : $operator->uid; $this->SQL->addLog( $operator, $_SERVER['REMOTE_ADDR'], "homedir_changed", - $this->getUID() + $this->uid ); $this->REDIS->setCache($this->uid, "homedir", $home); @@ -538,19 +508,17 @@ public function getHomeDir($ignorecache = false) { assert($this->exists()); if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->getUID(), "homedir"); + $cached_val = $this->REDIS->getCache($this->uid, "homedir"); if (!is_null($cached_val)) { return $cached_val; } } if ($this->exists()) { - $ldapUser = $this->getLDAPUser(); - - $homedir = $ldapUser->getAttribute("homedirectory"); + $homedir = $this->entry->getAttribute("homedirectory"); if (!$ignorecache) { - $this->REDIS->setCache($this->getUID(), "homedir", $homedir); + $this->REDIS->setCache($this->uid, "homedir", $homedir); } return $homedir; @@ -613,7 +581,7 @@ public function getGroups($ignorecache = false) $out = array(); if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->getUID(), "groups"); + $cached_val = $this->REDIS->getCache($this->uid, "groups"); if (!is_null($cached_val)) { $groups = $cached_val; foreach ($groups as $group) { @@ -637,14 +605,14 @@ public function getGroups($ignorecache = false) $cache_arr = array(); foreach ($all_pi_groups as $pi_group) { - if (in_array($this->getUID(), $pi_group->getGroupMemberUIDs())) { + if (in_array($this->uid, $pi_group->getGroupMemberUIDs())) { array_push($out, $pi_group); array_push($cache_arr, $pi_group->getPIUID()); } } if (!$ignorecache) { - $this->REDIS->setCache($this->getUID(), "groups", $cache_arr); + $this->REDIS->setCache($this->uid, "groups", $cache_arr); } return $out; @@ -655,12 +623,12 @@ public function getGroups($ignorecache = false) */ public function requestAccountDeletion() { - $this->SQL->addAccountDeletionRequest($this->getUID()); + $this->SQL->addAccountDeletionRequest($this->uid); $this->MAILER->sendMail( "admin", "account_deletion_request_admin", array( - "user" => $this->getUID(), + "user" => $this->uid, "name" => $this->getFullname(), "email" => $this->getMail() ) @@ -674,7 +642,7 @@ public function requestAccountDeletion() */ public function hasRequestedAccountDeletion() { - return $this->SQL->accDeletionRequestExists($this->getUID()); + return $this->SQL->accDeletionRequestExists($this->uid); } /** diff --git a/test/functional/AccountDeletionRequestTest.php b/test/functional/AccountDeletionRequestTest.php index 08eb2af4..e6fae600 100644 --- a/test/functional/AccountDeletionRequestTest.php +++ b/test/functional/AccountDeletionRequestTest.php @@ -9,10 +9,10 @@ private function assertNumberAccountDeletionRequests(int $x) global $USER, $SQL; if ($x == 0) { $this->assertFalse($USER->hasRequestedAccountDeletion()); - $this->assertFalse($SQL->accDeletionRequestExists($USER->getUID())); + $this->assertFalse($SQL->accDeletionRequestExists($USER->uid)); } elseif ($x > 0) { $this->assertTrue($USER->hasRequestedAccountDeletion()); - $this->assertTrue($SQL->accDeletionRequestExists($USER->getUID())); + $this->assertTrue($SQL->accDeletionRequestExists($USER->uid)); } else { throw new RuntimeError("x must not be negative"); } @@ -25,7 +25,7 @@ private function getNumberAccountDeletionRequests() $stmt = $SQL->getConn()->prepare( "SELECT * FROM account_deletion_requests WHERE uid=:uid" ); - $uid = $USER->getUID(); + $uid = $USER->uid; $stmt->bindParam(":uid", $uid); $stmt->execute(); return count($stmt->fetchAll()); @@ -49,7 +49,7 @@ public function testRequestAccountDeletionUserHasNoGroups() ); $this->assertNumberAccountDeletionRequests(1); } finally { - $SQL->deleteAccountDeletionRequest($USER->getUID()); + $SQL->deleteAccountDeletionRequest($USER->uid); $this->assertNumberAccountDeletionRequests(0); } } @@ -68,7 +68,7 @@ public function testRequestAccountDeletionUserHasGroup() ); $this->assertNumberAccountDeletionRequests(0); } finally { - $SQL->deleteAccountDeletionRequest($USER->getUID()); + $SQL->deleteAccountDeletionRequest($USER->uid); $this->assertNumberAccountDeletionRequests(0); } } diff --git a/test/functional/NewUserTest.php b/test/functional/NewUserTest.php index b0f0fb23..6178fc93 100644 --- a/test/functional/NewUserTest.php +++ b/test/functional/NewUserTest.php @@ -13,7 +13,7 @@ private function assertRequestedPIGroup(bool $expected) global $USER, $SQL; $this->assertEquals( $expected, - $SQL->requestExists($USER->getUID(), UnitySQL::REQUEST_BECOME_PI) + $SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI) ); } @@ -22,7 +22,7 @@ private function assertRequestedMembership(bool $expected, string $gid) global $USER, $SQL; $this->assertEquals( $expected, - $SQL->requestExists($USER->getUID(), $gid) + $SQL->requestExists($USER->uid, $gid) ); } @@ -58,26 +58,26 @@ private function cancelAllRequests() private function ensureUserDoesNotExist() { global $USER, $SQL, $LDAP; - $SQL->deleteRequestsByUser($USER->getUID()); + $SQL->deleteRequestsByUser($USER->uid); if ($USER->exists()) { $org = $USER->getOrgGroup(); if ($org->exists() and $org->inOrg($USER)) { $org->removeUser($USER); assert(!$org->inOrg($USER)); } - $USER->getLDAPUser()->delete(); + $LDAP->getUserEntry($USER->uid)->delete(); assert(!$USER->exists()); } $all_users_group = $LDAP->getUserGroup(); $all_member_uids = $all_users_group->getAttribute("memberuid"); - $new_uids = array_diff($all_member_uids, [$USER->getUID()]); - if (in_array($USER->getUID(), $all_member_uids)) { + $new_uids = array_diff($all_member_uids, [$USER->uid]); + if (in_array($USER->uid, $all_member_uids)) { $all_users_group->setAttribute( "memberuid", - array_diff($all_member_uids, [$USER->getUID()]) + array_diff($all_member_uids, [$USER->uid]) ); $all_users_group->write(); - assert(!in_array($USER->getUID(), $all_users_group->getAttribute("memberuid"))); + assert(!in_array($USER->uid, $all_users_group->getAttribute("memberuid"))); } } @@ -102,9 +102,9 @@ private function ensureUserNotInPIGroup(UnityGroup $pi_group) private function ensurePIGroupDoesNotExist() { - global $USER; + global $USER, $LDAP; if ($USER->getPIGroup()->exists()) { - $USER->getPIGroup()->getLDAPPIGroup()->delete(); + $LDAP->getPIGroupEntry($USER->getPIGroup()->getPIUID())->delete(); assert(!$USER->getPIGroup()->exists()); } } diff --git a/test/functional/PIMemberRequestTest.php b/test/functional/PIMemberRequestTest.php index ec4cff71..5ff7513f 100644 --- a/test/functional/PIMemberRequestTest.php +++ b/test/functional/PIMemberRequestTest.php @@ -34,7 +34,7 @@ public function testRequestMembership() $this->assertTrue(arraysAreEqualUnOrdered([$pi], $pi_group->getGroupMembers())); $this->assertEquals([], $SQL->getRequests($gid)); switchUser(...getUserNotPiNotRequestedBecomePi()); - $uid = $USER->getUID(); + $uid = $USER->uid; $this->assertFalse($USER->isPI()); $this->assertFalse($SQL->requestExists($uid, UnitySQL::REQUEST_BECOME_PI)); $this->assertFalse($pi_group->userExists($USER)); diff --git a/test/functional/PiBecomeRequestTest.php b/test/functional/PiBecomeRequestTest.php index 6c1bb3ba..abd446a1 100644 --- a/test/functional/PiBecomeRequestTest.php +++ b/test/functional/PiBecomeRequestTest.php @@ -9,9 +9,9 @@ private function assertNumberPiBecomeRequests(int $x) { global $USER, $SQL; if ($x == 0) { - $this->assertFalse($SQL->requestExists($USER->getUID())); + $this->assertFalse($SQL->requestExists($USER->uid)); } elseif ($x > 0) { - $this->assertTrue($SQL->requestExists($USER->getUID())); + $this->assertTrue($SQL->requestExists($USER->uid)); } else { throw new RuntimeError("x must not be negative"); } @@ -26,7 +26,7 @@ private function getNumberPiBecomeRequests() $stmt = $SQL->getConn()->prepare( "SELECT * FROM requests WHERE uid=:uid and request_for='admin'" ); - $uid = $USER->getUID(); + $uid = $USER->uid; $stmt->bindParam(":uid", $uid); $stmt->execute(); return count($stmt->fetchAll()); @@ -61,7 +61,7 @@ public function testRequestBecomePi() $this->assertNumberPiBecomeRequests(1); } finally { if ($SQL->requestExists($USER, UnitySQL::REQUEST_BECOME_PI)) { - $SQL->removeRequest($USER->getUID(), UnitySQL::REQUEST_BECOME_PI); + $SQL->removeRequest($USER->uid, UnitySQL::REQUEST_BECOME_PI); } } } @@ -72,7 +72,7 @@ public function testRequestBecomePiUserRequestedAccountDeletion() switchUser(...getUserNotPiNotRequestedBecomePiRequestedAccountDeletion()); $this->assertFalse($USER->isPI()); $this->assertNumberPiBecomeRequests(0); - $this->assertTrue($SQL->accDeletionRequestExists($USER->getUID())); + $this->assertTrue($SQL->accDeletionRequestExists($USER->uid)); try { http_post( __DIR__ . "/../../webroot/panel/account.php", @@ -81,7 +81,7 @@ public function testRequestBecomePiUserRequestedAccountDeletion() $this->assertNumberPiBecomeRequests(0); } finally { if ($SQL->requestExists($USER, UnitySQL::REQUEST_BECOME_PI)) { - $SQL->removeRequest($USER->getUID(), UnitySQL::REQUEST_BECOME_PI); + $SQL->removeRequest($USER->uid, UnitySQL::REQUEST_BECOME_PI); } } } diff --git a/test/functional/PiMemberApproveTest.php b/test/functional/PiMemberApproveTest.php index 94ee6af8..2dfb3b64 100644 --- a/test/functional/PiMemberApproveTest.php +++ b/test/functional/PiMemberApproveTest.php @@ -6,18 +6,19 @@ use UnityWebPortal\lib\UnityGroup; use UnityWebPortal\lib\UnitySSO; -class PiMemberApproveTest extends TestCase { - static $userWithRequestSwitchArgs; - static $userWithoutRequestSwitchArgs; - static $piSwitchArgs; - static $pi; - static $userWithRequestUID; - static $userWithoutRequestUID; - static $piUID; - static $userWithRequest; - static $userWithoutRequest; - static $piGroup; - static $piGroupGID; +class PiMemberApproveTest extends TestCase +{ + static $userWithRequestSwitchArgs; + static $userWithoutRequestSwitchArgs; + static $piSwitchArgs; + static $pi; + static $userWithRequestUID; + static $userWithoutRequestUID; + static $piUID; + static $userWithRequest; + static $userWithoutRequest; + static $piGroup; + static $piGroupGID; private function approveUser(string $uid) { @@ -52,9 +53,9 @@ public function testApproveRequest() $piSwitchArgs = getUserIsPIHasNoMembersNoMemberRequests(); switchUser(...$userSwitchArgs); $user = $USER; - $uid = $USER->getUID(); + $uid = $USER->uid; switchUser(...$piSwitchArgs); - $piUID = $USER->getUID(); + $piUID = $USER->uid; $piGroup = $USER->getPIGroup(); $this->assertTrue($piGroup->exists()); @@ -86,9 +87,9 @@ public function testApproveNonexistentRequest() global $USER; switchUser(...getNormalUser2()); $user = $USER; - $uid = $USER->getUID(); + $uid = $USER->uid; switchUser(...getUserIsPIHasNoMembersNoMemberRequests()); - $piUID = $USER->getUID(); + $piUID = $USER->uid; $piGroup = $USER->getPIGroup(); $this->assertTrue($piGroup->exists()); diff --git a/test/functional/PiMemberDenyTest.php b/test/functional/PiMemberDenyTest.php index 4278a1d5..ca203298 100644 --- a/test/functional/PiMemberDenyTest.php +++ b/test/functional/PiMemberDenyTest.php @@ -4,13 +4,15 @@ use PHPUnit\Framework\Attributes\DataProvider; use UnityWebPortal\lib\UnityUser; -class PiMemberDenyTest extends TestCase { +class PiMemberDenyTest extends TestCase +{ static $requestUid; - public static function setUpBeforeClass(): void{ + public static function setUpBeforeClass(): void + { global $USER; switchUser(...getNormalUser()); - self::$requestUid = $USER->getUID(); + self::$requestUid = $USER->uid; } private function denyUser(string $uid) @@ -30,7 +32,7 @@ public function testDenyRequest() $this->assertTrue($piGroup->exists()); $this->assertTrue( arraysAreEqualUnOrdered( - [$pi->getUID()], + [$pi->uid], $piGroup->getGroupMemberUIDs() ) ); @@ -50,7 +52,7 @@ public function testDenyRequest() $this->assertEmpty($piGroup->getRequests()); $this->assertTrue( arraysAreEqualUnOrdered( - [$pi->getUID()], + [$pi->uid], $piGroup->getGroupMemberUIDs() ) ); diff --git a/test/functional/PiRemoveUserTest.php b/test/functional/PiRemoveUserTest.php index 1d7dd72f..21ab26bc 100644 --- a/test/functional/PiRemoveUserTest.php +++ b/test/functional/PiRemoveUserTest.php @@ -4,7 +4,8 @@ use PHPUnit\Framework\Attributes\DataProvider; use UnityWebPortal\lib\UnityUser; -class PiRemoveUserTest extends TestCase { +class PiRemoveUserTest extends TestCase +{ private function removeUser(string $uid) { http_post( @@ -18,7 +19,7 @@ public function testRemoveUser() global $USER, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; switchUser(...getUserIsPIHasAtLeastOneMember()); $pi = $USER; - $piUid = $USER->getUID(); + $piUid = $USER->uid; $piGroup = $USER->getPIGroup(); $this->assertTrue($piGroup->exists()); $memberUIDs = $piGroup->getGroupMemberUIDs(); @@ -36,10 +37,10 @@ public function testRemoveUser() break; } } - $this->assertNotEquals($pi->getUID(), $memberToDelete->getUID()); + $this->assertNotEquals($pi->uid, $memberToDelete->uid); $this->assertTrue($piGroup->userExists($memberToDelete)); try { - $this->removeUser($memberToDelete->getUID()); + $this->removeUser($memberToDelete->uid); $this->assertFalse($piGroup->userExists($memberToDelete)); } finally { if (!$piGroup->userExists($memberToDelete)) { @@ -65,7 +66,7 @@ public function testRemovePIFromTheirOwnGroup() $this->assertTrue($piGroup->userExists($pi)); $this->expectException(Exception::class); try { - $this->removeUser($pi->getUID()); + $this->removeUser($pi->uid); $this->assertTrue($piGroup->userExists($pi)); } finally { if (!$piGroup->userExists($pi)) { @@ -78,6 +79,6 @@ public function testRemovePIFromTheirOwnGroup() ); $piGroup->approveUser($pi); } - } + } } } diff --git a/test/functional/ViewAsUserTest.php b/test/functional/ViewAsUserTest.php index 8d5be3c4..9c298586 100644 --- a/test/functional/ViewAsUserTest.php +++ b/test/functional/ViewAsUserTest.php @@ -10,10 +10,10 @@ public function _testViewAsUser(array $beforeUser, array $afterUser) { global $USER; switchUser(...$afterUser); - $afterUid = $USER->getUID(); + $afterUid = $USER->uid; switchUser(...$beforeUser); // $this->assertTrue($USER->isAdmin()); - $beforeUid = $USER->getUID(); + $beforeUid = $USER->uid; // $this->assertNotEquals($afterUid, $beforeUid); http_post( __DIR__ . "/../../webroot/admin/user-mgmt.php", @@ -28,7 +28,7 @@ public function _testViewAsUser(array $beforeUser, array $afterUser) session_write_close(); http_get(__DIR__ . "/../../resources/init.php"); // now we should be new user - $this->assertEquals($afterUid, $USER->getUID()); + $this->assertEquals($afterUid, $USER->uid); // $this->assertTrue($_SESSION["user_exists"]); http_post( __DIR__ . "/../../resources/templates/header.php", @@ -40,7 +40,7 @@ public function _testViewAsUser(array $beforeUser, array $afterUser) session_write_close(); http_get(__DIR__ . "/../../resources/init.php"); // now we should be back to original user - $this->assertEquals($beforeUid, $USER->getUID()); + $this->assertEquals($beforeUid, $USER->uid); } public function testViewAsUser() @@ -62,7 +62,7 @@ public function testNonAdminViewAsAdmin() { global $USER; switchUser(...getAdminUser()); - $adminUid = $USER->getUID(); + $adminUid = $USER->uid; $this->assertTrue($USER->isAdmin()); switchUser(...getNormalUser()); http_post( diff --git a/test/phpunit-bootstrap.php b/test/phpunit-bootstrap.php index be7fdd81..6f375410 100644 --- a/test/phpunit-bootstrap.php +++ b/test/phpunit-bootstrap.php @@ -6,6 +6,9 @@ require_once __DIR__ . "/../resources/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPEntry.php"; require_once __DIR__ . "/../resources/lib/phpopenldaper/src/PHPOpenLDAPer/LDAPConn.php"; +require_once __DIR__ . "/../resources/lib/ObjectClass.php"; +require_once __DIR__ . "/../resources/lib/ObjectClassUser.php"; +require_once __DIR__ . "/../resources/lib/ObjectClassGroup.php"; require_once __DIR__ . "/../resources/lib/UnityLDAP.php"; require_once __DIR__ . "/../resources/lib/UnityUser.php"; require_once __DIR__ . "/../resources/lib/UnityGroup.php"; diff --git a/webroot/admin/ajax/get_group_members.php b/webroot/admin/ajax/get_group_members.php index e3e56759..a8b598ec 100644 --- a/webroot/admin/ajax/get_group_members.php +++ b/webroot/admin/ajax/get_group_members.php @@ -20,7 +20,7 @@ $i = 0; $count = count($members) + count($requests); foreach ($members as $member) { - if ($member->getUID() == $group->getOwner()->getUID()) { + if ($member->uid == $group->getOwner()->uid) { continue; } @@ -31,14 +31,14 @@ } echo "