Merge remote-tracking branch 'origin/develop'

This commit is contained in:
snipe 2023-03-30 14:37:47 -07:00
commit 048be49c14
13 changed files with 126 additions and 19 deletions

View file

@ -463,7 +463,7 @@ class AssetsController extends Controller
{
$this->authorize('view', Asset::class);
$this->authorize('view', License::class);
$asset = Asset::where('id', $id)->withTrashed()->first();
$asset = Asset::where('id', $id)->withTrashed()->firstorfail();
$licenses = $asset->licenses()->get();
return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count());

View file

@ -49,6 +49,7 @@ class BulkAssetsController extends Controller
->with('settings', Setting::getSettings())
->with('bulkedit', true)
->with('count', 0);
case 'delete':
$assets = Asset::with('assignedTo', 'location')->find($asset_ids);
$assets->each(function ($asset) {
@ -56,6 +57,15 @@ class BulkAssetsController extends Controller
});
return view('hardware/bulk-delete')->with('assets', $assets);
case 'restore':
$assets = Asset::withTrashed()->find($asset_ids);
$assets->each(function ($asset) {
$this->authorize('delete', $asset);
});
return view('hardware/bulk-restore')->with('assets', $assets);
case 'edit':
return view('hardware/bulk')
->with('assets', $asset_ids)
@ -320,5 +330,18 @@ class BulkAssetsController extends Controller
} catch (ModelNotFoundException $e) {
return redirect()->route('hardware.bulkcheckout.show')->with('error', $e->getErrors());
}
}
public function restore(Request $request) {
$assetIds = $request->get('ids');
if (empty($assetIds)) {
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.restore.nothing_updated'));
} else {
foreach ($assetIds as $key => $assetId) {
$asset = Asset::withTrashed()->find($assetId);
$asset->restore();
}
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.restore.success'));
}
}
}

View file

