mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
allows multi location sync for ldap
This commit is contained in:
parent
4d65d09306
commit
3b6a0d6525
|
@ -18,7 +18,7 @@ class LdapSync extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'snipeit:ldap-sync {--location=} {--location_id=} {--base_dn=} {--filter=} {--summary} {--json_summary}';
|
protected $signature = 'snipeit:ldap-sync {--location=} {--location_id=*} {--base_dn=} {--filter=} {--summary} {--json_summary}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
|
@ -84,10 +84,13 @@ class LdapSync extends Command
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ( $this->option('location_id') != '') {
|
if ( $this->option('location_id') != '') {
|
||||||
$location_ou= Location::where('id', '=', $this->option('location_id'))->value('ldap_ou');
|
|
||||||
$search_base = $location_ou;
|
foreach($this->option('location_id') as $location_id){
|
||||||
Log::debug('Importing users from specified location OU: \"'.$search_base.'\".');
|
$location_ou= Location::where('id', '=', $location_id)->value('ldap_ou');
|
||||||
}
|
$search_base = $location_ou;
|
||||||
|
Log::debug('Importing users from specified location OU: \"'.$search_base.'\".');
|
||||||
|
}
|
||||||
|
}
|
||||||
else if ($this->option('base_dn') != '') {
|
else if ($this->option('base_dn') != '') {
|
||||||
$search_base = $this->option('base_dn');
|
$search_base = $this->option('base_dn');
|
||||||
Log::debug('Importing users from specified base DN: \"'.$search_base.'\".');
|
Log::debug('Importing users from specified base DN: \"'.$search_base.'\".');
|
||||||
|
@ -111,21 +114,21 @@ class LdapSync extends Command
|
||||||
|
|
||||||
/* Determine which location to assign users to by default. */
|
/* Determine which location to assign users to by default. */
|
||||||
$location = null; // TODO - this would be better called "$default_location", which is more explicit about its purpose
|
$location = null; // TODO - this would be better called "$default_location", which is more explicit about its purpose
|
||||||
|
if ($this->option('location') != '') {
|
||||||
|
if ($location = Location::where('name', '=', $this->option('location'))->first()) {
|
||||||
|
Log::debug('Location name ' . $this->option('location') . ' passed');
|
||||||
|
Log::debug('Importing to ' . $location->name . ' (' . $location->id . ')');
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif ($this->option('location_id') != '') {
|
||||||
|
foreach($this->option('location_id') as $location_id) {
|
||||||
|
if ($location = Location::where('id', '=', $location_id)->first()) {
|
||||||
|
Log::debug('Location ID ' . $location_id . ' passed');
|
||||||
|
Log::debug('Importing to ' . $location->name . ' (' . $location->id . ')');
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->option('location') != '') {
|
|
||||||
if ($location = Location::where('name', '=', $this->option('location'))->first()) {
|
|
||||||
Log::debug('Location name '.$this->option('location').' passed');
|
|
||||||
Log::debug('Importing to '.$location->name.' ('.$location->id.')');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif ($this->option('location_id') != '') {
|
|
||||||
if ($location = Location::where('id', '=', $this->option('location_id'))->first()) {
|
|
||||||
Log::debug('Location ID '.$this->option('location_id').' passed');
|
|
||||||
Log::debug('Importing to '.$location->name.' ('.$location->id.')');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($location)) {
|
if (! isset($location)) {
|
||||||
Log::debug('That location is invalid or a location was not provided, so no location will be assigned by default.');
|
Log::debug('That location is invalid or a location was not provided, so no location will be assigned by default.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,19 +49,19 @@ class LDAPImportController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('update', User::class);
|
$this->authorize('update', User::class);
|
||||||
// Call Artisan LDAP import command.
|
// Call Artisan LDAP import command.
|
||||||
$location_id = $request->input('location_id');
|
|
||||||
Artisan::call('snipeit:ldap-sync', ['--location_id' => $location_id, '--json_summary' => true]);
|
Artisan::call('snipeit:ldap-sync', ['--location_id' => $request->input('location_id'), '--json_summary' => true]);
|
||||||
|
|
||||||
// Collect and parse JSON summary.
|
// Collect and parse JSON summary.
|
||||||
$ldap_results_json = Artisan::output();
|
$ldap_results_json = Artisan::output();
|
||||||
$ldap_results = json_decode($ldap_results_json, true);
|
$ldap_results = json_decode($ldap_results_json, true);
|
||||||
|
|
||||||
if (!$ldap_results) {
|
if (!$ldap_results) {
|
||||||
return redirect()->back()->withInput()->with('error', trans('general.no_results'));
|
return redirect()->back()->withInput()->with('error', trans('general.no_results'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Direct user to appropriate status page.
|
// Direct user to appropriate status page.
|
||||||
if ($ldap_results['error']) {
|
if ($ldap_results['error']) {
|
||||||
|
|
||||||
return redirect()->back()->withInput()->with('error', $ldap_results['error_message']);
|
return redirect()->back()->withInput()->with('error', $ldap_results['error_message']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<!-- Location -->
|
<!-- Location -->
|
||||||
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id'])
|
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id[]', 'multiple' => true])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue