Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe 2022-06-23 18:56:04 -07:00
commit 9fc4565bc1
13 changed files with 121 additions and 10 deletions

View file

@ -36,6 +36,7 @@ class UsersController extends Controller
$users = User::select([ $users = User::select([
'users.activated', 'users.activated',
'users.created_by',
'users.address', 'users.address',
'users.avatar', 'users.avatar',
'users.city', 'users.city',
@ -66,7 +67,7 @@ class UsersController extends Controller
'users.remote', 'users.remote',
'users.ldap_import', 'users.ldap_import',
])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables') ])->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'); ->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count');
$users = Company::scopeCompanyables($users); $users = Company::scopeCompanyables($users);
@ -89,6 +90,10 @@ class UsersController extends Controller
$users = $users->where('users.location_id', '=', $request->input('location_id')); $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')) { if ($request->filled('email')) {
$users = $users->where('users.email', '=', $request->input('email')); $users = $users->where('users.email', '=', $request->input('email'));
} }
@ -182,6 +187,9 @@ class UsersController extends Controller
case 'department': case 'department':
$users = $users->OrderDepartment($order); $users = $users->OrderDepartment($order);
break; break;
case 'created_by':
$users = $users->CreatedBy($order);
break;
case 'company': case 'company':
$users = $users->OrderCompany($order); $users = $users->OrderCompany($order);
break; break;

View file

@ -117,6 +117,7 @@ class UsersController extends Controller
$user->zip = $request->input('zip', null); $user->zip = $request->input('zip', null);
$user->remote = $request->input('remote', 0); $user->remote = $request->input('remote', 0);
$user->website = $request->input('website', null); $user->website = $request->input('website', null);
$user->created_by = Auth::user()->id;
// Strip out the superuser permission if the user isn't a superadmin // Strip out the superuser permission if the user isn't a superadmin
$permissions_array = $request->input('permission'); $permissions_array = $request->input('permission');

View file

