mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-21 14:51:02 +00:00
Allow statusless posts (#677)
This commit is contained in:
parent
123c20efb1
commit
d07482f5a8
2 changed files with 30 additions and 4 deletions
|
@ -39,7 +39,7 @@ class PostPollSchema(Schema):
|
|||
|
||||
|
||||
class PostStatusSchema(Schema):
|
||||
status: str
|
||||
status: str | None
|
||||
in_reply_to_id: str | None = None
|
||||
sensitive: bool = False
|
||||
spoiler_text: str | None = None
|
||||
|
@ -82,9 +82,9 @@ def post_for_id(request: HttpRequest, id: str) -> Post:
|
|||
@api_view.post
|
||||
def post_status(request, details: PostStatusSchema) -> schemas.Status:
|
||||
# Check text length
|
||||
if len(details.status) > Config.system.post_length:
|
||||
if details.status and len(details.status) > Config.system.post_length:
|
||||
raise ApiError(400, "Status is too long")
|
||||
if len(details.status) == 0 and not details.media_ids:
|
||||
if not details.status and not details.media_ids:
|
||||
raise ApiError(400, "Status is empty")
|
||||
# Grab attachments
|
||||
attachments = [get_object_or_404(PostAttachment, pk=id) for id in details.media_ids]
|
||||
|
@ -103,7 +103,7 @@ def post_status(request, details: PostStatusSchema) -> schemas.Status:
|
|||
pass
|
||||
post = Post.create_local(
|
||||
author=request.identity,
|
||||
content=details.status,
|
||||
content=details.status or "",
|
||||
summary=details.spoiler_text,
|
||||
sensitive=details.sensitive,
|
||||
visibility=visibility_map[details.visibility],
|
||||
|
|
|
@ -56,6 +56,32 @@ def test_post_status(api_client, identity):
|
|||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_post_statusless(api_client, identity):
|
||||
"""
|
||||
Tests we can post with media but no status
|
||||
"""
|
||||
# Create media attachment
|
||||
attachment = PostAttachment.objects.create(
|
||||
mimetype="image/webp",
|
||||
name=None,
|
||||
state=PostAttachmentStates.fetched,
|
||||
author=identity,
|
||||
)
|
||||
# Post new one
|
||||
response = api_client.post(
|
||||
"/api/v1/statuses",
|
||||
content_type="application/json",
|
||||
data={
|
||||
"media_ids": [attachment.id],
|
||||
},
|
||||
)
|
||||
assert 200 <= response.status_code < 300
|
||||
body = response.json()
|
||||
assert body["content"] == "<p></p>"
|
||||
assert body["media_attachments"][0]["description"] is None
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_mention_format(api_client, identity, remote_identity):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue