diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 9348b04b57..cca829c23f 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -149,6 +149,14 @@ class UsersController extends Controller $users = $users->where('remote', '=', $request->input('remote')); } + if ($request->filled('two_factor_enrolled')) { + $users = $users->where('two_factor_enrolled', '=', $request->input('two_factor_enrolled')); + } + + if ($request->filled('two_factor_optin')) { + $users = $users->where('two_factor_optin', '=', $request->input('two_factor_optin')); + } + if ($request->filled('start_date')) { $users = $users->where('users.start_date', '=', $request->input('start_date')); } @@ -157,7 +165,6 @@ class UsersController extends Controller $users = $users->where('users.end_date', '=', $request->input('end_date')); } - if ($request->filled('assets_count')) { $users->has('assets', '=', $request->input('assets_count')); } @@ -208,11 +215,39 @@ class UsersController extends Controller default: $allowed_columns = [ - 'last_name', 'first_name', 'email', 'jobtitle', 'username', 'employee_num', - 'assets', 'accessories', 'consumables', 'licenses', 'groups', 'activated', 'created_at', - 'two_factor_enrolled', 'two_factor_optin', 'last_login', 'assets_count', 'licenses_count', - 'consumables_count', 'accessories_count', 'phone', 'address', 'city', 'state', - 'country', 'zip', 'id', 'ldap_import', 'remote', 'start_date', 'end_date', + 'last_name', + 'first_name', + 'email', + 'jobtitle', + 'username', + 'employee_num', + 'assets', + 'accessories', + 'consumables', + 'licenses', + 'groups', + 'activated', + 'created_at', + 'two_factor_enrolled', + 'two_factor_optin', + 'last_login', + 'assets_count', + 'licenses_count', + 'consumables_count', + 'accessories_count', + 'phone', + 'address', + 'city', + 'state', + 'country', + 'zip', + 'id', + 'ldap_import', + 'two_factor_optin', + 'two_factor_enrolled', + 'remote', + 'start_date', + 'end_date', ]; $sort = in_array($request->get('sort'), $allowed_columns) ? $request->get('sort') : 'first_name'; diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php index 4d291d22d4..f8636cc574 100644 --- a/app/Http/Transformers/UsersTransformer.php +++ b/app/Http/Transformers/UsersTransformer.php @@ -56,8 +56,8 @@ class UsersTransformer 'permissions' => $user->decodePermissions(), 'activated' => ($user->activated == '1') ? true : false, 'ldap_import' => ($user->ldap_import == '1') ? true : false, - 'two_factor_activated' => ($user->two_factor_active()) ? true : false, 'two_factor_enrolled' => ($user->two_factor_active_and_enrolled()) ? true : false, + 'two_factor_optin' => ($user->two_factor_active()) ? true : false, 'assets_count' => (int) $user->assets_count, 'licenses_count' => (int) $user->licenses_count, 'accessories_count' => (int) $user->accessories_count, diff --git a/app/Models/User.php b/app/Models/User.php index c3f7f80b94..399008430b 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -586,6 +586,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo if ((Setting::getSettings()->two_factor_enabled == '1') && ($this->two_factor_optin == '1')) { return true; } + // If the 2FA is required for everyone so is implicitly active elseif (Setting::getSettings()->two_factor_enabled == '2') { return true; @@ -594,18 +595,6 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo return false; } - /** - * Get the admin user who created this user - * - * @author [A. Gianotto] [] - * @since [v6.0.5] - * @return \Illuminate\Database\Eloquent\Relations\Relation - */ - public function createdBy() - { - return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed(); - } - /** * Check whether two-factor authorization is required and the user has activated it * and enrolled a device @@ -634,6 +623,19 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo } + /** + * Get the admin user who created this user + * + * @author [A. Gianotto] [] + * @since [v6.0.5] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function createdBy() + { + return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed(); + } + + public function decodePermissions() { diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index c2a003bdc1..8f5cfcccf5 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -268,9 +268,9 @@ class UserPresenter extends Presenter 'formatter' => 'trueFalseFormatter', ], [ - 'field' => 'two_factor_activated', + 'field' => 'two_factor_optin', 'searchable' => false, - 'sortable' => false, + 'sortable' => true, 'switchable' => true, 'title' => trans('admin/users/general.two_factor_active'), 'visible' => false,