From e6c2950666f58466fb38adf3ca5adfc20fedcfe2 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 16 Feb 2024 14:11:08 +0200 Subject: [PATCH] rename distinguish_level to distinguished --- files/classes/comment.py | 4 ++-- files/classes/post.py | 6 +++--- files/helpers/actions.py | 8 ++++---- files/helpers/alerts.py | 4 ++-- files/helpers/offsitementions.py | 2 +- files/helpers/sanitize.py | 2 +- files/routes/admin.py | 16 ++++++++-------- files/routes/awards.py | 2 +- files/routes/comments.py | 2 +- files/routes/posts.py | 2 +- files/templates/comments.html | 14 +++++++------- files/templates/post_actions.html | 4 ++-- files/templates/post_admin_actions_mobile.html | 4 ++-- files/templates/util/macros.html | 6 +++--- ...rename-distinguish-level-to-distinguished.sql | 9 +++++++++ 15 files changed, 47 insertions(+), 38 deletions(-) create mode 100644 migrations/20240216-rename-distinguish-level-to-distinguished.sql diff --git a/files/classes/comment.py b/files/classes/comment.py index b3d0bf40f..18b775815 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -182,7 +182,7 @@ class Comment(Base): ghost = Column(Boolean, default=False) bannedfor = Column(String) chuddedfor = Column(String) - distinguish_level = Column(Integer, default=0) + distinguished = Column(Boolean, default=False) deleted_utc = Column(Integer, default=0) is_approved = Column(Integer, ForeignKey("users.id")) level = Column(Integer, default=1) @@ -383,7 +383,7 @@ class Comment(Base): 'is_nsfw': self.nsfw, 'permalink': f'/comment/{self.id}#context', 'stickied': self.stickied, - 'distinguish_level': self.distinguish_level, + 'distinguished': self.distinguished, 'post_id': self.post.id if self.post else 0, 'score': self.score, 'upvotes': self.upvotes, diff --git a/files/classes/post.py b/files/classes/post.py index 30b57552f..11a1a03ac 100644 --- a/files/classes/post.py +++ b/files/classes/post.py @@ -38,7 +38,7 @@ class Post(Base): effortpost = Column(Boolean, default=False) views = Column(Integer, default=0) deleted_utc = Column(Integer, default=0) - distinguish_level = Column(Integer, default=0) + distinguished = Column(Boolean, default=False) stickied = Column(String) stickied_utc = Column(Integer) hole_pinned = Column(String) @@ -254,7 +254,7 @@ class Post(Base): 'downvotes': self.downvotes, 'stickied': self.stickied, 'private' : self.private, - 'distinguish_level': self.distinguish_level, + 'distinguished': self.distinguished, 'voted': self.voted if hasattr(self, 'voted') else 0, 'reports': reports, } @@ -269,7 +269,7 @@ class Post(Base): if v and v.poor: return 0 - if self.distinguish_level and SITE_NAME == 'WPD': + if self.distinguished and SITE_NAME == 'WPD': return 0 num = len([x for x in self.awards if x.kind == kind]) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 3130005e5..98238b00f 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -241,7 +241,7 @@ def execute_snappy(post, v): if len(body_html) < COMMENT_BODY_HTML_LENGTH_LIMIT: c = Comment(author_id=SNAPPY_ID, - distinguish_level=6, + distinguished=True, parent_post=post.id, level=1, nsfw=False, @@ -314,7 +314,7 @@ def execute_zozbot(c, level, post, v): body_html='

zoz

', top_comment_id=c.top_comment_id, ghost=c.ghost, - distinguish_level=6 + distinguished=True ) g.db.add(c2) @@ -332,7 +332,7 @@ def execute_zozbot(c, level, post, v): body_html='

zle

', top_comment_id=c.top_comment_id, ghost=c.ghost, - distinguish_level=6 + distinguished=True ) g.db.add(c3) @@ -349,7 +349,7 @@ def execute_zozbot(c, level, post, v): body_html='

zozzle

', top_comment_id=c.top_comment_id, ghost=c.ghost, - distinguish_level=6 + distinguished=True ) g.db.add(c4) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 345c28cce..d12d0211a 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -19,7 +19,7 @@ def create_comment(text_html): new_comment = Comment(author_id=AUTOJANNY_ID, parent_post=None, body_html=text_html, - distinguish_level=6, + distinguished=True, is_bot=True) g.db.add(new_comment) g.db.flush() @@ -310,7 +310,7 @@ def alert_admins(body): level=1, body_html=body_html, sentto=MODMAIL_ID, - distinguish_level=6, + distinguished=True, is_bot=True ) g.db.add(new_comment) diff --git a/files/helpers/offsitementions.py b/files/helpers/offsitementions.py index 2bf43bc06..c42c826da 100644 --- a/files/helpers/offsitementions.py +++ b/files/helpers/offsitementions.py @@ -99,7 +99,7 @@ def notify_mentions(mentions, send_to=None, mention_str='site mention'): author_id=const.AUTOJANNY_ID, parent_post=None, body_html=notif_text, - distinguish_level=6, + distinguished=True, created_utc=int(m['created_utc']), ) g.db.add(new_comment) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 533348625..b64d20a72 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -34,7 +34,7 @@ def create_comment_duplicated(text_html): new_comment = Comment(author_id=AUTOJANNY_ID, parent_post=None, body_html=text_html, - distinguish_level=6, + distinguished=True, is_bot=True) g.db.add(new_comment) g.db.flush() diff --git a/files/routes/admin.py b/files/routes/admin.py index 585f6b069..2766195e7 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1451,11 +1451,11 @@ def approve_post(post_id, v): def distinguish_post(post_id, v): post = get_post(post_id) - if post.distinguish_level: - post.distinguish_level = 0 + if post.distinguished: + post.distinguished = False kind = 'undistinguish_post' else: - post.distinguish_level = v.admin_level + post.distinguished = True kind = 'distinguish_post' g.db.add(post) @@ -1468,7 +1468,7 @@ def distinguish_post(post_id, v): g.db.add(ma) - if post.distinguish_level: return {"message": "Post distinguished!"} + if post.distinguished: return {"message": "Post distinguished!"} else: return {"message": "Post undistinguished!"} @@ -1686,11 +1686,11 @@ def approve_comment(c_id, v): def admin_distinguish_comment(c_id, v): comment = get_comment(c_id, v=v) - if comment.distinguish_level: - comment.distinguish_level = 0 + if comment.distinguished: + comment.distinguished = False kind = 'undistinguish_comment' else: - comment.distinguish_level = v.admin_level + comment.distinguished = True kind = 'distinguish_comment' g.db.add(comment) @@ -1703,7 +1703,7 @@ def admin_distinguish_comment(c_id, v): g.db.add(ma) - if comment.distinguish_level: return {"message": "Comment distinguished!"} + if comment.distinguished: return {"message": "Comment distinguished!"} else: return {"message": "Comment undistinguished!"} @app.get("/admin/banned_domains/") diff --git a/files/routes/awards.py b/files/routes/awards.py index 6a17ad2fc..4b6b66929 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -205,7 +205,7 @@ def award_thing(v, thing_type, id): if isinstance(obj, Post) and obj.id == 210983: abort(403, "You can't award this post!") - if isinstance(obj, Post) and obj.distinguish_level and AWARDS[kind]['cosmetic']: + if isinstance(obj, Post) and obj.distinguished and AWARDS[kind]['cosmetic']: abort(403, "Distinguished posts are immune to cosmetic awards!") if kind == "benefactor": diff --git a/files/routes/comments.py b/files/routes/comments.py index 34b0db5ac..6146be1bf 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -326,7 +326,7 @@ def comment(v): c_jannied = Comment(author_id=AUTOJANNY_ID, parent_post=post_target.id if posting_to_post else None, wall_user_id=post_target.id if not posting_to_post else None, - distinguish_level=6, + distinguished=True, parent_comment_id=c.id, level=level+1, is_bot=True, diff --git a/files/routes/posts.py b/files/routes/posts.py index 834c25a57..b89a416e9 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -674,7 +674,7 @@ def submit_post(v, hole=None): nsfw=False, is_bot=True, app_id=None, - distinguish_level=6, + distinguished=True, body=body, body_html=body_jannied_html, ghost=p.ghost diff --git a/files/templates/comments.html b/files/templates/comments.html index d9341140c..434db764d 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -153,7 +153,7 @@ {% endif %} - {% if c.distinguish_level and not c.ghost %} + {% if c.distinguished and not c.ghost %} {% endif %} @@ -174,7 +174,7 @@ {% endif %} {% if c.ghost %} - 👻 + 👻 {% else %} {% if FEATURES['PATRON_ICONS'] and c.author.patron > 1 %} {{c.author.patron_tooltip}} @@ -194,7 +194,7 @@ @{{c.author.username}}'s hat {%- endif %} - {{c.author_name}} + {{c.author_name}} {% if FEATURES['PRONOUNS'] %} {{c.author.pronouns_display}} @@ -422,9 +422,9 @@ {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %} - + - + {% endif %} {% if c.parent_post %} @@ -688,8 +688,8 @@ {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %} - - + + {% endif %} diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index e1a739b5d..0b773f6ea 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -59,8 +59,8 @@ {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %} - - + + {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} diff --git a/files/templates/post_admin_actions_mobile.html b/files/templates/post_admin_actions_mobile.html index d7ba70842..121dd8fce 100644 --- a/files/templates/post_admin_actions_mobile.html +++ b/files/templates/post_admin_actions_mobile.html @@ -23,9 +23,9 @@ {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH'] %} - + - + {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index 1375604c2..76e4c1bb1 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -51,7 +51,7 @@ {% endif %} - {% if p.distinguish_level %}{% endif %} + {% if p.distinguished %}{% endif %} {% if p.is_pinned and request.path != '/' %} {% endif %} @@ -66,7 +66,7 @@ {% endif %} {% if p.ghost %} - 👻 + 👻 {% else %} {% if FEATURES['PATRON_ICONS'] and p.author.patron > 1 %} {{p.author.patron_tooltip}} @@ -85,7 +85,7 @@ @{{p.author.username}}'s hat {%- endif %} - {{p.author_name}} + {{p.author_name}} {% if FEATURES['PRONOUNS'] %} {{p.author.pronouns_display}} diff --git a/migrations/20240216-rename-distinguish-level-to-distinguished.sql b/migrations/20240216-rename-distinguish-level-to-distinguished.sql new file mode 100644 index 000000000..d721074ca --- /dev/null +++ b/migrations/20240216-rename-distinguish-level-to-distinguished.sql @@ -0,0 +1,9 @@ +alter table posts add column distinguished bool default false not null; +update posts set distinguished=true where distinguish_level>0; +alter table comments add column distinguished bool default false not null; +update comments set distinguished=true where distinguish_level>0; + +alter table posts alter column distinguished drop default; +alter table posts drop column distinguish_level; +alter table comments alter column distinguished drop default; +alter table comments drop column distinguish_level;