mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat(fastapi): add /pkgbase/{name}/comments/{id}/edit (get)
This is needed so that users can edit comments when they don't have Javascript being used in their browser. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
01e27fa347
commit
9464de108f
3 changed files with 66 additions and 0 deletions
|
@ -384,6 +384,21 @@ async def pkgbase_comment_post(
|
||||||
status_code=HTTPStatus.SEE_OTHER)
|
status_code=HTTPStatus.SEE_OTHER)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/pkgbase/{name}/comments/{id}/edit")
|
||||||
|
@auth_required(True, redirect="/pkgbase/{name}/comments/{id}/edit")
|
||||||
|
async def pkgbase_comment_edit(request: Request, name: str, id: int,
|
||||||
|
next: str = Form(default=None)):
|
||||||
|
pkgbase = get_pkg_or_base(name, models.PackageBase)
|
||||||
|
comment = get_pkgbase_comment(pkgbase, id)
|
||||||
|
|
||||||
|
if not next:
|
||||||
|
next = f"/pkgbase/{name}"
|
||||||
|
|
||||||
|
context = await make_variable_context(request, "Edit comment", next=next)
|
||||||
|
context["comment"] = comment
|
||||||
|
return render_template(request, "packages/comments/edit.html", context)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/pkgbase/{name}/comments/{id}/delete")
|
@router.post("/pkgbase/{name}/comments/{id}/delete")
|
||||||
@auth_required(True, redirect="/pkgbase/{name}/comments/{id}/delete")
|
@auth_required(True, redirect="/pkgbase/{name}/comments/{id}/delete")
|
||||||
async def pkgbase_comment_delete(request: Request, name: str, id: int,
|
async def pkgbase_comment_delete(request: Request, name: str, id: int,
|
||||||
|
|
44
templates/packages/comments/edit.html
Normal file
44
templates/packages/comments/edit.html
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
{% extends "partials/layout.html" %}
|
||||||
|
|
||||||
|
{% block pageContent %}
|
||||||
|
<div class="box">
|
||||||
|
<h2>{{ "Edit comment for: %s" | tr | format(comment.PackageBase.Name) }}</h2>
|
||||||
|
|
||||||
|
<form action="/pkgbase/{{ comment.PackageBase.Name }}/comments/{{ comment.ID }}"
|
||||||
|
method="post">
|
||||||
|
<fieldset>
|
||||||
|
<div>
|
||||||
|
<input type="hidden" name="next" value="{{ next }}" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{{
|
||||||
|
"Git commit identifiers referencing commits in "
|
||||||
|
"the AUR package repository and URLs are converted "
|
||||||
|
"to links automatically." | tr
|
||||||
|
}}
|
||||||
|
{{
|
||||||
|
"%sMarkdown syntax%s is partiaully supported."
|
||||||
|
| tr | format(
|
||||||
|
'<a href="https://daringfireball.net/projects/markdown/syntax">',
|
||||||
|
"</a>"
|
||||||
|
) | safe
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<textarea id="id_comment"
|
||||||
|
name="comment"
|
||||||
|
cols="80"
|
||||||
|
rows="10">{{ comment.Comments }}</textarea>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<input type="submit" value="{{ 'Save' | tr }}" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -1084,6 +1084,13 @@ def test_pkgbase_comments(client: TestClient, maintainer: User, user: User,
|
||||||
assert len(bodies) == 1
|
assert len(bodies) == 1
|
||||||
|
|
||||||
assert bodies[0].text.strip() == "Test comment."
|
assert bodies[0].text.strip() == "Test comment."
|
||||||
|
comment_id = headers[0].attrib["id"].split("-")[-1]
|
||||||
|
|
||||||
|
# Test the non-javascript version of comment editing by
|
||||||
|
# visiting the /pkgbase/{name}/comments/{id}/edit route.
|
||||||
|
with client as request:
|
||||||
|
resp = request.get(f"{endpoint}/{comment_id}/edit", cookies=cookies)
|
||||||
|
assert resp.status_code == int(HTTPStatus.OK)
|
||||||
|
|
||||||
# Clear up the PackageNotification. This doubles as testing
|
# Clear up the PackageNotification. This doubles as testing
|
||||||
# that the notification was created and clears it up so we can
|
# that the notification was created and clears it up so we can
|
||||||
|
|
Loading…
Add table
Reference in a new issue