adds manager field to LDAP sync

This commit is contained in:
Godfrey M 2022-03-24 11:24:39 -07:00
parent 55680762de
commit c1f8252388
3 changed files with 13 additions and 1 deletions

View file

@ -56,6 +56,7 @@ class LdapSync extends Command
$ldap_result_jobtitle = Setting::getSettings()->ldap_jobtitle;
$ldap_result_country = Setting::getSettings()->ldap_country;
$ldap_result_dept = Setting::getSettings()->ldap_dept;
$ldap_result_manager = Setting::getSettings()->ldap_manager;
try {
$ldapconn = Ldap::connectToLdap();
@ -184,12 +185,12 @@ class LdapSync extends Command
$item['jobtitle'] = isset($results[$i][$ldap_result_jobtitle][0]) ? $results[$i][$ldap_result_jobtitle][0] : '';
$item['country'] = isset($results[$i][$ldap_result_country][0]) ? $results[$i][$ldap_result_country][0] : '';
$item['department'] = isset($results[$i][$ldap_result_dept][0]) ? $results[$i][$ldap_result_dept][0] : '';
$item['manager'] = isset($results[$i][$ldap_result_manager][0]) ? $results[$i][$ldap_result_manager][0] : '';
$department = Department::firstOrCreate([
'name' => $item['department'],
]);
$user = User::where('username', $item['username'])->first();
if ($user) {
// Updating an existing user.
@ -212,6 +213,15 @@ class LdapSync extends Command
$user->country = $item['country'];
$user->department_id = $department->id;
if($item['manager']!= null) {
//Captures only the Canonical Name
$item['manager'] = ltrim($item['manager'], "CN=");
$item['manager'] = substr($item['manager'],0, strpos($item['manager'], ','));
$ldap_manager = User::where('username', $item['manager'])->first();
$user->manager_id = $ldap_manager->id;
}
// Sync activated state for Active Directory.
if (array_key_exists('useraccountcontrol', $results[$i])) {
/* The following is _probably_ the correct logic, but we can't use it because

View file

@ -54,6 +54,7 @@ class UsersController extends Controller
'users.locale',
'users.location_id',
'users.manager_id',
'users.manager_name',
'users.notes',
'users.permissions',
'users.phone',

View file

@ -52,6 +52,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
'locale',
'location_id',
'manager_id',
'manager_name',
'password',
'phone',
'notes',