Skip to content

Commit eb1d27a

Browse files
authored
Merge pull request #16379 from azmcnutt/feature/settings_ldap_invert_active_flag
Feature/settings ldap invert active flag
2 parents a9ed9e2 + 149474b commit eb1d27a

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed

app/Console/Commands/LdapSync.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,15 @@ public function handle()
361361
// (Specifically, we don't handle a value of '0.0' correctly)
362362
$raw_value = @$results[$i][$ldap_map["active_flag"]][0];
363363
$filter_var = filter_var($raw_value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
364+
364365
$boolean_cast = (bool) $raw_value;
365-
366-
$user->activated = $filter_var ?? $boolean_cast; // if filter_var() was true or false, use that. If it's null, use the $boolean_cast
366+
367+
if (Setting::getSettings()->ldap_invert_active_flag === 1) {
368+
// Because ldap_active_flag is set, if filter_var is true or boolean_cast is true, then user is suspended
369+
$user->activated = !($filter_var ?? $boolean_cast);
370+
}else{
371+
$user->activated = $filter_var ?? $boolean_cast; // if filter_var() was true or false, use that. If it's null, use the $boolean_cast
372+
}
367373

368374
} elseif (array_key_exists('useraccountcontrol', $results[$i])) {
369375
// ....otherwise, (ie if no 'active' LDAP flag is defined), IF the UAC setting exists,

app/Http/Controllers/SettingsController.php

100755100644
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ public function postLdapSettings(StoreLdapSettings $request) : RedirectResponse
851851
$setting->ldap_auth_filter_query = $request->input('ldap_auth_filter_query');
852852
$setting->ldap_version = $request->input('ldap_version', 3);
853853
$setting->ldap_active_flag = $request->input('ldap_active_flag');
854+
$setting->ldap_invert_active_flag = $request->input('ldap_invert_active_flag');
854855
$setting->ldap_emp_num = $request->input('ldap_emp_num');
855856
$setting->ldap_email = $request->input('ldap_email');
856857
$setting->ldap_manager = $request->input('ldap_manager');
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('settings', function (Blueprint $table) {
15+
$table->boolean('ldap_invert_active_flag')->default(false);
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('settings', function (Blueprint $table) {
25+
$table->dropColumn('ldap_invert_active_flag');
26+
});
27+
}
28+
};

resources/lang/en-US/admin/settings/general.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@
118118
'ldap_version' => 'LDAP Version',
119119
'ldap_active_flag' => 'LDAP Active Flag',
120120
'ldap_activated_flag_help' => 'This value is used to determine whether a synced user can login to Snipe-IT. <strong>It does not affect the ability to check items in or out to them</strong>, and should be the <strong>attribute name</strong> within your AD/LDAP, <strong>not the value</strong>. <br><br>If this field is set to a field name that does not exist in your AD/LDAP, or the value in the AD/LDAP field is set to <code>0</code> or <code>false</code>, <strong>user login will be disabled</strong>. If the value in the AD/LDAP field is set to <code>1</code> or <code>true</code> or <em>any other text</em> means the user can log in. When the field is blank in your AD, we respect the <code>userAccountControl</code> attribute, which usually allows non-suspended users to log in.',
121+
'ldap_invert_active_flag' => 'LDAP Invert Active Flag',
122+
'ldap_invert_active_flag_help' => 'If enabled: when the value returned by LDAP Active Flag is <code>0</code> or <code>false</code> the user account will be active.',
121123
'ldap_emp_num' => 'LDAP Employee Number',
122124
'ldap_email' => 'LDAP Email',
123125
'ldap_test' => 'Test LDAP',

resources/views/settings/ldap.blade.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,32 @@
554554
</div>
555555
</div>
556556

557+
<!-- LDAP invert active flag -->
558+
<div class="form-group">
559+
<div class="col-md-3">
560+
{{ Form::label('ldap_invert_active_flag', trans('admin/settings/general.ldap_invert_active_flag')) }}
561+
</div>
562+
<div class="col-md-8">
563+
<label class="form-control">
564+
<input type="checkbox" name="ldap_invert_active_flag" value="1" id="ldap_invert_active_flag" @checked(old('ldap_invert_active_flag', $setting->ldap_invert_active_flag)) />
565+
<p class="help-block">{!! trans('admin/settings/general.ldap_invert_active_flag_help') !!}</p>
566+
</label>
567+
@error('ldap_invert_active_flag')
568+
<span class="alert-msg">
569+
<x-icon type="x" />
570+
{{ $message }}
571+
</span>
572+
@enderror
573+
574+
@if (config('app.lock_passwords')===true)
575+
<p class="text-warning">
576+
<x-icon type="locked" />
577+
{{ trans('general.feature_disabled') }}
578+
</p>
579+
@endif
580+
</div>
581+
</div>
582+
557583
<!-- LDAP emp number -->
558584
<div class="form-group {{ $errors->has('ldap_emp_num') ? 'error' : '' }}">
559585
<div class="col-md-3">

0 commit comments

Comments
 (0)