@ -60,7 +60,7 @@ class AssetImporter extends ItemImporter
$asset_tag = Asset::autoincrement_asset();
}
$asset = Asset::where(['asset_tag'=> $asset_tag])->first();
$asset = Asset::where(['asset_tag'=> (string) $asset_tag])->first();
if ($asset) {
if (! $this->updating) {
$this->log('A matching Asset '.$asset_tag.' already exists');

View file

@ -2,8 +2,11 @@
return [
'bulk_delete' => 'Confirm Bulk Delete Assets',
'bulk_restore' => 'Confirm Bulk Restore Assets',
'bulk_delete_help' => 'Review the assets for bulk deletion below. Once deleted, these assets can be restored, but they will no longer be associated with any users they are currently assigned to.',
'bulk_restore_help' => 'Review the assets for bulk restoration below. Once restored, these assets will not be associated with any users they were previously assigned to.',
'bulk_delete_warn' => 'You are about to delete :asset_count assets.',
'bulk_restore_warn' => 'You are about to restore :asset_count assets.',
'bulk_update' => 'Bulk Update Assets',
'bulk_update_help' => 'This form allows you to update multiple assets at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged. ',
'bulk_update_warn' => 'You are about to edit the properties of a single asset.|You are about to edit the properties of :asset_count assets.',

View file

@ -23,6 +23,8 @@ return [
'restore' => [
'error' => 'Asset was not restored, please try again',
'success' => 'Asset restored successfully.',
'bulk_success' => 'Asset restored successfully.',
'nothing_updated' => 'No assets were selected, so nothing was restored.',
],
'audit' => [

View file

@ -422,6 +422,8 @@ return [
'merged_log_this_user_from' => 'Merged user ID :from_id (:from_username) into this user (ID :to_id - :to_username)',
'clear_and_save' => 'Clear & Save',
'update_existing_values' => 'Update Existing Values?',
'auto_incrementing_asset_tags_disabled_so_tags_required' => 'Generating auto-incrementing asset tags is disabled so all rows need to have the "Asset Tag" column populated.',
'auto_incrementing_asset_tags_enabled_so_now_assets_will_be_created' => 'Note: Generating auto-incrementing asset tags is enabled so assets will be created for rows that do not have "Asset Tag" populated. Rows that do have "Asset Tag" populated will be updated with the provided information.',
'send_welcome_email_to_users' => ' Send Welcome Email for new Users?',
'back_before_importing' => 'Backup before importing?',
'csv_header_field' => 'CSV Header Field',

View file

@ -2,7 +2,7 @@
{{-- Page title --}}
@section('title')
{{ trans('general.accept_assets', array('name' => $user->present()->fullName())) }}
{{ trans('general.accept_assets', array('name' => empty($user) ? '' : $user->present()->full_name)) }}
@parent
@stop

View file

@ -0,0 +1,62 @@
@extends('layouts/default')
{{-- Page title --}}
@section('title')
{{ trans('admin/hardware/form.bulk_restore') }}
@parent
@stop
@section('header_right')
<a href="{{ URL::previous() }}" class="btn btn-primary pull-right">
{{ trans('general.back') }}</a>
@stop
{{-- Page content --}}
@section('content')
<div class="row">
<!-- left column -->
<div class="col-md-12">
<p>{{ trans('admin/hardware/form.bulk_restore_help') }}</p>
<form class="form-horizontal" method="post" action="{{ route('hardware/bulkrestore') }}" autocomplete="off" role="form">
{{csrf_field()}}
<div class="box box-default">
<div class="box-header with-border">
<h2 class="box-title" style="color: red">{{ trans('admin/hardware/form.bulk_restore_warn', ['asset_count' => count($assets)]) }}</h2>
</div>
<div class="box-body">
<table class="table table-striped table-condensed">
<thead>
<tr>
<td></td>
<td>{{ trans('admin/hardware/table.id') }}</td>
<td>{{ trans('admin/hardware/table.name') }}</td>
<td>{{ trans('admin/hardware/table.location')}}</td>
</tr>
</thead>
<tbody>
@foreach ($assets as $asset)
<tr>
<td><input type="checkbox" name="ids[]" value="{{ $asset->id }}" checked="checked"></td>
<td>{{ $asset->id }}</td>
<td>{{ $asset->present()->name() }}</td>
<td>
@if ($asset->location)
{{ $asset->location->name }}
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div><!-- /.box-body -->
<div class="box-footer text-right">
<a class="btn btn-link" href="{{ URL::previous() }}" method="post" enctype="multipart/form-data">{{ trans('button.cancel') }}</a>
<button type="submit" class="btn btn-success" id="submit-button"><i class="fas fa-check icon-white" aria-hidden="true"></i> {{ trans('button.restore') }}</button>
</div><!-- /.box-footer -->
</div><!-- /.box -->
</form>
</div> <!-- .col-md-12-->
</div><!--.row-->
@stop

View file

@ -63,13 +63,7 @@
<div class="row">
<div class="col-md-12">
@if (Request::get('status')!='Deleted')
@include('partials.asset-bulk-actions')
@endif
@include('partials.asset-bulk-actions', ['status' => Request::get('status')])
<table
data-advanced-search="true"

View file

@ -597,7 +597,7 @@
@if ($asset->serial && $asset->model->manufacturer)
@if ((strtolower($asset->model->manufacturer->name) == "apple") || (str_starts_with(str_replace(' ','',strtolower($asset->model->manufacturer->name)),"appleinc")))
<a href="https://checkcoverage.apple.com/us/{{ \App\Models\Setting::getSettings()->locale }}/?sn={{ $asset->serial }}" target="_blank">
<a href="https://checkcoverage.apple.com/?locale={{ (str_replace('-','_',\App\Models\Setting::getSettings()->locale)) }}" target="_blank">
<i class="fa-brands fa-apple" aria-hidden="true"><span class="sr-only">{{ trans('hardware/general.mfg_warranty_lookup') }}</span></i>
</a>
@elseif ((strtolower($asset->model->manufacturer->name) == "dell") || (str_starts_with(str_replace(' ','',strtolower($asset->model->manufacturer->name)),"dellinc")))

View file

@ -156,26 +156,36 @@
'data-minimum-results-for-search' => '-1', // Remove this if the list gets long enough that we need to search
'data-livewire-component' => $_instance->id
]) }}
@if ($activeFile->import_type === 'asset' && $snipeSettings->auto_increment_assets == 0)
<span class="help-block">
{{ trans('general.auto_incrementing_asset_tags_disabled_so_tags_required') }}
</span>
@endif
</div>
</div>
<div class="form-group col-md-12">
<label for="update" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
<input type="checkbox" class="minimal livewire-icheck" name="update" data-livewire-component="{{ $_instance->id }}">
<label for="update" class="col-md-9 col-md-offset-3 col-xs-12">
<input type="checkbox" class="minimal livewire-icheck" name="update" data-livewire-component="{{ $_instance->id }}" wire:model="update">
{{ trans('general.update_existing_values') }}
@if ($activeFile->import_type === 'asset' && $snipeSettings->auto_increment_assets == 1 && $update)
<span class="help-block">
{{ trans('general.auto_incrementing_asset_tags_enabled_so_now_assets_will_be_created') }}
</span>
@endif
</label>
</div>
<div class="form-group col-md-12">
<label for="send_welcome" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
<input type="checkbox" class="minimal livewire-icheck" name="send_welcome" data-livewire-component="{{ $_instance->id }}">
<label for="send_welcome" class="col-md-9 col-md-offset-3 col-xs-12">
<input type="checkbox" class="minimal livewire-icheck" name="send_welcome" data-livewire-component="{{ $_instance->id }}" wire:model="send_welcome">
{{ trans('general.send_welcome_email_to_users') }}
</label>
</div>
<div class="form-group col-md-12">
<label for="run_backup" class="col-md-9 col-md-offset-3 col-xs-12" wire:ignore>
<input type="checkbox" class="minimal livewire-icheck" name="run_backup" data-livewire-component="{{ $_instance->id }}">
<label for="run_backup" class="col-md-9 col-md-offset-3 col-xs-12">
<input type="checkbox" class="minimal livewire-icheck" name="run_backup" data-livewire-component="{{ $_instance->id }}" wire:model="run_backup">
{{ trans('general.back_before_importing') }}
</label>
</div>

View file

@ -13,6 +13,11 @@
</span>
</label>
<select name="bulk_actions" class="form-control select2" aria-label="bulk_actions" style="min-width: 350px;">
@if($status ?? '' == 'Deleted')
@can('delete', \App\Models\Asset::class)
<option value="restore">{{trans('button.restore')}}</option>
@endcan
@else
@can('update', \App\Models\Asset::class)
<option value="edit">{{ trans('button.edit') }}</option>
@endcan
@ -20,6 +25,7 @@
<option value="delete">{{ trans('button.delete') }}</option>
@endcan
<option value="labels" accesskey="l">{{ trans_choice('button.generate_labels', 2) }}</option>
@endif
</select>
<button class="btn btn-primary" id="{{ (isset($id_button)) ? $id_button : 'bulkAssetEditButton' }}" disabled>{{ trans('button.go') }}</button>

View file

@ -160,6 +160,11 @@ Route::group(
[BulkAssetsController::class, 'destroy']
)->name('hardware/bulkdelete');
Route::post(
'bulkrestore',
[BulkAssetsController::class, 'restore']
)->name('hardware/bulkrestore');
Route::post(
'bulksave',
[BulkAssetsController::class, 'update']