From eaf9332096eee5c694784f163fe41a2cc14cdc84 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 17 Jan 2023 17:21:03 -0800 Subject: [PATCH 1/5] Added filterability to 2FA fields Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 9348b04b57..c5f334fc31 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')); } From dbda288a4418e01d2fd5aaa3f3c6b7223e508b89 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 17 Jan 2023 17:21:20 -0800 Subject: [PATCH 2/5] Formatting changes only for readability Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 38 +++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index c5f334fc31..cca829c23f 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -215,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'; From 4ef0005e7cd8a7a619d2bca6a95278742be54d13 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 17 Jan 2023 17:21:40 -0800 Subject: [PATCH 3/5] BREAKING: changed API fieldname result for 2FA Signed-off-by: snipe --- app/Http/Transformers/UsersTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From f08babfa8aef29fe840f8dbbf7836e92c87b6443 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 17 Jan 2023 17:22:03 -0800 Subject: [PATCH 4/5] Just moved some stuff around - no actual meaningful code changes Signed-off-by: snipe --- app/Models/User.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) 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() { From c3e4d9d7731e7c5bdfacf94dcdac201f859cd0cf Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 17 Jan 2023 18:27:47 -0800 Subject: [PATCH 5/5] Make column name consistent with field name (BREAKING) Signed-off-by: snipe --- app/Presenters/UserPresenter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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,