Merge pull request #16694 from r-xyz/api-files-notes

Fixed #16689: re-add `note` field in API files listing for AssetModel
This commit is contained in:
snipe 2025-04-18 14:06:30 +01:00 committed by GitHub
commit cd63657a92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 3 deletions

View file

@ -105,6 +105,7 @@ class AssetModelsTransformer
$array = [
'id' => (int) $file->id,
'filename' => e($file->filename),
'note' => $file->note,
'url' => route('show/modelfile', [$assetmodel->id, $file->id]),
'created_by' => ($file->adminuser) ? [
'id' => (int) $file->adminuser->id,

View file

@ -59,11 +59,24 @@ class AssetModelFilesTest extends TestCase
// Create a superuser to run this as
$user = User::factory()->superuser()->create();
//Upload a file
// Upload a file
$this->actingAsForApi($user)
->post(
route('api.models.files.store', ['model_id' => $model[0]["id"]]), [
'file' => [UploadedFile::fake()->create("test.jpg", 100)]
'file' => [UploadedFile::fake()->create("test.jpg", 100)],
])
->assertOk()
->assertJsonStructure([
'status',
'messages',
]);
// Upload a file with notes
$this->actingAsForApi($user)
->post(
route('api.models.files.store', ['model_id' => $model[0]["id"]]), [
'file' => [UploadedFile::fake()->create("test.jpg", 100)],
'notes' => 'manual'
])
->assertOk()
->assertJsonStructure([
@ -75,7 +88,26 @@ class AssetModelFilesTest extends TestCase
$result = $this->actingAsForApi($user)
->getJson(
route('api.models.files.index', ['model_id' => $model[0]["id"]]))
->assertOk();
->assertOk()
->assertJsonStructure([
'total',
'rows'=>[
'*' => [
'id',
'filename',
'url',
'created_by',
'created_at',
'updated_at',
'deleted_at',
'note',
'available_actions'
]
]
])
->assertJsonPath('rows.0.note','')
->assertJsonPath('rows.1.note','manual');
// Get the file