From 541ae919d95f9a8b464fa7aee77a661fd4be38cd Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 23 Jun 2022 09:38:44 -0700 Subject: [PATCH 01/13] fixes dropdown column select font color in bootstrap tables --- resources/assets/less/skins/skin-black-dark.less | 4 +++- resources/assets/less/skins/skin-blue-dark.less | 8 ++++++-- resources/assets/less/skins/skin-orange-dark.less | 3 +++ resources/assets/less/skins/skin-purple-dark.less | 4 +++- resources/assets/less/skins/skin-red-dark.less | 3 +++ resources/assets/less/skins/skin-yellow-dark.less | 12 +++++++----- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/resources/assets/less/skins/skin-black-dark.less b/resources/assets/less/skins/skin-black-dark.less index 1ad32cc4ea..ab1d52d4d8 100644 --- a/resources/assets/less/skins/skin-black-dark.less +++ b/resources/assets/less/skins/skin-black-dark.less @@ -137,7 +137,9 @@ a { .bootstrap-table .fixed-table-container .table thead th .sortable { color: var(--nav-link); } - +.bootstrap-table .fixed-table-toolbar .columns label { + color:#000; +} .thead, .navbar-nav>li>a:link { color: var(--nav-link); } diff --git a/resources/assets/less/skins/skin-blue-dark.less b/resources/assets/less/skins/skin-blue-dark.less index 56233c5058..c4a0d69257 100644 --- a/resources/assets/less/skins/skin-blue-dark.less +++ b/resources/assets/less/skins/skin-blue-dark.less @@ -132,7 +132,9 @@ a { .bootstrap-table .fixed-table-container .table thead th .sortable { color: var(--nav-link); } - +.bootstrap-table .fixed-table-toolbar .columns label { + color:#000; +} .thead, .navbar-nav>li>a:link { color: var(--nav-link); } @@ -149,7 +151,9 @@ a:link { .btn-primary.hover { color: var(--nav-link); } - +.bootstrap-table .fixed-table-toolbar .columns label { + color:#000; +} .small-box h3, .small-box p { color: var(--nav-link) !important; a:hover { diff --git a/resources/assets/less/skins/skin-orange-dark.less b/resources/assets/less/skins/skin-orange-dark.less index 51a37f424c..17847a1352 100644 --- a/resources/assets/less/skins/skin-orange-dark.less +++ b/resources/assets/less/skins/skin-orange-dark.less @@ -119,6 +119,9 @@ .bootstrap-table .fixed-table-container .table thead th .sortable { color: var(--nav-link); } +.bootstrap-table .fixed-table-toolbar .columns label { + color:#000; +} .thead, .navbar-nav>li>a:link { color: var(--nav-link); diff --git a/resources/assets/less/skins/skin-purple-dark.less b/resources/assets/less/skins/skin-purple-dark.less index c84622345a..aee201bf49 100644 --- a/resources/assets/less/skins/skin-purple-dark.less +++ b/resources/assets/less/skins/skin-purple-dark.less @@ -132,7 +132,9 @@ a { .bootstrap-table .fixed-table-container .table thead th .sortable { color: var(--nav-link); } - +.bootstrap-table .fixed-table-toolbar .columns label { + color:#000; +} .thead, .navbar-nav>li>a:link { color: var(--nav-link); } diff --git a/resources/assets/less/skins/skin-red-dark.less b/resources/assets/less/skins/skin-red-dark.less index 2195224cb6..fae36405c2 100644 --- a/resources/assets/less/skins/skin-red-dark.less +++ b/resources/assets/less/skins/skin-red-dark.less @@ -133,6 +133,9 @@ a { .bootstrap-table .fixed-table-container .table thead th .sortable { color: var(--nav-link); } +.bootstrap-table .fixed-table-toolbar .columns label { + color:#000; +} .thead, .navbar-nav>li>a:link { color: var(--nav-link); diff --git a/resources/assets/less/skins/skin-yellow-dark.less b/resources/assets/less/skins/skin-yellow-dark.less index 88ace6295e..dd1ecc05ff 100644 --- a/resources/assets/less/skins/skin-yellow-dark.less +++ b/resources/assets/less/skins/skin-yellow-dark.less @@ -103,10 +103,10 @@ a { --back-main: #333; --back-sub: #3d4144; --back-sub-alt: rgba(0, 0, 0, 0.36); - --button-default: #FFFF00; - --button-primary: darken(#FFFF00, 25%); - --button-hover: darken(#FFFF00, 30%); - --header: #FFFF00; /* Use same as Header picker */ + --button-default: #FFCC32; + --button-primary: darken(#FFCC32, 25%); + --button-hover: darken(#FFCC32, 30%); + --header: #FFCC32; /* Use same as Header picker */ --text-main: #BBB; --text-sub: #9b9b9b; --link: #F0E68C; /* Use same as Header picker, lighten by 70% */ @@ -131,7 +131,9 @@ a.btn.btn-default{ .bootstrap-table .fixed-table-container .table thead th .sortable { color: var(--nav-link); } - +.bootstrap-table .fixed-table-toolbar .columns label { + color:#000; +} .thead, .navbar-nav>li>a:link { color: var(--nav-link); } From ef86c0273a907f6e43e4f60c5e32ffc18556c447 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 17:17:38 -0700 Subject: [PATCH 02/13] Added migration to store admin ID Signed-off-by: snipe --- ...2022_06_23_164407_add_user_id_to_users.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 database/migrations/2022_06_23_164407_add_user_id_to_users.php diff --git a/database/migrations/2022_06_23_164407_add_user_id_to_users.php b/database/migrations/2022_06_23_164407_add_user_id_to_users.php new file mode 100644 index 0000000000..04a7bf68af --- /dev/null +++ b/database/migrations/2022_06_23_164407_add_user_id_to_users.php @@ -0,0 +1,34 @@ +integer('created_by')->after('activated')->nullable()->default(null); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + if (Schema::hasColumn('users', 'created_by')) { + $table->dropColumn('created_by'); + } + }); + } +} From e63183649a51ac1df66f5c0fb09f59d44fe2c305 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 17:17:48 -0700 Subject: [PATCH 03/13] Show admin in user view Signed-off-by: snipe --- resources/views/users/view.blade.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index 41f7b47748..7789120a7f 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -463,6 +463,17 @@
{{ \App\Helpers\Helper::getFormattedDateObject($user->created_at, 'datetime')['formatted']}} + + @if ($user->adminuser) + by + @if ($user->adminuser->deleted_at=='') + {{ $user->adminuser->present()->fullName }} + @else + {{ $user->adminuser->present()->fullName }} + @endif + + + @endif
@endif From 2e5e8f363b915f13a2af62e6040be02cb2cadb63 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 17:18:04 -0700 Subject: [PATCH 04/13] Added admin to oresenter Signed-off-by: snipe --- app/Presenters/UserPresenter.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index 7654eb5e23..d4e8c01868 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -285,6 +285,14 @@ class UserPresenter extends Presenter 'visible' => true, 'formatter' => 'trueFalseFormatter', ], + [ + 'field' => 'created_by', + 'searchable' => false, + 'sortable' => true, + 'title' => trans('general.admin'), + 'visible' => true, + 'formatter' => 'usersLinkObjFormatter', + ], [ 'field' => 'created_at', 'searchable' => true, From 23c50ea9a55b8fd5282ae848443fdd28c4d71e2d Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 17:18:11 -0700 Subject: [PATCH 05/13] Added admihn scopes Signed-off-by: snipe --- app/Models/User.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/Models/User.php b/app/Models/User.php index 5c539ad1c9..0abca08320 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -561,6 +561,18 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo return false; } + /** + * Get action logs history for this asset + * + * @author [A. Gianotto] [] + * @since [v1.0] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function adminuser() + { + 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 @@ -685,6 +697,23 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo return $query->leftJoin('departments as departments_users', 'users.department_id', '=', 'departments_users.id')->orderBy('departments_users.name', $order); } + /** + * Query builder scope to order on admin user + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param string $order Order + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderAdmin($query, $order) + { + // Left join here, or it will only return results with parents + return $query->leftJoin('users as admin_user', 'users.created_by', '=', 'admin_user.id') + ->orderBy('admin_user.first_name', $order) + ->orderBy('admin_user.last_name', $order); + } + + /** * Query builder scope to order on company * From 7f050290894f10cb30f49525a05c290cb7100116 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 17:18:31 -0700 Subject: [PATCH 06/13] Added created_by to API output Signed-off-by: snipe --- app/Http/Transformers/UsersTransformer.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php index 5366a524c9..ecf6e1a125 100644 --- a/app/Http/Transformers/UsersTransformer.php +++ b/app/Http/Transformers/UsersTransformer.php @@ -63,6 +63,10 @@ class UsersTransformer 'accessories_count' => (int) $user->accessories_count, 'consumables_count' => (int) $user->consumables_count, 'company' => ($user->company) ? ['id' => (int) $user->company->id, 'name'=> e($user->company->name)] : null, + 'created_by' => ($user->adminuser) ? [ + 'id' => (int) $user->adminuser->id, + 'name'=> e($user->adminuser->present()->fullName), + ] : null, 'created_at' => Helper::getFormattedDateObject($user->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($user->updated_at, 'datetime'), 'last_login' => Helper::getFormattedDateObject($user->last_login, 'datetime'), From c9b81d65f169ebc681b6203bcd804c7d5a303af4 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 17:19:08 -0700 Subject: [PATCH 07/13] Save the user id who is creating the user Signed-off-by: snipe --- app/Http/Controllers/Users/UsersController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index 0f69e5925c..c67cbcb286 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -117,6 +117,7 @@ class UsersController extends Controller $user->zip = $request->input('zip', null); $user->remote = $request->input('remote', 0); $user->website = $request->input('website', null); + $user->created_by = Auth::user()->id; // Strip out the superuser permission if the user isn't a superadmin $permissions_array = $request->input('permission'); From d8daec2e0a01de86506dbbdf5dd43f452b85419e Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 17:19:30 -0700 Subject: [PATCH 08/13] Added created_by results to user index API Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 2dd323a109..adad3bca21 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -36,6 +36,7 @@ class UsersController extends Controller $users = User::select([ 'users.activated', + 'users.created_by', 'users.address', 'users.avatar', 'users.city', @@ -66,7 +67,7 @@ class UsersController extends Controller 'users.remote', 'users.ldap_import', - ])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables') + ])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'adminuser',) ->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count'); $users = Company::scopeCompanyables($users); @@ -89,6 +90,10 @@ class UsersController extends Controller $users = $users->where('users.location_id', '=', $request->input('location_id')); } + if ($request->filled('created_by')) { + $users = $users->where('users.created_by', '=', $request->input('created_by')); + } + if ($request->filled('email')) { $users = $users->where('users.email', '=', $request->input('email')); } @@ -182,6 +187,9 @@ class UsersController extends Controller case 'department': $users = $users->OrderDepartment($order); break; + case 'created_by': + $users = $users->OrderAdmin($order); + break; case 'company': $users = $users->OrderCompany($order); break; From 9c9f5be6fe29be69cfc0ff461bbe83193415f62e Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 17:28:34 -0700 Subject: [PATCH 09/13] Do not show the creating admin by default in list view Signed-off-by: snipe --- app/Presenters/UserPresenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index d4e8c01868..985348ca64 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -290,7 +290,7 @@ class UserPresenter extends Presenter 'searchable' => false, 'sortable' => true, 'title' => trans('general.admin'), - 'visible' => true, + 'visible' => false, 'formatter' => 'usersLinkObjFormatter', ], [ From 3e559044b22dd847ec0846244f2bd6bcd34b8530 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 18:41:13 -0700 Subject: [PATCH 10/13] Changed method and scope names Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 2 +- app/Http/Transformers/UsersTransformer.php | 6 +++--- app/Models/User.php | 4 ++-- resources/views/users/view.blade.php | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index adad3bca21..00847f6e82 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -188,7 +188,7 @@ class UsersController extends Controller $users = $users->OrderDepartment($order); break; case 'created_by': - $users = $users->OrderAdmin($order); + $users = $users->CreatedBy($order); break; case 'company': $users = $users->OrderCompany($order); diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php index ecf6e1a125..9a498a325e 100644 --- a/app/Http/Transformers/UsersTransformer.php +++ b/app/Http/Transformers/UsersTransformer.php @@ -63,9 +63,9 @@ class UsersTransformer 'accessories_count' => (int) $user->accessories_count, 'consumables_count' => (int) $user->consumables_count, 'company' => ($user->company) ? ['id' => (int) $user->company->id, 'name'=> e($user->company->name)] : null, - 'created_by' => ($user->adminuser) ? [ - 'id' => (int) $user->adminuser->id, - 'name'=> e($user->adminuser->present()->fullName), + 'created_by' => ($user->createdBy) ? [ + 'id' => (int) $user->createdBy->id, + 'name'=> e($user->createdBy->present()->fullName), ] : null, 'created_at' => Helper::getFormattedDateObject($user->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($user->updated_at, 'datetime'), diff --git a/app/Models/User.php b/app/Models/User.php index 0abca08320..2153194bf8 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -568,7 +568,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo * @since [v1.0] * @return \Illuminate\Database\Eloquent\Relations\Relation */ - public function adminuser() + public function createdBy() { return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed(); } @@ -705,7 +705,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo * * @return \Illuminate\Database\Query\Builder Modified query builder */ - public function scopeOrderAdmin($query, $order) + public function scopeCreatedBy($query, $order) { // Left join here, or it will only return results with parents return $query->leftJoin('users as admin_user', 'users.created_by', '=', 'admin_user.id') diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index 7789120a7f..d28759b841 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -464,12 +464,12 @@
{{ \App\Helpers\Helper::getFormattedDateObject($user->created_at, 'datetime')['formatted']}} - @if ($user->adminuser) + @if ($user->createdBy) by - @if ($user->adminuser->deleted_at=='') - {{ $user->adminuser->present()->fullName }} + @if ($user->createdBy->deleted_at=='') + {{ $user->createdBy->present()->fullName }} @else - {{ $user->adminuser->present()->fullName }} + {{ $user->createdBy->present()->fullName }} @endif From 9fd3541520742a3e9a03d94cb199f279d84c3e16 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 18:42:22 -0700 Subject: [PATCH 11/13] Missed on createdBy Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 00847f6e82..a4e74cddd4 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -67,7 +67,7 @@ class UsersController extends Controller 'users.remote', 'users.ldap_import', - ])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'adminuser',) + ])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy',) ->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count'); $users = Company::scopeCompanyables($users); From 62ab8670512782e03d214a30432aceee211aac9c Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 18:43:10 -0700 Subject: [PATCH 12/13] Fixed url param Signed-off-by: snipe --- resources/views/users/view.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index d28759b841..c41afe19f3 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -467,7 +467,7 @@ @if ($user->createdBy) by @if ($user->createdBy->deleted_at=='') - {{ $user->createdBy->present()->fullName }} + {{ $user->createdBy->present()->fullName }} @else {{ $user->createdBy->present()->fullName }} @endif From 0bc3ca5c423ea18d6beb672ca0dc6b43f8b77169 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 23 Jun 2022 18:44:27 -0700 Subject: [PATCH 13/13] Fixed comments Signed-off-by: snipe --- app/Models/User.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 2153194bf8..6dad9baee1 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -562,10 +562,10 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo } /** - * Get action logs history for this asset + * Get the admin user who created this user * * @author [A. Gianotto] [] - * @since [v1.0] + * @since [v6.0.5] * @return \Illuminate\Database\Eloquent\Relations\Relation */ public function createdBy()