mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
Merge pull request #15492 from snipe/fixes/edit_to_archived_warning
Some checks failed
Crowdin Action / upload-sources-to-crowdin (push) Has been cancelled
Docker images (Alpine) / docker (push) Has been cancelled
Docker images / docker (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Has been cancelled
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Has been cancelled
Some checks failed
Crowdin Action / upload-sources-to-crowdin (push) Has been cancelled
Docker images (Alpine) / docker (push) Has been cancelled
Docker images / docker (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Has been cancelled
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Has been cancelled
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Has been cancelled
Fix - warn user on changing status to undeployable when editing
This commit is contained in:
commit
8774da3921
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\Assets;
|
||||
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ImageUploadRequest;
|
||||
|
@ -330,14 +331,21 @@ class AssetsController extends Controller
|
|||
$asset->expected_checkin = $request->input('expected_checkin', null);
|
||||
|
||||
// If the box isn't checked, it's not in the request at all.
|
||||
$asset->requestable = $request->filled('requestable');
|
||||
$asset->requestable = $request->filled('requestable', 0);
|
||||
$asset->rtd_location_id = $request->input('rtd_location_id', null);
|
||||
$asset->byod = $request->input('byod', 0);
|
||||
|
||||
$status = Statuslabel::find($asset->status_id);
|
||||
$status = Statuslabel::find($request->input('status_id'));
|
||||
|
||||
if ($status && $status->archived) {
|
||||
// This is a non-deployable status label - we should check the asset back in.
|
||||
if (($status && $status->getStatuslabelType() != 'deployable') && ($target = $asset->assignedTo)) {
|
||||
|
||||
$originalValues = $asset->getRawOriginal();
|
||||
$asset->assigned_to = null;
|
||||
$asset->assigned_type = null;
|
||||
$asset->accepted = null;
|
||||
|
||||
event(new CheckoutableCheckedIn($asset, $target, auth()->user(), 'Checkin on asset update', date('Y-m-d H:i:s'), $originalValues));
|
||||
}
|
||||
|
||||
if ($asset->assigned_to == '') {
|
||||
|
|
|
@ -55,6 +55,7 @@ return [
|
|||
'asset_location_update_default' => 'Update only default location',
|
||||
'asset_location_update_actual' => 'Update only actual location',
|
||||
'asset_not_deployable' => 'That asset status is not deployable. This asset cannot be checked out.',
|
||||
'asset_not_deployable_checkin' => 'That asset status is not deployable. Using this status label will checkin the asset.',
|
||||
'asset_deployable' => 'That status is deployable. This asset can be checked out.',
|
||||
'processing_spinner' => 'Processing... (This might take a bit of time on large files)',
|
||||
'optional_infos' => 'Optional Information',
|
||||
|
|
|
@ -263,7 +263,7 @@
|
|||
$("#assignto_selector").hide();
|
||||
$("#selected_status_status").removeClass('text-success');
|
||||
$("#selected_status_status").addClass('text-danger');
|
||||
$("#selected_status_status").html('<x-icon type="warning" /> {{ trans('admin/hardware/form.asset_not_deployable')}} ');
|
||||
$("#selected_status_status").html('<x-icon type="warning" /> {{ (($item->assigned_to!='') && ($item->assigned_type!='') && ($item->deleted_at == '')) ? trans('admin/hardware/form.asset_not_deployable_checkin') : trans('admin/hardware/form.asset_not_deployable') }} ');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2,16 +2,20 @@
|
|||
|
||||
namespace Tests\Feature\Assets\Ui;
|
||||
|
||||
use App\Events\CheckoutableCheckedIn;
|
||||
use App\Models\Asset;
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\Location;
|
||||
use App\Models\StatusLabel;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EditAssetTest extends TestCase
|
||||
{
|
||||
|
||||
public function testPermissionRequiredToViewLicense()
|
||||
public function testPermissionRequiredToViewAsset()
|
||||
{
|
||||
$asset = Asset::factory()->create();
|
||||
$this->actingAs(User::factory()->create())
|
||||
|
@ -64,4 +68,38 @@ class EditAssetTest extends TestCase
|
|||
$this->assertDatabaseHas('assets', ['asset_tag' => 'New Asset Tag']);
|
||||
}
|
||||
|
||||
public function testNewCheckinIsLoggedIfStatusChangedToUndeployable()
|
||||
{
|
||||
Event::fake([CheckoutableCheckedIn::class]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
$deployable_status = Statuslabel::factory()->rtd()->create();
|
||||
$achived_status = Statuslabel::factory()->archived()->create();
|
||||
$asset = Asset::factory()->assignedToUser($user)->create(['status_id' => $deployable_status->id]);
|
||||
$this->assertTrue($asset->assignedTo->is($user));
|
||||
|
||||
$currentTimestamp = now();
|
||||
|
||||
$this->actingAs(User::factory()->viewAssets()->editAssets()->create())
|
||||
->from(route('hardware.edit', $asset->id))
|
||||
->put(route('hardware.update', $asset->id), [
|
||||
'status_id' => $achived_status->id,
|
||||
'model_id' => $asset->model_id,
|
||||
'asset_tags' => $asset->asset_tag,
|
||||
],
|
||||
)
|
||||
->assertStatus(302);
|
||||
//->assertRedirect(route('hardware.show', ['hardware' => $asset->id]));;
|
||||
|
||||
// $asset->refresh();
|
||||
$asset = Asset::find($asset->id);
|
||||
$this->assertNull($asset->assigned_to);
|
||||
$this->assertNull($asset->assigned_type);
|
||||
$this->assertEquals($achived_status->id, $asset->status_id);
|
||||
|
||||
Event::assertDispatched(function (CheckoutableCheckedIn $event) use ($currentTimestamp) {
|
||||
return Carbon::parse($event->action_date)->diffInSeconds($currentTimestamp) < 2;
|
||||
}, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue