mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-12 13:33:46 +08:00
Attachment API: Fixed error when name not provided in update
Fixes #5353
This commit is contained in:
parent
7e6f6af463
commit
55d074f1a5
|
@ -116,16 +116,18 @@ class AttachmentService
|
||||||
*/
|
*/
|
||||||
public function updateFile(Attachment $attachment, array $requestData): Attachment
|
public function updateFile(Attachment $attachment, array $requestData): Attachment
|
||||||
{
|
{
|
||||||
|
if (isset($requestData['name'])) {
|
||||||
$attachment->name = $requestData['name'];
|
$attachment->name = $requestData['name'];
|
||||||
$link = trim($requestData['link'] ?? '');
|
}
|
||||||
|
|
||||||
|
$link = trim($requestData['link'] ?? '');
|
||||||
if (!empty($link)) {
|
if (!empty($link)) {
|
||||||
if (!$attachment->external) {
|
if (!$attachment->external) {
|
||||||
$this->deleteFileInStorage($attachment);
|
$this->deleteFileInStorage($attachment);
|
||||||
$attachment->external = true;
|
$attachment->external = true;
|
||||||
$attachment->extension = '';
|
$attachment->extension = '';
|
||||||
}
|
}
|
||||||
$attachment->path = $requestData['link'];
|
$attachment->path = $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
$attachment->save();
|
$attachment->save();
|
||||||
|
|
|
@ -12,7 +12,7 @@ class AttachmentsApiTest extends TestCase
|
||||||
{
|
{
|
||||||
use TestsApi;
|
use TestsApi;
|
||||||
|
|
||||||
protected $baseEndpoint = '/api/attachments';
|
protected string $baseEndpoint = '/api/attachments';
|
||||||
|
|
||||||
public function test_index_endpoint_returns_expected_book()
|
public function test_index_endpoint_returns_expected_book()
|
||||||
{
|
{
|
||||||
|
@ -302,6 +302,23 @@ class AttachmentsApiTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_update_file_attachment_to_link()
|
public function test_update_file_attachment_to_link()
|
||||||
|
{
|
||||||
|
$this->actingAsApiAdmin();
|
||||||
|
$page = $this->entities->page();
|
||||||
|
$attachment = $this->createAttachmentForPage($page);
|
||||||
|
|
||||||
|
$resp = $this->putJson("{$this->baseEndpoint}/{$attachment->id}", [
|
||||||
|
'link' => 'https://example.com/donkey',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$resp->assertStatus(200);
|
||||||
|
$this->assertDatabaseHas('attachments', [
|
||||||
|
'id' => $attachment->id,
|
||||||
|
'path' => 'https://example.com/donkey',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_update_does_not_require_name()
|
||||||
{
|
{
|
||||||
$this->actingAsApiAdmin();
|
$this->actingAsApiAdmin();
|
||||||
$page = $this->entities->page();
|
$page = $this->entities->page();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user