From d387b93b56e75064d26788d5a9a8d5b4fde59da3 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 11:46:41 -0400 Subject: [PATCH 01/10] edge case empty admins group --- resources/lib/UnityUser.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index 4f88eac6..96e003f2 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -562,6 +562,7 @@ public function getHomeDir($ignorecache = false) public function isAdmin() { $admins = $this->LDAP->getAdminGroup()->getAttribute("memberuid"); + $admins = (is_null($admins) ? [] : $admins); return in_array($this->uid, $admins); } From da9ec8287dcebf69ac69526a9f2ad97080daac09 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 11:54:50 -0400 Subject: [PATCH 02/10] handle null memberuid, refactor --- resources/lib/UnityGroup.php | 69 +++++++++--------------- resources/lib/UnityOrg.php | 62 ++++++++++----------- resources/lib/UnityUser.php | 10 ++-- webroot/admin/ajax/get_group_members.php | 2 +- webroot/panel/ajax/get_group_members.php | 2 +- webroot/panel/pi.php | 2 +- workers/update-ldap-cache.php | 4 +- 7 files changed, 65 insertions(+), 86 deletions(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index d1616225..5d59d035 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -3,6 +3,7 @@ namespace UnityWebPortal\lib; use Exception; +use PHPOpenLDAPer\LdapEntry; /** * Class that represents a single PI group in the Unity Cluster. @@ -64,7 +65,7 @@ public function getPIUID() */ public function exists() { - return $this->getLDAPPiGroup()->exists(); + return $this->GetLDAPEntry()->exists(); } // @@ -213,10 +214,10 @@ public function removeGroup($send_mail = true) } // first, we must record the users in the group currently - $users = $this->getGroupMembers(); + $users = $this->getMembers(); // now we delete the ldap entry - $ldapPiGroupEntry = $this->getLDAPPiGroup(); + $ldapPiGroupEntry = $this->GetLDAPEntry(); if ($ldapPiGroupEntry->exists()) { if (!$ldapPiGroupEntry->delete()) { throw new Exception("Unable to delete PI ldap group"); @@ -407,54 +408,35 @@ public function getRequests() return $out; } - public function getGroupMembers($ignorecache = false) + public function getMemberUIDs($ignorecache = false): array { if (!$ignorecache) { $cached_val = $this->REDIS->getCache($this->getPIUID(), "members"); if (!is_null($cached_val)) { - $members = $cached_val; + return $cached_val; } } + $entry = $this->getLDAPEntry(); + $members = $entry->getAttribute("memberuid"); + $members = (is_null($members) ? [] : $members); + sort($members); + $this->REDIS->setCache($this->getPIUID(), "members", $members); + return $members; + } - $updatecache = false; - if (!isset($members)) { - $pi_group = $this->getLDAPPiGroup(); - $members = $pi_group->getAttribute("memberuid"); - $updatecache = true; - } + public function getMembers($ignorecache = false) + { + $memberuids = $this->getMemberUIDs($ignorecache); $out = array(); - $cache_arr = array(); - $owner_uid = $this->getOwner()->getUID(); foreach ($members as $member) { - $user_obj = new UnityUser( - $member, - $this->LDAP, - $this->SQL, - $this->MAILER, - $this->REDIS, - $this->WEBHOOK - ); - array_push($out, $user_obj); - array_push($cache_arr, $user_obj->getUID()); - } - - if (!$ignorecache && $updatecache) { - sort($cache_arr); - $this->REDIS->setCache($this->getPIUID(), "members", $cache_arr); + $user_obj = new UnityUser($member, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); + array_push($out, $user_obj); + array_push($cache_arr, $user_obj->getUID()); } - return $out; } - public function getGroupMemberUIDs() - { - $pi_group = $this->getLDAPPiGroup(); - $members = $pi_group->getAttribute("memberuid"); - - return $members; - } - public function requestExists($user) { $requesters = $this->getRequests(); @@ -479,7 +461,7 @@ private function init() $owner = $this->getOwner(); // (1) Create LDAP PI group - $ldapPiGroupEntry = $this->getLDAPPiGroup(); + $ldapPiGroupEntry = $this->GetLDAPEntry(); if (!$ldapPiGroupEntry->exists()) { $nextGID = $this->LDAP->getNextPiGIDNumber($this->SQL); @@ -501,7 +483,7 @@ private function init() private function addUserToGroup($new_user) { // Add to LDAP Group - $pi_group = $this->getLDAPPiGroup(); + $pi_group = $this->GetLDAPEntry(); $pi_group->appendAttribute("memberuid", $new_user->getUID()); if (!$pi_group->write()) { @@ -515,7 +497,7 @@ private function addUserToGroup($new_user) private function removeUserFromGroup($old_user) { // Remove from LDAP Group - $pi_group = $this->getLDAPPiGroup(); + $pi_group = $this->GetLDAPEntry(); $pi_group->removeAttributeEntryByValue("memberuid", $old_user->getUID()); if (!$pi_group->write()) { @@ -526,9 +508,10 @@ private function removeUserFromGroup($old_user) $this->REDIS->removeCacheArray($old_user->getUID(), "groups", $this->getPIUID()); } - public function userExists($user) + public function userExists(UnityUser $user): bool { - return in_array($user->getUID(), $this->getGroupMemberUIDs()); + $members = $this->getMemberUIDs($ignorecache); + return in_array($user->getUID(), $members); } private function addRequest($uid) @@ -557,7 +540,7 @@ public function getOwner() ); } - public function getLDAPPiGroup() + public function GetLDAPEntry(): LdapEntry { return $this->LDAP->getPIGroupEntry($this->pi_uid); } diff --git a/resources/lib/UnityOrg.php b/resources/lib/UnityOrg.php index 03f85818..5276f848 100644 --- a/resources/lib/UnityOrg.php +++ b/resources/lib/UnityOrg.php @@ -3,6 +3,7 @@ namespace UnityWebPortal\lib; use Exception; +use PHPOpenLDAPer\LdapEntry; class UnityOrg { @@ -27,15 +28,15 @@ public function __construct($orgid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK) public function init() { - $org_group = $this->getLDAPOrgGroup(); + $entry = $this->getLDAPEntry(); - if (!$org_group->exists()) { + if (!$entry->exists()) { $nextGID = $this->LDAP->getNextOrgGIDNumber($this->SQL); - $org_group->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS); - $org_group->setAttribute("gidnumber", strval($nextGID)); + $entry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS); + $entry->setAttribute("gidnumber", strval($nextGID)); - if (!$org_group->write()) { + if (!$entry->write()) { throw new Exception("Failed to create POSIX group for " . $this->orgid); // this shouldn't execute } } @@ -45,10 +46,10 @@ public function init() public function exists() { - return $this->getLDAPOrgGroup()->exists(); + return $this->getLDAPEntry()->exists(); } - public function getLDAPOrgGroup() + public function getLDAPEntry(): LdapEntry { return $this->LDAP->getOrgGroupEntry($this->orgid); } @@ -58,51 +59,46 @@ public function getOrgID() return $this->orgid; } - public function inOrg($user) + public function userExists(UnityUser $user, $ignorecache = false): bool { - $org_group = $this->getLDAPOrgGroup(); - $members = $org_group->getAttribute("memberuid"); - return in_array($user, $members); + $members = $this->getMemberUIDs($ignorecache); + return in_array($user->getUID(), $members); } - public function getOrgMembers($ignorecache = false) + public function getMemberUIDs($ignorecache = false): array { if (!$ignorecache) { $cached_val = $this->REDIS->getCache($this->getOrgID(), "members"); if (!is_null($cached_val)) { - $members = $cached_val; + return $cached_val; } } + $entry = $this->getLDAPEntry(); + $members = $entry->getAttribute("memberuid"); + $members = (is_null($members) ? [] : $members); + sort($members); + $this->REDIS->setCache($this->getOrgID(), "members", $members); + return $members; + } - $updatecache = false; - if (!isset($members)) { - $org_group = $this->getLDAPOrgGroup(); - $members = $org_group->getAttribute("memberuid"); - $updatecache = true; - } - + public function getMembers($ignorecache = false) + { + $memberuids = $this->getMemberUIDs($ignorecache); $out = array(); - $cache_arr = array(); foreach ($members as $member) { $user_obj = new UnityUser($member, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); array_push($out, $user_obj); array_push($cache_arr, $user_obj->getUID()); } - - if (!$ignorecache && $updatecache) { - sort($cache_arr); - $this->REDIS->setCache($this->getOrgID(), "members", $cache_arr); - } - return $out; } public function addUser($user) { - $org_group = $this->getLDAPOrgGroup(); - $org_group->appendAttribute("memberuid", $user->getUID()); + $entry = $this->getLDAPEntry(); + $entry->appendAttribute("memberuid", $user->getUID()); - if (!$org_group->write()) { + if (!$entry->write()) { throw new Exception("Unable to write to org group"); } @@ -111,10 +107,10 @@ public function addUser($user) public function removeUser($user) { - $org_group = $this->getLDAPOrgGroup(); - $org_group->removeAttributeEntryByValue("memberuid", $user->getUID()); + $entry = $this->getLDAPEntry(); + $entry->removeAttributeEntryByValue("memberuid", $user->getUID()); - if (!$org_group->write()) { + if (!$entry->write()) { throw new Exception("Unable to write to org group"); } diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index 96e003f2..d02317c6 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -105,7 +105,7 @@ public function init($send_mail = true) $orgEntry->init(); } - if (!$orgEntry->inOrg($this->uid)) { + if (!$orgEntry->userExists($this)) { $orgEntry->addUser($this); } @@ -139,7 +139,7 @@ public function init($send_mail = true) * * @return ldapEntry posix account */ - public function getLDAPUser() + public function getLDAPUser(): LdapEntry { return $this->LDAP->getUserEntry($this->uid); } @@ -149,7 +149,7 @@ public function getLDAPUser() * * @return ldapEntry posix group */ - public function getLDAPGroup() + public function getLDAPGroup(): LdapEntry { return $this->LDAP->getGroupEntry($this->uid); } @@ -633,7 +633,7 @@ 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->getUID(), $pi_group->getMemberUIDs())) { array_push($out, $pi_group); array_push($cache_arr, $pi_group->getPIUID()); } @@ -695,6 +695,6 @@ public function isInGroup($uid, $group) $group_checked = $group; } - return in_array($uid, $group_checked->getGroupMemberUIDs()); + return in_array($uid, $group_checked->getMemberUIDs()); } } diff --git a/webroot/admin/ajax/get_group_members.php b/webroot/admin/ajax/get_group_members.php index 2f5ff45b..d006bb97 100644 --- a/webroot/admin/ajax/get_group_members.php +++ b/webroot/admin/ajax/get_group_members.php @@ -13,7 +13,7 @@ } $group = new UnityGroup($_GET["pi_uid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); -$members = $group->getGroupMembers(); +$members = $group->getMembers(); $requests = $group->getRequests(); $key = 0; diff --git a/webroot/panel/ajax/get_group_members.php b/webroot/panel/ajax/get_group_members.php index 92015cbf..ba57b767 100644 --- a/webroot/panel/ajax/get_group_members.php +++ b/webroot/panel/ajax/get_group_members.php @@ -9,7 +9,7 @@ } $group = new UnityGroup($_GET["pi_uid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); -$members = $group->getGroupMembers(); +$members = $group->getMembers(); // verify that the user querying is actually in the group $found = false; diff --git a/webroot/panel/pi.php b/webroot/panel/pi.php index 85258581..65f59471 100644 --- a/webroot/panel/pi.php +++ b/webroot/panel/pi.php @@ -46,7 +46,7 @@ getRequests(); -$assocs = $group->getGroupMembers(); +$assocs = $group->getMembers(); if (count($requests) + count($assocs) == 1) { echo "

You do not have any users attached to your PI account. diff --git a/workers/update-ldap-cache.php b/workers/update-ldap-cache.php index 026b94f5..e761eefd 100644 --- a/workers/update-ldap-cache.php +++ b/workers/update-ldap-cache.php @@ -41,7 +41,7 @@ array_push($sorted_groups, $gid); $parsed_members = array(); - foreach ($group->getGroupMembers(true) as $member) { + foreach ($group->getMembers(true) as $member) { array_push($parsed_members, $member->getUID()); } @@ -61,7 +61,7 @@ array_push($sorted_orgs, $orgid); $parsed_orgs = array(); - foreach ($org->getOrgMembers(true) as $member) { + foreach ($org->getMembers(true) as $member) { array_push($parsed_members, $member->getUID()); } From 56600287d8b36ccb63b9959d4b3fb304f22ed0d5 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 12:05:15 -0400 Subject: [PATCH 03/10] undo member func rename --- resources/lib/UnityGroup.php | 10 +++++----- resources/lib/UnityOrg.php | 8 ++++---- resources/lib/UnityUser.php | 4 ++-- webroot/admin/ajax/get_group_members.php | 2 +- webroot/panel/ajax/get_group_members.php | 2 +- webroot/panel/pi.php | 2 +- workers/update-ldap-cache.php | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index 5d59d035..fa12752c 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -214,7 +214,7 @@ public function removeGroup($send_mail = true) } // first, we must record the users in the group currently - $users = $this->getMembers(); + $users = $this->getGroupMembers(); // now we delete the ldap entry $ldapPiGroupEntry = $this->GetLDAPEntry(); @@ -408,7 +408,7 @@ public function getRequests() return $out; } - public function getMemberUIDs($ignorecache = false): array + public function getGroupMemberUIDs($ignorecache = false): array { if (!$ignorecache) { $cached_val = $this->REDIS->getCache($this->getPIUID(), "members"); @@ -425,9 +425,9 @@ public function getMemberUIDs($ignorecache = false): array } - public function getMembers($ignorecache = false) + public function getGroupMembers($ignorecache = false) { - $memberuids = $this->getMemberUIDs($ignorecache); + $memberuids = $this->getGroupMemberUIDs($ignorecache); $out = array(); foreach ($members as $member) { $user_obj = new UnityUser($member, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); @@ -510,7 +510,7 @@ private function removeUserFromGroup($old_user) public function userExists(UnityUser $user): bool { - $members = $this->getMemberUIDs($ignorecache); + $members = $this->getGroupMemberUIDs($ignorecache); return in_array($user->getUID(), $members); } diff --git a/resources/lib/UnityOrg.php b/resources/lib/UnityOrg.php index 5276f848..42661d98 100644 --- a/resources/lib/UnityOrg.php +++ b/resources/lib/UnityOrg.php @@ -61,11 +61,11 @@ public function getOrgID() public function userExists(UnityUser $user, $ignorecache = false): bool { - $members = $this->getMemberUIDs($ignorecache); + $members = $this->getOrgMemberUIDs($ignorecache); return in_array($user->getUID(), $members); } - public function getMemberUIDs($ignorecache = false): array + public function getOrgMemberUIDs($ignorecache = false): array { if (!$ignorecache) { $cached_val = $this->REDIS->getCache($this->getOrgID(), "members"); @@ -81,9 +81,9 @@ public function getMemberUIDs($ignorecache = false): array return $members; } - public function getMembers($ignorecache = false) + public function getOrgMembers($ignorecache = false) { - $memberuids = $this->getMemberUIDs($ignorecache); + $memberuids = $this->getOrgMemberUIDs($ignorecache); $out = array(); foreach ($members as $member) { $user_obj = new UnityUser($member, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index d02317c6..9d3a114c 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -633,7 +633,7 @@ public function getGroups($ignorecache = false) $cache_arr = array(); foreach ($all_pi_groups as $pi_group) { - if (in_array($this->getUID(), $pi_group->getMemberUIDs())) { + if (in_array($this->getUID(), $pi_group->getGroupMemberUIDs())) { array_push($out, $pi_group); array_push($cache_arr, $pi_group->getPIUID()); } @@ -695,6 +695,6 @@ public function isInGroup($uid, $group) $group_checked = $group; } - return in_array($uid, $group_checked->getMemberUIDs()); + return in_array($uid, $group_checked->getGroupMemberUIDs()); } } diff --git a/webroot/admin/ajax/get_group_members.php b/webroot/admin/ajax/get_group_members.php index d006bb97..2f5ff45b 100644 --- a/webroot/admin/ajax/get_group_members.php +++ b/webroot/admin/ajax/get_group_members.php @@ -13,7 +13,7 @@ } $group = new UnityGroup($_GET["pi_uid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); -$members = $group->getMembers(); +$members = $group->getGroupMembers(); $requests = $group->getRequests(); $key = 0; diff --git a/webroot/panel/ajax/get_group_members.php b/webroot/panel/ajax/get_group_members.php index ba57b767..92015cbf 100644 --- a/webroot/panel/ajax/get_group_members.php +++ b/webroot/panel/ajax/get_group_members.php @@ -9,7 +9,7 @@ } $group = new UnityGroup($_GET["pi_uid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); -$members = $group->getMembers(); +$members = $group->getGroupMembers(); // verify that the user querying is actually in the group $found = false; diff --git a/webroot/panel/pi.php b/webroot/panel/pi.php index 65f59471..85258581 100644 --- a/webroot/panel/pi.php +++ b/webroot/panel/pi.php @@ -46,7 +46,7 @@ getRequests(); -$assocs = $group->getMembers(); +$assocs = $group->getGroupMembers(); if (count($requests) + count($assocs) == 1) { echo "

You do not have any users attached to your PI account. diff --git a/workers/update-ldap-cache.php b/workers/update-ldap-cache.php index e761eefd..026b94f5 100644 --- a/workers/update-ldap-cache.php +++ b/workers/update-ldap-cache.php @@ -41,7 +41,7 @@ array_push($sorted_groups, $gid); $parsed_members = array(); - foreach ($group->getMembers(true) as $member) { + foreach ($group->getGroupMembers(true) as $member) { array_push($parsed_members, $member->getUID()); } @@ -61,7 +61,7 @@ array_push($sorted_orgs, $orgid); $parsed_orgs = array(); - foreach ($org->getMembers(true) as $member) { + foreach ($org->getOrgMembers(true) as $member) { array_push($parsed_members, $member->getUID()); } From fa2b3569ef27f5424690ae0560f8d49773f4d185 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 12:08:05 -0400 Subject: [PATCH 04/10] fix var name --- resources/lib/UnityGroup.php | 4 ++-- resources/lib/UnityOrg.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index fa12752c..a9236dca 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -429,8 +429,8 @@ public function getGroupMembers($ignorecache = false) { $memberuids = $this->getGroupMemberUIDs($ignorecache); $out = array(); - foreach ($members as $member) { - $user_obj = new UnityUser($member, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); + foreach ($memberuids as $uid) { + $user_obj = new UnityUser($uid, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); array_push($out, $user_obj); array_push($cache_arr, $user_obj->getUID()); } diff --git a/resources/lib/UnityOrg.php b/resources/lib/UnityOrg.php index 42661d98..ba572c68 100644 --- a/resources/lib/UnityOrg.php +++ b/resources/lib/UnityOrg.php @@ -85,8 +85,8 @@ public function getOrgMembers($ignorecache = false) { $memberuids = $this->getOrgMemberUIDs($ignorecache); $out = array(); - foreach ($members as $member) { - $user_obj = new UnityUser($member, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); + foreach ($memberuids as $uid) { + $user_obj = new UnityUser($uid, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); array_push($out, $user_obj); array_push($cache_arr, $user_obj->getUID()); } From 80195a079567aab81ef1668bd79baf42edba343a Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 12:08:37 -0400 Subject: [PATCH 05/10] delete old reference --- resources/lib/UnityGroup.php | 1 - resources/lib/UnityOrg.php | 1 - 2 files changed, 2 deletions(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index a9236dca..e111ff46 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -432,7 +432,6 @@ public function getGroupMembers($ignorecache = false) foreach ($memberuids as $uid) { $user_obj = new UnityUser($uid, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); array_push($out, $user_obj); - array_push($cache_arr, $user_obj->getUID()); } return $out; } diff --git a/resources/lib/UnityOrg.php b/resources/lib/UnityOrg.php index ba572c68..de607735 100644 --- a/resources/lib/UnityOrg.php +++ b/resources/lib/UnityOrg.php @@ -88,7 +88,6 @@ public function getOrgMembers($ignorecache = false) foreach ($memberuids as $uid) { $user_obj = new UnityUser($uid, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); array_push($out, $user_obj); - array_push($cache_arr, $user_obj->getUID()); } return $out; } From 58dc0c945bb995ea5da9ee587bf2df8f5e169e6c Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 12:09:38 -0400 Subject: [PATCH 06/10] preserve func order --- resources/lib/UnityGroup.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index e111ff46..205bfd42 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -408,6 +408,17 @@ public function getRequests() return $out; } + public function getGroupMembers($ignorecache = false) + { + $memberuids = $this->getGroupMemberUIDs($ignorecache); + $out = array(); + foreach ($memberuids as $uid) { + $user_obj = new UnityUser($uid, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); + array_push($out, $user_obj); + } + return $out; + } + public function getGroupMemberUIDs($ignorecache = false): array { if (!$ignorecache) { @@ -424,18 +435,6 @@ public function getGroupMemberUIDs($ignorecache = false): array return $members; } - - public function getGroupMembers($ignorecache = false) - { - $memberuids = $this->getGroupMemberUIDs($ignorecache); - $out = array(); - foreach ($memberuids as $uid) { - $user_obj = new UnityUser($uid, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK); - array_push($out, $user_obj); - } - return $out; - } - public function requestExists($user) { $requesters = $this->getRequests(); From 3a8115fe51063195ae786cde66e506c541e40a94 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 12:19:46 -0400 Subject: [PATCH 07/10] missing argument --- resources/lib/UnityGroup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index 205bfd42..677c546e 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -506,7 +506,7 @@ private function removeUserFromGroup($old_user) $this->REDIS->removeCacheArray($old_user->getUID(), "groups", $this->getPIUID()); } - public function userExists(UnityUser $user): bool + public function userExists(UnityUser $user, $ignorecache = false): bool { $members = $this->getGroupMemberUIDs($ignorecache); return in_array($user->getUID(), $members); From 04beab37216c35c96a30c10149ba54f6ad131802 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 13:35:35 -0400 Subject: [PATCH 08/10] fix capitalization --- resources/lib/UnityGroup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index 677c546e..0f515edd 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -538,7 +538,7 @@ public function getOwner() ); } - public function GetLDAPEntry(): LdapEntry + public function getLDAPEntry(): LdapEntry { return $this->LDAP->getPIGroupEntry($this->pi_uid); } From 5681befb0eab385cfb4741dac54ce013164f995c Mon Sep 17 00:00:00 2001 From: simonLeary42 <71396965+simonLeary42@users.noreply.github.com> Date: Mon, 7 Apr 2025 22:39:14 -0400 Subject: [PATCH 09/10] use null coalescing operator --- resources/lib/UnityGroup.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index 0f515edd..d3a892d3 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -428,8 +428,7 @@ public function getGroupMemberUIDs($ignorecache = false): array } } $entry = $this->getLDAPEntry(); - $members = $entry->getAttribute("memberuid"); - $members = (is_null($members) ? [] : $members); + $members = $entry->getAttribute("memberuid") ?? []; sort($members); $this->REDIS->setCache($this->getPIUID(), "members", $members); return $members; From 5510ec672c16b31ed3bb6bdfb7f8c76d2e7e6d9f Mon Sep 17 00:00:00 2001 From: simonLeary42 <71396965+simonLeary42@users.noreply.github.com> Date: Mon, 7 Apr 2025 22:39:58 -0400 Subject: [PATCH 10/10] use null coalescing operator --- resources/lib/UnityOrg.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/resources/lib/UnityOrg.php b/resources/lib/UnityOrg.php index de607735..5bc0fe0e 100644 --- a/resources/lib/UnityOrg.php +++ b/resources/lib/UnityOrg.php @@ -74,8 +74,7 @@ public function getOrgMemberUIDs($ignorecache = false): array } } $entry = $this->getLDAPEntry(); - $members = $entry->getAttribute("memberuid"); - $members = (is_null($members) ? [] : $members); + $members = $entry->getAttribute("memberuid") ?? []; sort($members); $this->REDIS->setCache($this->getOrgID(), "members", $members); return $members;