diff --git a/app/Http/Requests/StoreImageAnnotations.php b/app/Http/Requests/StoreImageAnnotations.php index 9456ee364..1db16b1de 100644 --- a/app/Http/Requests/StoreImageAnnotations.php +++ b/app/Http/Requests/StoreImageAnnotations.php @@ -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'); diff --git a/tests/php/Http/Controllers/Api/ImageAnnotationBulkControllerTest.php b/tests/php/Http/Controllers/Api/ImageAnnotationBulkControllerTest.php index 9c58972bd..285a63c0e 100644 --- a/tests/php/Http/Controllers/Api/ImageAnnotationBulkControllerTest.php +++ b/tests/php/Http/Controllers/Api/ImageAnnotationBulkControllerTest.php @@ -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); + } }