From 6ede837b4f50c61d9110d0e048dee3f3b570c519 Mon Sep 17 00:00:00 2001
From: Leonidas Spyropoulos
Date: Fri, 21 Apr 2023 19:47:55 +0100
Subject: [PATCH] feat: allow users to hide deleted comments
Closes: #435
Signed-off-by: Leonidas Spyropoulos
---
aurweb/routers/accounts.py | 6 ++
aurweb/schema.py | 6 ++
aurweb/users/update.py | 2 +
...ffce091_add_hidedeletedcomments_to_user.py | 33 ++++++++++
po/aurweb.pot | 4 ++
templates/partials/account/comment.html | 3 +-
templates/partials/account_form.html | 19 +++++-
templates/partials/packages/comment.html | 2 +
test/test_packages_routes.py | 62 ++++++++++++++++++-
9 files changed, 132 insertions(+), 5 deletions(-)
create mode 100644 migrations/versions/e4e49ffce091_add_hidedeletedcomments_to_user.py
diff --git a/aurweb/routers/accounts.py b/aurweb/routers/accounts.py
index 07962c37..77988d7f 100644
--- a/aurweb/routers/accounts.py
+++ b/aurweb/routers/accounts.py
@@ -209,6 +209,7 @@ def make_account_form_context(
context["cn"] = args.get("CN", user.CommentNotify)
context["un"] = args.get("UN", user.UpdateNotify)
context["on"] = args.get("ON", user.OwnershipNotify)
+ context["hdc"] = args.get("HDC", user.HideDeletedComments)
context["inactive"] = args.get("J", user.InactivityTS != 0)
else:
context["username"] = args.get("U", str())
@@ -227,6 +228,7 @@ def make_account_form_context(
context["cn"] = args.get("CN", True)
context["un"] = args.get("UN", False)
context["on"] = args.get("ON", True)
+ context["hdc"] = args.get("HDC", False)
context["inactive"] = args.get("J", False)
context["password"] = args.get("P", str())
@@ -253,6 +255,7 @@ async def account_register(
CN: bool = Form(default=False), # Comment Notify
CU: bool = Form(default=False), # Update Notify
CO: bool = Form(default=False), # Owner Notify
+ HDC: bool = Form(default=False), # Hide Deleted Comments
captcha: str = Form(default=str()),
):
context = await make_variable_context(request, "Register")
@@ -281,6 +284,7 @@ async def account_register_post(
CN: bool = Form(default=False),
UN: bool = Form(default=False),
ON: bool = Form(default=False),
+ HDC: bool = Form(default=False),
captcha: str = Form(default=None),
captcha_salt: str = Form(...),
):
@@ -334,6 +338,7 @@ async def account_register_post(
CommentNotify=CN,
UpdateNotify=UN,
OwnershipNotify=ON,
+ HideDeletedComments=HDC,
ResetKey=resetkey,
AccountType=atype,
)
@@ -417,6 +422,7 @@ async def account_edit_post(
CN: bool = Form(default=False), # Comment Notify
UN: bool = Form(default=False), # Update Notify
ON: bool = Form(default=False), # Owner Notify
+ HDC: bool = Form(default=False), # Hide Deleted Comments
T: int = Form(default=None),
passwd: str = Form(default=str()),
):
diff --git a/aurweb/schema.py b/aurweb/schema.py
index 0ba3e9c2..d01d07c9 100644
--- a/aurweb/schema.py
+++ b/aurweb/schema.py
@@ -108,6 +108,12 @@ Users = Table(
Column("OwnershipNotify", TINYINT(1), nullable=False, server_default=text("1")),
Column("SSOAccountID", String(255), nullable=True, unique=True),
Index("UsersAccountTypeID", "AccountTypeID"),
+ Column(
+ "HideDeletedComments",
+ TINYINT(unsigned=True),
+ nullable=False,
+ server_default=text("0"),
+ ),
mysql_engine="InnoDB",
mysql_charset="utf8mb4",
mysql_collate="utf8mb4_general_ci",
diff --git a/aurweb/users/update.py b/aurweb/users/update.py
index df41f843..21349a39 100644
--- a/aurweb/users/update.py
+++ b/aurweb/users/update.py
@@ -22,6 +22,7 @@ def simple(
CN: bool = False,
UN: bool = False,
ON: bool = False,
+ HDC: bool = False,
S: bool = False,
user: models.User = None,
**kwargs,
@@ -41,6 +42,7 @@ def simple(
user.CommentNotify = strtobool(CN)
user.UpdateNotify = strtobool(UN)
user.OwnershipNotify = strtobool(ON)
+ user.HideDeletedComments = strtobool(HDC)
@db.retry_deadlock
diff --git a/migrations/versions/e4e49ffce091_add_hidedeletedcomments_to_user.py b/migrations/versions/e4e49ffce091_add_hidedeletedcomments_to_user.py
new file mode 100644
index 00000000..bc18b519
--- /dev/null
+++ b/migrations/versions/e4e49ffce091_add_hidedeletedcomments_to_user.py
@@ -0,0 +1,33 @@
+"""Add HideDeletedComments to User
+
+Revision ID: e4e49ffce091
+Revises: 9e3158957fd7
+Create Date: 2023-04-19 23:24:25.854874
+
+"""
+from alembic import op
+from sqlalchemy.exc import OperationalError
+
+from aurweb.models.user import User
+
+# revision identifiers, used by Alembic.
+revision = "e4e49ffce091"
+down_revision = "9e3158957fd7"
+branch_labels = None
+depends_on = None
+
+table = User.__table__
+
+
+def upgrade():
+ try:
+ op.add_column(table.name, table.c.HideDeletedComments)
+ except OperationalError:
+ print(
+ f"Column HideDeletedComments already exists in '{table.name}',"
+ f" skipping migration."
+ )
+
+
+def downgrade():
+ op.drop_column(table.name, "HideDeletedComments")
diff --git a/po/aurweb.pot b/po/aurweb.pot
index 7e798a21..f4e3c1ba 100644
--- a/po/aurweb.pot
+++ b/po/aurweb.pot
@@ -1402,6 +1402,10 @@ msgstr ""
msgid "Specify multiple SSH Keys separated by new line, empty lines are ignored."
msgstr ""
+#: templates/partials/account_form.html
+msgid "Hide deleted comments"
+msgstr ""
+
#: template/account_edit_form.php
msgid "SSH Public Key"
msgstr ""
diff --git a/templates/partials/account/comment.html b/templates/partials/account/comment.html
index f88aab02..41c9ac08 100644
--- a/templates/partials/account/comment.html
+++ b/templates/partials/account/comment.html
@@ -4,7 +4,7 @@
{% endif %}
{% if not comment.Deleter or request.user.has_credential(creds.COMMENT_VIEW_DELETED, approved=[comment.Deleter]) %}
-
+{% if not (request.user.HideDeletedComments and comment.DelTS) %}
{% set commented_at = comment.CommentTS | dt | as_timezone(timezone) %}
-
+
{% trans %}Language{% endtrans %}:
@@ -202,10 +202,10 @@
-
+
- {% trans %}Timezone{% endtrans %}
+ {% trans %}Timezone{% endtrans %}:
@@ -219,6 +219,19 @@
+
+
+
+ {% trans %}Hide deleted comments{% endtrans %}:
+
+
+
+
+
{% if form_type == "UpdateAccount" %}
diff --git a/templates/partials/packages/comment.html b/templates/partials/packages/comment.html
index e4818837..faac0753 100644
--- a/templates/partials/packages/comment.html
+++ b/templates/partials/packages/comment.html
@@ -6,6 +6,7 @@
{% endif %}
{% if not comment.Deleter or request.user.has_credential(creds.COMMENT_VIEW_DELETED, approved=[comment.Deleter]) %}
+{% if not (request.user.HideDeletedComments and comment.DelTS) %}