Skip to content

Commit 4d41d56

Browse files
authored
remove only native users from qualified users group (#546)
1 parent 3cf346b commit 4d41d56

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

test/functional/WorkerUpdateQualifiedUsersGroupTest.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ public function testQualifyUser()
1111
$pi_group = $USER->getPIGroup();
1212
$this->switchUser("Blank");
1313
$user = $USER;
14-
$expectedOutput = ["added" => [$user->uid], "removed" => []];
14+
$expectedOutput = [
15+
"added" => [$user->uid],
16+
"removed" => [],
17+
"not removed (non-native)" => [],
18+
];
1519
try {
1620
$pi_group_entry = $LDAP->getPIGroupEntry($pi_group->gid);
1721
$pi_group_entry->appendAttribute("memberuid", $user->uid);
@@ -36,7 +40,11 @@ public function testDisqualifyUser()
3640
{
3741
global $USER, $LDAP, $SQL, $MAILER, $WEBHOOK;
3842
$this->switchUser("Blank");
39-
$expectedOutput = ["added" => [], "removed" => [$USER->uid]];
43+
$expectedOutput = [
44+
"added" => [],
45+
"removed" => [$USER->uid],
46+
"not removed (non-native)" => [],
47+
];
4048
try {
4149
$qualified_user_group = $LDAP->userFlagGroups["qualified"];
4250
$qualified_user_group->addMemberUID($USER->uid);
@@ -54,4 +62,33 @@ public function testDisqualifyUser()
5462
}
5563
}
5664
}
65+
66+
public function testIgnoreNonNativeUser()
67+
{
68+
global $USER, $LDAP, $SQL, $MAILER, $WEBHOOK;
69+
$this->switchUser("Blank");
70+
$expectedOutput = [
71+
"added" => [],
72+
"removed" => [],
73+
"not removed (non-native)" => ["non_native_user1"],
74+
];
75+
try {
76+
$qualified_user_group = $LDAP->userFlagGroups["qualified"];
77+
$qualified_user_group->addMemberUID("non_native_user1");
78+
[$_, $output_lines] = executeWorker("update-qualified-users-group.php");
79+
$output_str = implode("\n", $output_lines);
80+
$output = jsonDecode($output_str, associative: true);
81+
$this->assertEquals($expectedOutput, $output);
82+
// refresh LDAP to pick up changes from subprocess
83+
unset($GLOBALS["ldapconn"]);
84+
$this->switchUser("Blank");
85+
$this->assertTrue(
86+
$LDAP->userFlagGroups["qualified"]->memberUIDExists("non_native_user1"),
87+
);
88+
} finally {
89+
if ($LDAP->userFlagGroups["qualified"]->memberUIDExists("non_native_user1")) {
90+
$LDAP->userFlagGroups["qualified"]->removeMemberUID("non_native_user1");
91+
}
92+
}
93+
}
5794
}

workers/update-qualified-users-group.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818
$users_with_at_least_one_group = array_merge(
1919
...array_map(fn($x) => $x["memberuid"], $pi_groups_attributes),
2020
);
21-
$qualified_list_after = array_values(array_unique($users_with_at_least_one_group));
21+
$users_with_at_least_one_group = array_values(array_unique($users_with_at_least_one_group));
22+
$native_users_attributes = $LDAP->getAllNativeUsersAttributes(["uid"]);
23+
$native_users = array_map(fn($x) => $x["uid"][0], $native_users_attributes);
24+
$non_native_users = array_diff($qualified_list_before, $native_users);
25+
$non_native_users = array_values(array_unique($non_native_users));
26+
$qualified_list_after = array_merge($users_with_at_least_one_group, $non_native_users);
2227
sort($qualified_list_after);
2328
$users_added = array_values(array_diff($qualified_list_after, $qualified_list_before));
2429
$users_removed = array_values(array_diff($qualified_list_before, $qualified_list_after));
2530
echo jsonEncode(
2631
[
2732
"added" => $users_added,
2833
"removed" => $users_removed,
34+
"not removed (non-native)" => $non_native_users,
2935
],
3036
JSON_PRETTY_PRINT,
3137
) . "\n";

0 commit comments

Comments
 (0)