From 5e8f04b2ac3026e7bdb18e6d09eb026797f3f272 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 23 Jun 2023 19:49:23 +0300 Subject: [PATCH] rename flags to reports --- files/assets/css/main.css | 4 +-- files/assets/css/transparent.css | 2 +- files/assets/css/win98.css | 2 +- files/assets/js/admin/post.js | 4 +-- files/assets/js/comments.js | 4 +-- files/assets/js/delete_post_modal.js | 2 +- files/classes/__init__.py | 2 +- files/classes/comment.py | 17 ++++++------ files/classes/post.py | 17 ++++++------ files/classes/{flags.py => reports.py} | 12 ++++----- files/helpers/actions.py | 6 ++--- files/helpers/config/const.py | 2 +- files/helpers/get.py | 2 +- files/routes/admin.py | 4 +-- files/routes/reporting.py | 26 +++++++++---------- files/templates/comments.html | 4 +-- files/templates/post.html | 2 +- files/templates/post_listing.html | 2 +- files/templates/util/macros.html | 22 ++++++++-------- .../20230623-rename-flags-to-reports.sql | 12 +++++++++ 20 files changed, 81 insertions(+), 67 deletions(-) rename files/classes/{flags.py => reports.py} (84%) create mode 100644 migrations/20230623-rename-flags-to-reports.sql diff --git a/files/assets/css/main.css b/files/assets/css/main.css index 997b4f49e..36a279778 100644 --- a/files/assets/css/main.css +++ b/files/assets/css/main.css @@ -4512,7 +4512,7 @@ small, .small { height: 60px; } } -.post-actions .comments, .post-actions .share, .post-actions .flag { +.post-actions .comments, .post-actions .share, .post-actions .report { margin-right: 0.5rem; vertical-align: top; } @@ -5304,7 +5304,7 @@ span.green { .btn-primary:focus, .btn-primary.focus { box-shadow: none !important; } -.flaggers { +.reports { margin: 7px; border: 1px solid var(--primary); padding: 10px; diff --git a/files/assets/css/transparent.css b/files/assets/css/transparent.css index dcb67d09a..d9b1eb435 100644 --- a/files/assets/css/transparent.css +++ b/files/assets/css/transparent.css @@ -14,6 +14,6 @@ background-color: rgb(var(--background)) !important; } -.App-side, .flaggers, .comment-section { +.App-side, .reports, .comment-section { background: transparent !important; } diff --git a/files/assets/css/win98.css b/files/assets/css/win98.css index a2e323586..d03ef37a9 100644 --- a/files/assets/css/win98.css +++ b/files/assets/css/win98.css @@ -98,7 +98,7 @@ blockquote { color: #000 !important } -.flaggers { +.reports { background-color: var(--white) !important; } diff --git a/files/assets/js/admin/post.js b/files/assets/js/admin/post.js index fe3c0f62b..ef2838ab8 100644 --- a/files/assets/js/admin/post.js +++ b/files/assets/js/admin/post.js @@ -8,7 +8,7 @@ function removePost(t,post_id,button1,button2,cls) { () => { if (location.pathname == '/admin/reported/posts') { - document.getElementById("flaggers-"+post_id).remove() + document.getElementById("reports-"+post_id).remove() document.getElementById("post-"+post_id).remove() } else @@ -30,7 +30,7 @@ function approvePost(t,post_id,button1,button2,cls) { () => { if (location.pathname == '/admin/reported/posts') { - document.getElementById("flaggers-"+post_id).remove() + document.getElementById("reports-"+post_id).remove() document.getElementById("post-"+post_id).remove() } else diff --git a/files/assets/js/comments.js b/files/assets/js/comments.js index b2ac7ee2a..c3face05c 100644 --- a/files/assets/js/comments.js +++ b/files/assets/js/comments.js @@ -27,8 +27,8 @@ function collapse_comment(id) { window.scrollBy(0, - 100) } - const flags = document.getElementById(`flaggers-${id}`) - if (flags) flags.classList.add('d-none') + const reports = document.getElementById(`reports-${id}`) + if (reports) reports.classList.add('d-none') vids = element.getElementsByTagName('video') for (let i=0; i < vids.length; i++) diff --git a/files/assets/js/delete_post_modal.js b/files/assets/js/delete_post_modal.js index 20176437e..94977b4ba 100644 --- a/files/assets/js/delete_post_modal.js +++ b/files/assets/js/delete_post_modal.js @@ -6,7 +6,7 @@ function delete_postModal(t, id) { () => { if (location.pathname == '/admin/reported/posts') { - document.getElementById("flaggers-"+id).remove() + document.getElementById("reports-"+id).remove() document.getElementById("post-"+id).remove() } else diff --git a/files/classes/__init__.py b/files/classes/__init__.py index 98d20689e..d17d699fe 100644 --- a/files/classes/__init__.py +++ b/files/classes/__init__.py @@ -7,7 +7,7 @@ from .alts import * from .clients import * from .comment import * from .domains import * -from .flags import * +from .reports import * from .user import * from .badges import * from .userblock import * diff --git a/files/classes/comment.py b/files/classes/comment.py index 67b574bd6..ea1e2436a 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -145,7 +145,7 @@ class Comment(Base): senttouser = relationship("User", primaryjoin="User.id==Comment.sentto") parent_comment = relationship("Comment", remote_side=[id]) awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", back_populates="comment") - flags = relationship("CommentFlag", order_by="CommentFlag.created_utc") + reports = relationship("CommentReport", order_by="CommentReport.created_utc") options = relationship("CommentOption", order_by="CommentOption.id") casino_game = relationship("CasinoGame") wall_user = relationship("User", primaryjoin="User.id==Comment.wall_user_id") @@ -279,8 +279,9 @@ class Comment(Base): 'parent': self.parent_fullname } else: - flags = {} - for f in self.flags: flags[f.user.username] = f.reason + reports = {} + for r in self.reports: + reports[r.user.username] = r.reason data = { 'id': self.id, @@ -302,7 +303,7 @@ class Comment(Base): 'upvotes': self.upvotes, 'downvotes': self.downvotes, 'is_bot': self.is_bot, - 'flags': flags, + 'reports': reports, 'author': '👻' if self.ghost else self.author.json, # 'replies': [x.json for x in self.replies(sort="old", v=None)] # WORKER TIMEOUTS ON BUGTHREAD } @@ -399,12 +400,12 @@ class Comment(Base): def is_op(self): return self.author_id==self.post.author_id @lazy - def filtered_flags(self, v): - return [f for f in self.flags if not f.user.shadowbanned or (v and v.id == f.user_id) or (v and v.admin_level)] + def filtered_reports(self, v): + return [r for r in self.reports if not r.user.shadowbanned or (v and v.id == r.user_id) or (v and v.admin_level)] @lazy - def active_flags(self, v): - return len(self.filtered_flags(v)) + def active_reports(self, v): + return len(self.filtered_reports(v)) @property @lazy diff --git a/files/classes/post.py b/files/classes/post.py index a19728ebf..ecb369634 100644 --- a/files/classes/post.py +++ b/files/classes/post.py @@ -65,7 +65,7 @@ class Post(Base): oauth_app = relationship("OauthApp") approved_by = relationship("User", uselist=False, primaryjoin="Post.is_approved==User.id") awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", back_populates="post") - flags = relationship("Flag", order_by="Flag.created_utc") + reports = relationship("Report", order_by="Report.created_utc") comments = relationship("Comment", primaryjoin="Comment.parent_post==Post.id", back_populates="post") subr = relationship("Sub", primaryjoin="foreign(Post.sub)==remote(Sub.name)") options = relationship("PostOption", order_by="PostOption.id") @@ -203,8 +203,9 @@ class Post(Base): 'permalink': self.permalink, } - flags = {} - for f in self.flags: flags[f.user.username] = f.reason + reports = {} + for r in self.reports: + reports[r.user.username] = r.reason data = {'author_name': self.author_name if self.author else '', 'permalink': self.permalink, @@ -231,7 +232,7 @@ class Post(Base): 'private' : self.private, 'distinguish_level': self.distinguish_level, 'voted': self.voted if hasattr(self, 'voted') else 0, - 'flags': flags, + 'reports': reports, 'author': '👻' if self.ghost else self.author.json } @@ -364,12 +365,12 @@ class Post(Base): return self.url and any((str(self.url).lower().split('?')[0].endswith(f'.{x}') for x in IMAGE_FORMATS)) and is_safe_url(self.url) @lazy - def filtered_flags(self, v): - return [f for f in self.flags if not f.user.shadowbanned or (v and v.id == f.user_id) or (v and v.admin_level)] + def filtered_reports(self, v): + return [r for r in self.reports if not r.user.shadowbanned or (v and v.id == r.user_id) or (v and v.admin_level)] @lazy - def active_flags(self, v): - return len(self.filtered_flags(v)) + def active_reports(self, v): + return len(self.filtered_reports(v)) @property @lazy diff --git a/files/classes/flags.py b/files/classes/reports.py similarity index 84% rename from files/classes/flags.py rename to files/classes/reports.py index cc1d1c8cb..3ee76145e 100644 --- a/files/classes/flags.py +++ b/files/classes/reports.py @@ -8,15 +8,15 @@ from files.classes import Base from files.helpers.lazy import lazy from files.helpers.regex import censor_slurs -class Flag(Base): - __tablename__ = "flags" +class Report(Base): + __tablename__ = "reports" post_id = Column(Integer, ForeignKey("posts.id"), primary_key=True) user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) reason = Column(String) created_utc = Column(Integer) - user = relationship("User", primaryjoin = "Flag.user_id == User.id", uselist = False) + user = relationship("User", primaryjoin = "Report.user_id == User.id", uselist = False) def __init__(self, *args, **kwargs): if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) @@ -36,15 +36,15 @@ class Flag(Base): return self.post_id -class CommentFlag(Base): - __tablename__ = "commentflags" +class CommentReport(Base): + __tablename__ = "commentreports" comment_id = Column(Integer, ForeignKey("comments.id"), primary_key=True) user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) reason = Column(String) created_utc = Column(Integer) - user = relationship("User", primaryjoin = "CommentFlag.user_id == User.id", uselist = False) + user = relationship("User", primaryjoin = "CommentReport.user_id == User.id", uselist = False) def __init__(self, *args, **kwargs): if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index be52943ff..c47104797 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -7,7 +7,7 @@ import gevent import requests from flask import g -from files.classes.flags import Flag +from files.classes.reports import Report from files.classes.mod_logs import ModAction from files.classes.notifications import Notification from files.classes.polls import CommentOption, PostOption @@ -46,8 +46,8 @@ def archive_url(url): gevent.spawn(_archiveorg, url) def snappy_report(post, reason): - flag = Flag(post_id=post.id, user_id=SNAPPY_ID, reason=reason) - g.db.add(flag) + report = Report(post_id=post.id, user_id=SNAPPY_ID, reason=reason) + g.db.add(report) message = f'@Snappy reported [{post.title}]({post.shortlink})\n\n> {reason}' send_repeatable_notification(post.author_id, message) diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index c4f32cb5c..b05afe986 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -466,7 +466,7 @@ PERMS = { # Minimum admin_level to perform action. 'MESSAGE_BLOCKED_USERS': 1, 'ADMIN_MOP_VISIBLE': 1, 'ADMIN_HOME_VISIBLE': 1, - 'FLAGS_REMOVE': 1, + 'REPORTS_REMOVE': 1, 'POST_COMMENT_MODERATION': 1, 'USER_BAN': 1, 'USER_SHADOWBAN': 1, diff --git a/files/helpers/get.py b/files/helpers/get.py index 81eed8ab6..efa558850 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -211,7 +211,7 @@ def get_posts(pids:Iterable[int], v:Optional[User]=None, eager:bool=False, extra selectinload(User.sub_mods), selectinload(User.sub_exiles), ), - selectinload(Post.flags), + selectinload(Post.reports), selectinload(Post.awards), selectinload(Post.options), ) diff --git a/files/routes/admin.py b/files/routes/admin.py index 152c8aa58..1da7fb7e2 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -327,7 +327,7 @@ def reported_posts(v): is_approved=None, is_banned=False, deleted_utc=0 - ).join(Post.flags) + ).join(Post.reports) total = listing.count() @@ -350,7 +350,7 @@ def reported_comments(v): is_approved=None, is_banned=False, deleted_utc=0 - ).join(Comment.flags) + ).join(Comment.reports) total = listing.count() diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 45e1b69ca..3d5dd61ab 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -1,6 +1,6 @@ from flask import g -from files.classes.flags import Flag, CommentFlag +from files.classes.reports import Report, CommentReport from files.classes.mod_logs import ModAction from files.classes.sub_logs import SubAction from files.helpers.actions import * @@ -17,7 +17,7 @@ from files.__main__ import app, limiter, cache @limiter.limit(DEFAULT_RATELIMIT) @limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) @auth_required -def flag_post(pid, v): +def report_post(pid, v): if v.is_muted: abort(403, "You are forbidden from making reports!") post = get_post(pid) @@ -62,10 +62,10 @@ def flag_post(pid, v): moved = move_post(post, v, reason) if moved: return {"message": moved} - existing = g.db.query(Flag.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none() + existing = g.db.query(Report.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none() if existing: abort(409, "You already reported this post!") - flag = Flag(post_id=post.id, user_id=v.id, reason=reason_html) - g.db.add(flag) + report = Report(post_id=post.id, user_id=v.id, reason=reason_html) + g.db.add(report) if v.id != post.author_id and not v.shadowbanned and not post.author.has_blocked(v): message = f'@{v.username} reported [{post.title}]({post.shortlink})\n\n> {reason}' @@ -80,12 +80,12 @@ def flag_post(pid, v): @limiter.limit(DEFAULT_RATELIMIT) @limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) @auth_required -def flag_comment(cid, v): +def report_comment(cid, v): if v.is_muted: abort(403, "You are forbidden from making reports!") comment = get_comment(cid) - existing = g.db.query(CommentFlag.comment_id).filter_by(user_id=v.id, comment_id=comment.id).one_or_none() + existing = g.db.query(CommentReport.comment_id).filter_by(user_id=v.id, comment_id=comment.id).one_or_none() if existing: abort(409, "You already reported this comment!") reason = request.values.get("reason", "").strip() @@ -96,8 +96,8 @@ def flag_comment(cid, v): if len(reason_html) > 350: abort(400, "Too long!") - flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason_html) - g.db.add(flag) + report = CommentReport(comment_id=comment.id, user_id=v.id, reason=reason_html) + g.db.add(report) if v.id != comment.author_id and not v.shadowbanned and not comment.author.has_blocked(v): message = f'@{v.username} reported your [comment]({comment.shortlink})\n\n> {reason}' @@ -111,13 +111,13 @@ def flag_comment(cid, v): @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit("100/minute;300/hour;2000/day") @limiter.limit("100/minute;300/hour;2000/day", key_func=get_ID) -@admin_level_required(PERMS['FLAGS_REMOVE']) +@admin_level_required(PERMS['REPORTS_REMOVE']) def remove_report_post(v, pid, uid): try: pid = int(pid) uid = int(uid) except: abort(404) - report = g.db.query(Flag).filter_by(post_id=pid, user_id=uid).one_or_none() + report = g.db.query(Report).filter_by(post_id=pid, user_id=uid).one_or_none() if report: g.db.delete(report) @@ -137,13 +137,13 @@ def remove_report_post(v, pid, uid): @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit("100/minute;300/hour;2000/day") @limiter.limit("100/minute;300/hour;2000/day", key_func=get_ID) -@admin_level_required(PERMS['FLAGS_REMOVE']) +@admin_level_required(PERMS['REPORTS_REMOVE']) def remove_report_comment(v, cid, uid): try: cid = int(cid) uid = int(uid) except: abort(404) - report = g.db.query(CommentFlag).filter_by(comment_id=cid, user_id=uid).one_or_none() + report = g.db.query(CommentReport).filter_by(comment_id=cid, user_id=uid).one_or_none() if report: g.db.delete(report) diff --git a/files/templates/comments.html b/files/templates/comments.html index 94b222a08..000b539b6 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -143,7 +143,7 @@ {% endif %} - {% if c.active_flags(v) %}{% endif %} + {% if c.active_reports(v) %}{% endif %} {% if c.over_18 %}+18{% endif %} {% if v and v.admin_level >= PERMS['USER_SHADOWBAN'] and c.author.shadowbanned %}{% endif %} {% if c.stickied %} @@ -235,7 +235,7 @@ {% endif %} - {{macros.flags(c, 'comment')}} + {{macros.reports(c, 'comment')}} {% if c.is_banned and c.ban_reason %}
removed by @{{c.ban_reason}} (Admin)
diff --git a/files/templates/post.html b/files/templates/post.html index 9728494ca..3ca79ad79 100644 --- a/files/templates/post.html +++ b/files/templates/post.html @@ -77,7 +77,7 @@ {{macros.post_meta(p)}} - {{macros.flags(p, 'post')}} + {{macros.reports(p, 'post')}} {% if p.realurl(v) and not v_forbid_deleted %}

diff --git a/files/templates/post_listing.html b/files/templates/post_listing.html index c6583d6d2..fcb33d38b 100644 --- a/files/templates/post_listing.html +++ b/files/templates/post_listing.html @@ -26,7 +26,7 @@ {% set v_forbid_deleted = (p.deleted_utc != 0 or p.is_banned) and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == p.author_id) %} -{{macros.flags(p, 'post')}} +{{macros.reports(p, 'post')}}
diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index 3e1dc2310..624fb6e40 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -54,7 +54,7 @@ {% if p.is_blocking and not p.ghost %}{% endif %} {% if p.is_blocked and not p.ghost %}{% endif %} {% if p.private %}Draft{% endif %} - {% if p.active_flags(v) %}{% endif %} + {% if p.active_reports(v) %}{% endif %} {% if p.ghost %} 👻 @@ -197,20 +197,20 @@ {% endif %} {% endmacro %} -{% macro flags(i, kind) %} -{% if i.active_flags(v) %} -
+{% macro reports(i, kind) %} +{% if i.active_reports(v) %} +
Reported by:
    - {% for f in i.filtered_flags(v) %} + {% for r in i.filtered_reports(v) %}
  • - {% if v and v.admin_level and f.user.shadowbanned %} - + {% if v and v.admin_level and r.user.shadowbanned %} + {% endif %} - {{f.user.username}} - {% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} - {% if v and v.admin_level >= PERMS['FLAGS_REMOVE'] %} - + {{r.user.username}} + {% if r.reason %}: {{r.realreason(v) | safe}}{% endif %} + {% if v and v.admin_level >= PERMS['REPORTS_REMOVE'] %} + {% endif %}
  • {% endfor %} diff --git a/migrations/20230623-rename-flags-to-reports.sql b/migrations/20230623-rename-flags-to-reports.sql new file mode 100644 index 000000000..81905ce98 --- /dev/null +++ b/migrations/20230623-rename-flags-to-reports.sql @@ -0,0 +1,12 @@ +alter table commentflags rename to commentreports; +alter table flags rename to reports; + +alter table commentreports rename constraint commentflags_pkey to commentreports_pkey; +alter table commentreports rename constraint commentflags_comment_id_fkey to commentreports_comment_id_fkey; +alter table commentreports rename constraint commentflags_user_id_fkey to commentreports_user_id_fkey; +alter table reports rename constraint flags_pkey to reports_pkey; +alter table reports rename constraint flags_post_id_fkey to reports_post_id_fkey; +alter table reports rename constraint flags_user_id_fkey to reports_user_id_fkey; + +alter index cflag_user_idx rename to creport_user_idx; +alter index flag_user_idx rename to report_user_idx;