From 9804a365da3a2aa36c2011e8475f6205ef3d15dc Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 18 Feb 2024 17:29:53 +0200 Subject: [PATCH] rename a bunch of columns --- files/assets/css/themes/classic.css | 10 +-- files/assets/js/admin/pinpost.js | 4 +- files/classes/comment.py | 8 +-- files/classes/post.py | 12 ++-- files/classes/user.py | 2 +- files/helpers/actions.py | 6 +- files/helpers/cron.py | 8 +-- files/routes/admin.py | 62 +++++++++---------- files/routes/awards.py | 22 +++---- files/routes/comments.py | 22 +++---- files/routes/front.py | 10 +-- files/routes/holes.py | 10 +-- files/routes/notifications.py | 2 +- files/routes/posts.py | 49 ++++++++------- files/routes/search.py | 4 +- files/routes/users.py | 15 +++-- files/templates/comments.html | 22 +++---- files/templates/post.html | 2 +- files/templates/post_actions.html | 10 +-- files/templates/post_actions_mobile.html | 6 +- .../templates/post_admin_actions_mobile.html | 4 +- files/templates/post_listing.html | 2 +- files/templates/util/macros.html | 8 +-- migrations/20240218-rename-columns.sql | 13 ++++ schema.sql | 29 +++++---- 25 files changed, 177 insertions(+), 165 deletions(-) create mode 100644 migrations/20240218-rename-columns.sql diff --git a/files/assets/css/themes/classic.css b/files/assets/css/themes/classic.css index 5c5b3ea95..10a6548d9 100644 --- a/files/assets/css/themes/classic.css +++ b/files/assets/css/themes/classic.css @@ -6,7 +6,7 @@ --gray: #888; --upvote: #ff8b60; --downvote: #9393ff; - --sticky: #228822; + --pinned: #228822; --background: 255, 255, 255; } @@ -82,11 +82,11 @@ input, textarea, .form-control { } .fa-thumbtack.text-admin { - color: var(--sticky); + color: var(--pinned); } .fa-broom { - color: var(--sticky) !important; + color: var(--pinned) !important; } .tooltip { @@ -152,8 +152,8 @@ a.btn-block[href~="/submit"] { color: #369; } -#frontpage .card.stickied .post-title a { - color: var(--sticky); +#frontpage .card.pinned .post-title a { + color: var(--pinned); } /*posts*/ diff --git a/files/assets/js/admin/pinpost.js b/files/assets/js/admin/pinpost.js index 3cb0b7528..7ff36557e 100644 --- a/files/assets/js/admin/pinpost.js +++ b/files/assets/js/admin/pinpost.js @@ -1,5 +1,5 @@ function pinPost(t, id) { - postToast(t, `/sticky/${id}`, + postToast(t, `/pin_post/${id}`, { }, (xhr) => { @@ -15,7 +15,7 @@ function pinPost(t, id) { } function unpinPost(t, id) { - postToast(t, `/unsticky/${id}`, + postToast(t, `/unpin_post/${id}`, { }, () => { diff --git a/files/classes/comment.py b/files/classes/comment.py index 18b775815..026af6cbc 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -189,8 +189,8 @@ class Comment(Base): parent_comment_id = Column(Integer, ForeignKey("comments.id")) top_comment_id = Column(Integer) is_bot = Column(Boolean, default=False) - stickied = Column(String) - stickied_utc = Column(Integer) + pinned = Column(String) + pinned_utc = Column(Integer) num_of_pinned_children = Column(Integer, default=0) sentto = Column(Integer, ForeignKey("users.id")) app_id = Column(Integer, ForeignKey("oauth_apps.id")) @@ -288,7 +288,7 @@ class Comment(Base): if self.replies2 != None: return self.replies2 - replies = g.db.query(Comment).filter_by(parent_comment_id=self.id).order_by(Comment.stickied, Comment.num_of_pinned_children.desc()) + replies = g.db.query(Comment).filter_by(parent_comment_id=self.id).order_by(Comment.pinned, Comment.num_of_pinned_children.desc()) if not self.parent_post: sort='old' return sort_objects(sort, replies, Comment).all() @@ -382,7 +382,7 @@ class Comment(Base): 'deleted_utc': self.deleted_utc, 'is_nsfw': self.nsfw, 'permalink': f'/comment/{self.id}#context', - 'stickied': self.stickied, + 'pinned': self.pinned, 'distinguished': self.distinguished, 'post_id': self.post.id if self.post else 0, 'score': self.score, diff --git a/files/classes/post.py b/files/classes/post.py index 5fc1b5a6d..09a4cc936 100644 --- a/files/classes/post.py +++ b/files/classes/post.py @@ -39,12 +39,12 @@ class Post(Base): views = Column(Integer, default=0) deleted_utc = Column(Integer, default=0) distinguished = Column(Boolean, default=False) - stickied = Column(String) - stickied_utc = Column(Integer) + pinned = Column(String) + pinned_utc = Column(Integer) + profile_pinned = Column(Boolean, default=False) hole_pinned = Column(String) hole = Column(String, ForeignKey("holes.name")) - is_pinned = Column(Boolean, default=False) - private = Column(Boolean, default=False) + draft = Column(Boolean, default=False) comment_count = Column(Integer, default=0) is_approved = Column(Integer, ForeignKey("users.id")) is_bot = Column(Boolean, default=False) @@ -252,8 +252,8 @@ class Post(Base): 'score': self.score, 'upvotes': self.upvotes, 'downvotes': self.downvotes, - 'stickied': self.stickied, - 'private' : self.private, + 'pinned': self.pinned, + 'draft' : self.draft, 'distinguished': self.distinguished, 'voted': self.voted if hasattr(self, 'voted') else 0, 'reports': reports, diff --git a/files/classes/user.py b/files/classes/user.py index a419110c7..24d22219f 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -847,7 +847,7 @@ class User(Base): Post.created_utc > self.last_viewed_post_notifs, Post.deleted_utc == 0, Post.is_banned == False, - Post.private == False, + Post.draft == False, Post.author_id != self.id, Post.author_id.notin_(self.userblocks), or_(Post.hole == None, Post.hole.notin_(self.hole_blocks)), diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 98238b00f..3a8a70f7a 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -262,8 +262,8 @@ def execute_snappy(post, v): g.db.add(snappy) if FEATURES['PINS'] and (body.startswith(':#marseypin:') or body.startswith(':#marseypin2:')): - post.stickied = "Snappy" - post.stickied_utc = int(time.time()) + 3600 + post.pinned = "Snappy" + post.pinned_utc = int(time.time()) + 3600 elif SITE_NAME == 'rDrama' and body.startswith(':#marseyban:'): days = 0.01 @@ -463,7 +463,7 @@ def execute_antispam_post_check(title, v, url): for post in similar_posts + similar_urls: post.is_banned = True - post.is_pinned = False + post.profile_pinned = False post.ban_reason = "AutoJanny" g.db.add(post) ma = ModAction( diff --git a/files/helpers/cron.py b/files/helpers/cron.py index 106e2f7d3..282ca6cf0 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -156,7 +156,7 @@ def _hole_inactive_purge_task(): one_week_ago = time.time() - 604800 active_holes = [x[0] for x in g.db.query(Post.hole).distinct() \ .filter(Post.hole != None, Post.created_utc > one_week_ago, - Post.private == False, Post.is_banned == False, + Post.draft == False, Post.is_banned == False, Post.deleted_utc == 0)] active_holes.extend(['changelog','countryclub','museumofrdrama','highrollerclub','test']) # holes immune from deletion @@ -330,11 +330,11 @@ def _unpin_expired(): pins = [] for cls in (Post, Comment): - pins += g.db.query(cls).options(load_only(cls.id)).filter(cls.stickied_utc < t) + pins += g.db.query(cls).options(load_only(cls.id)).filter(cls.pinned_utc < t) for pin in pins: - pin.stickied = None - pin.stickied_utc = None + pin.pinned = None + pin.pinned_utc = None g.db.add(pin) if isinstance(pin, Comment): pin.unpin_parents() diff --git a/files/routes/admin.py b/files/routes/admin.py index 7ed871b41..5ab0d3bd5 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1386,11 +1386,11 @@ def remove_post(post_id, v): post.is_banned = True post.is_approved = None - if not FEATURES['AWARDS'] or not post.stickied or not post.stickied.endswith(PIN_AWARD_TEXT): - post.stickied = None - post.stickied_utc = None + if not FEATURES['AWARDS'] or not post.pinned or not post.pinned.endswith(PIN_AWARD_TEXT): + post.pinned = None + post.pinned_utc = None - post.is_pinned = False + post.profile_pinned = False post.ban_reason = v.username g.db.add(post) @@ -1443,26 +1443,26 @@ def approve_post(post_id, v): return {"message": "Post approved!"} -@app.post("/sticky/") +@app.post("/pin_post/") @feature_required('PINS') @limiter.limit('1/second', scope=rpath) @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @admin_level_required(PERMS['POST_COMMENT_MODERATION']) -def sticky_post(post_id, v): +def pin_post(post_id, v): post = get_post(post_id) if post.is_banned: - abort(403, "Can't sticky removed posts!") + abort(403, "Can't pin removed posts!") - if FEATURES['AWARDS'] and post.stickied and post.stickied.endswith(PIN_AWARD_TEXT) and v.admin_level < PERMS["UNDO_AWARD_PINS"]: + if FEATURES['AWARDS'] and post.pinned and post.pinned.endswith(PIN_AWARD_TEXT) and v.admin_level < PERMS["UNDO_AWARD_PINS"]: abort(403, "Can't pin award pins!") - pins = g.db.query(Post).filter(Post.stickied != None, Post.is_banned == False).count() + pins = g.db.query(Post).filter(Post.pinned != None, Post.is_banned == False).count() - if not post.stickied_utc: - post.stickied_utc = int(time.time()) + 3600 + if not post.pinned_utc: + post.pinned_utc = int(time.time()) + 3600 pin_time = 'for 1 hour' code = 200 if v.id != post.author_id: @@ -1470,11 +1470,11 @@ def sticky_post(post_id, v): else: if pins >= PIN_LIMIT + 1: abort(403, f"Can't exceed {PIN_LIMIT} pinned posts limit!") - post.stickied_utc = None + post.pinned_utc = None pin_time = 'permanently' code = 201 - post.stickied = v.username + post.pinned = v.username g.db.add(post) @@ -1491,20 +1491,20 @@ def sticky_post(post_id, v): return {"message": f"Post pinned {pin_time}!"}, code -@app.post("/unsticky/") +@app.post("/unpin_post/") @limiter.limit('1/second', scope=rpath) @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @admin_level_required(PERMS['POST_COMMENT_MODERATION']) -def unsticky_post(post_id, v): +def unpin_post(post_id, v): post = get_post(post_id) - if post.stickied: - if FEATURES['AWARDS'] and post.stickied.endswith(PIN_AWARD_TEXT) and v.admin_level < PERMS["UNDO_AWARD_PINS"]: + if post.pinned: + if FEATURES['AWARDS'] and post.pinned.endswith(PIN_AWARD_TEXT) and v.admin_level < PERMS["UNDO_AWARD_PINS"]: abort(403, "Can't unpin award pins!") - post.stickied = None - post.stickied_utc = None + post.pinned = None + post.pinned_utc = None g.db.add(post) ma = ModAction( @@ -1520,23 +1520,23 @@ def unsticky_post(post_id, v): cache.delete_memoized(frontlist) return {"message": "Post unpinned!"} -@app.post("/sticky_comment/") +@app.post("/pin_comment/") @limiter.limit('1/second', scope=rpath) @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @admin_level_required(PERMS['POST_COMMENT_MODERATION']) -def sticky_comment(cid, v): +def pin_comment(cid, v): comment = get_comment(cid, v=v) if comment.is_banned: - abort(403, "Can't sticky removed comments!") + abort(403, "Can't pin removed comments!") - if FEATURES['AWARDS'] and comment.stickied and comment.stickied.endswith(PIN_AWARD_TEXT) and v.admin_level < PERMS["UNDO_AWARD_PINS"]: + if FEATURES['AWARDS'] and comment.pinned and comment.pinned.endswith(PIN_AWARD_TEXT) and v.admin_level < PERMS["UNDO_AWARD_PINS"]: abort(403, "Can't pin award pins!") - if not comment.stickied: - comment.stickied = v.username + if not comment.pinned: + comment.pinned = v.username g.db.add(comment) ma = ModAction( @@ -1555,21 +1555,21 @@ def sticky_comment(cid, v): return {"message": "Comment pinned!"} -@app.post("/unsticky_comment/") +@app.post("/unpin_comment/") @limiter.limit('1/second', scope=rpath) @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @admin_level_required(PERMS['POST_COMMENT_MODERATION']) -def unsticky_comment(cid, v): +def unpin_comment(cid, v): comment = get_comment(cid, v=v) - if comment.stickied: - if FEATURES['AWARDS'] and comment.stickied.endswith(PIN_AWARD_TEXT) and v.admin_level < PERMS["UNDO_AWARD_PINS"]: + if comment.pinned: + if FEATURES['AWARDS'] and comment.pinned.endswith(PIN_AWARD_TEXT) and v.admin_level < PERMS["UNDO_AWARD_PINS"]: abort(403, "Can't unpin award pins!") - comment.stickied = None - comment.stickied_utc = None + comment.pinned = None + comment.pinned_utc = None g.db.add(comment) ma = ModAction( diff --git a/files/routes/awards.py b/files/routes/awards.py index 4b6b66929..c76a98b2c 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -311,39 +311,39 @@ def award_thing(v, thing_type, id): if not FEATURES['PINS']: abort(403) if obj.is_banned: abort(403) - if obj.stickied and not obj.stickied_utc: + if obj.pinned and not obj.pinned_utc: abort(400, f"This {thing_type} is already pinned permanently!") if isinstance(obj, Comment): add = 3600*6 else: add = 3600 - if obj.stickied_utc: - obj.stickied_utc += add + if obj.pinned_utc: + obj.pinned_utc += add else: - obj.stickied_utc = int(time.time()) + add + obj.pinned_utc = int(time.time()) + add if isinstance(obj, Comment): obj.pin_parents() - obj.stickied = f'{v.username}{PIN_AWARD_TEXT}' + obj.pinned = f'{v.username}{PIN_AWARD_TEXT}' if isinstance(obj, Post): cache.delete_memoized(frontlist) elif kind == "unpin": - if not obj.stickied_utc: abort(400) + if not obj.pinned_utc: abort(400) if not obj.author.deflector or v == obj.author: if isinstance(obj, Comment): - t = obj.stickied_utc - 3600*6 + t = obj.pinned_utc - 3600*6 else: - t = obj.stickied_utc - 3600 + t = obj.pinned_utc - 3600 if time.time() > t: - obj.stickied = None - obj.stickied_utc = None + obj.pinned = None + obj.pinned_utc = None if isinstance(obj, Post): cache.delete_memoized(frontlist) else: obj.unpin_parents() - else: obj.stickied_utc = t + else: obj.pinned_utc = t elif kind == "queen": if not author.queen: characters = list(filter(str.isalpha, author.username)) diff --git a/files/routes/comments.py b/files/routes/comments.py index fdc4ef8c2..0c0248678 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -439,9 +439,9 @@ def delete_comment(cid, v): c.deleted_utc = int(time.time()) g.db.add(c) - if c.stickied: - c.stickied = None - c.stickied_utc = None + if c.pinned: + c.pinned = None + c.pinned_utc = None c.unpin_parents() if not (c.parent_post in ADMIGGER_THREADS and c.level == 1): @@ -498,11 +498,11 @@ def pin_comment(cid, v): comment = get_comment(cid, v=v) - if not comment.stickied: + if not comment.pinned: if v.id != comment.post.author_id: abort(403) - if comment.post.ghost: comment.stickied = "(OP)" - else: comment.stickied = v.username + " (OP)" + if comment.post.ghost: comment.pinned = "(OP)" + else: comment.pinned = v.username + " (OP)" g.db.add(comment) @@ -526,14 +526,14 @@ def unpin_comment(cid, v): comment = get_comment(cid, v=v) - if comment.stickied: + if comment.pinned: if v.id != comment.post.author_id: abort(403) - if not comment.stickied.endswith(" (OP)"): + if not comment.pinned.endswith(" (OP)"): abort(403, "You can only unpin comments you have pinned!") - comment.stickied = None - comment.stickied_utc = None + comment.pinned = None + comment.pinned_utc = None g.db.add(comment) comment.unpin_parents() @@ -646,7 +646,7 @@ def toggle_comment_nsfw(cid, v): def edit_comment(cid, v): c = get_comment(cid, v=v) - if time.time() - c.created_utc > 31*24*60*60 and not (c.post and c.post.private) \ + if time.time() - c.created_utc > 31*24*60*60 and not (c.post and c.post.draft) \ and v.admin_level < PERMS["IGNORE_1MONTH_EDITING_LIMIT"] and v.id not in EXEMPT_FROM_1MONTH_EDITING_LIMIT: abort(403, "You can't edit comments older than 1 month!") diff --git a/files/routes/front.py b/files/routes/front.py index 6cced0039..b6432e836 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -134,7 +134,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' posts = posts.filter( Post.is_banned == False, - Post.private == False, + Post.draft == False, Post.deleted_utc == 0, ) @@ -148,7 +148,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' if pins and not gt and not lt: if hole: posts = posts.filter(Post.hole_pinned == None) - else: posts = posts.filter(Post.stickied == None) + else: posts = posts.filter(Post.pinned == None) if v: posts = posts.filter(Post.author_id.notin_(v.userblocks)) @@ -193,7 +193,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' if hole: pins = g.db.query(Post).options(load_only(Post.id)).filter(Post.hole == hole.name, Post.hole_pinned != None) else: - pins = g.db.query(Post).options(load_only(Post.id)).filter(Post.stickied != None, Post.is_banned == False) + pins = g.db.query(Post).options(load_only(Post.id)).filter(Post.pinned != None, Post.is_banned == False) if v: pins = pins.filter(or_(Post.hole == None, Post.hole.notin_(v.hole_blocks))) @@ -216,7 +216,7 @@ def random_post(v): p = g.db.query(Post.id).filter( Post.deleted_utc == 0, Post.is_banned == False, - Post.private == False, + Post.draft == False, or_(Post.hole == None, Post.hole.notin_(v.hole_blocks)), ).order_by(func.random()).first() @@ -255,7 +255,7 @@ def comment_idlist(v=None, page=1, sort="new", t="day", gt=0, lt=0): Comment.is_banned == False, Comment.deleted_utc == 0, Comment.author_id.notin_(v.userblocks), - or_(Comment.parent_post == None, Post.private == False), + or_(Comment.parent_post == None, Post.draft == False), ) if gt: comments = comments.filter(Comment.created_utc > gt) diff --git a/files/routes/holes.py b/files/routes/holes.py index 7eaf72bb7..ede737178 100644 --- a/files/routes/holes.py +++ b/files/routes/holes.py @@ -900,10 +900,10 @@ def pin_comment_mod(cid, v): comment = get_comment(cid, v=v) - if not comment.stickied: + if not comment.pinned: if not v.mods_hole(comment.post.hole): abort(403) - comment.stickied = v.username + " (Mod)" + comment.pinned = v.username + " (Mod)" g.db.add(comment) @@ -933,11 +933,11 @@ def unpin_comment_mod(cid, v): comment = get_comment(cid, v=v) - if comment.stickied: + if comment.pinned: if not v.mods_hole(comment.post.hole): abort(403) - comment.stickied = None - comment.stickied_utc = None + comment.pinned = None + comment.pinned_utc = None g.db.add(comment) comment.unpin_parents() diff --git a/files/routes/notifications.py b/files/routes/notifications.py index d94a2b6d0..c358c2ccc 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -188,7 +188,7 @@ def notifications_posts(v): listing = g.db.query(Post).filter( Post.deleted_utc == 0, Post.is_banned == False, - Post.private == False, + Post.draft == False, Post.author_id != v.id, Post.author_id.notin_(v.userblocks), or_(Post.hole == None, Post.hole.notin_(v.hole_blocks)), diff --git a/files/routes/posts.py b/files/routes/posts.py index 6dc497b9a..999d9d53f 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -54,11 +54,12 @@ def _add_post_view(pid): def publish(pid, v): p = get_post(pid) - if not p.private: return {"message": "Post published!"} + if not p.draft: + return {"message": "Post published!"} if p.author_id != v.id: abort(403) - p.private = False + p.draft = False p.created_utc = int(time.time()) g.db.add(p) @@ -70,7 +71,7 @@ def publish(pid, v): p.title_html = filter_emojis_only(p.title, golden=False, obj=p, author=p.author) p.body_html = sanitize(p.body, golden=False, limit_pings=100, obj=p, author=p.author) - if p.private or not complies_with_chud(p): + if p.draft or not complies_with_chud(p): abort(403, f'You have to include "{p.author.chud_phrase}" in your post!') notify_users = NOTIFY_USERS(f'{p.title} {p.body}', v, ghost=p.ghost, obj=p, followers_ping=False) @@ -138,8 +139,8 @@ def post_id(pid, v, anything=None, hole=None): comments, output = get_comments_v_properties(v, None, Comment.parent_post == p.id, Comment.level < 10) if sort == "hot": - pinned = [c[0] for c in comments.filter(Comment.stickied != None).order_by(Comment.created_utc.desc())] - comments = comments.filter(Comment.stickied == None) + pinned = [c[0] for c in comments.filter(Comment.pinned != None).order_by(Comment.created_utc.desc())] + comments = comments.filter(Comment.pinned == None) comments = comments.filter(Comment.level == 1) comments = sort_objects(sort, comments, Comment) @@ -148,8 +149,8 @@ def post_id(pid, v, anything=None, hole=None): comments = g.db.query(Comment).filter(Comment.parent_post == p.id) if sort == "hot": - pinned = comments.filter(Comment.stickied != None).order_by(Comment.created_utc.desc()).all() - comments = comments.filter(Comment.stickied == None) + pinned = comments.filter(Comment.pinned != None).order_by(Comment.created_utc.desc()).all() + comments = comments.filter(Comment.pinned == None) comments = comments.filter(Comment.level == 1) comments = sort_objects(sort, comments, Comment) @@ -224,7 +225,7 @@ def view_more(v, pid, sort, offset): comments, output = get_comments_v_properties(v, None, Comment.parent_post == pid, Comment.id.notin_(ids), Comment.level < 10) if sort == "hot": - comments = comments.filter(Comment.stickied == None) + comments = comments.filter(Comment.pinned == None) comments = comments.filter(Comment.level == 1) comments = sort_objects(sort, comments, Comment) @@ -238,7 +239,7 @@ def view_more(v, pid, sort, offset): ) if sort == "hot": - comments = comments.filter(Comment.stickied == None) + comments = comments.filter(Comment.pinned == None) comments = sort_objects(sort, comments, Comment) @@ -321,7 +322,7 @@ def postprocess_post(post_url, post_body, post_body_html, pid, generate_thumb, e p.body_html = post_body_html g.db.add(p) - if not p.private and not edit: + if not p.draft and not edit: execute_snappy(p, p.author) g.db.commit() @@ -591,7 +592,7 @@ def submit_post(v, hole=None): if SITE_NAME == 'WPD': p.cw = request.values.get("cw", False, bool) - if not p.private: + if not p.draft: p.chudded = v.chud and hole != 'chudrama' and not (p.is_longpost and not v.chudded_by) p.queened = v.queen and not p.is_longpost p.sharpened = v.sharpen and not p.is_longpost @@ -660,7 +661,7 @@ def submit_post(v, hole=None): else: abort(415) - if not p.private and not complies_with_chud(p): + if not p.draft and not complies_with_chud(p): p.is_banned = True p.ban_reason = "AutoJanny" @@ -695,7 +696,7 @@ def submit_post(v, hole=None): autojanny.comment_count += 1 g.db.add(autojanny) - if not p.private: + if not p.draft: notify_users = NOTIFY_USERS(f'{title} {body}', v, ghost=p.ghost, obj=p, followers_ping=False) if notify_users: @@ -710,8 +711,8 @@ def submit_post(v, hole=None): g.db.add(v) if v.id in PINNED_POSTS_IDS and not p.ghost and not (p.hole and p.hole_obj.stealth): - p.stickied_utc = time.time() + PINNED_POSTS_IDS[v.id] * 3600 - p.stickied = "AutoJanny" + p.pinned_utc = time.time() + PINNED_POSTS_IDS[v.id] * 3600 + p.pinned = "AutoJanny" cache.delete_memoized(frontlist) cache.delete_memoized(userpagelisting) @@ -756,9 +757,9 @@ def delete_post_pid(pid, v): if not p.deleted_utc: p.deleted_utc = int(time.time()) - p.is_pinned = False - p.stickied = None - p.stickied_utc = None + p.profile_pinned = False + p.pinned = None + p.pinned_utc = None g.db.add(p) @@ -917,7 +918,7 @@ def unsave_post(pid, v): return {"message": "Post unsaved!"} -@app.post("/pin/") +@app.post("/profile_pin/") @limiter.limit('1/second', scope=rpath) @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @@ -927,10 +928,10 @@ def pin_post(post_id, v): p = get_post(post_id) if p: if v.id != p.author_id: abort(403, "Only the post author can do that!") - p.is_pinned = not p.is_pinned + p.profile_pinned = not p.profile_pinned g.db.add(p) cache.delete_memoized(userpagelisting) - if p.is_pinned: return {"message": "Post pinned!"} + if p.profile_pinned: return {"message": "Post pinned!"} else: return {"message": "Post unpinned!"} return abort(404, "Post not found!") @@ -1023,7 +1024,7 @@ def edit_post(pid, v): if not v.can_edit(p): abort(403) # Disable edits on things older than 1wk unless it's a draft or editor is a jannie - if time.time() - p.created_utc > 31*24*60*60 and not p.private \ + if time.time() - p.created_utc > 31*24*60*60 and not p.draft \ and v.admin_level < PERMS["IGNORE_1MONTH_EDITING_LIMIT"] and v.id not in EXEMPT_FROM_1MONTH_EDITING_LIMIT: abort(403, "You can't edit posts older than 1 month!") @@ -1044,7 +1045,7 @@ def edit_post(pid, v): abort(400, "Please enter a better title!") - if not p.private: + if not p.draft: notify_users = NOTIFY_USERS(f'{title} {body}', v, oldtext=f'{p.title} {p.body}', ghost=p.ghost, obj=p, followers_ping=False) if notify_users: cid, text = notif_comment_mention(p) @@ -1093,7 +1094,7 @@ def edit_post(pid, v): gevent.spawn(postprocess_post, p.url, p.body, p.body_html, p.id, False, True) - if not p.private and not complies_with_chud(p): + if not p.draft and not complies_with_chud(p): abort(403, f'You have to include "{p.author.chud_phrase}" in your post!') diff --git a/files/routes/search.py b/files/routes/search.py index e8701be8e..faaf37653 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -67,7 +67,7 @@ def searchposts(v): posts = posts.filter( Post.deleted_utc == 0, Post.is_banned == False, - Post.private == False) + Post.draft == False) if 'author' in criteria: author = get_user(criteria['author'], v=v) @@ -245,7 +245,7 @@ def searchcomments(v): comments = apply_time_filter(t, comments, Comment) if v.admin_level < PERMS['POST_COMMENT_MODERATION']: - private = [x[0] for x in g.db.query(Post.id).filter(Post.private == True)] + private = [x[0] for x in g.db.query(Post.id).filter(Post.draft == True)] comments = comments.filter( Comment.is_banned==False, diff --git a/files/routes/users.py b/files/routes/users.py index 3db992271..1fb398c00 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -404,10 +404,10 @@ def all_upvoters_downvoters(v, username, vote_dir, is_who_simps_hates): votes = [] votes2 = [] if is_who_simps_hates: - votes = g.db.query(Post.author_id, func.count(Post.author_id)).join(Vote).filter(Post.private == False, Post.ghost == False, Post.is_banned == False, Post.deleted_utc == 0, Vote.vote_type==vote_dir, Vote.user_id==id).group_by(Post.author_id).order_by(func.count(Post.author_id).desc()).all() + votes = g.db.query(Post.author_id, func.count(Post.author_id)).join(Vote).filter(Post.draft == False, Post.ghost == False, Post.is_banned == False, Post.deleted_utc == 0, Vote.vote_type==vote_dir, Vote.user_id==id).group_by(Post.author_id).order_by(func.count(Post.author_id).desc()).all() votes2 = g.db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote).filter(Comment.ghost == False, Comment.is_banned == False, Comment.deleted_utc == 0, CommentVote.vote_type==vote_dir, CommentVote.user_id==id).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all() else: - votes = g.db.query(Vote.user_id, func.count(Vote.user_id)).join(Post).filter(Post.private == False, Post.ghost == False, Post.is_banned == False, Post.deleted_utc == 0, Vote.vote_type==vote_dir, Post.author_id==id).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all() + votes = g.db.query(Vote.user_id, func.count(Vote.user_id)).join(Post).filter(Post.draft == False, Post.ghost == False, Post.is_banned == False, Post.deleted_utc == 0, Vote.vote_type==vote_dir, Post.author_id==id).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all() votes2 = g.db.query(CommentVote.user_id, func.count(CommentVote.user_id)).join(Comment).filter(Comment.ghost == False, Comment.is_banned == False, Comment.deleted_utc == 0, CommentVote.vote_type==vote_dir, Comment.author_id==id).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).all() votes = Counter(dict(votes)) + Counter(dict(votes2)) total_items = sum(votes.values()) @@ -954,11 +954,10 @@ def u_username(v, username): ids, total = userpagelisting(u, v=v, page=page, sort=sort, t=t) if page == 1 and sort == 'new': - sticky = [] - sticky = g.db.query(Post).filter_by(is_pinned=True, author_id=u.id, is_banned=False).all() - if sticky: - for p in sticky: - ids = [p.id] + ids + pinned = [] + pinned = g.db.query(Post).filter_by(profile_pinned=True, author_id=u.id, is_banned=False).all() + for p in pinned: + ids = [p.id] + ids listing = get_posts(ids, v=v) @@ -992,7 +991,7 @@ def u_username(v, username): @cache.memoize() def userpagelisting(u, v=None, page=1, sort="new", t="all"): - posts = g.db.query(Post).filter_by(author_id=u.id, is_pinned=False).options(load_only(Post.id)) + posts = g.db.query(Post).filter_by(author_id=u.id, profile_pinned=False).options(load_only(Post.id)) if v.id != u.id and v.admin_level < PERMS['POST_COMMENT_MODERATION']: posts = posts.filter_by(is_banned=False, private=False, ghost=False) diff --git a/files/templates/comments.html b/files/templates/comments.html index db5056b74..9e99d9f8c 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -173,8 +173,8 @@ {%- include 'admin/shadowbanned_tooltip.html' -%} {% endwith %} - {% if c.stickied %} - + {% if c.pinned %} + {% endif %} {% if c.distinguished and not c.ghost %} @@ -467,7 +467,7 @@ {% set url = "" %} {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} - {% set url = "sticky_comment" %} + {% set url = "pin_comment" %} {% elif v.id == c.post.author_id %} {% set url = "pin_comment" %} {% elif v.mods_hole(c.post.hole) %} @@ -475,9 +475,9 @@ {% endif %} {% if url != "" %} - + - + {% endif %} {% endif %} @@ -683,11 +683,11 @@ {% if v.admin_level < PERMS['POST_COMMENT_MODERATION'] %} {% if c.parent_post and v.id == c.post.author_id %} - - + + {% elif v.mods_hole(c.post.hole) %} - - + + {% endif %} {% endif %} @@ -733,8 +733,8 @@ {% endif %} - - + + {% if FEATURES['NSFW_MARKING'] %} diff --git a/files/templates/post.html b/files/templates/post.html index c3da4571c..ec1fa434c 100644 --- a/files/templates/post.html +++ b/files/templates/post.html @@ -74,7 +74,7 @@
-
+
{% if p.thumb_url and not p.deleted_utc and not p.is_image and not p.is_video and not p.is_audio and not p.embed %} diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index eaa8b8ce4..9f0de0572 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -1,4 +1,4 @@ -{% if v and v.id == p.author_id and p.private %} +{% if v and v.id == p.author_id and p.draft %} {% endif %} @@ -29,8 +29,8 @@ {% if v and v.id == p.author_id %} {% if request.path.startswith('/@') %} - - + + {% endif %} @@ -64,8 +64,8 @@ {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} - - + + {% endif %} {% if v.mods_hole(p.hole) %} diff --git a/files/templates/post_actions_mobile.html b/files/templates/post_actions_mobile.html index a9d38f40e..a51b071b6 100644 --- a/files/templates/post_actions_mobile.html +++ b/files/templates/post_actions_mobile.html @@ -1,4 +1,4 @@ -{% if v.id == p.author_id and p.private %} +{% if v.id == p.author_id and p.draft %} @@ -31,8 +31,8 @@ {% if v.id == p.author_id and request.path.startswith('/@') %} - - + + {% endif %} {% if v.id == p.author_id %} diff --git a/files/templates/post_admin_actions_mobile.html b/files/templates/post_admin_actions_mobile.html index 121dd8fce..2fba6c5de 100644 --- a/files/templates/post_admin_actions_mobile.html +++ b/files/templates/post_admin_actions_mobile.html @@ -29,8 +29,8 @@ {% endif %} {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %} - - + + diff --git a/files/templates/post_listing.html b/files/templates/post_listing.html index 8f75e88c7..30abc68f0 100644 --- a/files/templates/post_listing.html +++ b/files/templates/post_listing.html @@ -34,7 +34,7 @@ {{macros.reports(p, 'post')}} -
+
{% if v %} diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index 7ea1d6e0e..d57e65381 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -43,8 +43,8 @@ {%- include 'admin/shadowbanned_tooltip.html' -%} {% endwith %} - {% if p.stickied %} - + {% if p.pinned %} + {% endif %} {% if p.hole_pinned %} @@ -60,14 +60,14 @@ {%- endif -%} , speaking officially"> {% endif %} - {% if p.is_pinned and request.path != '/' %} + {% if p.profile_pinned and request.path != '/' %} {% endif %} {% if p.nsfw %}NSFW{% endif %} {% if p.is_bot %} {% endif %} {% 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.draft %}Draft{% endif %} {% if p.active_reports(v) %} diff --git a/migrations/20240218-rename-columns.sql b/migrations/20240218-rename-columns.sql new file mode 100644 index 000000000..f3807bd52 --- /dev/null +++ b/migrations/20240218-rename-columns.sql @@ -0,0 +1,13 @@ +alter table posts rename column private to draft; + +alter table posts rename column is_pinned to profile_pinned; +alter table posts rename column stickied to pinned; +alter table posts rename column stickied_utc to pinned_utc; +alter table comments rename column stickied to pinned; +alter table comments rename column stickied_utc to pinned_utc; + +alter index post_is_pinned_idx rename to post_profile_pinned_idx; +alter index posts_stickied_idx rename to post_pinned_idex; +alter index post_sticked_utc_idx rename to post_pinned_utc_idex; + +alter index comment_sticked_utc_idx rename to comment_pinned_utc_idex; diff --git a/schema.sql b/schema.sql index 888d4972a..812e1c371 100644 --- a/schema.sql +++ b/schema.sql @@ -438,13 +438,13 @@ CREATE TABLE public.comments ( app_id integer, sentto integer, bannedfor character varying(313), - stickied character varying(40), + pinned character varying(40), body character varying(10000), body_html character varying(40000), ban_reason character varying(25), realupvotes integer DEFAULT 1 NOT NULL, top_comment_id integer, - stickied_utc integer, + pinned_utc integer, ghost boolean DEFAULT false NOT NULL, slots_result character varying(36), blackjack_result character varying(860), @@ -837,17 +837,17 @@ CREATE TABLE public.posts ( deleted_utc integer DEFAULT 0 NOT NULL, is_approved integer, edited_utc integer DEFAULT 0 NOT NULL, - is_pinned boolean DEFAULT false NOT NULL, + profile_pinned boolean DEFAULT false NOT NULL, upvotes integer DEFAULT 1 NOT NULL, downvotes integer DEFAULT 0 NOT NULL, app_id integer, thumburl character varying(200), - private boolean DEFAULT false NOT NULL, + draft boolean DEFAULT false NOT NULL, views integer DEFAULT 0 NOT NULL, is_bot boolean DEFAULT false NOT NULL, bannedfor character varying(313), comment_count integer DEFAULT 0 NOT NULL, - stickied character varying(40), + pinned character varying(40), title character varying(500) NOT NULL, url character varying(2083), body character varying(100000), @@ -857,7 +857,7 @@ CREATE TABLE public.posts ( title_html character varying(1500) NOT NULL, realupvotes integer, flair character varying(350), - stickied_utc integer, + pinned_utc integer, ghost boolean DEFAULT false NOT NULL, hole character varying(25), new boolean, @@ -1709,10 +1709,10 @@ CREATE INDEX comment_post_id_index ON public.comments USING btree (parent_post); -- --- Name: comment_sticked_utc_idx; Type: INDEX; Schema: public; Owner: - +-- Name: comment_pinned_utc_idx; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX comment_sticked_utc_idx ON public.comments USING btree (stickied_utc); +CREATE INDEX comment_pinned_utc_idx ON public.comments USING btree (pinned_utc); -- @@ -2094,10 +2094,10 @@ CREATE INDEX post_deleted_utc_idx ON public.posts USING btree (deleted_utc); -- --- Name: post_is_pinned_idx; Type: INDEX; Schema: public; Owner: - +-- Name: post_profile_pinned_idx; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX post_is_pinned_idx ON public.posts USING btree (is_pinned); +CREATE INDEX post_profile_pinned_idx ON public.posts USING btree (profile_pinned); -- @@ -2115,10 +2115,10 @@ CREATE INDEX post_nsfw_idx ON public.posts USING btree (nsfw); -- --- Name: post_sticked_utc_idx; Type: INDEX; Schema: public; Owner: - +-- Name: post_pinned_utc_idx; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX post_sticked_utc_idx ON public.posts USING btree (stickied_utc); +CREATE INDEX post_pinned_utc_idx ON public.posts USING btree (pinned_utc); -- @@ -2129,10 +2129,10 @@ CREATE INDEX posts_bump_utc_idx ON public.posts USING btree (bump_utc); -- --- Name: posts_stickied_idx; Type: INDEX; Schema: public; Owner: - +-- Name: posts_pinned_idx; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX posts_stickied_idx ON public.posts USING btree (stickied); +CREATE INDEX posts_pinned_idx ON public.posts USING btree (pinned); -- @@ -3073,4 +3073,3 @@ ALTER TABLE ONLY public.comments -- -- PostgreSQL database dump complete -- -