From d920ae47c1915ee991a22df5f50ee5c6ced64549 Mon Sep 17 00:00:00 2001 From: Aevann Date: Tue, 15 Aug 2023 23:34:06 +0300 Subject: [PATCH] addendum to last commit --- files/helpers/config/modaction_types.py | 5 ++++ files/routes/comments.py | 35 +++++++++++++++++-------- files/routes/posts.py | 4 +-- files/templates/comments.html | 2 +- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/files/helpers/config/modaction_types.py b/files/helpers/config/modaction_types.py index 8fa9b65f5..a3b28a67e 100644 --- a/files/helpers/config/modaction_types.py +++ b/files/helpers/config/modaction_types.py @@ -116,6 +116,11 @@ MODACTION_TYPES = { "icon": 'fa-dollar-sign', "color": 'bg-success' }, + 'edit_comment': { + "str": 'edited {self.target_link}', + "icon": 'fa-edit', + "color": 'bg-primary' + }, 'edit_post': { "str": 'edited {self.target_link}', "icon": 'fa-edit', diff --git a/files/routes/comments.py b/files/routes/comments.py index c54cb708e..0d6e79147 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -630,10 +630,12 @@ def edit_comment(cid, v): abort(400, "You have to actually type something!") if body != c.body or request.files.get("file") and not g.is_tor: - if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')): - abort(403, "You have to type more than 280 characters!") - elif v.bird and len(body) > 140: - abort(403, "You have to type less than 140 characters!") + + if v.id == c.author_id: + if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')): + abort(403, "You have to type more than 280 characters!") + elif v.bird and len(body) > 140: + abort(403, "You have to type less than 140 characters!") execute_antispam_comment_check(body, v) @@ -641,10 +643,13 @@ def edit_comment(cid, v): body = body[:COMMENT_BODY_LENGTH_LIMIT].strip() # process_files potentially adds characters to the post body_for_sanitize = body - if v.owoify: - body_for_sanitize = owoify(body_for_sanitize) - if v.marsify and not v.chud: - body_for_sanitize = marsify(body_for_sanitize) + + if v.id == c.author_id: + if v.owoify: + body_for_sanitize = owoify(body_for_sanitize) + if v.marsify and not v.chud: + body_for_sanitize = marsify(body_for_sanitize) + if c.sharpened: body_for_sanitize = sharpen(body_for_sanitize) @@ -652,7 +657,7 @@ def edit_comment(cid, v): if len(body_html) > COMMENT_BODY_HTML_LENGTH_LIMIT: abort(400) - if v.marseyawarded and marseyaward_body_regex.search(body_html): + if v.id == c.author_id and v.marseyawarded and marseyaward_body_regex.search(body_html): abort(403, "You can only type marseys!") oldtext = c.body @@ -668,8 +673,16 @@ def edit_comment(cid, v): process_poll_options(v, c) - if int(time.time()) - c.created_utc > 60 * 3: - c.edited_utc = int(time.time()) + if v.id == c.author_id: + if int(time.time()) - c.created_utc > 60 * 3: + c.edited_utc = int(time.time()) + else: + ma=ModAction( + kind="edit_comment", + user_id=v.id, + target_comment_id=c.id + ) + g.db.add(ma) g.db.add(c) diff --git a/files/routes/posts.py b/files/routes/posts.py index 113ba6ff7..ed9cd34f9 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1041,8 +1041,8 @@ def edit_post(pid, v): if v.id == p.author_id: - if int(time.time()) - p.created_utc > 60 * 3: p.edited_utc = int(time.time()) - g.db.add(p) + if int(time.time()) - p.created_utc > 60 * 3: + p.edited_utc = int(time.time()) else: ma=ModAction( kind="edit_post", diff --git a/files/templates/comments.html b/files/templates/comments.html index dc7dd8421..6ad2a34a2 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -252,7 +252,7 @@ {% if c.parent_post or c.wall_user_id %} - {% if v and v.id==c.author_id %} + {% if v and (v.id == c.author_id or v.admin_level >= PERMS['POST_COMMENT_EDITING']) %}