Merge pull request #11542 from snipe/features/users_checkin_without_delete
Features/users checkin without delete
This commit is contained in:
commit
5926441984
5 changed files with 51 additions and 18 deletions
|
@ -5,10 +5,13 @@ namespace App\Http\Controllers\Users;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Accessory;
|
use App\Models\Accessory;
|
||||||
|
use App\Models\License;
|
||||||
use App\Models\Actionlog;
|
use App\Models\Actionlog;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\Group;
|
use App\Models\Group;
|
||||||
use App\Models\LicenseSeat;
|
use App\Models\LicenseSeat;
|
||||||
|
use App\Models\ConsumableAssignment;
|
||||||
|
use App\Models\Consumable;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
@ -162,13 +165,11 @@ class BulkUsersController extends Controller
|
||||||
if ((! $request->filled('ids')) || (count($request->input('ids')) == 0)) {
|
if ((! $request->filled('ids')) || (count($request->input('ids')) == 0)) {
|
||||||
return redirect()->back()->with('error', 'No users selected');
|
return redirect()->back()->with('error', 'No users selected');
|
||||||
}
|
}
|
||||||
if ((! $request->filled('status_id')) || ($request->input('status_id') == '')) {
|
|
||||||
return redirect()->route('users.index')->with('error', 'No status selected');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config('app.lock_passwords')) {
|
if (config('app.lock_passwords')) {
|
||||||
return redirect()->route('users.index')->with('error', 'Bulk delete is not enabled in this installation');
|
return redirect()->route('users.index')->with('error', 'Bulk delete is not enabled in this installation');
|
||||||
}
|
}
|
||||||
|
|
||||||
$user_raw_array = request('ids');
|
$user_raw_array = request('ids');
|
||||||
|
|
||||||
if (($key = array_search(Auth::id(), $user_raw_array)) !== false) {
|
if (($key = array_search(Auth::id(), $user_raw_array)) !== false) {
|
||||||
|
@ -179,11 +180,18 @@ class BulkUsersController extends Controller
|
||||||
$assets = Asset::whereIn('assigned_to', $user_raw_array)->where('assigned_type', \App\Models\User::class)->get();
|
$assets = Asset::whereIn('assigned_to', $user_raw_array)->where('assigned_type', \App\Models\User::class)->get();
|
||||||
$accessories = DB::table('accessories_users')->whereIn('assigned_to', $user_raw_array)->get();
|
$accessories = DB::table('accessories_users')->whereIn('assigned_to', $user_raw_array)->get();
|
||||||
$licenses = DB::table('license_seats')->whereIn('assigned_to', $user_raw_array)->get();
|
$licenses = DB::table('license_seats')->whereIn('assigned_to', $user_raw_array)->get();
|
||||||
|
$consumables = DB::table('consumables_users')->whereIn('assigned_to', $user_raw_array)->get();
|
||||||
|
|
||||||
|
if ((($assets->count() > 0) && ((!$request->filled('status_id')) || ($request->input('status_id') == '')))) {
|
||||||
|
return redirect()->route('users.index')->with('error', 'No status selected');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->logItemCheckinAndDelete($assets, Asset::class);
|
$this->logItemCheckinAndDelete($assets, Asset::class);
|
||||||
$this->logItemCheckinAndDelete($accessories, Accessory::class);
|
$this->logItemCheckinAndDelete($accessories, Accessory::class);
|
||||||
$this->logItemCheckinAndDelete($licenses, LicenseSeat::class);
|
$this->logItemCheckinAndDelete($licenses, License::class);
|
||||||
|
$this->logItemCheckinAndDelete($consumables, Consumable::class);
|
||||||
|
|
||||||
|
|
||||||
Asset::whereIn('id', $assets->pluck('id'))->update([
|
Asset::whereIn('id', $assets->pluck('id'))->update([
|
||||||
'status_id' => e(request('status_id')),
|
'status_id' => e(request('status_id')),
|
||||||
|
@ -193,13 +201,26 @@ class BulkUsersController extends Controller
|
||||||
|
|
||||||
|
|
||||||
LicenseSeat::whereIn('id', $licenses->pluck('id'))->update(['assigned_to' => null]);
|
LicenseSeat::whereIn('id', $licenses->pluck('id'))->update(['assigned_to' => null]);
|
||||||
|
ConsumableAssignment::whereIn('id', $consumables->pluck('id'))->delete();
|
||||||
|
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
|
|
||||||
|
$user->consumables()->sync([]);
|
||||||
$user->accessories()->sync([]);
|
$user->accessories()->sync([]);
|
||||||
|
if ($request->input('delete_user')=='1') {
|
||||||
$user->delete();
|
$user->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('users.index')->with('success', 'Your selected users have been deleted and their assets have been updated.');
|
}
|
||||||
|
|
||||||
|
$msg = trans('general.bulk_checkin_success');
|
||||||
|
if ($request->input('delete_user')=='1') {
|
||||||
|
$msg = trans('general.bulk_checkin_delete_success');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return redirect()->route('users.index')->with('success', $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -217,7 +238,7 @@ class BulkUsersController extends Controller
|
||||||
$logAction->target_id = $item->assigned_to;
|
$logAction->target_id = $item->assigned_to;
|
||||||
$logAction->target_type = User::class;
|
$logAction->target_type = User::class;
|
||||||
$logAction->user_id = Auth::id();
|
$logAction->user_id = Auth::id();
|
||||||
$logAction->note = 'Bulk checkin items and delete user';
|
$logAction->note = 'Bulk checkin items';
|
||||||
$logAction->logaction('checkin from');
|
$logAction->logaction('checkin from');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ return [
|
||||||
'admin_permission_warning' => 'Only users with admins rights or greater may grant a user admin access.',
|
'admin_permission_warning' => 'Only users with admins rights or greater may grant a user admin access.',
|
||||||
'remove_group_memberships' => 'Remove Group Memberships',
|
'remove_group_memberships' => 'Remove Group Memberships',
|
||||||
'warning_deletion' => 'WARNING:',
|
'warning_deletion' => 'WARNING:',
|
||||||
'warning_deletion_information' => 'You are about to delete the :count user(s) listed below. Super admin names are highlighted in red.',
|
'warning_deletion_information' => 'You are about to checkin ALL items from the :count user(s) listed below. Super admin names are highlighted in red.',
|
||||||
'update_user_assets_status' => 'Update all assets for these users to this status',
|
'update_user_assets_status' => 'Update all assets for these users to this status',
|
||||||
'checkin_user_properties' => 'Check in all properties associated with these users',
|
'checkin_user_properties' => 'Check in all properties associated with these users',
|
||||||
'remote_label' => 'This is a remote user',
|
'remote_label' => 'This is a remote user',
|
||||||
|
|
|
@ -4,7 +4,7 @@ return [
|
||||||
'actions' => 'Actions',
|
'actions' => 'Actions',
|
||||||
'add' => 'Add New',
|
'add' => 'Add New',
|
||||||
'cancel' => 'Cancel',
|
'cancel' => 'Cancel',
|
||||||
'checkin_and_delete' => 'Checkin & Delete User',
|
'checkin_and_delete' => 'Checkin All / Delete User',
|
||||||
'delete' => 'Delete',
|
'delete' => 'Delete',
|
||||||
'edit' => 'Edit',
|
'edit' => 'Edit',
|
||||||
'restore' => 'Restore',
|
'restore' => 'Restore',
|
||||||
|
|
|
@ -37,7 +37,7 @@ return [
|
||||||
'bulk_edit' => 'Bulk Edit',
|
'bulk_edit' => 'Bulk Edit',
|
||||||
'bulk_delete' => 'Bulk Delete',
|
'bulk_delete' => 'Bulk Delete',
|
||||||
'bulk_actions' => 'Bulk Actions',
|
'bulk_actions' => 'Bulk Actions',
|
||||||
'bulk_checkin_delete' => 'Bulk Checkin & Delete',
|
'bulk_checkin_delete' => 'Bulk Checkin Items from Users',
|
||||||
'bystatus' => 'by Status',
|
'bystatus' => 'by Status',
|
||||||
'cancel' => 'Cancel',
|
'cancel' => 'Cancel',
|
||||||
'categories' => 'Categories',
|
'categories' => 'Categories',
|
||||||
|
@ -365,5 +365,9 @@ return [
|
||||||
'backup_delete_not_allowed' => 'Deleting backups has been disabled in the .env file. Contact support or your systems administrator.',
|
'backup_delete_not_allowed' => 'Deleting backups has been disabled in the .env file. Contact support or your systems administrator.',
|
||||||
'additional_files' => 'Additional Files',
|
'additional_files' => 'Additional Files',
|
||||||
'shitty_browser' => 'No signature detected. If you are using an older browser, please use a more modern browser to complete your asset acceptance.',
|
'shitty_browser' => 'No signature detected. If you are using an older browser, please use a more modern browser to complete your asset acceptance.',
|
||||||
|
'bulk_soft_delete' =>'Also soft-delete these users. Their asset history will remain intact unless/until you purge deleted records in the Admin Settings.',
|
||||||
|
'bulk_checkin_delete_success' => 'Your selected users have been deleted and their items have been checked in.',
|
||||||
|
'bulk_checkin_success' => 'The items for the selected users have been checked in.',
|
||||||
|
|
||||||
|
|
||||||
];
|
];
|
|
@ -26,7 +26,7 @@
|
||||||
@if (config('app.lock_passwords'))
|
@if (config('app.lock_passwords'))
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="callout callout-warning">
|
<div class="callout callout-warning">
|
||||||
<p>{{ trans('feature_disabled') }}</p>
|
<p>{{ trans('general.feature_disabled') }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
@ -42,6 +42,7 @@
|
||||||
<th class="col-md-5">{{ trans('general.assets') }}</th>
|
<th class="col-md-5">{{ trans('general.assets') }}</th>
|
||||||
<th class="col-md-5">{{ trans('general.accessories') }}</th>
|
<th class="col-md-5">{{ trans('general.accessories') }}</th>
|
||||||
<th class="col-md-5">{{ trans('general.licenses') }}</th>
|
<th class="col-md-5">{{ trans('general.licenses') }}</th>
|
||||||
|
<th class="col-md-5">{{ trans('general.consumables') }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -49,14 +50,14 @@
|
||||||
<tr {!! ($user->isSuperUser() ? ' class="danger"':'') !!}>
|
<tr {!! ($user->isSuperUser() ? ' class="danger"':'') !!}>
|
||||||
<td>
|
<td>
|
||||||
@if (Auth::id()!=$user->id)
|
@if (Auth::id()!=$user->id)
|
||||||
<input type="checkbox" name="ids[]" value="{{ $user->id }}" checked="checked">
|
<input type="checkbox" name="ids[]" value="{{ $user->id }}" class="minimal" checked="checked">
|
||||||
@else
|
@else
|
||||||
<input type="checkbox" name="ids[]" value="{{ $user->id }}" disabled>
|
<input type="checkbox" name="ids[]" value="{{ $user->id }}" class="minimal" disabled>
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<span {{ (Auth::user()->id==$user->id ? ' style="text-decoration: line-through"' : '') }}>
|
<span {!! (Auth::user()->id==$user->id ? ' style="text-decoration: line-through"' : '') !!}>
|
||||||
{{ $user->present()->fullName() }} ({{ $user->username }})
|
{{ $user->present()->fullName() }} ({{ $user->username }})
|
||||||
</span>
|
</span>
|
||||||
{{ (Auth::id()==$user->id ? ' (cannot delete yourself)' : '') }}
|
{{ (Auth::id()==$user->id ? ' (cannot delete yourself)' : '') }}
|
||||||
|
@ -77,19 +78,26 @@
|
||||||
<td>
|
<td>
|
||||||
{{ number_format($user->licenses()->count()) }}
|
{{ number_format($user->licenses()->count()) }}
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ number_format($user->consumables()->count()) }}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="warning">
|
<td colspan="7">
|
||||||
{{ Form::select('status_id', $statuslabel_list , Request::old('status_id'), array('class'=>'select2', 'style'=>'width:250px')) }}
|
{{ Form::select('status_id', $statuslabel_list , Request::old('status_id'), array('class'=>'select2', 'style'=>'width:250px')) }}
|
||||||
<label>{{ trans('admin/users/general.update_user_assets_status') }}</label></label>
|
<label>{{ trans('admin/users/general.update_user_assets_status') }}</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="warning">
|
<td colspan="7" class="text-danger">
|
||||||
<label><input type="checkbox" name="ids['.e($user->id).']" checked>{{ trans('admin/users/general.checkin_user_properties') }}</label>
|
<label>
|
||||||
|
<input type="checkbox" name="delete_user" value="1" class="minimal">
|
||||||
|
<i class="fa fa-warning text-danger"></i> {{ trans('general.bulk_soft_delete') }}
|
||||||
|
</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
|
|
Loading…
Add table
Reference in a new issue