Skip to content

Commit 546255c

Browse files
remove redis (#368)
Co-authored-by: Copilot <[email protected]>
1 parent ddad19d commit 546255c

31 files changed

+77
-643
lines changed

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ See the Docker Compose environment (`tools/docker-dev/`) for an (unsafe for prod
5050
- Composer (`apt install composer` on Ubuntu)
5151
- Dependencies:
5252
- PHP extensions
53-
- curl, intl, ldap, mbstring, mysql, pdo, redis, xml (`apt install php-<extension>` on Ubuntu)
53+
- curl, intl, ldap, mbstring, mysql, pdo, xml (`apt install php-<extension>` on Ubuntu)
5454
- Libraries
5555
- `COMPOSER_ALLOW_SUPERUSER=1 composer --no-dev --no-scripts --no-plugins install`
5656
- `httpd` `DocumentRoot` set to `webroot/`
@@ -139,14 +139,7 @@ Now, LDAP entries are created immediately for every user, so this is no longer n
139139
$_SERVER["REMOTE_ADDR"] = "127.0.0.1";
140140
require_once __DIR__ . "/../resources/autoload.php";
141141
foreach ($SQL->getAllRequests() as $request) {
142-
$user = new UnityUser(
143-
$request["uid"],
144-
$LDAP,
145-
$SQL,
146-
$MAILER,
147-
$REDIS,
148-
$WEBHOOK,
149-
);
142+
$user = new UnityUser($request["uid"], $LDAP, $SQL, $MAILER, $WEBHOOK);
150143
if (!$user->exists()) {
151144
echo "creating user: " . jsonEncode($request) . "\n";
152145
$user->init(

defaults/config.ini.default

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ user = "" ; smtp username, if exists
4949
pass = "" ; smtp password, if exists
5050
ssl_verify = "false" ; set to true to verify ssl certificates
5151

52-
[redis]
53-
host = "redis"
54-
port = "6379"
55-
5652
[colors]
5753
light_background = "#ffffff" ; Background color when in light mode
5854
light_foreground = "#1a1a1a" ; Text color when in light mode

resources/autoload.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
require_once __DIR__ . "/lib/UnityHTTPD.php";
2323
require_once __DIR__ . "/lib/UnityConfig.php";
2424
require_once __DIR__ . "/lib/UnityWebhook.php";
25-
require_once __DIR__ . "/lib/UnityRedis.php";
2625
require_once __DIR__ . "/lib/UnityGithub.php";
2726
require_once __DIR__ . "/lib/utils.php";
2827
require_once __DIR__ . "/lib/exceptions/NoDieException.php";

resources/init.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use UnityWebPortal\lib\UnitySQL;
1010
use UnityWebPortal\lib\UnitySSO;
1111
use UnityWebPortal\lib\UnityUser;
12-
use UnityWebPortal\lib\UnityRedis;
1312
use UnityWebPortal\lib\UnityWebhook;
1413
use UnityWebPortal\lib\UnityGithub;
1514
use UnityWebPortal\lib\UnityHTTPD;
@@ -20,7 +19,6 @@
2019

2120
session_start();
2221

23-
$REDIS = new UnityRedis();
2422
if (isset($GLOBALS["ldapconn"])) {
2523
$LDAP = $GLOBALS["ldapconn"];
2624
} else {
@@ -37,11 +35,11 @@
3735
$SSO = UnitySSO::getSSO();
3836
$_SESSION["SSO"] = $SSO;
3937

40-
$OPERATOR = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
38+
$OPERATOR = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $WEBHOOK);
4139
$_SESSION["is_admin"] = $OPERATOR->isAdmin();
4240

4341
if (isset($_SESSION["viewUser"]) && $_SESSION["is_admin"]) {
44-
$USER = new UnityUser($_SESSION["viewUser"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
42+
$USER = new UnityUser($_SESSION["viewUser"], $LDAP, $SQL, $MAILER, $WEBHOOK);
4543
} else {
4644
$USER = $OPERATOR;
4745
}
@@ -51,14 +49,6 @@
5149
$SEND_PIMESG_TO_ADMINS = CONFIG["mail"]["send_pimesg_to_admins"];
5250

5351
$SQL->addLog($OPERATOR->uid, $_SERVER["REMOTE_ADDR"], "user_login", $OPERATOR->uid);
54-
55-
if (!$_SESSION["user_exists"]) {
56-
// populate cache
57-
$REDIS->setCache($SSO["user"], "org", $SSO["org"]);
58-
$REDIS->setCache($SSO["user"], "firstname", $SSO["firstname"]);
59-
$REDIS->setCache($SSO["user"], "lastname", $SSO["lastname"]);
60-
$REDIS->setCache($SSO["user"], "mail", $SSO["mail"]);
61-
}
6252
}
6353

6454
$LOC_HEADER = __DIR__ . "/templates/header.php";

resources/lib/UnityGroup.php

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ class UnityGroup
1818
private UnitySQL $SQL;
1919
private UnityMailer $MAILER;
2020
private UnityWebhook $WEBHOOK;
21-
private UnityRedis $REDIS;
2221

2322
public function __construct(
2423
string $gid,
2524
UnityLDAP $LDAP,
2625
UnitySQL $SQL,
2726
UnityMailer $MAILER,
28-
UnityRedis $REDIS,
2927
UnityWebhook $WEBHOOK,
3028
) {
3129
$gid = trim($gid);
@@ -35,7 +33,6 @@ public function __construct(
3533
$this->LDAP = $LDAP;
3634
$this->SQL = $SQL;
3735
$this->MAILER = $MAILER;
38-
$this->REDIS = $REDIS;
3936
$this->WEBHOOK = $WEBHOOK;
4037
}
4138

@@ -184,17 +181,6 @@ public function cancelGroupJoinRequest(UnityUser $user, bool $send_mail = true):
184181
// // now we delete the ldap entry
185182
// $this->entry->ensureExists();
186183
// $this->entry->delete();
187-
// $default_value_getter = [$this->LDAP, "getSortedGroupsForRedis"];
188-
// $this->REDIS->removeCacheArray("sorted_groups", "", $this->gid, $default_value_getter);
189-
// foreach ($users as $user) {
190-
// $this->REDIS->removeCacheArray(
191-
// $user->uid,
192-
// "groups",
193-
// $this->gid,
194-
// fn() => $this->getGroupMemberUIDs(true),
195-
// );
196-
// }
197-
// // FIXME group not removed from user's groups array
198184

199185
// // send email to every user of the now deleted PI group
200186
// if ($send_mail) {
@@ -315,49 +301,34 @@ public function getRequests(): array
315301
$this->LDAP,
316302
$this->SQL,
317303
$this->MAILER,
318-
$this->REDIS,
319304
$this->WEBHOOK,
320305
);
321306
array_push($out, [$user, $request["timestamp"]]);
322307
}
323308
return $out;
324309
}
325310

326-
public function getGroupMembers(bool $ignorecache = false): array
311+
public function getGroupMembers(): array
327312
{
328-
$members = $this->getGroupMemberUIDs($ignorecache);
313+
$members = $this->getGroupMemberUIDs();
329314
$out = [];
330315
foreach ($members as $member) {
331316
$user_obj = new UnityUser(
332317
$member,
333318
$this->LDAP,
334319
$this->SQL,
335320
$this->MAILER,
336-
$this->REDIS,
337321
$this->WEBHOOK,
338322
);
339323
array_push($out, $user_obj);
340324
}
341325
return $out;
342326
}
343327

344-
public function getGroupMemberUIDs(bool $ignorecache = false): array
328+
public function getGroupMemberUIDs(): array
345329
{
346-
if (!$ignorecache) {
347-
$cached_val = $this->REDIS->getCache($this->gid, "members");
348-
if (!is_null($cached_val)) {
349-
$members = $cached_val;
350-
}
351-
}
352-
$updatecache = false;
353-
if (!isset($members)) {
354-
$members = $this->entry->getAttribute("memberuid");
355-
$updatecache = true;
356-
}
357-
if (!$ignorecache && $updatecache) {
358-
sort($members);
359-
$this->REDIS->setCache($this->gid, "members", $members);
360-
}
330+
$members = $this->entry->getAttribute("memberuid");
331+
sort($members);
361332
return $members;
362333
}
363334

@@ -383,8 +354,6 @@ private function init(): void
383354
$this->entry->setAttribute("gidnumber", strval($nextGID));
384355
$this->entry->setAttribute("memberuid", [$owner->uid]);
385356
$this->entry->write();
386-
$default_value_getter = [$this->LDAP, "getSortedGroupsForRedis"];
387-
$this->REDIS->appendCacheArray("sorted_groups", "", $this->gid, $default_value_getter);
388357
// TODO if we ever make this project based,
389358
// we need to update the cache here with the memberuid
390359
}
@@ -393,36 +362,12 @@ private function addUserToGroup(UnityUser $new_user): void
393362
{
394363
$this->entry->appendAttribute("memberuid", $new_user->uid);
395364
$this->entry->write();
396-
$this->REDIS->appendCacheArray(
397-
$this->gid,
398-
"members",
399-
$new_user->uid,
400-
fn() => $this->getGroupMemberUIDs(true),
401-
);
402-
$this->REDIS->appendCacheArray(
403-
$new_user->uid,
404-
"groups",
405-
$this->gid,
406-
fn() => $this->LDAP->getPIGroupGIDsWithMemberUID($new_user->uid),
407-
);
408365
}
409366

410367
private function removeUserFromGroup(UnityUser $old_user): void
411368
{
412369
$this->entry->removeAttributeEntryByValue("memberuid", $old_user->uid);
413370
$this->entry->write();
414-
$this->REDIS->removeCacheArray(
415-
$this->gid,
416-
"members",
417-
$old_user->uid,
418-
fn() => $this->getGroupMemberUIDs(true),
419-
);
420-
$this->REDIS->removeCacheArray(
421-
$old_user->uid,
422-
"groups",
423-
$this->gid,
424-
fn() => $this->LDAP->getPIGroupGIDsWithMemberUID($old_user->uid),
425-
);
426371
}
427372

428373
public function memberExists(UnityUser $user): bool
@@ -442,7 +387,6 @@ public function getOwner(): UnityUser
442387
$this->LDAP,
443388
$this->SQL,
444389
$this->MAILER,
445-
$this->REDIS,
446390
$this->WEBHOOK,
447391
);
448392
}

resources/lib/UnityLDAP.php

Lines changed: 5 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -194,39 +194,14 @@ public function getQualifiedUsersUIDs(): array
194194
return $this->qualifiedUserGroup->getAttribute("memberuid");
195195
}
196196

197-
public function getQualifiedUsers(
198-
$UnitySQL,
199-
$UnityMailer,
200-
$UnityRedis,
201-
$UnityWebhook,
202-
$ignorecache = false,
203-
): array {
197+
public function getQualifiedUsers($UnitySQL, $UnityMailer, $UnityWebhook): array
198+
{
204199
$out = [];
205200

206-
if (!$ignorecache) {
207-
$qualifiedUsers = $UnityRedis->getCache("sorted_qualified_users", "");
208-
if (!is_null($qualifiedUsers)) {
209-
foreach ($qualifiedUsers as $user) {
210-
array_push(
211-
$out,
212-
new UnityUser(
213-
$user,
214-
$this,
215-
$UnitySQL,
216-
$UnityMailer,
217-
$UnityRedis,
218-
$UnityWebhook,
219-
),
220-
);
221-
}
222-
return $out;
223-
}
224-
}
225-
226201
$qualifiedUsers = $this->getQualifiedUsersUIDs();
227202
sort($qualifiedUsers);
228203
foreach ($qualifiedUsers as $user) {
229-
$params = [$user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook];
204+
$params = [$user, $this, $UnitySQL, $UnityMailer, $UnityWebhook];
230205
array_push($out, new UnityUser(...$params));
231206
}
232207
return $out;
@@ -254,24 +229,10 @@ public function getQualifiedUsersAttributes(
254229
public function getAllPIGroups(
255230
UnitySQL $UnitySQL,
256231
UnityMailer $UnityMailer,
257-
UnityRedis $UnityRedis,
258232
UnityWebhook $UnityWebhook,
259-
bool $ignorecache = false,
260233
) {
261234
$out = [];
262235

263-
if (!$ignorecache) {
264-
$groups = $UnityRedis->getCache("sorted_groups", "");
265-
if (!is_null($groups)) {
266-
foreach ($groups as $group) {
267-
$params = [$group, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook];
268-
array_push($out, new UnityGroup(...$params));
269-
}
270-
271-
return $out;
272-
}
273-
}
274-
275236
$pi_groups = $this->pi_groupOU->getChildren(true);
276237

277238
foreach ($pi_groups as $pi_group) {
@@ -282,7 +243,6 @@ public function getAllPIGroups(
282243
$this,
283244
$UnitySQL,
284245
$UnityMailer,
285-
$UnityRedis,
286246
$UnityWebhook,
287247
),
288248
);
@@ -373,35 +333,10 @@ public function getQualifiedUID2PIGIDs(): array
373333
return $uid2pigids;
374334
}
375335

376-
public function getAllOrgGroups(
377-
$UnitySQL,
378-
$UnityMailer,
379-
$UnityRedis,
380-
$UnityWebhook,
381-
$ignorecache = false,
382-
): array {
336+
public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityWebhook): array
337+
{
383338
$out = [];
384339

385-
if (!$ignorecache) {
386-
$orgs = $UnityRedis->getCache("sorted_orgs", "");
387-
if (!is_null($orgs)) {
388-
foreach ($orgs as $org) {
389-
array_push(
390-
$out,
391-
new UnityOrg(
392-
$org,
393-
$this,
394-
$UnitySQL,
395-
$UnityMailer,
396-
$UnityRedis,
397-
$UnityWebhook,
398-
),
399-
);
400-
}
401-
return $out;
402-
}
403-
}
404-
405340
$org_groups = $this->org_groupOU->getChildren(true);
406341

407342
foreach ($org_groups as $org_group) {
@@ -412,7 +347,6 @@ public function getAllOrgGroups(
412347
$this,
413348
$UnitySQL,
414349
$UnityMailer,
415-
$UnityRedis,
416350
$UnityWebhook,
417351
),
418352
);
@@ -466,29 +400,6 @@ public function getUidFromEmail(string $email): LDAPEntry
466400
throw new exceptions\EntryNotFoundException($email);
467401
}
468402

469-
public function getSortedQualifiedUsersForRedis(): array
470-
{
471-
$qualified_users = $this->getQualifiedUsersUIDs();
472-
sort($qualified_users);
473-
return $qualified_users;
474-
}
475-
476-
public function getSortedOrgsForRedis(): array
477-
{
478-
$attributes = $this->getAllOrgGroupsAttributes(["cn"]);
479-
$groups = array_map(fn($x) => $x["cn"][0], $attributes);
480-
sort($groups);
481-
return $groups;
482-
}
483-
484-
public function getSortedGroupsForRedis(): array
485-
{
486-
$attributes = $this->getAllPIGroupsAttributes(["cn"]);
487-
$groups = array_map(fn($x) => $x["cn"][0], $attributes);
488-
sort($groups);
489-
return $groups;
490-
}
491-
492403
/**
493404
* returns an array with each UID as an array key
494405
* @throws \UnityWebPortal\lib\exceptions\EntryNotFoundException

0 commit comments

Comments
 (0)