Skip to content

Commit

Permalink
Fix image annotation bulk controller with string IDs as input
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Sep 1, 2023
1 parent 919dca1 commit 67ed9ed
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/Http/Requests/StoreImageAnnotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ public function authorize()
$this->imageIds = $input->pluck('image_id')
->unique()
// Filter because the IDs are validated *after* authorization and could be
// e.g. floats here.
->filter(fn ($id) => is_int($id));
// e.g. random strings here.
->filter(fn ($id) => is_numeric($id));

$this->images = Image::findMany($this->imageIds, ['id', 'volume_id']);

$labelIds = $input->pluck('label_id')
->unique()
// Filter because the IDs are validated *after* authorization and could be
// e.g. floats here.
->filter(fn ($id) => is_int($id));
// e.g. random strings here.
->filter(fn ($id) => is_numeric($id));

$this->labels = Label::findMany($labelIds)->keyBy('id');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,36 @@ public function storeLimit($url)
$this->postJson($url, $data)
->assertStatus(422);
}

public function testStoreLabelIdIsString()
{
$this->beEditor();
$this->postJson('api/v1/annotations', [
[
'image_id' => $this->annotation->image_id,
'shape_id' => Shape::pointId(),
'points' => [100, 100],
'label_id' => strval($this->labelRoot()->id),
'confidence' => 1.0,
],
])
->assertStatus(200);

$this->assertEquals(2, $this->annotation->image->annotations()->count());
}

public function testStoreLabelIdIsFloat()
{
$this->beEditor();
$this->postJson('api/v1/annotations', [
[
'image_id' => $this->annotation->image_id,
'shape_id' => Shape::pointId(),
'points' => [100, 100],
'label_id' => 1.5,
'confidence' => 1.0,
],
])
->assertStatus(422);
}
}

0 comments on commit 67ed9ed

Please sign in to comment.