@ -63,6 +63,10 @@ class UsersTransformer
'accessories_count' => (int) $user->accessories_count, 'accessories_count' => (int) $user->accessories_count,
'consumables_count' => (int) $user->consumables_count, 'consumables_count' => (int) $user->consumables_count,
'company' => ($user->company) ? ['id' => (int) $user->company->id, 'name'=> e($user->company->name)] : null, 'company' => ($user->company) ? ['id' => (int) $user->company->id, 'name'=> e($user->company->name)] : null,
'created_by' => ($user->createdBy) ? [
'id' => (int) $user->createdBy->id,
'name'=> e($user->createdBy->present()->fullName),
] : null,
'created_at' => Helper::getFormattedDateObject($user->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($user->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($user->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($user->updated_at, 'datetime'),
'last_login' => Helper::getFormattedDateObject($user->last_login, 'datetime'), 'last_login' => Helper::getFormattedDateObject($user->last_login, 'datetime'),

View file

@ -561,6 +561,18 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
return false; return false;
} }
/**
* Get the admin user who created this user
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @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 * Check whether two-factor authorization is required and the user has activated it
* and enrolled a device * 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); 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 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')
->orderBy('admin_user.first_name', $order)
->orderBy('admin_user.last_name', $order);
}
/** /**
* Query builder scope to order on company * Query builder scope to order on company
* *

View file

@ -285,6 +285,14 @@ class UserPresenter extends Presenter
'visible' => true, 'visible' => true,
'formatter' => 'trueFalseFormatter', 'formatter' => 'trueFalseFormatter',
], ],
[
'field' => 'created_by',
'searchable' => false,
'sortable' => true,
'title' => trans('general.admin'),
'visible' => false,
'formatter' => 'usersLinkObjFormatter',
],
[ [
'field' => 'created_at', 'field' => 'created_at',
'searchable' => true, 'searchable' => true,

View file

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddUserIdToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->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');
}
});
}
}

View file

@ -137,7 +137,9 @@ a {
.bootstrap-table .fixed-table-container .table thead th .sortable { .bootstrap-table .fixed-table-container .table thead th .sortable {
color: var(--nav-link); color: var(--nav-link);
} }
.bootstrap-table .fixed-table-toolbar .columns label {
color:#000;
}
.thead, .navbar-nav>li>a:link { .thead, .navbar-nav>li>a:link {
color: var(--nav-link); color: var(--nav-link);
} }

View file

@ -132,7 +132,9 @@ a {
.bootstrap-table .fixed-table-container .table thead th .sortable { .bootstrap-table .fixed-table-container .table thead th .sortable {
color: var(--nav-link); color: var(--nav-link);
} }
.bootstrap-table .fixed-table-toolbar .columns label {
color:#000;
}
.thead, .navbar-nav>li>a:link { .thead, .navbar-nav>li>a:link {
color: var(--nav-link); color: var(--nav-link);
} }
@ -149,7 +151,9 @@ a:link {
.btn-primary.hover { .btn-primary.hover {
color: var(--nav-link); color: var(--nav-link);
} }
.bootstrap-table .fixed-table-toolbar .columns label {
color:#000;
}
.small-box h3, .small-box p { .small-box h3, .small-box p {
color: var(--nav-link) !important; color: var(--nav-link) !important;
a:hover { a:hover {

View file

@ -119,6 +119,9 @@
.bootstrap-table .fixed-table-container .table thead th .sortable { .bootstrap-table .fixed-table-container .table thead th .sortable {
color: var(--nav-link); color: var(--nav-link);
} }
.bootstrap-table .fixed-table-toolbar .columns label {
color:#000;
}
.thead, .navbar-nav>li>a:link { .thead, .navbar-nav>li>a:link {
color: var(--nav-link); color: var(--nav-link);

View file

@ -132,7 +132,9 @@ a {
.bootstrap-table .fixed-table-container .table thead th .sortable { .bootstrap-table .fixed-table-container .table thead th .sortable {
color: var(--nav-link); color: var(--nav-link);
} }
.bootstrap-table .fixed-table-toolbar .columns label {
color:#000;
}
.thead, .navbar-nav>li>a:link { .thead, .navbar-nav>li>a:link {
color: var(--nav-link); color: var(--nav-link);
} }

View file

@ -133,6 +133,9 @@ a {
.bootstrap-table .fixed-table-container .table thead th .sortable { .bootstrap-table .fixed-table-container .table thead th .sortable {
color: var(--nav-link); color: var(--nav-link);
} }
.bootstrap-table .fixed-table-toolbar .columns label {
color:#000;
}
.thead, .navbar-nav>li>a:link { .thead, .navbar-nav>li>a:link {
color: var(--nav-link); color: var(--nav-link);

View file

@ -103,10 +103,10 @@ a {
--back-main: #333; --back-main: #333;
--back-sub: #3d4144; --back-sub: #3d4144;
--back-sub-alt: rgba(0, 0, 0, 0.36); --back-sub-alt: rgba(0, 0, 0, 0.36);
--button-default: #FFFF00; --button-default: #FFCC32;
--button-primary: darken(#FFFF00, 25%); --button-primary: darken(#FFCC32, 25%);
--button-hover: darken(#FFFF00, 30%); --button-hover: darken(#FFCC32, 30%);
--header: #FFFF00; /* Use same as Header picker */ --header: #FFCC32; /* Use same as Header picker */
--text-main: #BBB; --text-main: #BBB;
--text-sub: #9b9b9b; --text-sub: #9b9b9b;
--link: #F0E68C; /* Use same as Header picker, lighten by 70% */ --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 { .bootstrap-table .fixed-table-container .table thead th .sortable {
color: var(--nav-link); color: var(--nav-link);
} }
.bootstrap-table .fixed-table-toolbar .columns label {
color:#000;
}
.thead, .navbar-nav>li>a:link { .thead, .navbar-nav>li>a:link {
color: var(--nav-link); color: var(--nav-link);
} }

View file

@ -463,6 +463,17 @@
</div> </div>
<div class="col-md-9"> <div class="col-md-9">
{{ \App\Helpers\Helper::getFormattedDateObject($user->created_at, 'datetime')['formatted']}} {{ \App\Helpers\Helper::getFormattedDateObject($user->created_at, 'datetime')['formatted']}}
@if ($user->createdBy)
by
@if ($user->createdBy->deleted_at=='')
<a href="{{ route('users.show', ['user' => $user->created_by]) }}">{{ $user->createdBy->present()->fullName }}</a>
@else
<del>{{ $user->createdBy->present()->fullName }}</del>
@endif
@endif
</div> </div>
</div> </div>
@endif @endif