From 9464de108f39e3fe633083ddf3c7a3526426fd98 Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Fri, 29 Oct 2021 21:37:52 -0700 Subject: [PATCH] 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 --- aurweb/routers/packages.py | 15 +++++++++ templates/packages/comments/edit.html | 44 +++++++++++++++++++++++++++ test/test_packages_routes.py | 7 +++++ 3 files changed, 66 insertions(+) create mode 100644 templates/packages/comments/edit.html diff --git a/aurweb/routers/packages.py b/aurweb/routers/packages.py index 27125b60..c574ec18 100644 --- a/aurweb/routers/packages.py +++ b/aurweb/routers/packages.py @@ -384,6 +384,21 @@ async def pkgbase_comment_post( 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") @auth_required(True, redirect="/pkgbase/{name}/comments/{id}/delete") async def pkgbase_comment_delete(request: Request, name: str, id: int, diff --git a/templates/packages/comments/edit.html b/templates/packages/comments/edit.html new file mode 100644 index 00000000..f938287e --- /dev/null +++ b/templates/packages/comments/edit.html @@ -0,0 +1,44 @@ +{% extends "partials/layout.html" %} + +{% block pageContent %} +
+

{{ "Edit comment for: %s" | tr | format(comment.PackageBase.Name) }}

+ +
+
+
+ +
+ +

+ {{ + "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( + '', + "" + ) | safe + }} +

+ +

+ +

+ +

+ +

+ +
+
+ +
+{% endblock %} diff --git a/test/test_packages_routes.py b/test/test_packages_routes.py index 2ef3f3d8..207be379 100644 --- a/test/test_packages_routes.py +++ b/test/test_packages_routes.py @@ -1084,6 +1084,13 @@ def test_pkgbase_comments(client: TestClient, maintainer: User, user: User, assert len(bodies) == 1 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 # that the notification was created and clears it up so we can