From 22e13cd4d221d412b86c44f541d60daa44c6925a Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 19 Oct 2017 17:15:21 -0700 Subject: [PATCH] Allow sorting on asset counts, disable delete button if the user has items checked out to them --- app/Http/Controllers/Api/UsersController.php | 3 ++- app/Http/Transformers/UsersTransformer.php | 2 +- app/Presenters/UserPresenter.php | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index f3be10cf7a..7ae2e20d22 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -92,7 +92,8 @@ class UsersController extends Controller [ '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' + 'two_factor_enrolled','two_factor_optin','last_login', 'assets_count', 'licenses_count', + 'consumables_count', 'accessories_count' ]; $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 406dd372d9..2db1d1c801 100644 --- a/app/Http/Transformers/UsersTransformer.php +++ b/app/Http/Transformers/UsersTransformer.php @@ -58,7 +58,7 @@ class UsersTransformer $permissions_array['available_actions'] = [ 'update' => (Gate::allows('update', User::class) && ($user->deleted_at=='')) ? true : false, - 'delete' => (Gate::allows('delete', User::class) && ($user->deleted_at=='')) ? true : false, + 'delete' => (Gate::allows('delete', User::class) && ($user->deleted_at=='') && ($user->assets_count == 0) && ($user->licenses_count == 0) && ($user->accessories_count == 0) && ($user->consumables_count == 0)) ? true : false, 'clone' => (Gate::allows('create', User::class) && ($user->deleted_at=='')) , 'restore' => (Gate::allows('create', User::class) && ($user->deleted_at!='')) ? true : false, ]; diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index 9460ea23d6..5ff2f0d179 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -115,7 +115,7 @@ class UserPresenter extends Presenter [ "field" => "assets_count", "searchable" => false, - "sortable" => false, + "sortable" => true, "switchable" => true, "title" => ' ' .'', @@ -124,7 +124,7 @@ class UserPresenter extends Presenter [ "field" => "licenses_count", "searchable" => false, - "sortable" => false, + "sortable" => true, "switchable" => true, "title" => ' ' .'', @@ -133,7 +133,7 @@ class UserPresenter extends Presenter [ "field" => "consumables_count", "searchable" => false, - "sortable" => false, + "sortable" => true, "switchable" => true, "title" => ' ' .'', @@ -142,7 +142,7 @@ class UserPresenter extends Presenter [ "field" => "accessories_count", "searchable" => false, - "sortable" => false, + "sortable" => true, "switchable" => true, "title" => ' ' .'',