alright, in a working place

This commit is contained in:
spencerrlongg 2024-05-07 14:08:47 -05:00
parent e177993bcc
commit 17ef20ea92
3 changed files with 11 additions and 15 deletions

View file

@ -13,6 +13,7 @@ use App\Models\Setting;
use App\View\Label; use App\View\Label;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Session;
@ -189,13 +190,11 @@ class BulkAssetsController extends Controller
* Save bulk edits * Save bulk edits
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @return Redirect
* @internal param array $assets * @internal param array $assets
* @since [v2.0] * @since [v2.0]
*/ */
public function update(Request $request) public function update(Request $request)
{ {
//dd($request->all());
$this->authorize('update', Asset::class); $this->authorize('update', Asset::class);
$has_errors = 0; $has_errors = 0;
$error_array = array(); $error_array = array();
@ -390,7 +389,7 @@ class BulkAssetsController extends Controller
* but it wasn't. * but it wasn't.
*/ */
if ($decrypted_old != $this->update_array[$field->db_column]) { 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 { } else {
/* /*
* Remove the encrypted custom field from the update_array, since nothing changed * Remove the encrypted custom field from the update_array, since nothing changed

View file

@ -56,10 +56,8 @@ class CustomFieldsetFactory extends Factory
public function hasMultipleCustomFields(array $fields = null): self public function hasMultipleCustomFields(array $fields = null): self
{ {
return $this->afterCreating(function (CustomFieldset $fieldset) { return $this->afterCreating(function (CustomFieldset $fieldset) use ($fields) {
if (empty($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(); $mac_address = CustomField::factory()->macAddress()->create();
$ram = CustomField::factory()->ram()->create(); $ram = CustomField::factory()->ram()->create();
$cpu = CustomField::factory()->cpu()->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($mac_address, ['order' => '1', 'required' => false]);
$fieldset->fields()->attach($ram, ['order' => '2', 'required' => false]); $fieldset->fields()->attach($ram, ['order' => '2', 'required' => false]);
$fieldset->fields()->attach($cpu, ['order' => '3', 'required' => false]); $fieldset->fields()->attach($cpu, ['order' => '3', 'required' => false]);
});
} else { } else {
foreach ($fields as $field) { foreach ($fields as $field) {
$fieldset->fields()->attach($field, ['order' => '1', 'required' => false]); $fieldset->fields()->attach($field, ['order' => '1', 'required' => false]);

View file

@ -82,19 +82,19 @@ class AssetsBulkEditTest extends TestCase
{ {
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL'); $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
$mac_address = CustomField::factory()->macAddress()->create(); CustomField::factory()->macAddress()->create();
$ram = CustomField::factory()->ram()->create(); CustomField::factory()->ram()->create();
$cpu = CustomField::factory()->cpu()->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([ $assets = Asset::factory()->count(10)->hasMultipleCustomFields([$mac_address, $ram, $cpu])->create([
$ram->db_column => 8, $ram->db_column => 8,
$cpu->db_column => '2.1', $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(); $id_array = $assets->pluck('id')->toArray();
$this->actingAs(User::factory()->editAssets()->create())->post(route('hardware/bulksave'), [ $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) { Asset::findMany($id_array)->each(function (Asset $asset) use ($ram, $cpu, $mac_address) {
$this->assertEquals(16, $asset->{$ram->db_column}); $this->assertEquals(16, $asset->{$ram->db_column});
$this->assertEquals('4.1', $asset->{$ram->db_column}); $this->assertEquals('4.1', $asset->{$cpu->db_column});
}); });
} }
} }