Skip to content

Commit 65e5572

Browse files
committed
1st attempt
1 parent cdd85a3 commit 65e5572

File tree

2 files changed

+66
-21
lines changed

2 files changed

+66
-21
lines changed

resources/lib/UnityLDAP.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ public function getUnassignedID($uid, $UnitySQL)
218218
return $next_uid;
219219
}
220220

221+
public function getAllUsersUIDs()
222+
{
223+
// should not use $user_ou->getChildren or $this->search(objectClass=posixAccount, $base_dn)
224+
// Unity users might be outside user ou, and not all users in LDAP tree are unity users
225+
return $this->userGroup->getAttribute("memberuid");
226+
}
227+
221228
//
222229
// Functions that return user/group objects
223230
//
@@ -236,14 +243,24 @@ public function getAllUsers($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook,
236243
}
237244
}
238245

239-
$users = $this->userGroup->getAttribute("memberuid");
246+
$users = $this->getAllUsersUIDs();
240247
sort($users);
241248
foreach ($users as $user) {
242249
$params = array($user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook);
243250
array_push($out, new UnityUser(...$params));
244251
}
252+
}
245253

246-
return $out;
254+
public function getAllUsersEntries()
255+
{
256+
$include_uids = $this->getAllUsersUIDs();
257+
$user_entries = $this->search("objectClass=posixAccount", $CONFIG["ldap"]["basedn"], []);
258+
foreach ($user_entries as $i => $entry) {
259+
if (!in_array($entry["uid"], $include_uids)) {
260+
unset($user_entries[$i]);
261+
}
262+
}
263+
return $user_entries;
247264
}
248265

249266
public function getAllPIGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
@@ -278,6 +295,32 @@ public function getAllPIGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebho
278295
return $out;
279296
}
280297

298+
public function getAllPIGroupsEntries()
299+
{
300+
return $this->pi_groupOU->getChildrenArray(true);
301+
}
302+
303+
/** Returns an assosiative array where keys are UIDs and values are lists of PI GIDs */
304+
public function getAllUID2PIGIDs()
305+
{
306+
// initialize output so each UID is a key with an empty array as its value
307+
$UID2PIGIDs = array_combine(
308+
$this->getAllUsersUIDs(),
309+
array_map(
310+
fn($x) => [],
311+
$this->getAllUsersUIDs()
312+
)
313+
);
314+
// for each PI group, append that GID to the member list for each of its member UIDs
315+
foreach ($this->getAllPIGroupsEntries() as $entry) {
316+
$gid = $entry["cn"];
317+
foreach ($entry["memberUid"] as $uid) {
318+
array_push($UID2PIGIDs[$uid], $gid);
319+
}
320+
}
321+
return $UID2PIGIDs;
322+
}
323+
281324
public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
282325
{
283326
$out = array();
@@ -309,6 +352,11 @@ public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebh
309352
return $out;
310353
}
311354

355+
public function getAllOrgGroupsEntries()
356+
{
357+
return $this->org_groupOU->getChildrenArray(true);
358+
}
359+
312360
public function getUserEntry($uid)
313361
{
314362
$uid = ldap_escape($uid, LDAP_ESCAPE_DN);

webroot/admin/user-mgmt.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,33 @@
3737
</tr>
3838

3939
<?php
40-
$users = $LDAP->getAllUsers($SQL, $MAILER, $REDIS, $WEBHOOK);
41-
42-
usort($users, function ($a, $b) {
43-
return strcmp($a->getUID(), $b->getUID());
40+
$UID2PIGIDs = $LDAP->getAllUID2PIGIDs();
41+
$user_entries = $LDAP->getAllUsersEntries();
42+
usort($user_entries, function ($a, $b) {
43+
return strcmp($a["uid"], $b["uid"]);
4444
});
45-
46-
foreach ($users as $user) {
47-
if ($user->hasRequestedAccountDeletion()) {
45+
foreach ($user_entries as $entry) {
46+
$uid = $entry["uid"];
47+
if ($SQL->accDeletionRequestExists($uid)) {
4848
echo "<tr style='color:grey; font-style: italic'>";
4949
} else {
5050
echo "<tr>";
5151
}
52-
echo "<td>" . $user->getFirstname() . " " . $user->getLastname() . "</td>";
53-
echo "<td>" . $user->getUID() . "</td>";
54-
echo "<td>" . $user->getOrg() . "</td>";
55-
echo "<td><a href='mailto:" . $user->getMail() . "'>" . $user->getMail() . "</a></td>";
52+
echo "<td>" . $entry["gecos"] . "</td>";
53+
echo "<td>" . $uid . "</td>";
54+
echo "<td>" . $user["o"] . "</td>";
55+
echo "<td><a href='mailto:" . $user["mail"] . "'>" . $user["mail"] . "</a></td>";
5656
echo "<td>";
57-
$cur_user_groups = $user->getGroups();
58-
foreach ($cur_user_groups as $cur_group) {
59-
echo "<a href='mailto:" . $cur_group->getOwner()->getMail() . "'>" . $cur_group->getPIUID() . "</a>";
60-
if ($cur_group !== array_key_last($cur_user_groups)) {
61-
echo '<br>';
62-
}
57+
foreach ($UID2PIGIDS[$uid] as $GID) {
58+
echo "<p>$GID</p>";
6359
}
60+
echo "<br>";
6461
echo "</td>";
6562
echo "<td>";
6663
echo "<form class='viewAsUserForm' action='' method='POST'
67-
onsubmit='return confirm(\"Are you sure you want to switch to the user " . $user->getUID() . "?\");'>
64+
onsubmit='return confirm(\"Are you sure you want to switch to the user '$uid'?\");'>
6865
<input type='hidden' name='form_type' value='viewAsUser'>
69-
<input type='hidden' name='uid' value='" . $user->getUID() . "'>
66+
<input type='hidden' name='uid' value='$uid'>
7067
<input type='submit' name='action' value='Access'>
7168
</form>";
7269
echo "</td>";

0 commit comments

Comments
 (0)