Merge branch 'develop' of https://github.com/snipe/snipe-it into develop

This commit is contained in:
snipe 2019-01-25 13:34:57 -08:00
commit c1a4fbee16
3 changed files with 64 additions and 46 deletions

View file

@ -26,6 +26,7 @@ class LDAPImportController extends Controller
{
parent::__construct();
$this->ldap = $ldap;
$this->ldap->init();
}
/**

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Services;
use Adldap\Schemas\Schema;
use App\Models\User;
use App\Helpers\Helper;
use Exception;
@ -94,21 +95,15 @@ class LdapAd extends LdapAdConfiguration
}
// Should we sync the logged in user
try {
Log::debug('Attempting to find user in LDAP directory');
$record = $this->ldap->search()->findBy($this->ldapSettings['ldap_username_field'], $username);
Log::debug('Attempting to find user in LDAP directory');
$record = $this->ldap->search()->findBy($this->ldapSettings['ldap_username_field'], $username);
if($record) {
if ($this->isLdapSync($record)) {
$this->syncUserLdapLogin($record, $password);
}
if($record) {
if ($this->isLdapSync($record)) {
$this->syncUserLdapLogin($record, $password);
}
else {
Log::error($e->getMessage());
throw new Exception('Unable to find user in LDAP directory!');
}
} catch (ModelNotFoundException $e) {
Log::error($e->getMessage());
}
else {
throw new Exception('Unable to find user in LDAP directory!');
}
@ -142,6 +137,8 @@ class LdapAd extends LdapAdConfiguration
$snipeUser['lastname'] = $user->{$this->ldapSettings['ldap_lname_field']}[0] ?? '';
$snipeUser['firstname'] = $user->{$this->ldapSettings['ldap_fname_field']}[0] ?? '';
$snipeUser['email'] = $user->{$this->ldapSettings['ldap_email']}[0] ?? '';
$snipeUser['title'] = $user->getTitle() ?? '';
$snipeUser['telephonenumber'] = $user->getTelephoneNumber() ?? '';
$snipeUser['location_id'] = $this->getLocationId($user, $defaultLocation, $mappedLocations);
$snipeUser['activated'] = $this->getActiveStatus($user);
@ -171,6 +168,8 @@ class LdapAd extends LdapAdConfiguration
$user->last_name = trim($userInfo['lastname']);
$user->email = trim($userInfo['email']);
$user->employee_num = trim($userInfo['employee_number']);
$user->jobtitle = trim($userInfo['title']);
$user->phone = trim($userInfo['telephonenumber']);
$user->activated = $userInfo['activated'];
$user->location_id = $userInfo['location_id'];
$user->notes = 'Imported from LDAP';
@ -223,7 +222,7 @@ class LdapAd extends LdapAdConfiguration
*/
private function isLdapSync(AdldapUser $user): bool
{
return (false === $this->ldapSettings['ldap_active_flag'])
return (false == $this->ldapSettings['ldap_active_flag'])
|| ('true' == strtolower($user->{$this->ldapSettings['ldap_active_flag']}[0]));
}
@ -245,11 +244,11 @@ class LdapAd extends LdapAdConfiguration
* Check to see if we are connected to an AD server
* if so, check the Active Directory User Account Control Flags
*/
if ($this->ldapSettings['is_ad']) {
if ($user->hasAttribute($user->getSchema()->userAccountControl())) {
$activeStatus = (in_array($user->getUserAccountControl(), self::AD_USER_ACCOUNT_CONTROL_FLAGS)) ? 1 : 0;
} else {
// If there is no activated flag, assume this is handled via the OU and activate the users
if (false === $this->ldapSettings['ldap_active_flag']) {
if (false == $this->ldapSettings['ldap_active_flag']) {
$activeStatus = 1;
}
}
@ -281,7 +280,7 @@ class LdapAd extends LdapAdConfiguration
// Check to see if the user is in a mapped location
if ($mappedLocations) {
$location = $mappedLocations->filter(function ($value, $key) use ($user) {
if ($user->inGroup([$value], true)) {
if ($user->inOu($value)) {
return $key;
}
});
@ -348,6 +347,8 @@ class LdapAd extends LdapAdConfiguration
*/
private function getSelectedFields(): array
{
/** @var Schema $schema */
$schema = new $this->ldapConfig['schema'];
return [
$this->ldapSettings['ldap_username_field'],
$this->ldapSettings['ldap_fname_field'],
@ -355,8 +356,10 @@ class LdapAd extends LdapAdConfiguration
$this->ldapSettings['ldap_email'],
$this->ldapSettings['ldap_emp_num'],
$this->ldapSettings['ldap_active_flag'],
'memberOf',
'useraccountcontrol',
$schema->memberOf(),
$schema->userAccountControl(),
$schema->title(),
$schema->telephone(),
];
}

View file

@ -13,6 +13,21 @@
[v-cloak] {
display:none;
}
/* Rules for the div table */
.tbl_head {
font-weight: bold
}
.div_tbl {
display: table
}
.div_tbl_row {
display: table-row
}
.div_tbl_cell {
display: table-cell;
padding: 2px
}
</style>
<div id="app">
@ -49,33 +64,32 @@
</div>
<div class="row">
<div class="col-md-12" style="padding-top: 30px;">
<table class="table table-striped" id="upload-table">
<thead>
<th>File</th>
<th>Created</th>
<th>Size</th>
<th></th>
</thead>
<tbody>
<template v-for="currentFile in files">
<tr>
<td>@{{ currentFile.file_path }}</td>
<td>@{{ currentFile.created_at }} </td>
<td>@{{ currentFile.filesize }}</td>
<td>
<div class="table table-striped div_tbl" id="upload-table">
<div class="div_tbl_row">
<div class="div_tbl_cell tbl_head">File</div>
<div class="div_tbl_cell tbl_head">Created</div>
<div class="div_tbl_cell tbl_head">Size</div>
<div class="div_tbl_cell tbl_head"></div>
</div>
<template v-for="currentFile in files">
<div class="div_tbl_row">
<div class="div_tbl_cell">@{{ currentFile.file_path }}</div>
<div class="div_tbl_cell">@{{ currentFile.created_at }} </div>
<div class="div_tbl_cell">@{{ currentFile.filesize }}</div>
<div class="div_tbl_cell">
<button class="btn btn-sm btn-info" @click="toggleEvent(currentFile.id)">Process</button>
<button class="btn btn-sm btn-danger" @click="deleteFile(currentFile)"><i class="fa fa-trash icon-white"></i></button>
</td>
</tr>
<import-file
:key="currentFile.id"
:file="currentFile"
:custom-fields="customFields"
@alert="updateAlert(alert)">
</import-file>
</template>
</tbody>
</table>
<button class="btn btn-sm btn-danger" @click="deleteFile(currentFile)"><i class="fa fa-trash icon-white"></i></button>
</div>
</div>
<import-file
:key="currentFile.id"
:file="currentFile"
:custom-fields="customFields"
@alert="updateAlert(alert)">
</import-file>
</template>
</div>
</div>
</div>
</div>