mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
alright, in a working place
This commit is contained in:
parent
e177993bcc
commit
17ef20ea92
|
@ -13,6 +13,7 @@ use App\Models\Setting;
|
|||
use App\View\Label;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
@ -189,13 +190,11 @@ class BulkAssetsController extends Controller
|
|||
* Save bulk edits
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @return Redirect
|
||||
* @internal param array $assets
|
||||
* @since [v2.0]
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
//dd($request->all());
|
||||
$this->authorize('update', Asset::class);
|
||||
$has_errors = 0;
|
||||
$error_array = array();
|
||||
|
@ -390,7 +389,7 @@ class BulkAssetsController extends Controller
|
|||
* but it wasn't.
|
||||
*/
|
||||
if ($decrypted_old != $this->update_array[$field->db_column]) {
|
||||
$asset->{$field->db_column} = \Crypt::encrypt($this->update_array[$field->db_column]);
|
||||
$asset->{$field->db_column} = Crypt::encrypt($this->update_array[$field->db_column]);
|
||||
} else {
|
||||
/*
|
||||
* Remove the encrypted custom field from the update_array, since nothing changed
|
||||
|
|
|
@ -56,10 +56,8 @@ class CustomFieldsetFactory extends Factory
|
|||
|
||||
public function hasMultipleCustomFields(array $fields = null): self
|
||||
{
|
||||
return $this->afterCreating(function (CustomFieldset $fieldset) {
|
||||
return $this->afterCreating(function (CustomFieldset $fieldset) use ($fields) {
|
||||
if (empty($fields)) {
|
||||
//why are there two after creating and why does it break if i remove one
|
||||
return $this->afterCreating(function (CustomFieldset $fieldset) {
|
||||
$mac_address = CustomField::factory()->macAddress()->create();
|
||||
$ram = CustomField::factory()->ram()->create();
|
||||
$cpu = CustomField::factory()->cpu()->create();
|
||||
|
@ -67,7 +65,6 @@ class CustomFieldsetFactory extends Factory
|
|||
$fieldset->fields()->attach($mac_address, ['order' => '1', 'required' => false]);
|
||||
$fieldset->fields()->attach($ram, ['order' => '2', 'required' => false]);
|
||||
$fieldset->fields()->attach($cpu, ['order' => '3', 'required' => false]);
|
||||
});
|
||||
} else {
|
||||
foreach ($fields as $field) {
|
||||
$fieldset->fields()->attach($field, ['order' => '1', 'required' => false]);
|
||||
|
|
|
@ -82,19 +82,19 @@ class AssetsBulkEditTest extends TestCase
|
|||
{
|
||||
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
|
||||
|
||||
$mac_address = CustomField::factory()->macAddress()->create();
|
||||
$ram = CustomField::factory()->ram()->create();
|
||||
$cpu = CustomField::factory()->cpu()->create();
|
||||
CustomField::factory()->macAddress()->create();
|
||||
CustomField::factory()->ram()->create();
|
||||
CustomField::factory()->cpu()->create();
|
||||
|
||||
$mac_address = CustomField::where('name', 'MAC Address')->first();
|
||||
$ram = CustomField::where('name', 'RAM')->first();
|
||||
$cpu = CustomField::where('name', 'CPU')->first();
|
||||
|
||||
$assets = Asset::factory()->count(10)->hasMultipleCustomFields([$mac_address, $ram, $cpu])->create([
|
||||
$ram->db_column => 8,
|
||||
$cpu->db_column => '2.1',
|
||||
]);
|
||||
|
||||
// seems like the fieldset is random, so bulkedit isn't working because assets don't have the "correct" fieldset
|
||||
// look into more tomorrow
|
||||
dd(Asset::find(1)->model->fieldset);
|
||||
|
||||
$id_array = $assets->pluck('id')->toArray();
|
||||
|
||||
$this->actingAs(User::factory()->editAssets()->create())->post(route('hardware/bulksave'), [
|
||||
|
@ -105,7 +105,7 @@ class AssetsBulkEditTest extends TestCase
|
|||
|
||||
Asset::findMany($id_array)->each(function (Asset $asset) use ($ram, $cpu, $mac_address) {
|
||||
$this->assertEquals(16, $asset->{$ram->db_column});
|
||||
$this->assertEquals('4.1', $asset->{$ram->db_column});
|
||||
$this->assertEquals('4.1', $asset->{$cpu->db_column});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue