Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,7 @@ static public function getRedirectOption($request, $id, $table, $item_id = null)
$redirect_option = Session::get('redirect_option');
$checkout_to_type = Session::get('checkout_to_type');
$checkedInFrom = Session::get('checkedInFrom');
$other_redirect = Session::get('other_redirect');

// return to index
if ($redirect_option == 'index') {
Expand Down Expand Up @@ -1535,6 +1536,16 @@ static public function getRedirectOption($request, $id, $table, $item_id = null)
return route('hardware.show', $request->assigned_asset ?? $checkedInFrom);
}
}

// return to somewhere else
if ($redirect_option == 'other_redirect') {
switch ($other_redirect) {
case 'audit':
return route('assets.audit.due');
}

}

return redirect()->back()->with('error', trans('admin/hardware/message.checkout.error'));
}

Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/Assets/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,10 @@ public function auditStore(UploadFileRequest $request, Asset $asset)

$this->authorize('audit', Asset::class);

session()->put('redirect_option', $request->get('redirect_option'));
session()->put('other_redirect', 'audit');


$originalValues = $asset->getRawOriginal();

$asset->next_audit_date = $request->input('next_audit_date');
Expand Down Expand Up @@ -974,7 +978,7 @@ public function auditStore(UploadFileRequest $request, Asset $asset)
}

$asset->logAudit($request->input('note'), $request->input('location_id'), $file_name, $originalValues);
return redirect()->route('assets.audit.due')->with('success', trans('admin/hardware/message.audit.success'));
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))->with('success', trans('admin/hardware/message.audit.success'));
}

return redirect()->back()->withInput()->withErrors($asset->getErrors());
Expand Down
19 changes: 12 additions & 7 deletions resources/views/hardware/audit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,18 @@


</div> <!--/.box-body-->
<div class="box-footer">
<a class="btn btn-link" href="{{ URL::previous() }}"> {{ trans('button.cancel') }}</a>
<button type="submit" class="btn btn-success pull-right{{ (!$asset->model ? ' disabled' : '') }}"{!! (!$asset->model ? ' data-tooltip="true" title="'.trans('admin/hardware/general.model_invalid_fix').'" disabled' : '') !!}>
<x-icon type="checkmark" />
{{ trans('general.audit') }}
</button>
</div>

<x-redirect_submit_options
index_route="hardware.index"
:button_label="trans('general.audit')"
:disabled_select="!$asset->model"
:options="[
'index' => trans('admin/hardware/form.redirect_to_all', ['type' => trans('general.assets')]),
'item' => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.asset')]),
'other_redirect' => trans('general.audit_due')
]"
/>

</form>
</div>
</div> <!--/.col-md-7-->
Expand Down
2 changes: 1 addition & 1 deletion resources/views/partials/bootstrap-table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function licenseKeyFormatter(value, row) {


function hardwareAuditFormatter(value, row) {
return '<a href="{{ config('app.url') }}/hardware/' + row.id + '/audit" class="btn btn-sm bg-yellow" data-tooltip="true" title="Audit this item">{{ trans('general.audit') }}</a>';
return '<a href="{{ config('app.url') }}/hardware/' + row.id + '/audit" class="actions btn btn-sm btn-primary" data-tooltip="true" title="{{ trans('general.audit') }}"><x-icon type="audit" /><span class="sr-only">{{ trans('general.audit') }}</span></a>&nbsp;';
}


Expand Down
45 changes: 41 additions & 4 deletions tests/Feature/Assets/Ui/AuditAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,50 @@ public function testPageCanBeAccessed(): void
->assertStatus(200);
}

public function testAssetCanBeAudited()
public function testAssetAuditPostIsRedirectedToAssetIndexIfRedirectSelectionIsIndex()
{
$response = $this->actingAs(User::factory()->auditAssets()->create())
->post(route('asset.audit.store', Asset::factory()->create()))
$asset = Asset::factory()->create();

$response = $this->actingAs(User::factory()->viewAssets()->editAssets()->auditAssets()->create())
->from(route('asset.audit.create', $asset))
->post(route('asset.audit.store', $asset),
[
'redirect_option' => 'index',
])
->assertStatus(302)
->assertRedirect(route('assets.audit.due'));
->assertRedirect(route('hardware.index'));
$this->followRedirects($response)->assertSee('success');

}

public function testAssetAuditPostIsRedirectedToAssetPageIfRedirectSelectionIsAsset()
{
$asset = Asset::factory()->create();

$response = $this->actingAs(User::factory()->viewAssets()->editAssets()->auditAssets()->create())
->from(route('asset.audit.create', $asset))
->post(route('asset.audit.store', $asset),
[
'redirect_option' => 'item',
])
->assertStatus(302)
->assertRedirect(route('hardware.show', $asset));
$this->followRedirects($response)->assertSee('success');
}

public function testAssetAuditPostIsRedirectedToAuditDuePageIfRedirectSelectionIsList()
{
$asset = Asset::factory()->create();

$response = $this->actingAs(User::factory()->viewAssets()->editAssets()->auditAssets()->create())
->from(route('asset.audit.create', $asset))
->post(route('asset.audit.store', $asset),
[
'redirect_option' => 'other_redirect',
])
->assertStatus(302)
->assertRedirect(route('assets.audit.due'));
$this->followRedirects($response)->assertSee('success');
}

}
Loading