Skip to content

remove sorted_users sorted_groups sorted_orgs #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,6 @@ public function cancelGroupJoinRequest($user, $send_mail = true)
// $ldapPiGroupEntry = $this->getLDAPPiGroup();
// if ($ldapPiGroupEntry->exists()) {
// $ldapPiGroupEntry->delete();
// $this->REDIS->removeCacheArray("sorted_groups", "", $this->getPIUID());
// foreach ($users as $user) {
// $this->REDIS->removeCacheArray($user->getUID(), "groups", $this->getPIUID());
// }
// }

// // send email to every user of the now deleted PI group
Expand Down Expand Up @@ -532,9 +528,6 @@ private function init()
$ldapPiGroupEntry->setAttribute("memberuid", array($owner->getUID()));
$ldapPiGroupEntry->write();
}

$this->REDIS->appendCacheArray("sorted_groups", "", $this->getPIUID());

// TODO if we ever make this project based, we need to update the cache here with the memberuid
}

Expand Down
42 changes: 0 additions & 42 deletions resources/lib/UnityLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,46 +224,19 @@ public function getUnassignedID($uid, $UnitySQL)
public function getAllUsers($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
{
$out = array();

if (!$ignorecache) {
$users = $UnityRedis->getCache("sorted_users", "");
if (!is_null($users)) {
foreach ($users as $user) {
array_push($out, new UnityUser($user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook));
}

return $out;
}
}

$users = $this->userGroup->getAttribute("memberuid");
sort($users);
foreach ($users as $user) {
$params = array($user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook);
array_push($out, new UnityUser(...$params));
}

return $out;
}

public function getAllPIGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
{
$out = array();

if (!$ignorecache) {
$groups = $UnityRedis->getCache("sorted_groups", "");
if (!is_null($groups)) {
foreach ($groups as $group) {
$params = array($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) {
array_push($out, new UnityGroup(
$pi_group->getAttribute("cn")[0],
Expand All @@ -274,27 +247,13 @@ public function getAllPIGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebho
$UnityWebhook
));
}

return $out;
}

public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
{
$out = array();

if (!$ignorecache) {
$orgs = $UnityRedis->getCache("sorted_orgs", "");
if (!is_null($orgs)) {
foreach ($orgs as $org) {
array_push($out, new UnityOrg($org, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook));
}

return $out;
}
}

$org_groups = $this->org_groupOU->getChildren(true);

foreach ($org_groups as $org_group) {
array_push($out, new UnityOrg(
$org_group->getAttribute("cn")[0],
Expand All @@ -305,7 +264,6 @@ public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebh
$UnityWebhook
));
}

return $out;
}

Expand Down
2 changes: 0 additions & 2 deletions resources/lib/UnityOrg.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function init()
$org_group->setAttribute("gidnumber", strval($nextGID));
$org_group->write();
}

$this->REDIS->appendCacheArray("sorted_orgs", "", $this->getOrgID());
}

public function exists()
Expand Down
3 changes: 0 additions & 3 deletions resources/lib/UnityUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ public function init($send_mail = true)
$this->LDAP->getUserGroup()->appendAttribute("memberuid", $this->getUID());
$this->LDAP->getUserGroup()->write();

// add user to cache
$this->REDIS->appendCacheArray("sorted_users", "", $this->getUID());

//
// add to audit log
//
Expand Down
3 changes: 0 additions & 3 deletions test/functional/NewUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ private function ensureUserDoesNotExist()
$all_users_group->write();
assert(!in_array($USER->getUID(), $all_users_group->getAttribute("memberuid")));
}
$REDIS->removeCacheArray("sorted_users", "", $USER->getUID());
}

private function ensureOrgGroupDoesNotExist()
Expand All @@ -76,7 +75,6 @@ private function ensureOrgGroupDoesNotExist()
$org_group->getLDAPOrgGroup()->delete();
assert(!$org_group->exists());
}
$REDIS->removeCacheArray("sorted_orgs", "", $USER->getOrgGroup()->getOrgID());
}

private function ensureUserNotInPIGroup(UnityGroup $pi_group)
Expand All @@ -95,7 +93,6 @@ private function ensurePIGroupDoesNotExist()
$USER->getPIGroup()->getLDAPPIGroup()->delete();
assert(!$USER->getPIGroup()->exists());
}
$REDIS->removeCacheArray("sorted_groups", "", $USER->getPIGroup()->getPIUID());
}

public function testCreateUserByJoinGoup()
Expand Down
7 changes: 0 additions & 7 deletions workers/update-ldap-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
$users = $LDAP->search("objectClass=posixAccount", $CONFIG["ldap"]["basedn"]);
echo "response received.\n";
$user_CNs = $LDAP->getUserGroup()->getAttribute("memberuid");
sort($user_CNs);
$REDIS->setCache("sorted_users", "", $user_CNs);
foreach ($users as $user) {
$uid = $user->getAttribute("cn")[0];
if (!in_array($uid, $user_CNs)) {
Expand All @@ -61,8 +59,6 @@
// phpcs:disable
$org_group_CNs = array_map(function($x){return $x["cn"][0];}, $org_groups);
// phpcs:enable
sort($org_group_CNs);
$REDIS->setCache("sorted_orgs", "", $org_group_CNs);
foreach ($org_groups as $org_group) {
$gid = $org_group["cn"][0];
$REDIS->setCache($gid, "members", (@$org_group["memberuid"] ?? []));
Expand All @@ -75,9 +71,6 @@
// phpcs:disable
$pi_group_CNs = array_map(function($x){return $x["cn"][0];}, $pi_groups);
// phpcs:enable
sort($pi_group_CNs);
// FIXME should be sorted_pi_groups
$REDIS->setCache("sorted_groups", "", $pi_group_CNs);

$user_pi_group_member_of = [];
foreach ($user_CNs as $uid) {
Expand Down