From 6c7eb8a3b2d911f8e46801ac894dc464574795c8 Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 15 Feb 2024 20:48:36 +0200 Subject: [PATCH] do this https://watchpeopledie.tv/h/meta/post/61549/megathread-for-bugs-and-suggestions/2715484#context --- files/classes/group.py | 1 + files/routes/groups.py | 8 ++++++++ files/templates/group_memberships.html | 4 ++-- files/templates/groups.html | 4 ++-- migrations/20240215-add-description-html-for-groups.sql | 2 ++ 5 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 migrations/20240215-add-description-html-for-groups.sql diff --git a/files/classes/group.py b/files/classes/group.py index 4e34a1521..525e607f2 100644 --- a/files/classes/group.py +++ b/files/classes/group.py @@ -16,6 +16,7 @@ class Group(Base): created_utc = Column(Integer) owner_id = Column(Integer, ForeignKey("users.id")) description = Column(String) + description_html = Column(String) memberships = relationship("GroupMembership", primaryjoin="GroupMembership.group_name==Group.name", order_by="GroupMembership.approved_utc") owner = relationship("User", primaryjoin="Group.owner_id==User.id") diff --git a/files/routes/groups.py b/files/routes/groups.py index 81f785f35..a46b71040 100644 --- a/files/routes/groups.py +++ b/files/routes/groups.py @@ -353,10 +353,18 @@ def group_change_description(v, group_name): if description: description = description.strip() + if len(description) > 100: + abort(400, "New description is too long (max 100 characters)") + + description_html = filter_emojis_only(description) + if len(description_html) > 500: + abort(400, "Rendered description is too long!") else: description = None + description_html = None group.description = description + group.description_html = description_html g.db.add(group) return {"message": 'Description changed successfully!'} diff --git a/files/templates/group_memberships.html b/files/templates/group_memberships.html index bcb9543dc..73d57b6c4 100644 --- a/files/templates/group_memberships.html +++ b/files/templates/group_memberships.html @@ -33,9 +33,9 @@ - {% elif group.description %} + {% elif group.description_html %}
!{{group}} Description
-

{{group.description}}

+

{{group.description_html | safe}}

{% endif %}
diff --git a/files/templates/groups.html b/files/templates/groups.html index 62b7ef9a9..3cf79349e 100644 --- a/files/templates/groups.html +++ b/files/templates/groups.html @@ -62,8 +62,8 @@ {% endif %} - {% if group.description %} - {{group.description}} + {% if group.description_html %} + {{group.description_html | safe}} {% endif %} diff --git a/migrations/20240215-add-description-html-for-groups.sql b/migrations/20240215-add-description-html-for-groups.sql new file mode 100644 index 000000000..6fefb3e1f --- /dev/null +++ b/migrations/20240215-add-description-html-for-groups.sql @@ -0,0 +1,2 @@ +alter table groups add column description_html varchar(500); +update groups set description_html=description;