mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-03-29 02:35:16 +08:00
Applied latest changes from styleCI
This commit is contained in:
parent
7bbcaa7cbc
commit
859934d6a3
app
tests/Api
@ -20,13 +20,13 @@ class AttachmentApiController extends ApiController
|
||||
'name' => 'required|min:1|max:255|string',
|
||||
'uploaded_to' => 'required|integer|exists:pages,id',
|
||||
'file' => 'required_without:link|file',
|
||||
'link' => 'required_without:file|min:1|max:255|safe_url'
|
||||
'link' => 'required_without:file|min:1|max:255|safe_url',
|
||||
],
|
||||
'update' => [
|
||||
'name' => 'min:1|max:255|string',
|
||||
'uploaded_to' => 'integer|exists:pages,id',
|
||||
'file' => 'file',
|
||||
'link' => 'min:1|max:255|safe_url'
|
||||
'link' => 'min:1|max:255|safe_url',
|
||||
],
|
||||
];
|
||||
|
||||
@ -72,11 +72,14 @@ class AttachmentApiController extends ApiController
|
||||
$attachment = $this->attachmentService->saveNewUpload($uploadedFile, $page->id);
|
||||
} else {
|
||||
$attachment = $this->attachmentService->saveNewFromLink(
|
||||
$requestData['name'], $requestData['link'], $page->id
|
||||
$requestData['name'],
|
||||
$requestData['link'],
|
||||
$page->id
|
||||
);
|
||||
}
|
||||
|
||||
$this->attachmentService->updateFile($attachment, $requestData);
|
||||
|
||||
return response()->json($attachment);
|
||||
}
|
||||
|
||||
@ -140,6 +143,7 @@ class AttachmentApiController extends ApiController
|
||||
}
|
||||
|
||||
$this->attachmentService->updateFile($attachment, $requestData);
|
||||
|
||||
return response()->json($attachment);
|
||||
}
|
||||
|
||||
@ -158,5 +162,4 @@ class AttachmentApiController extends ApiController
|
||||
|
||||
return response('', 204);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ class Attachment extends Model
|
||||
public function scopeVisible(): Builder
|
||||
{
|
||||
$permissionService = app()->make(PermissionService::class);
|
||||
|
||||
return $permissionService->filterRelatedEntity(
|
||||
Page::class,
|
||||
Attachment::query(),
|
||||
|
@ -171,6 +171,7 @@ class AttachmentService
|
||||
}
|
||||
|
||||
$attachment->save();
|
||||
|
||||
return $attachment->refresh();
|
||||
}
|
||||
|
||||
|
@ -143,8 +143,8 @@ class AttachmentsApiTest extends TestCase
|
||||
'error' => [
|
||||
'message' => 'The given data was invalid.',
|
||||
'validation' => [
|
||||
"file" => ["The file field is required when link is not present."],
|
||||
"link" => ["The link field is required when file is not present."],
|
||||
'file' => ['The file field is required when link is not present.'],
|
||||
'link' => ['The link field is required when file is not present.'],
|
||||
],
|
||||
'code' => 422,
|
||||
],
|
||||
@ -179,8 +179,8 @@ class AttachmentsApiTest extends TestCase
|
||||
'name' => $attachment->createdBy->name,
|
||||
],
|
||||
'links' => [
|
||||
"html" => "<a target=\"_blank\" href=\"http://localhost/attachments/{$attachment->id}\">my attachment</a>",
|
||||
"markdown" => "[my attachment](http://localhost/attachments/{$attachment->id})"
|
||||
'html' => "<a target=\"_blank\" href=\"http://localhost/attachments/{$attachment->id}\">my attachment</a>",
|
||||
'markdown' => "[my attachment](http://localhost/attachments/{$attachment->id})",
|
||||
],
|
||||
]);
|
||||
}
|
||||
@ -216,8 +216,8 @@ class AttachmentsApiTest extends TestCase
|
||||
'name' => $attachment->updatedBy->name,
|
||||
],
|
||||
'links' => [
|
||||
"html" => "<a target=\"_blank\" href=\"http://localhost/attachments/{$attachment->id}\">My file attachment</a>",
|
||||
"markdown" => "[My file attachment](http://localhost/attachments/{$attachment->id})"
|
||||
'html' => "<a target=\"_blank\" href=\"http://localhost/attachments/{$attachment->id}\">My file attachment</a>",
|
||||
'markdown' => "[My file attachment](http://localhost/attachments/{$attachment->id})",
|
||||
],
|
||||
]);
|
||||
|
||||
@ -250,7 +250,6 @@ class AttachmentsApiTest extends TestCase
|
||||
$attachment = $this->createAttachmentForPage($page);
|
||||
$file = $this->getTestFile('textfile.txt');
|
||||
|
||||
|
||||
$resp = $this->call('PUT', "{$this->baseEndpoint}/{$attachment->id}", ['name' => 'My updated file'], [], ['file' => $file]);
|
||||
$resp->assertStatus(200);
|
||||
|
||||
@ -278,7 +277,7 @@ class AttachmentsApiTest extends TestCase
|
||||
|
||||
$details = [
|
||||
'name' => 'My updated API attachment',
|
||||
'link' => 'https://cats.example.com'
|
||||
'link' => 'https://cats.example.com',
|
||||
];
|
||||
|
||||
$resp = $this->putJson("{$this->baseEndpoint}/{$attachment->id}", $details);
|
||||
@ -315,8 +314,9 @@ class AttachmentsApiTest extends TestCase
|
||||
'order' => 1,
|
||||
'created_by' => $admin->id,
|
||||
'updated_by' => $admin->id,
|
||||
'path' => 'https://attachment.example.com'
|
||||
'path' => 'https://attachment.example.com',
|
||||
], $attributes));
|
||||
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user