mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Merge pull request #15356 from snipe/validate_location_parent
Fixed #15341 - validate parent ID
This commit is contained in:
commit
d0acf5b8a6
|
@ -33,7 +33,7 @@ class Location extends SnipeModel
|
||||||
'country' => 'min:2|max:191|nullable',
|
'country' => 'min:2|max:191|nullable',
|
||||||
'zip' => 'max:10|nullable',
|
'zip' => 'max:10|nullable',
|
||||||
'manager_id' => 'exists:users,id|nullable',
|
'manager_id' => 'exists:users,id|nullable',
|
||||||
'parent_id' => 'non_circular:locations,id',
|
'parent_id' => 'nullable|exists:locations,id|non_circular:locations,id',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
|
|
@ -32,6 +32,20 @@ class CreateLocationsTest extends TestCase
|
||||||
|
|
||||||
$this->assertTrue(Location::where('name', 'Test Location')->exists());
|
$this->assertTrue(Location::where('name', 'Test Location')->exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUserCannotCreateLocationsWithInvalidParent()
|
||||||
|
{
|
||||||
|
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->superuser()->create())
|
||||||
|
->from(route('locations.create'))
|
||||||
|
->post(route('locations.store'), [
|
||||||
|
'name' => 'Test Location',
|
||||||
|
'parent_id' => '100000000'
|
||||||
|
])
|
||||||
|
->assertRedirect(route('locations.create'));
|
||||||
|
|
||||||
|
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,21 @@ class UpdateLocationsTest extends TestCase
|
||||||
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUserCannotEditLocationsWithInvalidParent()
|
||||||
|
{
|
||||||
|
$location = Location::factory()->create();
|
||||||
|
$response = $this->actingAs(User::factory()->superuser()->create())
|
||||||
|
->from(route('locations.edit', ['location' => $location->id]))
|
||||||
|
->put(route('locations.update', ['location' => $location]), [
|
||||||
|
'name' => 'Test Location',
|
||||||
|
'parent_id' => '100000000'
|
||||||
|
])
|
||||||
|
->assertRedirect(route('locations.edit', ['location' => $location->id]));
|
||||||
|
|
||||||
|
$this->followRedirects($response)->assertSee(trans('general.error'));
|
||||||
|
$this->assertFalse(Location::where('name', 'Test Location')->exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue