From d9b044919cd99b2ee27c8d2c554d633b28652fc5 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Wed, 26 Nov 2025 17:16:55 -0500 Subject: [PATCH 1/6] start removing redis --- README.md | 11 +- defaults/config.ini.default | 4 - resources/autoload.php | 1 - resources/init.php | 14 +-- resources/lib/UnityGroup.php | 43 ------- resources/lib/UnityLDAP.php | 24 ---- resources/lib/UnityOrg.php | 18 --- resources/lib/UnityRedis.php | 105 ------------------ resources/lib/UnityUser.php | 29 ----- test/functional/PIBecomeApproveTest.php | 2 +- test/functional/PageLoadTest.php | 2 +- test/functional/PiMemberApproveTest.php | 4 +- test/functional/PiMemberDenyTest.php | 4 +- test/functional/PiRemoveUserTest.php | 6 +- test/functional/RegisterUserTest.php | 2 +- test/phpunit-bootstrap.php | 30 ++--- tools/docker-dev/docker-compose.yml | 14 --- tools/docker-dev/redis/Dockerfile | 4 - tools/docker-dev/web/Dockerfile | 1 - webroot/admin/ajax/get_group_members.php | 2 +- webroot/admin/pi-mgmt.php | 8 +- webroot/panel/ajax/get_group_members.php | 2 +- webroot/panel/groups.php | 5 +- webroot/panel/modal/pi_search.php | 2 +- webroot/panel/new_account.php | 2 +- webroot/panel/pi.php | 2 +- workers/group_user_request_owner_reminder.php | 2 +- workers/remove-users-from-group.php | 4 +- workers/update-ldap-cache.php | 105 ------------------ 29 files changed, 35 insertions(+), 417 deletions(-) delete mode 100644 resources/lib/UnityRedis.php delete mode 100644 tools/docker-dev/redis/Dockerfile delete mode 100755 workers/update-ldap-cache.php diff --git a/README.md b/README.md index a50d64e3..a072e123 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ See the Docker Compose environment (`tools/docker-dev/`) for an (unsafe for prod - Composer (`apt install composer` on Ubuntu) - Dependencies: - PHP extensions - - curl, intl, ldap, mbstring, mysql, pdo, redis, xml (`apt install php-` on Ubuntu) + - curl, intl, ldap, mbstring, mysql, pdo, xml (`apt install php-` on Ubuntu) - Libraries - `COMPOSER_ALLOW_SUPERUSER=1 composer --no-dev --no-scripts --no-plugins install` - `httpd` `DocumentRoot` set to `webroot/` @@ -139,14 +139,7 @@ Now, LDAP entries are created immediately for every user, so this is no longer n $_SERVER["REMOTE_ADDR"] = "127.0.0.1"; require_once __DIR__ . "/../resources/autoload.php"; foreach ($SQL->getAllRequests() as $request) { - $user = new UnityUser( - $request["uid"], - $LDAP, - $SQL, - $MAILER, - $REDIS, - $WEBHOOK, - ); + $user = new UnityUser($request["uid"], $LDAP, $SQL, $MAILER, $WEBHOOK); if (!$user->exists()) { echo "creating user: " . jsonEncode($request) . "\n"; $user->init( diff --git a/defaults/config.ini.default b/defaults/config.ini.default index 3044f7e1..70301033 100644 --- a/defaults/config.ini.default +++ b/defaults/config.ini.default @@ -49,10 +49,6 @@ user = "" ; smtp username, if exists pass = "" ; smtp password, if exists ssl_verify = "false" ; set to true to verify ssl certificates -[redis] -host = "redis" -port = "6379" - [colors] light_background = "#ffffff" ; Background color when in light mode light_foreground = "#1a1a1a" ; Text color when in light mode diff --git a/resources/autoload.php b/resources/autoload.php index e74c7fad..7f262cdc 100644 --- a/resources/autoload.php +++ b/resources/autoload.php @@ -22,7 +22,6 @@ require_once __DIR__ . "/lib/UnityHTTPD.php"; require_once __DIR__ . "/lib/UnityConfig.php"; require_once __DIR__ . "/lib/UnityWebhook.php"; -require_once __DIR__ . "/lib/UnityRedis.php"; require_once __DIR__ . "/lib/UnityGithub.php"; require_once __DIR__ . "/lib/utils.php"; require_once __DIR__ . "/lib/exceptions/NoDieException.php"; diff --git a/resources/init.php b/resources/init.php index b9c63d80..3a62a7ed 100644 --- a/resources/init.php +++ b/resources/init.php @@ -9,7 +9,6 @@ use UnityWebPortal\lib\UnitySQL; use UnityWebPortal\lib\UnitySSO; use UnityWebPortal\lib\UnityUser; -use UnityWebPortal\lib\UnityRedis; use UnityWebPortal\lib\UnityWebhook; use UnityWebPortal\lib\UnityGithub; use UnityWebPortal\lib\UnityHTTPD; @@ -20,7 +19,6 @@ session_start(); -$REDIS = new UnityRedis(); if (isset($GLOBALS["ldapconn"])) { $LDAP = $GLOBALS["ldapconn"]; } else { @@ -37,11 +35,11 @@ $SSO = UnitySSO::getSSO(); $_SESSION["SSO"] = $SSO; - $OPERATOR = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $OPERATOR = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $WEBHOOK); $_SESSION["is_admin"] = $OPERATOR->isAdmin(); if (isset($_SESSION["viewUser"]) && $_SESSION["is_admin"]) { - $USER = new UnityUser($_SESSION["viewUser"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $USER = new UnityUser($_SESSION["viewUser"], $LDAP, $SQL, $MAILER, $WEBHOOK); } else { $USER = $OPERATOR; } @@ -51,14 +49,6 @@ $SEND_PIMESG_TO_ADMINS = CONFIG["mail"]["send_pimesg_to_admins"]; $SQL->addLog($OPERATOR->uid, $_SERVER["REMOTE_ADDR"], "user_login", $OPERATOR->uid); - - if (!$_SESSION["user_exists"]) { - // populate cache - $REDIS->setCache($SSO["user"], "org", $SSO["org"]); - $REDIS->setCache($SSO["user"], "firstname", $SSO["firstname"]); - $REDIS->setCache($SSO["user"], "lastname", $SSO["lastname"]); - $REDIS->setCache($SSO["user"], "mail", $SSO["mail"]); - } } $LOC_HEADER = __DIR__ . "/templates/header.php"; diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index e2084906..290720cb 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -18,14 +18,12 @@ class UnityGroup private UnitySQL $SQL; private UnityMailer $MAILER; private UnityWebhook $WEBHOOK; - private UnityRedis $REDIS; public function __construct( string $gid, UnityLDAP $LDAP, UnitySQL $SQL, UnityMailer $MAILER, - UnityRedis $REDIS, UnityWebhook $WEBHOOK, ) { $gid = trim($gid); @@ -35,7 +33,6 @@ public function __construct( $this->LDAP = $LDAP; $this->SQL = $SQL; $this->MAILER = $MAILER; - $this->REDIS = $REDIS; $this->WEBHOOK = $WEBHOOK; } @@ -184,17 +181,6 @@ public function cancelGroupJoinRequest(UnityUser $user, bool $send_mail = true): // // now we delete the ldap entry // $this->entry->ensureExists(); // $this->entry->delete(); - // $default_value_getter = [$this->LDAP, "getSortedGroupsForRedis"]; - // $this->REDIS->removeCacheArray("sorted_groups", "", $this->gid, $default_value_getter); - // foreach ($users as $user) { - // $this->REDIS->removeCacheArray( - // $user->uid, - // "groups", - // $this->gid, - // fn() => $this->getGroupMemberUIDs(true), - // ); - // } - // // FIXME group not removed from user's groups array // // send email to every user of the now deleted PI group // if ($send_mail) { @@ -315,7 +301,6 @@ public function getRequests(): array $this->LDAP, $this->SQL, $this->MAILER, - $this->REDIS, $this->WEBHOOK, ); array_push($out, [$user, $request["timestamp"]]); @@ -333,7 +318,6 @@ public function getGroupMembers(bool $ignorecache = false): array $this->LDAP, $this->SQL, $this->MAILER, - $this->REDIS, $this->WEBHOOK, ); array_push($out, $user_obj); @@ -383,8 +367,6 @@ private function init(): void $this->entry->setAttribute("gidnumber", strval($nextGID)); $this->entry->setAttribute("memberuid", [$owner->uid]); $this->entry->write(); - $default_value_getter = [$this->LDAP, "getSortedGroupsForRedis"]; - $this->REDIS->appendCacheArray("sorted_groups", "", $this->gid, $default_value_getter); // TODO if we ever make this project based, // we need to update the cache here with the memberuid } @@ -393,36 +375,12 @@ private function addUserToGroup(UnityUser $new_user): void { $this->entry->appendAttribute("memberuid", $new_user->uid); $this->entry->write(); - $this->REDIS->appendCacheArray( - $this->gid, - "members", - $new_user->uid, - fn() => $this->getGroupMemberUIDs(true), - ); - $this->REDIS->appendCacheArray( - $new_user->uid, - "groups", - $this->gid, - fn() => $this->LDAP->getPIGroupGIDsWithMemberUID($new_user->uid), - ); } private function removeUserFromGroup(UnityUser $old_user): void { $this->entry->removeAttributeEntryByValue("memberuid", $old_user->uid); $this->entry->write(); - $this->REDIS->removeCacheArray( - $this->gid, - "members", - $old_user->uid, - fn() => $this->getGroupMemberUIDs(true), - ); - $this->REDIS->removeCacheArray( - $old_user->uid, - "groups", - $this->gid, - fn() => $this->LDAP->getPIGroupGIDsWithMemberUID($old_user->uid), - ); } public function memberExists(UnityUser $user): bool @@ -442,7 +400,6 @@ public function getOwner(): UnityUser $this->LDAP, $this->SQL, $this->MAILER, - $this->REDIS, $this->WEBHOOK, ); } diff --git a/resources/lib/UnityLDAP.php b/resources/lib/UnityLDAP.php index 0b7ede67..be45aca0 100644 --- a/resources/lib/UnityLDAP.php +++ b/resources/lib/UnityLDAP.php @@ -197,7 +197,6 @@ public function getQualifiedUsersUIDs(): array public function getQualifiedUsers( $UnitySQL, $UnityMailer, - $UnityRedis, $UnityWebhook, $ignorecache = false, ): array { @@ -466,29 +465,6 @@ public function getUidFromEmail(string $email): LDAPEntry throw new exceptions\EntryNotFoundException($email); } - public function getSortedQualifiedUsersForRedis(): array - { - $qualified_users = $this->getQualifiedUsersUIDs(); - sort($qualified_users); - return $qualified_users; - } - - public function getSortedOrgsForRedis(): array - { - $attributes = $this->getAllOrgGroupsAttributes(["cn"]); - $groups = array_map(fn($x) => $x["cn"][0], $attributes); - sort($groups); - return $groups; - } - - public function getSortedGroupsForRedis(): array - { - $attributes = $this->getAllPIGroupsAttributes(["cn"]); - $groups = array_map(fn($x) => $x["cn"][0], $attributes); - sort($groups); - return $groups; - } - /** * returns an array with each UID as an array key * @throws \UnityWebPortal\lib\exceptions\EntryNotFoundException diff --git a/resources/lib/UnityOrg.php b/resources/lib/UnityOrg.php index 96cb5f97..fe15f89f 100644 --- a/resources/lib/UnityOrg.php +++ b/resources/lib/UnityOrg.php @@ -11,14 +11,12 @@ class UnityOrg private UnitySQL $SQL; private UnityMailer $MAILER; private UnityWebhook $WEBHOOK; - private UnityRedis $REDIS; public function __construct( string $gid, UnityLDAP $LDAP, UnitySQL $SQL, UnityMailer $MAILER, - UnityRedis $REDIS, UnityWebhook $WEBHOOK, ) { $gid = trim($gid); @@ -29,7 +27,6 @@ public function __construct( $this->SQL = $SQL; $this->MAILER = $MAILER; $this->WEBHOOK = $WEBHOOK; - $this->REDIS = $REDIS; } public function init(): void @@ -39,8 +36,6 @@ public function init(): void $this->entry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS); $this->entry->setAttribute("gidnumber", strval($nextGID)); $this->entry->write(); - $default_value_getter = [$this->LDAP, "getSortedOrgsForRedis"]; - $this->REDIS->appendCacheArray("sorted_orgs", "", $this->gid, $default_value_getter); } public function exists(): bool @@ -63,7 +58,6 @@ public function getOrgMembers(bool $ignorecache = false): array $this->LDAP, $this->SQL, $this->MAILER, - $this->REDIS, $this->WEBHOOK, ); array_push($out, $user_obj); @@ -95,23 +89,11 @@ public function addUser(UnityUser $user): void { $this->entry->appendAttribute("memberuid", $user->uid); $this->entry->write(); - $this->REDIS->appendCacheArray( - $this->gid, - "members", - $user->uid, - fn() => $this->getOrgMemberUIDs(true), - ); } public function removeUser(UnityUser $user): void { $this->entry->removeAttributeEntryByValue("memberuid", $user->uid); $this->entry->write(); - $this->REDIS->removeCacheArray( - $this->gid, - "members", - $user->uid, - fn() => $this->getOrgMemberUIDs(true), - ); } } diff --git a/resources/lib/UnityRedis.php b/resources/lib/UnityRedis.php deleted file mode 100644 index b24a6094..00000000 --- a/resources/lib/UnityRedis.php +++ /dev/null @@ -1,105 +0,0 @@ -enabled = false; - } else { - $this->enabled = true; - $this->client = new Redis(); - $this->client->connect($host, $port); - } - } - - public function setCache(string $object, string $key, mixed $data): void - { - if (!$this->enabled) { - return; - } - - if (!empty($key)) { - $keyStr = $object . "_" . $key; - } else { - $keyStr = $object; - } - if (is_null($data)) { - UnityHTTPD::errorLog("warning", "setting '$keyStr' to null"); - } - $this->client->set($keyStr, serialize($data)); - } - - public function getCache(string $object, string $key): mixed - { - if (!$this->enabled) { - return null; - } - - if (!empty($key)) { - $keyStr = $object . "_" . $key; - } else { - $keyStr = $object; - } - - $cached_val = $this->client->get($keyStr); - if ($cached_val) { - return unserialize($cached_val); - } - - return null; - } - - public function appendCacheArray( - string $object, - string $key, - mixed $value, - callable $default_value_getter, - ): void { - if (!$this->enabled) { - return; - } - $old_val = $this->getCache($object, $key) ?? $default_value_getter(); - if (!is_array($old_val)) { - throw new TypeError("redis[$object][$key] is not an array!"); - } - $new_val = $old_val; - array_push($new_val, $value); - sort($new_val); - $this->setCache($object, $key, $new_val); - } - - public function removeCacheArray( - string $object, - string $key, - mixed $value, - callable $default_value_getter, - ) { - if (!$this->enabled) { - return; - } - $old_val = $this->getCache($object, $key) ?? $default_value_getter(); - if (!is_array($old_val)) { - throw new TypeError("redis[$object][$key] is not an array!"); - } - $new_val = array_diff($old_val, [$value]); - sort($new_val); - $this->setCache($object, $key, $new_val); - } - - public function flushAll(): void - { - $this->client->flushAll(); - } -} diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index 76c839a8..f072ae43 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -15,14 +15,12 @@ class UnityUser private UnitySQL $SQL; private UnityMailer $MAILER; private UnityWebhook $WEBHOOK; - private UnityRedis $REDIS; public function __construct( string $uid, UnityLDAP $LDAP, UnitySQL $SQL, UnityMailer $MAILER, - UnityRedis $REDIS, UnityWebhook $WEBHOOK, ) { $uid = trim($uid); @@ -32,7 +30,6 @@ public function __construct( $this->LDAP = $LDAP; $this->SQL = $SQL; $this->MAILER = $MAILER; - $this->REDIS = $REDIS; $this->WEBHOOK = $WEBHOOK; } @@ -88,14 +85,6 @@ public function init( $this->entry->setAttribute("gidnumber", strval($id)); $this->entry->write(); - $this->REDIS->setCache($this->uid, "firstname", $firstname); - $this->REDIS->setCache($this->uid, "lastname", $lastname); - $this->REDIS->setCache($this->uid, "mail", $email); - $this->REDIS->setCache($this->uid, "org", $org); - $this->REDIS->setCache($this->uid, "homedir", self::HOME_DIR . $this->uid); - $this->REDIS->setCache($this->uid, "loginshell", $this->LDAP->getDefUserShell()); - $this->REDIS->setCache($this->uid, "sshkeys", []); - $org = $this->getOrgGroup(); if (!$org->exists()) { $org->init(); @@ -122,13 +111,6 @@ public function setIsQualified(bool $newIsQualified, bool $doSendMail = true): v if ($newIsQualified) { $this->LDAP->getQualifiedUserGroup()->appendAttribute("memberuid", $this->uid); $this->LDAP->getQualifiedUserGroup()->write(); - $default_value_getter = [$this->LDAP, "getSortedQualifiedUsersForRedis"]; - $this->REDIS->appendCacheArray( - "sorted_qualified_users", - "", - $this->uid, - $default_value_getter, - ); if ($doSendMail) { $this->MAILER->sendMail($this->getMail(), "user_qualified", [ "user" => $this->uid, @@ -140,13 +122,6 @@ public function setIsQualified(bool $newIsQualified, bool $doSendMail = true): v ->getQualifiedUserGroup() ->removeAttributeEntryByValue("memberuid", $this->uid); $this->LDAP->getQualifiedUserGroup()->write(); - $default_value_getter = [$this->LDAP, "getSortedQualifiedUsersForRedis"]; - $this->REDIS->removeCacheArray( - "sorted_qualified_users", - "", - $this->uid, - $default_value_getter, - ); if ($doSendMail) { $this->MAILER->sendMail($this->getMail(), "user_dequalified", [ "user" => $this->uid, @@ -173,7 +148,6 @@ public function setOrg(UnityOrg $org): void { $this->entry->setAttribute("o", $org); $this->entry->write(); - $this->REDIS->setCache($this->uid, "org", $org); } public function getOrg(bool $ignorecache = false): string @@ -452,7 +426,6 @@ public function getPIGroup(): UnityGroup $this->LDAP, $this->SQL, $this->MAILER, - $this->REDIS, $this->WEBHOOK, ); } @@ -464,7 +437,6 @@ public function getOrgGroup(): UnityOrg $this->LDAP, $this->SQL, $this->MAILER, - $this->REDIS, $this->WEBHOOK, ); } @@ -520,7 +492,6 @@ public function isInGroup(string $uid, UnityGroup $group): bool $this->LDAP, $this->SQL, $this->MAILER, - $this->REDIS, $this->WEBHOOK, ); } else { diff --git a/test/functional/PIBecomeApproveTest.php b/test/functional/PIBecomeApproveTest.php index e384e1b9..8ac7b019 100644 --- a/test/functional/PIBecomeApproveTest.php +++ b/test/functional/PIBecomeApproveTest.php @@ -42,7 +42,7 @@ private function approveGroup($uid) public function testApprovePI() { - global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; + global $USER, $SSO, $LDAP, $SQL, $MAILER, $WEBHOOK; $user_to_qualify_args = getUnqualifiedUser(); switchuser(...$user_to_qualify_args); $pi_group = $USER->getPIGroup(); diff --git a/test/functional/PageLoadTest.php b/test/functional/PageLoadTest.php index 71d531dd..646620b4 100644 --- a/test/functional/PageLoadTest.php +++ b/test/functional/PageLoadTest.php @@ -27,7 +27,7 @@ public static function provider() #[DataProvider("provider")] public function testLoadPage($user, $path) { - global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; + global $USER, $SSO, $LDAP, $SQL, $MAILER, $WEBHOOK; switchuser(...$user); http_get($path); $this->assertTrue(true); // assert there were no errors diff --git a/test/functional/PiMemberApproveTest.php b/test/functional/PiMemberApproveTest.php index b1db2fe5..4dfd6d4e 100644 --- a/test/functional/PiMemberApproveTest.php +++ b/test/functional/PiMemberApproveTest.php @@ -81,7 +81,7 @@ public function testApproveNonexistentRequest() } public function testApproveMemberByPI() { - global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; + global $USER, $SSO, $LDAP, $SQL, $MAILER, $WEBHOOK; $user_to_approve_args = getUnqualifiedUser(); $pi_user_args = getUserIsPIHasNoMembersNoMemberRequests(); switchUser(...$pi_user_args); @@ -142,7 +142,7 @@ public function testApproveMemberByPI() public function testApproveMemberByAdmin() { - global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; + global $USER, $SSO, $LDAP, $SQL, $MAILER, $WEBHOOK; $user_to_approve_args = getUnqualifiedUser(); switchUser(...getUserIsPIHasNoMembersNoMemberRequests()); $pi_group = $USER->getPIGroup(); diff --git a/test/functional/PiMemberDenyTest.php b/test/functional/PiMemberDenyTest.php index aa3092c5..be8f5c81 100644 --- a/test/functional/PiMemberDenyTest.php +++ b/test/functional/PiMemberDenyTest.php @@ -27,14 +27,14 @@ private function denyUser(string $uid) public function testDenyRequest() { - global $USER, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; + global $USER, $LDAP, $SQL, $MAILER, $WEBHOOK; switchUser(...getUserIsPIHasNoMembersNoMemberRequests()); $pi = $USER; $piGroup = $USER->getPIGroup(); $this->assertTrue($piGroup->exists()); $this->assertEqualsCanonicalizing([$pi->uid], $piGroup->getGroupMemberUIDs()); $this->assertEmpty($piGroup->getRequests()); - $requestedUser = new UnityUser(self::$requestUid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $requestedUser = new UnityUser(self::$requestUid, $LDAP, $SQL, $MAILER, $WEBHOOK); try { $piGroup->newUserRequest($requestedUser); $this->assertFalse($piGroup->memberExists($requestedUser)); diff --git a/test/functional/PiRemoveUserTest.php b/test/functional/PiRemoveUserTest.php index 954e01b8..254600cd 100644 --- a/test/functional/PiRemoveUserTest.php +++ b/test/functional/PiRemoveUserTest.php @@ -16,7 +16,7 @@ private function removeUser(string $uid) public function testRemoveUser() { - global $USER, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; + global $USER, $LDAP, $SQL, $MAILER, $WEBHOOK; switchUser(...getUserIsPIHasAtLeastOneMember()); $pi = $USER; $piUid = $USER->uid; @@ -30,7 +30,7 @@ public function testRemoveUser() $memberToDelete = null; foreach ($memberUIDs as $uid) { if ($uid != $piUid) { - $memberToDelete = new UnityUser($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $memberToDelete = new UnityUser($uid, $LDAP, $SQL, $MAILER, $WEBHOOK); if ($memberToDelete->hasRequestedAccountDeletion()) { continue; } @@ -52,7 +52,7 @@ public function testRemoveUser() public function testRemovePIFromTheirOwnGroup() { - global $USER, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; + global $USER, $LDAP, $SQL, $MAILER, $WEBHOOK; switchUser(...getUserIsPIHasAtLeastOneMember()); $pi = $USER; $piGroup = $USER->getPIGroup(); diff --git a/test/functional/RegisterUserTest.php b/test/functional/RegisterUserTest.php index a51c7309..a98230c8 100644 --- a/test/functional/RegisterUserTest.php +++ b/test/functional/RegisterUserTest.php @@ -22,7 +22,7 @@ private function register() #[DataProvider("provider")] public function testRegisterUserAndCreateOrg($user_to_register_args, $expected_uid_gid) { - global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; + global $USER, $SSO, $LDAP, $SQL, $MAILER, $WEBHOOK; switchuser(...$user_to_register_args); $user_entry = $LDAP->getUserEntry($USER->uid); $user_group_entry = $LDAP->getGroupEntry($USER->uid); diff --git a/test/phpunit-bootstrap.php b/test/phpunit-bootstrap.php index 05d1a2cc..0643a7e8 100644 --- a/test/phpunit-bootstrap.php +++ b/test/phpunit-bootstrap.php @@ -13,7 +13,6 @@ require_once __DIR__ . "/../resources/lib/UnityHTTPD.php"; require_once __DIR__ . "/../resources/lib/UnityConfig.php"; require_once __DIR__ . "/../resources/lib/UnityWebhook.php"; -require_once __DIR__ . "/../resources/lib/UnityRedis.php"; require_once __DIR__ . "/../resources/lib/UnityGithub.php"; require_once __DIR__ . "/../resources/lib/utils.php"; require_once __DIR__ . "/../resources/lib/exceptions/NoDieException.php"; @@ -64,8 +63,7 @@ function switchUser( string $mail, ?string $session_id = null, ): void { - global $REDIS, - $LDAP, + global $LDAP, $SQL, $MAILER, $WEBHOOK, @@ -96,8 +94,7 @@ function switchUser( function http_post(string $phpfile, array $post_data): void { - global $REDIS, - $LDAP, + global $LDAP, $SQL, $MAILER, $WEBHOOK, @@ -131,8 +128,7 @@ function http_post(string $phpfile, array $post_data): void function http_get(string $phpfile, array $get_data = []): void { - global $REDIS, - $LDAP, + global $LDAP, $SQL, $MAILER, $WEBHOOK, @@ -167,7 +163,7 @@ function http_get(string $phpfile, array $get_data = []): void // does not remove user from PI groups function ensureUserDoesNotExist() { - global $USER, $SQL, $LDAP, $REDIS; + global $USER, $SQL, $LDAP; $SQL->deleteRequestsByUser($USER->uid); if ($USER->exists()) { $org = $USER->getOrgGroup(); @@ -194,47 +190,35 @@ function ensureUserDoesNotExist() $qualified_users_group->write(); ensure(!in_array($USER->uid, $qualified_users_group->getAttribute("memberuid"))); } - $default_value_getter = [$LDAP, "getSortedQualifiedUsersForRedis"]; - $REDIS->removeCacheArray("sorted_qualified_users", "", $USER->uid, $default_value_getter); } function ensureOrgGroupDoesNotExist() { - global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; + global $USER, $SSO, $LDAP, $SQL, $MAILER, $WEBHOOK; $org_group = $LDAP->getOrgGroupEntry($SSO["org"]); if ($org_group->exists()) { $org_group->delete(); ensure(!$org_group->exists()); } - $default_value_getter = [$LDAP, "getSortedOrgsForRedis"]; - $REDIS->removeCacheArray("sorted_orgs", "", $SSO["org"], $default_value_getter); } function ensureUserNotInPIGroup(UnityGroup $pi_group) { - global $USER, $REDIS; + global $USER; if ($pi_group->memberExists($USER)) { $pi_group->removeUser($USER); ensure(!$pi_group->memberExists($USER)); } - $REDIS->removeCacheArray( - $pi_group->gid, - "members", - $USER->uid, - fn() => $pi_group->getGroupMemberUIDs(true), - ); } function ensurePIGroupDoesNotExist() { - global $USER, $LDAP, $REDIS; + global $USER, $LDAP; $gid = $USER->getPIGroup()->gid; if ($USER->getPIGroup()->exists()) { $LDAP->getPIGroupEntry($gid)->delete(); ensure(!$USER->getPIGroup()->exists()); } - $default_value_getter = [$LDAP, "getSortedGroupsForRedis"]; - $REDIS->removeCacheArray("sorted_groups", "", $gid, $default_value_getter); } function getNormalUser() diff --git a/tools/docker-dev/docker-compose.yml b/tools/docker-dev/docker-compose.yml index 3a712dc6..94f5a446 100644 --- a/tools/docker-dev/docker-compose.yml +++ b/tools/docker-dev/docker-compose.yml @@ -33,18 +33,6 @@ services: image: schickling/mailcatcher ports: - "8030:1080" - redis: - hostname: redis - build: redis - ports: - - "6379:6379" - healthcheck: - test: - [ - "CMD-SHELL", - "if [ -f /tmp/up ]; then (nc -z localhost 6379 && touch /tmp/up); else true; fi", - ] - interval: 1s web: hostname: web build: web @@ -59,5 +47,3 @@ services: condition: service_healthy smtp: condition: service_started - redis: - condition: service_healthy diff --git a/tools/docker-dev/redis/Dockerfile b/tools/docker-dev/redis/Dockerfile deleted file mode 100644 index a45f7196..00000000 --- a/tools/docker-dev/redis/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM redis - -ARG DEBIAN_FRONTEND=noninteractive -RUN apt-get update && apt-get install -y netcat-openbsd diff --git a/tools/docker-dev/web/Dockerfile b/tools/docker-dev/web/Dockerfile index 22e1d472..24000697 100644 --- a/tools/docker-dev/web/Dockerfile +++ b/tools/docker-dev/web/Dockerfile @@ -11,7 +11,6 @@ RUN apt-get update && apt-get install -y \ php-mysql \ php-ldap \ php-pdo \ - php-redis \ php-cli \ php-mbstring \ php-xml \ diff --git a/webroot/admin/ajax/get_group_members.php b/webroot/admin/ajax/get_group_members.php index d2434e55..53d822ae 100644 --- a/webroot/admin/ajax/get_group_members.php +++ b/webroot/admin/ajax/get_group_members.php @@ -13,7 +13,7 @@ UnityHTTPD::badRequest("PI UID not set"); } -$group = new UnityGroup($_GET["gid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); +$group = new UnityGroup($_GET["gid"], $LDAP, $SQL, $MAILER, $WEBHOOK); $members = $group->getGroupMembersAttributes(["gecos", "mail"]); $requests = $group->getRequests(); diff --git a/webroot/admin/pi-mgmt.php b/webroot/admin/pi-mgmt.php index 5a2ae67d..3fdd28fc 100644 --- a/webroot/admin/pi-mgmt.php +++ b/webroot/admin/pi-mgmt.php @@ -12,7 +12,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { if (isset($_POST["uid"])) { - $form_user = new UnityUser($_POST["uid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $form_user = new UnityUser($_POST["uid"], $LDAP, $SQL, $MAILER, $WEBHOOK); } switch ($_POST["form_type"]) { @@ -27,7 +27,7 @@ break; case "reqChild": - $parent_group = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $parent_group = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $WEBHOOK); if ($_POST["action"] == "Approve") { $parent_group->approveUser($form_user); } elseif ($_POST["action"] == "Deny") { @@ -36,7 +36,7 @@ break; case "remUserChild": - $parent = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $parent = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $WEBHOOK); $parent->removeUser($form_user); break; @@ -66,7 +66,7 @@ foreach ($requests as $request) { $uid = $request["uid"]; - $request_user = new UnityUser($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $request_user = new UnityUser($uid, $LDAP, $SQL, $MAILER, $WEBHOOK); $name = $request_user->getFullname(); $email = $request_user->getMail(); echo ""; diff --git a/webroot/panel/ajax/get_group_members.php b/webroot/panel/ajax/get_group_members.php index 920b0ab2..91d8e560 100644 --- a/webroot/panel/ajax/get_group_members.php +++ b/webroot/panel/ajax/get_group_members.php @@ -9,7 +9,7 @@ UnityHTTPD::badRequest("PI UID not set"); } -$group = new UnityGroup($_GET["gid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); +$group = new UnityGroup($_GET["gid"], $LDAP, $SQL, $MAILER, $WEBHOOK); if (!$group->memberExists($USER)) { UnityHTTPD::forbidden("not a group member"); } diff --git a/webroot/panel/groups.php b/webroot/panel/groups.php index cabefae3..ec0f60ef 100644 --- a/webroot/panel/groups.php +++ b/webroot/panel/groups.php @@ -18,7 +18,7 @@ } catch (EntryNotFoundException) { } } - $pi_account = new UnityGroup($pi_groupname, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $pi_account = new UnityGroup($pi_groupname, $LDAP, $SQL, $MAILER, $WEBHOOK); if (!$pi_account->exists()) { array_push($modalErrors, "This PI doesn't exist"); } @@ -86,7 +86,6 @@ $LDAP, $SQL, $MAILER, - $REDIS, $WEBHOOK ); $requested_owner = $requested_account->getOwner(); @@ -133,7 +132,7 @@ echo ""; foreach ($PIGroupGIDs as $gid) { - $group = new UnityGroup($gid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $group = new UnityGroup($gid, $LDAP, $SQL, $MAILER, $WEBHOOK); $owner = $group->getOwner(); $full_name = $owner->getFirstname() . " " . $owner->getLastname(); if ($USER->uid == $owner->uid) { diff --git a/webroot/panel/modal/pi_search.php b/webroot/panel/modal/pi_search.php index be2250f8..6872e5ad 100644 --- a/webroot/panel/modal/pi_search.php +++ b/webroot/panel/modal/pi_search.php @@ -10,7 +10,7 @@ UnityHTTPD::die(); } -$assocs = $LDAP->getAllPIGroups($SQL, $MAILER, $REDIS, $WEBHOOK); +$assocs = $LDAP->getAllPIGroups($SQL, $MAILER, $WEBHOOK); $MAX_COUNT = 10; // Max results of PI search diff --git a/webroot/panel/new_account.php b/webroot/panel/new_account.php index 336db9f1..c1dc05c8 100644 --- a/webroot/panel/new_account.php +++ b/webroot/panel/new_account.php @@ -9,7 +9,7 @@ UnityHTTPD::redirect(CONFIG["site"]["prefix"] . "/panel/account.php"); } if ($_SERVER["REQUEST_METHOD"] == "POST") { - $user = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $user = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $WEBHOOK); $user->init($SSO["firstname"], $SSO["lastname"], $SSO["mail"], $SSO["org"]); // header.php will redirect to this same page again and then this page will redirect to account } diff --git a/webroot/panel/pi.php b/webroot/panel/pi.php index efcc5257..39450798 100644 --- a/webroot/panel/pi.php +++ b/webroot/panel/pi.php @@ -13,7 +13,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { if (isset($_POST["uid"])) { - $form_user = new UnityUser($_POST["uid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $form_user = new UnityUser($_POST["uid"], $LDAP, $SQL, $MAILER, $WEBHOOK); } switch ($_POST["form_type"]) { diff --git a/workers/group_user_request_owner_reminder.php b/workers/group_user_request_owner_reminder.php index 9464712c..c85adf98 100755 --- a/workers/group_user_request_owner_reminder.php +++ b/workers/group_user_request_owner_reminder.php @@ -11,7 +11,7 @@ use UnityWebPortal\lib\UnityGroup; $today = time(); -$accounts = $LDAP->getAllPIGroups($SQL, $MAILER, $REDIS, $WEBHOOK); +$accounts = $LDAP->getAllPIGroups($SQL, $MAILER, $WEBHOOK); foreach ($accounts as $pi_group) { $pi_user = $pi_group->getOwner(); $requests = $pi_group->getRequests(); diff --git a/workers/remove-users-from-group.php b/workers/remove-users-from-group.php index 01fe8c99..20fbb52e 100755 --- a/workers/remove-users-from-group.php +++ b/workers/remove-users-from-group.php @@ -19,14 +19,14 @@ function _die($msg) $gid = $argv[1]; $filename = $argv[2]; -$group = new UnityGroup($gid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); +$group = new UnityGroup($gid, $LDAP, $SQL, $MAILER, $WEBHOOK); if (!$group->exists()) { _die("No such group '$gid'\n"); } ($handle = fopen($filename, "r")) or _die("Can't open '$filename'\n"); while (($line = fgets($handle)) !== false) { $uid = trim($line); - $user = new UnityUser($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); + $user = new UnityUser($uid, $LDAP, $SQL, $MAILER, $WEBHOOK); if (!$group->memberExists($user)) { print "Skipping '$uid' who doesn't appear to be in '$gid'\n"; continue; diff --git a/workers/update-ldap-cache.php b/workers/update-ldap-cache.php deleted file mode 100755 index d4e5c396..00000000 --- a/workers/update-ldap-cache.php +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env php -flushAll(); -} - -if (!is_null($REDIS->getCache("initialized", "")) and !array_key_exists("u", $options)) { - echo "cache is already initialized, nothing doing."; - echo " use -f argument to flush cache, or -u argument to update without flush.\n"; -} else { - echo "updating cache...\n"; - - // search entire tree, some users created for admin purposes might not be in the normal OU - echo "waiting for LDAP search (users)...\n"; - $users = $LDAP->search("objectClass=posixAccount", CONFIG["ldap"]["basedn"], []); - echo "response received.\n"; - $sorted_qualified_users_UIDs = $LDAP->getSortedQualifiedUsersForRedis(); - $REDIS->setCache("sorted_qualified_users", "", $sorted_qualified_users_UIDs); - foreach ($users as $user) { - $uid = $user->getAttribute("cn")[0]; - if (!in_array($uid, $sorted_qualified_users_UIDs)) { - continue; - } - $REDIS->setCache($uid, "firstname", $user->getAttribute("givenname")[0]); - $REDIS->setCache($uid, "lastname", $user->getAttribute("sn")[0]); - $REDIS->setCache($uid, "org", $user->getAttribute("o")[0]); - $REDIS->setCache($uid, "mail", $user->getAttribute("mail")[0]); - $REDIS->setCache($uid, "sshkeys", $user->getAttribute("sshpublickey")); - $REDIS->setCache($uid, "loginshell", $user->getAttribute("loginshell")[0]); - $REDIS->setCache($uid, "homedir", $user->getAttribute("homedirectory")[0]); - } - - $org_group_ou = new LDAPEntry($LDAP->getConn(), CONFIG["ldap"]["orggroup_ou"]); - echo "waiting for LDAP search (org groups)...\n"; - $org_groups = $org_group_ou->getChildrenArrayStrict( - ["cn", "memberuid"], - true, - default_values: ["memberuid" => []], - ); - echo "response received.\n"; - $REDIS->setCache("sorted_orgs", "", $LDAP->getSortedOrgsForRedis()); - foreach ($org_groups as $org_group) { - $gid = $org_group["cn"][0]; - $REDIS->setCache($gid, "members", $org_group["memberuid"] ?? []); - } - - $pi_group_ou = new LDAPEntry($LDAP->getConn(), CONFIG["ldap"]["pigroup_ou"]); - echo "waiting for LDAP search (pi groups)...\n"; - $pi_groups = $pi_group_ou->getChildrenArrayStrict( - ["cn", "memberuid"], - true, - default_values: ["memberuid" => []], - ); - echo "response received.\n"; - $REDIS->setCache("sorted_groups", "", $LDAP->getSortedGroupsForRedis()); - - $user_pi_group_member_of = []; - foreach ($sorted_qualified_users_UIDs as $uid) { - $user_pi_group_member_of[$uid] = []; - } - foreach ($pi_groups as $pi_group) { - $gid = $pi_group["cn"][0]; - $members = $pi_group["memberuid"] ?? []; - foreach ($members as $uid) { - if (in_array($uid, $sorted_qualified_users_UIDs)) { - array_push($user_pi_group_member_of[$uid], $gid); - } else { - echo "warning: group '$gid' has member '$uid' who is not qualfied!\n"; - } - } - $REDIS->setCache($gid, "members", $pi_group["memberuid"] ?? []); - } - foreach ($user_pi_group_member_of as $uid => $pi_groups) { - // FIXME should be pi_groups - $REDIS->setCache($uid, "groups", $pi_groups); - } - $REDIS->setCache("initializing", "", false); - $REDIS->setCache("initialized", "", true); - echo "done!\n"; -} - From 3198d228fd8486916955f11ae4dd62085d05be50 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Wed, 26 Nov 2025 17:17:48 -0500 Subject: [PATCH 2/6] remove more redis --- resources/lib/UnityLDAP.php | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/resources/lib/UnityLDAP.php b/resources/lib/UnityLDAP.php index be45aca0..98ab900f 100644 --- a/resources/lib/UnityLDAP.php +++ b/resources/lib/UnityLDAP.php @@ -208,14 +208,7 @@ public function getQualifiedUsers( foreach ($qualifiedUsers as $user) { array_push( $out, - new UnityUser( - $user, - $this, - $UnitySQL, - $UnityMailer, - $UnityRedis, - $UnityWebhook, - ), + new UnityUser($user, $this, $UnitySQL, $UnityMailer, $UnityWebhook), ); } return $out; @@ -253,7 +246,6 @@ public function getQualifiedUsersAttributes( public function getAllPIGroups( UnitySQL $UnitySQL, UnityMailer $UnityMailer, - UnityRedis $UnityRedis, UnityWebhook $UnityWebhook, bool $ignorecache = false, ) { @@ -281,7 +273,6 @@ public function getAllPIGroups( $this, $UnitySQL, $UnityMailer, - $UnityRedis, $UnityWebhook, ), ); @@ -375,7 +366,6 @@ public function getQualifiedUID2PIGIDs(): array public function getAllOrgGroups( $UnitySQL, $UnityMailer, - $UnityRedis, $UnityWebhook, $ignorecache = false, ): array { @@ -387,14 +377,7 @@ public function getAllOrgGroups( foreach ($orgs as $org) { array_push( $out, - new UnityOrg( - $org, - $this, - $UnitySQL, - $UnityMailer, - $UnityRedis, - $UnityWebhook, - ), + new UnityOrg($org, $this, $UnitySQL, $UnityMailer, $UnityWebhook), ); } return $out; @@ -411,7 +394,6 @@ public function getAllOrgGroups( $this, $UnitySQL, $UnityMailer, - $UnityRedis, $UnityWebhook, ), ); From 67cedd51c0f0fa85d88e8a3732416767da6eb5cb Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Wed, 26 Nov 2025 17:27:39 -0500 Subject: [PATCH 3/6] remove redis from getters (copilot) --- resources/lib/UnityGroup.php | 23 ++----- resources/lib/UnityLDAP.php | 57 ++-------------- resources/lib/UnityOrg.php | 27 ++------ resources/lib/UnityUser.php | 123 +++++------------------------------ 4 files changed, 32 insertions(+), 198 deletions(-) diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index 290720cb..bc057410 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -308,9 +308,9 @@ public function getRequests(): array return $out; } - public function getGroupMembers(bool $ignorecache = false): array + public function getGroupMembers(): array { - $members = $this->getGroupMemberUIDs($ignorecache); + $members = $this->getGroupMemberUIDs(); $out = []; foreach ($members as $member) { $user_obj = new UnityUser( @@ -325,23 +325,10 @@ public function getGroupMembers(bool $ignorecache = false): array return $out; } - public function getGroupMemberUIDs(bool $ignorecache = false): array + public function getGroupMemberUIDs(): array { - if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->gid, "members"); - if (!is_null($cached_val)) { - $members = $cached_val; - } - } - $updatecache = false; - if (!isset($members)) { - $members = $this->entry->getAttribute("memberuid"); - $updatecache = true; - } - if (!$ignorecache && $updatecache) { - sort($members); - $this->REDIS->setCache($this->gid, "members", $members); - } + $members = $this->entry->getAttribute("memberuid"); + sort($members); return $members; } diff --git a/resources/lib/UnityLDAP.php b/resources/lib/UnityLDAP.php index 98ab900f..292be4a1 100644 --- a/resources/lib/UnityLDAP.php +++ b/resources/lib/UnityLDAP.php @@ -194,31 +194,14 @@ public function getQualifiedUsersUIDs(): array return $this->qualifiedUserGroup->getAttribute("memberuid"); } - public function getQualifiedUsers( - $UnitySQL, - $UnityMailer, - $UnityWebhook, - $ignorecache = false, - ): array { + public function getQualifiedUsers($UnitySQL, $UnityMailer, $UnityWebhook): array + { $out = []; - if (!$ignorecache) { - $qualifiedUsers = $UnityRedis->getCache("sorted_qualified_users", ""); - if (!is_null($qualifiedUsers)) { - foreach ($qualifiedUsers as $user) { - array_push( - $out, - new UnityUser($user, $this, $UnitySQL, $UnityMailer, $UnityWebhook), - ); - } - return $out; - } - } - $qualifiedUsers = $this->getQualifiedUsersUIDs(); sort($qualifiedUsers); foreach ($qualifiedUsers as $user) { - $params = [$user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook]; + $params = [$user, $this, $UnitySQL, $UnityMailer, $UnityWebhook]; array_push($out, new UnityUser(...$params)); } return $out; @@ -247,22 +230,9 @@ public function getAllPIGroups( UnitySQL $UnitySQL, UnityMailer $UnityMailer, UnityWebhook $UnityWebhook, - bool $ignorecache = false, ) { $out = []; - if (!$ignorecache) { - $groups = $UnityRedis->getCache("sorted_groups", ""); - if (!is_null($groups)) { - foreach ($groups as $group) { - $params = [$group, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook]; - array_push($out, new UnityGroup(...$params)); - } - - return $out; - } - } - $pi_groups = $this->pi_groupOU->getChildren(true); foreach ($pi_groups as $pi_group) { @@ -363,27 +333,10 @@ public function getQualifiedUID2PIGIDs(): array return $uid2pigids; } - public function getAllOrgGroups( - $UnitySQL, - $UnityMailer, - $UnityWebhook, - $ignorecache = false, - ): array { + public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityWebhook): array + { $out = []; - if (!$ignorecache) { - $orgs = $UnityRedis->getCache("sorted_orgs", ""); - if (!is_null($orgs)) { - foreach ($orgs as $org) { - array_push( - $out, - new UnityOrg($org, $this, $UnitySQL, $UnityMailer, $UnityWebhook), - ); - } - return $out; - } - } - $org_groups = $this->org_groupOU->getChildren(true); foreach ($org_groups as $org_group) { diff --git a/resources/lib/UnityOrg.php b/resources/lib/UnityOrg.php index fe15f89f..07d12ec1 100644 --- a/resources/lib/UnityOrg.php +++ b/resources/lib/UnityOrg.php @@ -43,14 +43,14 @@ public function exists(): bool return $this->entry->exists(); } - public function inOrg(UnityUser $user, bool $ignorecache = false): bool + public function inOrg(UnityUser $user): bool { - return in_array($user->uid, $this->getOrgMemberUIDs($ignorecache)); + return in_array($user->uid, $this->getOrgMemberUIDs()); } - public function getOrgMembers(bool $ignorecache = false): array + public function getOrgMembers(): array { - $members = $this->getOrgMemberUIDs($ignorecache); + $members = $this->getOrgMemberUIDs(); $out = []; foreach ($members as $member) { $user_obj = new UnityUser( @@ -65,23 +65,10 @@ public function getOrgMembers(bool $ignorecache = false): array return $out; } - public function getOrgMemberUIDs(bool $ignorecache = false): array + public function getOrgMemberUIDs(): array { - if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->gid, "members"); - if (!is_null($cached_val)) { - $members = $cached_val; - } - } - $updatecache = false; - if (!isset($members)) { - $members = $this->entry->getAttribute("memberuid"); - $updatecache = true; - } - if (!$ignorecache && $updatecache) { - sort($members); - $this->REDIS->setCache($this->gid, "members", $members); - } + $members = $this->entry->getAttribute("memberuid"); + sort($members); return $members; } diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index f072ae43..1024c264 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -150,19 +150,9 @@ public function setOrg(UnityOrg $org): void $this->entry->write(); } - public function getOrg(bool $ignorecache = false): string + public function getOrg(): string { $this->entry->ensureExists(); - if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->uid, "org"); - if (!is_null($cached_val)) { - return $cached_val; - } - } - $org = $this->entry->getAttribute("o")[0]; - if (!$ignorecache) { - $this->REDIS->setCache($this->uid, "org", $org); - } return $this->entry->getAttribute("o")[0]; } @@ -177,26 +167,15 @@ public function setFirstname(string $firstname, ?UnityUser $operator = null): vo $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "firstname_changed", $this->uid); $this->entry->write(); - $this->REDIS->setCache($this->uid, "firstname", $firstname); } /** * Gets the firstname of the account */ - public function getFirstname(bool $ignorecache = false): string + public function getFirstname(): string { $this->entry->ensureExists(); - if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->uid, "firstname"); - if (!is_null($cached_val)) { - return $cached_val; - } - } - $firstname = $this->entry->getAttribute("givenname")[0]; - if (!$ignorecache) { - $this->REDIS->setCache($this->uid, "firstname", $firstname); - } - return $firstname; + return $this->entry->getAttribute("givenname")[0]; } /** @@ -210,26 +189,15 @@ public function setLastname(string $lastname, $operator = null): void $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "lastname_changed", $this->uid); $this->entry->write(); - $this->REDIS->setCache($this->uid, "lastname", $lastname); } /** * Get method for the lastname on the account */ - public function getLastname(bool $ignorecache = false): string + public function getLastname(): string { $this->entry->ensureExists(); - if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->uid, "lastname"); - if (!is_null($cached_val)) { - return $cached_val; - } - } - $lastname = $this->entry->getAttribute("sn")[0]; - if (!$ignorecache) { - $this->REDIS->setCache($this->uid, "lastname", $lastname); - } - return $lastname; + return $this->entry->getAttribute("sn")[0]; } public function getFullname(): string @@ -249,26 +217,15 @@ public function setMail(string $email, ?UnityUser $operator = null): void $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "email_changed", $this->uid); $this->entry->write(); - $this->REDIS->setCache($this->uid, "mail", $email); } /** * Method to get the mail instance var */ - public function getMail(bool $ignorecache = false): string + public function getMail(): string { $this->entry->ensureExists(); - if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->uid, "mail"); - if (!is_null($cached_val)) { - return $cached_val; - } - } - $mail = $this->entry->getAttribute("mail")[0]; - if (!$ignorecache) { - $this->REDIS->setCache($this->uid, "mail", $mail); - } - return $mail; + return $this->entry->getAttribute("mail")[0]; } /** @@ -282,8 +239,6 @@ public function setSSHKeys($keys, $operator = null, bool $send_mail = true): voi $this->entry->setAttribute("sshpublickey", $keys_filt); $this->entry->write(); - $this->REDIS->setCache($this->uid, "sshkeys", $keys_filt); - $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "sshkey_modify", $this->uid); if ($send_mail) { @@ -296,25 +251,11 @@ public function setSSHKeys($keys, $operator = null, bool $send_mail = true): voi /** * Returns the SSH keys attached to the account */ - public function getSSHKeys(bool $ignorecache = false): array + public function getSSHKeys(): array { $this->entry->ensureExists(); - if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->uid, "sshkeys"); - if (!is_null($cached_val)) { - return $cached_val; - } - } $result = $this->entry->getAttribute("sshpublickey"); - if (is_null($result)) { - $keys = []; - } else { - $keys = $result; - } - if (!$ignorecache) { - $this->REDIS->setCache($this->uid, "sshkeys", $keys); - } - return $keys; + return $result; } /** @@ -343,8 +284,6 @@ public function setLoginShell( $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "loginshell_changed", $this->uid); - $this->REDIS->setCache($this->uid, "loginshell", $shell); - if ($send_mail) { $this->MAILER->sendMail($this->getMail(), "user_loginshell", [ "new_shell" => $this->getLoginShell(), @@ -355,20 +294,10 @@ public function setLoginShell( /** * Gets the login shell of the account */ - public function getLoginShell(bool $ignorecache = false): string + public function getLoginShell(): string { $this->entry->ensureExists(); - if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->uid, "loginshell"); - if (!is_null($cached_val)) { - return $cached_val; - } - } - $loginshell = $this->entry->getAttribute("loginshell")[0]; - if (!$ignorecache) { - $this->REDIS->setCache($this->uid, "loginshell", $loginshell); - } - return $loginshell; + return $this->entry->getAttribute("loginshell")[0]; } public function setHomeDir(string $home, ?UnityUser $operator = null): void @@ -379,27 +308,15 @@ public function setHomeDir(string $home, ?UnityUser $operator = null): void $operator = is_null($operator) ? $this->uid : $operator->uid; $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "homedir_changed", $this->uid); - - $this->REDIS->setCache($this->uid, "homedir", $home); } /** * Gets the home directory of the user */ - public function getHomeDir(bool $ignorecache = false): string + public function getHomeDir(): string { $this->entry->ensureExists(); - if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->uid, "homedir"); - if (!is_null($cached_val)) { - return $cached_val; - } - } - $homedir = $this->entry->getAttribute("homedirectory"); - if (!$ignorecache) { - $this->REDIS->setCache($this->uid, "homedir", $homedir); - } - return $homedir; + return $this->entry->getAttribute("homedirectory"); } /** @@ -444,19 +361,9 @@ public function getOrgGroup(): UnityOrg /** * Gets the groups this user is assigned to, can be more than one */ - public function getPIGroupGIDs(bool $ignorecache = false): array + public function getPIGroupGIDs(): array { - if (!$ignorecache) { - $cached_val = $this->REDIS->getCache($this->uid, "groups"); - if (!is_null($cached_val)) { - return $cached_val; - } - } - $gids = $this->LDAP->getPIGroupGIDsWithMemberUID($this->uid); - if (!$ignorecache) { - $this->REDIS->setCache($this->uid, "groups", $gids); - } - return $gids; + return $this->LDAP->getPIGroupGIDsWithMemberUID($this->uid); } /** From 0a8f5dab6daf482b9eb226f271aca55a140c4ace Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Wed, 26 Nov 2025 17:29:38 -0500 Subject: [PATCH 4/6] dont run redis worker in container --- tools/docker-dev/web/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker-dev/web/Dockerfile b/tools/docker-dev/web/Dockerfile index 24000697..dae5c650 100644 --- a/tools/docker-dev/web/Dockerfile +++ b/tools/docker-dev/web/Dockerfile @@ -34,4 +34,4 @@ RUN echo 'xdebug.mode=coverage' >> /etc/php/8.3/cli/php.ini # Start apache2 server EXPOSE 80 -CMD ["bash", "-c", "pushd /var/www/unity-web-portal/workers >/dev/null && echo 'updating LDAP cache...' && php ./update-ldap-cache.php && popd >/dev/null && apache2ctl -D FOREGROUND"] +CMD ["bash", "-c", "cd /var/www/unity-web-portal/workers && apache2ctl -D FOREGROUND"] From 229e6bab806bc13edfa80a40d88b88cb5d3a6524 Mon Sep 17 00:00:00 2001 From: simonLeary42 <71396965+simonLeary42@users.noreply.github.com> Date: Wed, 26 Nov 2025 18:34:25 -0500 Subject: [PATCH 5/6] Update tools/docker-dev/web/Dockerfile Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- tools/docker-dev/web/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker-dev/web/Dockerfile b/tools/docker-dev/web/Dockerfile index dae5c650..2aebf47f 100644 --- a/tools/docker-dev/web/Dockerfile +++ b/tools/docker-dev/web/Dockerfile @@ -34,4 +34,4 @@ RUN echo 'xdebug.mode=coverage' >> /etc/php/8.3/cli/php.ini # Start apache2 server EXPOSE 80 -CMD ["bash", "-c", "cd /var/www/unity-web-portal/workers && apache2ctl -D FOREGROUND"] +CMD ["apache2ctl", "-D", "FOREGROUND"] From a9159f161d4cd21ec49b9fd62364e2df6e085e13 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Wed, 26 Nov 2025 18:34:37 -0500 Subject: [PATCH 6/6] remove $ignorecache argument --- test/functional/SSHKeyAddTest.php | 6 +++--- test/functional/SSHKeyDeleteTest.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/functional/SSHKeyAddTest.php b/test/functional/SSHKeyAddTest.php index 1a8ea3a5..5060b67a 100644 --- a/test/functional/SSHKeyAddTest.php +++ b/test/functional/SSHKeyAddTest.php @@ -92,7 +92,7 @@ public static function provider() public function getKeyCount() { global $USER; - return count($USER->getSSHKeys(true)); + return count($USER->getSSHKeys()); } #[DataProvider("provider")] @@ -100,12 +100,12 @@ public function testAddSshKeys(string $methodName, int $expectedKeysAdded, array { global $USER; switchUser(...getUserHasNoSshKeys()); - $numKeysBefore = $this->getKeyCount($USER); + $numKeysBefore = $this->getKeyCount(); $this->assertEquals(0, $numKeysBefore); try { call_user_func([SSHKeyAddTest::class, $methodName], $keys); // $method($keys); - $numKeysAfter = $this->getKeyCount($USER); + $numKeysAfter = $this->getKeyCount(); $this->assertEquals($expectedKeysAdded, $numKeysAfter - $numKeysBefore); } finally { $USER->setSSHKeys([]); diff --git a/test/functional/SSHKeyDeleteTest.php b/test/functional/SSHKeyDeleteTest.php index c4a3aaab..b45f2a37 100644 --- a/test/functional/SSHKeyDeleteTest.php +++ b/test/functional/SSHKeyDeleteTest.php @@ -11,7 +11,7 @@ public static function setUpBeforeClass(): void { global $USER; switchUser(...getUserWithOneKey()); - self::$initialKeys = $USER->getSSHKeys(true); + self::$initialKeys = $USER->getSSHKeys(); } private function deleteKey(string $index): void @@ -36,7 +36,7 @@ public function testDeleteKeyGarbageInput(string $index) global $USER; try { $this->deleteKey($index); - $this->assertEquals(self::$initialKeys, $USER->getSSHKeys(true)); + $this->assertEquals(self::$initialKeys, $USER->getSSHKeys()); } finally { $USER->setSSHKeys(self::$initialKeys); } @@ -47,7 +47,7 @@ public function testDeleteKeyNegativeIndex() global $USER; try { $this->deleteKey("-1"); - $this->assertEquals(self::$initialKeys, $USER->getSSHKeys(true)); + $this->assertEquals(self::$initialKeys, $USER->getSSHKeys()); } finally { $USER->setSSHKeys(self::$initialKeys); } @@ -58,7 +58,7 @@ public function testDeleteKeyIndexTooLarge() global $USER; try { $this->deleteKey("99"); - $this->assertEquals(self::$initialKeys, $USER->getSSHKeys(true)); + $this->assertEquals(self::$initialKeys, $USER->getSSHKeys()); } finally { $USER->setSSHKeys(self::$initialKeys); } @@ -69,7 +69,7 @@ public function testDeleteKeyDecimal() global $USER; try { $this->deleteKey("0.5"); - $this->assertEquals(self::$initialKeys, $USER->getSSHKeys(true)); + $this->assertEquals(self::$initialKeys, $USER->getSSHKeys()); } finally { $USER->setSSHKeys(self::$initialKeys); } @@ -80,7 +80,7 @@ public function testDeleteKey() global $USER; try { $this->deleteKey("0"); - $this->assertEquals([], $USER->getSSHKeys(true)); + $this->assertEquals([], $USER->getSSHKeys()); } finally { $USER->setSSHKeys(self::$initialKeys); }