mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Merge remote-tracking branch 'origin/develop'
Some checks are pending
CodeQL Security Scan / CodeQL Security Scan (javascript) (push) Waiting to run
Codacy Security Scan / Codacy Security Scan (push) Waiting to run
Docker images (Alpine) / docker (push) Waiting to run
Docker images / docker (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Waiting to run
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Waiting to run
Some checks are pending
CodeQL Security Scan / CodeQL Security Scan (javascript) (push) Waiting to run
Codacy Security Scan / Codacy Security Scan (push) Waiting to run
Docker images (Alpine) / docker (push) Waiting to run
Docker images / docker (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Waiting to run
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Waiting to run
This commit is contained in:
commit
1328366a48
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Assets;
|
namespace App\Http\Controllers\Assets;
|
||||||
|
|
||||||
|
use App\Events\CheckoutableCheckedIn;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\ImageUploadRequest;
|
use App\Http\Requests\ImageUploadRequest;
|
||||||
|
@ -330,14 +331,21 @@ class AssetsController extends Controller
|
||||||
$asset->expected_checkin = $request->input('expected_checkin', null);
|
$asset->expected_checkin = $request->input('expected_checkin', null);
|
||||||
|
|
||||||
// If the box isn't checked, it's not in the request at all.
|
// 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->rtd_location_id = $request->input('rtd_location_id', null);
|
||||||
$asset->byod = $request->input('byod', 0);
|
$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_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 == '') {
|
if ($asset->assigned_to == '') {
|
||||||
|
|
|
@ -55,6 +55,7 @@ return [
|
||||||
'asset_location_update_default' => 'Update only default location',
|
'asset_location_update_default' => 'Update only default location',
|
||||||
'asset_location_update_actual' => 'Update only actual 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' => '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.',
|
'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)',
|
'processing_spinner' => 'Processing... (This might take a bit of time on large files)',
|
||||||
'optional_infos' => 'Optional Information',
|
'optional_infos' => 'Optional Information',
|
||||||
|
|
|
@ -263,7 +263,7 @@
|
||||||
$("#assignto_selector").hide();
|
$("#assignto_selector").hide();
|
||||||
$("#selected_status_status").removeClass('text-success');
|
$("#selected_status_status").removeClass('text-success');
|
||||||
$("#selected_status_status").addClass('text-danger');
|
$("#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;
|
namespace Tests\Feature\Assets\Ui;
|
||||||
|
|
||||||
|
use App\Events\CheckoutableCheckedIn;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\AssetModel;
|
use App\Models\AssetModel;
|
||||||
|
use App\Models\Location;
|
||||||
use App\Models\StatusLabel;
|
use App\Models\StatusLabel;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class EditAssetTest extends TestCase
|
class EditAssetTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testPermissionRequiredToViewLicense()
|
public function testPermissionRequiredToViewAsset()
|
||||||
{
|
{
|
||||||
$asset = Asset::factory()->create();
|
$asset = Asset::factory()->create();
|
||||||
$this->actingAs(User::factory()->create())
|
$this->actingAs(User::factory()->create())
|
||||||
|
@ -64,4 +68,38 @@ class EditAssetTest extends TestCase
|
||||||
$this->assertDatabaseHas('assets', ['asset_tag' => 'New Asset Tag']);
|
$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