Merge pull request #11707 from wewhite/manager_name

Fixed #11706 Manager name
This commit is contained in:
snipe 2022-08-22 16:15:52 -07:00 committed by GitHub
commit aba8449dc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View file

@ -217,16 +217,23 @@ class LdapSync extends Command
$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();
if ( $ldap_manager && isset($ldap_manager->id) ) {
$user->manager_id = $ldap_manager->id;
// Get the LDAP Manager
$ldap_manager = Ldap::findLdapUsers($item['manager'], -1, $this->option('filter'));
if($ldap_manager["count"] > 0) {
// Get the Managers username
$ldapManagerUsername = $ldap_manager[0][$ldap_result_username][0];
// Get User from Manager username.
$ldap_manager = User::where('username', $ldapManagerUsername)->first();
if ( $ldap_manager && isset($ldap_manager->id) ) {
// Link user to manager id.
$user->manager_id = $ldap_manager->id;
}
}
}
// Sync activated state for Active Directory.
if ( !empty($ldap_result_active_flag)) { // IF we have an 'active' flag set....
// ....then *most* things that are truthy will activate the user. Anything falsey will deactivate them.

View file

@ -33,7 +33,7 @@ class UsersTransformer
'employee_num' => e($user->employee_num),
'manager' => ($user->manager) ? [
'id' => (int) $user->manager->id,
'name'=> e($user->manager->username),
'name'=> e($user->manager->first_name).' '.e($user->manager->last_name),
] : null,
'jobtitle' => ($user->jobtitle) ? e($user->jobtitle) : null,
'phone' => ($user->phone) ? e($user->phone) : null,