mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat: cancel button for comment editing
Adds button that allows cancellation while editing a comment Signed-off-by: moson-mo <mo-son@mailbox.org>
This commit is contained in:
parent
52c962a590
commit
7d1827ffc5
4 changed files with 35 additions and 0 deletions
|
@ -293,8 +293,14 @@ async def pkgbase_comment_post(
|
|||
comment: str = Form(default=str()),
|
||||
enable_notifications: bool = Form(default=False),
|
||||
next: str = Form(default=None),
|
||||
cancel: bool = Form(default=False),
|
||||
):
|
||||
"""Edit an existing comment."""
|
||||
if cancel:
|
||||
return RedirectResponse(
|
||||
f"/pkgbase/{name}#comment-{id}", status_code=HTTPStatus.SEE_OTHER
|
||||
)
|
||||
|
||||
pkgbase = get_pkg_or_base(name, PackageBase)
|
||||
db_comment = get_pkgbase_comment(pkgbase, id)
|
||||
|
||||
|
|
|
@ -2354,3 +2354,7 @@ msgstr ""
|
|||
#: aurweb/routers/accounts.py
|
||||
msgid "The account has not been deleted, check the confirmation checkbox."
|
||||
msgstr ""
|
||||
|
||||
#: templates/partials/packages/comment_form.html
|
||||
msgid "Cancel"
|
||||
msgstr ""
|
||||
|
|
|
@ -33,6 +33,11 @@ Routes:
|
|||
<button type="submit" class="button">
|
||||
{{ ("Save" if comment else "Add Comment") | tr }}
|
||||
</button>
|
||||
{% if comment %}
|
||||
<button type="submit" class="button" name="cancel" value="true">
|
||||
{{ "Cancel" | tr }}
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if not request.user.notified(pkgbase) %}
|
||||
<span class="comment-enable-notifications">
|
||||
<input type="checkbox" name="enable_notifications"
|
||||
|
|
|
@ -512,6 +512,26 @@ def test_pkgbase_comments(
|
|||
).first()
|
||||
assert db_notif is not None
|
||||
|
||||
# Now, let's edit again, but cancel.
|
||||
endpoint = f"/pkgbase/{pkgbasename}/comments/{comment_id}"
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
resp = request.post(
|
||||
endpoint,
|
||||
data={"comment": "Edited comment with cancel.", "cancel": True},
|
||||
)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
|
||||
with client as request:
|
||||
resp = request.get(resp.headers.get("location"), follow_redirects=True)
|
||||
assert resp.status_code == int(HTTPStatus.OK)
|
||||
|
||||
root = parse_root(resp.text)
|
||||
bodies = root.xpath('//div[@class="article-content"]/div/p')
|
||||
|
||||
# Make sure our comment was NOT changed
|
||||
assert bodies[0].text.strip() == "Edited comment."
|
||||
|
||||
# Delete notification for next test.
|
||||
with db.begin():
|
||||
db.delete(db_notif)
|
||||
|
|
Loading…
Add table
Reference in a new issue