Skip to content

Commit

Permalink
added ldap_location to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Godmartinz committed Apr 25, 2023
1 parent 7d9062c commit cb68f41
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/Console/Commands/LdapSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function handle()
$ldap_result_phone = Setting::getSettings()->ldap_phone_field;
$ldap_result_jobtitle = Setting::getSettings()->ldap_jobtitle;
$ldap_result_country = Setting::getSettings()->ldap_country;
$ldap_result_location = Setting::getSettings()->ldap_location;
$ldap_result_dept = Setting::getSettings()->ldap_dept;
$ldap_result_manager = Setting::getSettings()->ldap_manager;
$ldap_default_group = Setting::getSettings()->ldap_default_group;
Expand Down Expand Up @@ -209,8 +210,11 @@ public function handle()
$item['country'] = $results[$i][$ldap_result_country][0] ?? '';
$item['department'] = $results[$i][$ldap_result_dept][0] ?? '';
$item['manager'] = $results[$i][$ldap_result_manager][0] ?? '';
$item['location'] = $results[$i][$ldap_result_location][0] ?? '';


$location = Location::firstOrCreate([
'name' => $item['location'],
]);
$department = Department::firstOrCreate([
'name' => $item['department'],
]);
Expand All @@ -236,6 +240,7 @@ public function handle()
$user->jobtitle = $item['jobtitle'];
$user->country = $item['country'];
$user->department_id = $department->id;
$user->location_id = $location->id;

if($item['manager'] != null) {
// Check Cache first
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ public function postLdapSettings(Request $request)
$setting->ldap_phone_field = $request->input('ldap_phone');
$setting->ldap_jobtitle = $request->input('ldap_jobtitle');
$setting->ldap_country = $request->input('ldap_country');
$setting->ldap_location = $request->input('ldap_location');
$setting->ldap_dept = $request->input('ldap_dept');
$setting->ldap_client_tls_cert = $request->input('ldap_client_tls_cert');
$setting->ldap_client_tls_key = $request->input('ldap_client_tls_key');
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public static function parseAndMapLdapAttributes($ldapattributes)
$ldap_result_phone = Setting::getSettings()->ldap_phone;
$ldap_result_jobtitle = Setting::getSettings()->ldap_jobtitle;
$ldap_result_country = Setting::getSettings()->ldap_country;
$ldap_result_location = Setting::getSettings()->ldap_locationl;
$ldap_result_dept = Setting::getSettings()->ldap_dept;
$ldap_result_manager = Setting::getSettings()->ldap_manager;
// Get LDAP user data
Expand All @@ -227,6 +228,7 @@ public static function parseAndMapLdapAttributes($ldapattributes)
$item['country'] = $ldapattributes[$ldap_result_country][0] ?? '';
$item['department'] = $ldapattributes[$ldap_result_dept][0] ?? '';
$item['manager'] = $ldapattributes[$ldap_result_manager][0] ?? '';
$item['location'] = $ldapattributes[$ldap_result_location][0] ?? '';

return $item;
}
Expand Down
10 changes: 9 additions & 1 deletion app/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,15 @@ public static function getLdapSettings(): Collection
'ad_domain',
'ad_append_domain',
'ldap_client_tls_key',
'ldap_client_tls_cert'
'ldap_client_tls_cert',
'ldap_default_group',
'ldap_dept',
'ldap_emp_num',
'ldap_phone_field',
'ldap_jobtitle',
'ldap_manager',
'ldap_country',
'ldap_location',
])->first()->getAttributes();

return collect($ldapSettings);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddsLdapLocationToSettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('settings', function (Blueprint $table) {
$table->string('ldap_location')->after('ldap_country')->nullable()->default(null);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('settings', function (Blueprint $table) {
$table->dropColumn('ldap_location');
});
}
}
2 changes: 2 additions & 0 deletions resources/lang/en/admin/settings/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
'ldap_settings' => 'LDAP Settings',
'ldap_client_tls_cert_help' => 'Client-Side TLS Certificate and Key for LDAP connections are usually only useful in Google Workspace configurations with "Secure LDAP." Both are required.',
'ldap_client_tls_key' => 'LDAP Client-Side TLS key',
'ldap_location' => 'LDAP Location',
'ldap_location_help' => 'The Ldap Location field should be used if <strong>an OU is not being used in the Base Bind DN.</strong> Leave this blank if an OU search is being used.',
'ldap_login_test_help' => 'Enter a valid LDAP username and password from the base DN you specified above to test whether your LDAP login is configured correctly. YOU MUST SAVE YOUR UPDATED LDAP SETTINGS FIRST.',
'ldap_login_sync_help' => 'This only tests that LDAP can sync correctly. If your LDAP Authentication query is not correct, users may still not be able to login. YOU MUST SAVE YOUR UPDATED LDAP SETTINGS FIRST.',
'ldap_manager' => 'LDAP Manager',
Expand Down
14 changes: 14 additions & 0 deletions resources/views/settings/ldap.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,20 @@ class="form-control select2"
@endif
</div>
</div>
<!-- LDAP Location -->
<div class="form-group {{ $errors->has('ldap_location') ? 'error' : '' }}">
<div class="col-md-3">
{{ Form::label('ldap_location', trans('admin/settings/general.ldap_location')) }}
</div>
<div class="col-md-9">
{{ Form::text('ldap_location', Request::old('ldap_location', $setting->ldap_location), ['class' => 'form-control','placeholder' => trans('general.example') .'physicaldeliveryofficename', $setting->demoMode]) }}
<p class="help-block">{!! trans('admin/settings/general.ldap_location_help') !!}</p>
{!! $errors->first('ldap_location', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
@if (config('app.lock_passwords')===true)
<p class="text-warning"><i class="fas fa-lock" aria-hidden="true"></i> {{ trans('general.feature_disabled') }}</p>
@endif
</div>
</div>
@if ($setting->ldap_enabled)

<!-- LDAP test -->
Expand Down

0 comments on commit cb68f41

Please sign in to comment.