From 62d1940a8fd25d9a27311412a4692df7b8411def Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 7 Oct 2023 20:55:50 +0300 Subject: [PATCH] sub -> hole --- files/assets/css/main.css | 10 +- files/assets/js/submit.js | 10 +- files/classes/__init__.py | 4 +- files/classes/comment.py | 12 +- files/classes/exiles.py | 4 +- files/classes/{sub.py => hole.py} | 26 +- files/classes/{sub_logs.py => hole_logs.py} | 20 +- ...b_relationship.py => hole_relationship.py} | 20 +- files/classes/mod.py | 4 +- files/classes/post.py | 20 +- files/classes/user.py | 66 +-- files/helpers/actions.py | 6 +- files/helpers/alerts.py | 2 +- files/helpers/can_see.py | 6 +- files/helpers/config/const.py | 20 +- ...subaction_types.py => holeaction_types.py} | 4 +- files/helpers/const_stateful.py | 4 +- files/helpers/cron.py | 36 +- files/helpers/get.py | 14 +- files/helpers/sanitize.py | 4 +- files/routes/__init__.py | 2 +- files/routes/admin.py | 6 +- files/routes/awards.py | 4 +- files/routes/comments.py | 24 +- files/routes/front.py | 58 +- files/routes/{subs.py => holes.py} | 538 +++++++++--------- files/routes/notifications.py | 14 +- files/routes/polls.py | 14 +- files/routes/posts.py | 80 +-- files/routes/reporting.py | 68 +-- files/routes/search.py | 4 +- files/routes/users.py | 8 +- files/routes/votes.py | 4 +- files/templates/comments.html | 38 +- files/templates/default.html | 14 +- .../templates/events/shared/eye_tracking.html | 2 +- files/templates/events/shared/music.html | 2 +- files/templates/header.html | 14 +- files/templates/{sub => hole}/blockers.html | 4 +- .../templates/{sub => hole}/create_hole.html | 2 +- files/templates/{sub => hole}/exilees.html | 8 +- .../{sub/subs.html => hole/holes.html} | 14 +- files/templates/{sub => hole}/mods.html | 12 +- files/templates/{sub => hole}/settings.html | 36 +- files/templates/home.html | 48 +- files/templates/log.html | 10 +- files/templates/notifications.html | 6 +- files/templates/post_actions.html | 22 +- files/templates/post_actions_mobile.html | 22 +- files/templates/post_listing.html | 2 +- files/templates/sidebar_rDrama.html | 28 +- files/templates/submit.html | 8 +- files/templates/userpage/banner.html | 8 +- files/templates/util/html_head.html | 8 +- files/templates/util/macros.html | 16 +- migrations/20231007-rename-sub-to-hole.sql | 19 + 56 files changed, 739 insertions(+), 720 deletions(-) rename files/classes/{sub.py => hole.py} (62%) rename files/classes/{sub_logs.py => hole_logs.py} (76%) rename files/classes/{sub_relationship.py => hole_relationship.py} (58%) rename files/helpers/config/{subaction_types.py => holeaction_types.py} (97%) rename files/routes/{subs.py => holes.py} (63%) rename files/templates/{sub => hole}/blockers.html (81%) rename files/templates/{sub => hole}/create_hole.html (96%) rename files/templates/{sub => hole}/exilees.html (75%) rename files/templates/{sub/subs.html => hole/holes.html} (55%) rename files/templates/{sub => hole}/mods.html (72%) rename files/templates/{sub => hole}/settings.html (63%) create mode 100644 migrations/20231007-rename-sub-to-hole.sql diff --git a/files/assets/css/main.css b/files/assets/css/main.css index 22cf52b6d..f2620ee4b 100644 --- a/files/assets/css/main.css +++ b/files/assets/css/main.css @@ -4203,7 +4203,7 @@ small, .small { min-height: 30px; } -.sub-flair { +.hole-flair { padding: 3px 5px 2px 5px; border-radius: 5px; color: white; @@ -4211,7 +4211,7 @@ small, .small { margin-right: 3px; font-weight: bold; } -.sub-flair:hover { +.hole-flair:hover { color: var(--white); text-decoration: none; } @@ -6919,7 +6919,7 @@ div.markdown { } } -.sub-banner-update-section .sub-settings-subsection { +.hole-banner-update-section .hole-settings-subsection { margin-bottom: 1em; } @@ -7568,12 +7568,12 @@ p { /* DO NOT REMOVE */ overflow: hidden !important; } -#sub-name { +#hole-name { font-size: max(14px, 1.2vw); } @media (min-width: 768px) { - #sub-name { + #hole-name { font-size: 1.5vw; } } diff --git a/files/assets/js/submit.js b/files/assets/js/submit.js index d72eef34b..fa4e2f297 100644 --- a/files/assets/js/submit.js +++ b/files/assets/js/submit.js @@ -1,4 +1,4 @@ -const save_value = ['post-title', 'post-text', 'post-url', 'sub'] +const save_value = ['post-title', 'post-text', 'post-url', 'hole'] for (const id of save_value) { const value = localStorage.getItem(id) if (value) @@ -106,15 +106,15 @@ function autoSuggestTitle() { function ghost_toggle(t) { const followers = document.getElementById("post-notify") - const sub = document.getElementById("sub") + const hole = document.getElementById("hole") if (t.checked == true) { followers.checked = false; followers.disabled = true; - sub.value = ''; - sub.disabled = true; + hole.value = ''; + hole.disabled = true; } else { followers.disabled = false; - sub.disabled = false; + hole.disabled = false; } } diff --git a/files/classes/__init__.py b/files/classes/__init__.py index 4ba1425cf..1f3ae0901 100644 --- a/files/classes/__init__.py +++ b/files/classes/__init__.py @@ -18,7 +18,7 @@ from .domains import * from .subscriptions import * from .mod_logs import * from .award import * -from .sub_relationship import * +from .hole_relationship import * from .saves import * from .views import * from .notifications import * @@ -28,7 +28,7 @@ from .casino_game import * from .hats import * from .emoji import * from .transactions import * -from .sub_logs import * +from .hole_logs import * from .media import * from .push_subscriptions import * from .group import * diff --git a/files/classes/comment.py b/files/classes/comment.py index 38453a9b4..318eb4396 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -126,13 +126,13 @@ def add_options(self, body, v): if v: if kind == 'post': - sub = self.sub + hole = self.hole elif self.parent_post: - sub = self.post.sub + hole = self.post.hole else: - sub = None + hole = None - if sub in {'furry','vampire','racist','femboy','edgy'} and not v.house.lower().startswith(sub): + if hole in {'furry','vampire','racist','femboy','edgy'} and not v.house.lower().startswith(hole): disabled = True option_body += ' disabled ' @@ -407,7 +407,7 @@ class Comment(Base): body = add_options(self, body, v) if body: - if not (self.parent_post and self.post.sub == 'chudrama'): + if not (self.parent_post and self.post.hole == 'chudrama'): body = censor_slurs_profanities(body, v) body = normalize_urls_runtime(body, v) @@ -423,7 +423,7 @@ class Comment(Base): if not body: return "" - if not (self.parent_post and self.post.sub == 'chudrama'): + if not (self.parent_post and self.post.hole == 'chudrama'): body = censor_slurs_profanities(body, v, True) return body diff --git a/files/classes/exiles.py b/files/classes/exiles.py index 1a93c35c1..9486efdc8 100644 --- a/files/classes/exiles.py +++ b/files/classes/exiles.py @@ -9,7 +9,7 @@ from files.classes import Base class Exile(Base): __tablename__ = "exiles" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) - sub = Column(String, ForeignKey("subs.name"), primary_key=True) + hole = Column(String, ForeignKey("holes.name"), primary_key=True) exiler_id = Column(Integer, ForeignKey("users.id")) created_utc = Column(Integer) @@ -20,4 +20,4 @@ class Exile(Base): super().__init__(*args, **kwargs) def __repr__(self): - return f"<{self.__class__.__name__}(user_id={self.user_id}, sub={self.sub})>" + return f"<{self.__class__.__name__}(user_id={self.user_id}, hole={self.hole})>" diff --git a/files/classes/sub.py b/files/classes/hole.py similarity index 62% rename from files/classes/sub.py rename to files/classes/hole.py index d0b303447..43f103cfb 100644 --- a/files/classes/sub.py +++ b/files/classes/hole.py @@ -11,23 +11,23 @@ from files.classes import Base from files.helpers.lazy import lazy from files.helpers.config.const import * -from .sub_relationship import * +from .hole_relationship import * -class Sub(Base): - __tablename__ = "subs" - name = Column(VARCHAR(SUB_NAME_COLUMN_LENGTH), primary_key=True) - sidebar = Column(VARCHAR(SUB_SIDEBAR_COLUMN_LENGTH)) - sidebar_html = Column(VARCHAR(SUB_SIDEBAR_HTML_COLUMN_LENGTH)) - sidebarurl = Column(VARCHAR(SUB_SIDEBAR_URL_COLUMN_LENGTH)) - bannerurls = Column(MutableList.as_mutable(ARRAY(VARCHAR(SUB_BANNER_URL_COLUMN_LENGTH))), default=MutableList([]), nullable=False) - marseyurl = Column(VARCHAR(SUB_MARSEY_URL_LENGTH)) - css = Column(VARCHAR(SUB_CSS_COLUMN_LENGTH)) +class Hole(Base): + __tablename__ = "holes" + name = Column(VARCHAR(HOLE_NAME_COLUMN_LENGTH), primary_key=True) + sidebar = Column(VARCHAR(HOLE_SIDEBAR_COLUMN_LENGTH)) + sidebar_html = Column(VARCHAR(HOLE_SIDEBAR_HTML_COLUMN_LENGTH)) + sidebarurl = Column(VARCHAR(HOLE_SIDEBAR_URL_COLUMN_LENGTH)) + bannerurls = Column(MutableList.as_mutable(ARRAY(VARCHAR(HOLE_BANNER_URL_COLUMN_LENGTH))), default=MutableList([]), nullable=False) + marseyurl = Column(VARCHAR(HOLE_MARSEY_URL_LENGTH)) + css = Column(VARCHAR(HOLE_CSS_COLUMN_LENGTH)) stealth = Column(Boolean) created_utc = Column(Integer) - blocks = relationship("SubBlock", primaryjoin="SubBlock.sub==Sub.name") - followers = relationship("SubSubscription", primaryjoin="SubSubscription.sub==Sub.name") - joins = relationship("SubJoin", lazy="dynamic", primaryjoin="SubJoin.sub==Sub.name") + blocks = relationship("HoleBlock", primaryjoin="HoleBlock.hole==Hole.name") + followers = relationship("HoleFollow", primaryjoin="HoleFollow.hole==Hole.name") + joins = relationship("StealthHoleUnblock", lazy="dynamic", primaryjoin="StealthHoleUnblock.hole==Hole.name") def __init__(self, *args, **kwargs): if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) diff --git a/files/classes/sub_logs.py b/files/classes/hole_logs.py similarity index 76% rename from files/classes/sub_logs.py rename to files/classes/hole_logs.py index 9cca9b9e0..153d15280 100644 --- a/files/classes/sub_logs.py +++ b/files/classes/hole_logs.py @@ -10,10 +10,10 @@ from files.helpers.lazy import lazy from files.helpers.slurs_and_profanities import censor_slurs_profanities from files.helpers.sorting_and_time import make_age_string -class SubAction(Base): - __tablename__ = "subactions" +class HoleAction(Base): + __tablename__ = "hole_actions" id = Column(Integer, primary_key=True) - sub = Column(String, ForeignKey("subs.name")) + hole = Column(String, ForeignKey("holes.name")) user_id = Column(Integer, ForeignKey("users.id")) kind = Column(String) target_user_id = Column(Integer, ForeignKey("users.id")) @@ -22,8 +22,8 @@ class SubAction(Base): _note = Column(String) created_utc = Column(Integer) - user = relationship("User", primaryjoin="User.id==SubAction.user_id") - target_user = relationship("User", primaryjoin="User.id==SubAction.target_user_id") + user = relationship("User", primaryjoin="User.id==HoleAction.user_id") + target_user = relationship("User", primaryjoin="User.id==HoleAction.target_user_id") target_post = relationship("Post") target_comment = relationship("Comment") @@ -42,7 +42,7 @@ class SubAction(Base): @property @lazy def string(self): - output = SUBACTION_TYPES[self.kind]["str"].format(self=self) + output = HOLEACTION_TYPES[self.kind]["str"].format(self=self) if self._note: output += f" ({self._note})" return output @@ -59,16 +59,16 @@ class SubAction(Base): @property @lazy def icon(self): - return SUBACTION_TYPES[self.kind]['icon'] + return HOLEACTION_TYPES[self.kind]['icon'] @property @lazy def color(self): - return SUBACTION_TYPES[self.kind]['color'] + return HOLEACTION_TYPES[self.kind]['color'] @property @lazy def permalink(self): - return f"{SITE_FULL}/h/{self.sub}/log/{self.id}" + return f"{SITE_FULL}/h/{self.hole}/log/{self.id}" -from files.helpers.config.subaction_types import SUBACTION_TYPES +from files.helpers.config.holeaction_types import HOLEACTION_TYPES diff --git a/files/classes/sub_relationship.py b/files/classes/hole_relationship.py similarity index 58% rename from files/classes/sub_relationship.py rename to files/classes/hole_relationship.py index 4a0dd427d..d26eeb1ac 100644 --- a/files/classes/sub_relationship.py +++ b/files/classes/hole_relationship.py @@ -6,7 +6,7 @@ from sqlalchemy.sql.sqltypes import * from files.classes import Base -class SubRelationship(Base): +class HoleRelationship(Base): __tablename__ = NotImplemented __abstract__ = True @@ -15,8 +15,8 @@ class SubRelationship(Base): return Column(Integer, ForeignKey("users.id"), primary_key=True) @declared_attr - def sub(self): - return Column(String(20), ForeignKey("subs.name"), primary_key=True) + def hole(self): + return Column(String(20), ForeignKey("holes.name"), primary_key=True) @declared_attr def created_utc(self): @@ -27,13 +27,13 @@ class SubRelationship(Base): super().__init__(*args, **kwargs) def __repr__(self): - return f"<{self.__class__.__name__}(user_id={self.user_id}, sub={self.sub})>" + return f"<{self.__class__.__name__}(user_id={self.user_id}, hole={self.hole})>" -class SubJoin(SubRelationship): - __tablename__ = "sub_joins" +class StealthHoleUnblock(HoleRelationship): + __tablename__ = "stealth_hole_unblocks" -class SubBlock(SubRelationship): - __tablename__ = "sub_blocks" +class HoleBlock(HoleRelationship): + __tablename__ = "hole_blocks" -class SubSubscription(SubRelationship): - __tablename__ = "sub_subscriptions" +class HoleFollow(HoleRelationship): + __tablename__ = "hole_follows" diff --git a/files/classes/mod.py b/files/classes/mod.py index 5ded526fd..c5664dfb4 100644 --- a/files/classes/mod.py +++ b/files/classes/mod.py @@ -9,7 +9,7 @@ from files.helpers.lazy import * class Mod(Base): __tablename__ = "mods" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) - sub = Column(String, ForeignKey("subs.name"), primary_key=True) + hole = Column(String, ForeignKey("holes.name"), primary_key=True) created_utc = Column(Integer) def __init__(self, *args, **kwargs): @@ -17,4 +17,4 @@ class Mod(Base): super().__init__(*args, **kwargs) def __repr__(self): - return f"<{self.__class__.__name__}(user_id={self.user_id}, sub={self.sub})>" + return f"<{self.__class__.__name__}(user_id={self.user_id}, hole={self.hole})>" diff --git a/files/classes/post.py b/files/classes/post.py index ac5614a18..44a2d1f02 100644 --- a/files/classes/post.py +++ b/files/classes/post.py @@ -17,7 +17,7 @@ from files.helpers.sorting_and_time import make_age_string from .comment import normalize_urls_runtime, add_options, get_award_classes from .polls import * -from .sub import * +from .hole import * from .subscriptions import * from .saves import SaveRelationship @@ -40,7 +40,7 @@ class Post(Base): stickied = Column(String) stickied_utc = Column(Integer) hole_pinned = Column(String) - sub = Column(String, ForeignKey("subs.name")) + hole = Column(String, ForeignKey("holes.name")) is_pinned = Column(Boolean, default=False) private = Column(Boolean, default=False) comment_count = Column(Integer, default=0) @@ -74,7 +74,7 @@ class Post(Base): awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", back_populates="post") 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)") + hole_obj = relationship("Hole", primaryjoin="foreign(Post.hole)==remote(Hole.name)") options = relationship("PostOption", order_by="PostOption.id") def __init__(self, *args, **kwargs): @@ -126,9 +126,9 @@ class Post(Base): @lazy def shortlink(self): link = f"/post/{self.id}" - if self.sub: link = f"/h/{self.sub}{link}" + if self.hole: link = f"/h/{self.hole}{link}" - if self.sub and self.sub in {'chudrama', 'countryclub', 'highrollerclub'}: + if self.hole and self.hole in {'chudrama', 'countryclub', 'highrollerclub'}: output = '-' else: title = self.plaintitle(None).lower() @@ -228,7 +228,7 @@ class Post(Base): 'is_bot': self.is_bot, 'thumb_url': self.thumb_url, 'domain': self.domain, - 'sub': self.sub, + 'hole': self.hole, 'url': self.realurl(None), 'body': self.body, 'body_html': self.body_html, @@ -307,7 +307,7 @@ class Post(Base): body = add_options(self, body, v) - if self.sub != 'chudrama': + if self.hole != 'chudrama': body = censor_slurs_profanities(body, v) body = normalize_urls_runtime(body, v) @@ -322,7 +322,7 @@ class Post(Base): body = self.body if not body: return "" - if self.sub != 'chudrama': + if self.hole != 'chudrama': body = censor_slurs_profanities(body, v, True) body = normalize_urls_runtime(body, v) @@ -333,7 +333,7 @@ class Post(Base): def realtitle(self, v): title = self.title_html - if self.sub != 'chudrama': + if self.hole != 'chudrama': title = censor_slurs_profanities(title, v) return title @@ -342,7 +342,7 @@ class Post(Base): def plaintitle(self, v): title = self.title - if self.sub != 'chudrama': + if self.hole != 'chudrama': title = censor_slurs_profanities(title, v, True) return title diff --git a/files/classes/user.py b/files/classes/user.py index 0e6e3d6dc..c7ed0210a 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -13,7 +13,7 @@ from flask import g, session, request from files.classes import Base from files.classes.casino_game import CasinoGame from files.classes.group import GroupMembership -from files.classes.sub import Sub +from files.classes.hole import Hole from files.helpers.config.const import * from files.helpers.config.modaction_types import * from files.helpers.config.awards import AWARDS_ENABLED, HOUSE_AWARDS @@ -33,8 +33,8 @@ from .mod import * from .mod_logs import * from .notifications import Notification from .saves import * -from .sub_relationship import * -from .sub_logs import * +from .hole_relationship import * +from .hole_logs import * from .subscriptions import * from .userblock import * from .usermute import * @@ -171,7 +171,7 @@ class User(Base): designed_hats = relationship("HatDef", primaryjoin="User.id==HatDef.author_id", back_populates="author") owned_hats = relationship("Hat", back_populates="owners") hats_equipped = relationship("Hat", lazy="raise", viewonly=True) - sub_mods = relationship("Mod", primaryjoin="User.id == Mod.user_id", lazy="raise") + hole_mods = relationship("Mod", primaryjoin="User.id == Mod.user_id", lazy="raise") def __init__(self, **kwargs): @@ -414,13 +414,13 @@ class User(Base): return True @lazy - def mods(self, sub): + def mods(self, hole): if self.is_permabanned or self.shadowbanned: return False if self.admin_level >= PERMS['MODS_EVERY_HOLE']: return True try: - return any(map(lambda x: x.sub == sub, self.sub_mods)) + return any(map(lambda x: x.hole == hole, self.hole_mods)) except: - return bool(g.db.query(Mod.user_id).filter_by(user_id=self.id, sub=sub).one_or_none()) + return bool(g.db.query(Mod.user_id).filter_by(user_id=self.id, hole=hole).one_or_none()) @lazy def mods_group(self, group): @@ -430,8 +430,8 @@ class User(Base): return bool(g.db.query(GroupMembership.user_id).filter_by(user_id=self.id, group_name=group.name, is_mod=True).one_or_none()) @lazy - def exiler_username(self, sub): - exile = g.db.query(Exile).options(load_only(Exile.exiler_id)).filter_by(user_id=self.id, sub=sub).one_or_none() + def exiler_username(self, hole): + exile = g.db.query(Exile).options(load_only(Exile.exiler_id)).filter_by(user_id=self.id, hole=hole).one_or_none() if exile: return exile.exiler.username else: @@ -439,35 +439,35 @@ class User(Base): @property @lazy - def sub_blocks(self): - stealth = set([x[0] for x in g.db.query(Sub.name).filter_by(stealth=True)]) - stealth = stealth - set([x[0] for x in g.db.query(SubJoin.sub).filter_by(user_id=self.id)]) + def hole_blocks(self): + stealth = set([x[0] for x in g.db.query(Hole.name).filter_by(stealth=True)]) + stealth = stealth - set([x[0] for x in g.db.query(StealthHoleUnblock.hole).filter_by(user_id=self.id)]) if self.chud == 1: stealth = stealth - {'chudrama'} - return list(stealth) + [x[0] for x in g.db.query(SubBlock.sub).filter_by(user_id=self.id)] + return list(stealth) + [x[0] for x in g.db.query(HoleBlock.hole).filter_by(user_id=self.id)] @lazy - def blocks(self, sub): - return g.db.query(SubBlock).filter_by(user_id=self.id, sub=sub).one_or_none() + def blocks(self, hole): + return g.db.query(HoleBlock).filter_by(user_id=self.id, hole=hole).one_or_none() @lazy - def subscribes(self, sub): - return g.db.query(SubJoin).filter_by(user_id=self.id, sub=sub).one_or_none() + def subscribes(self, hole): + return g.db.query(StealthHoleUnblock).filter_by(user_id=self.id, hole=hole).one_or_none() @property @lazy def all_follows(self): - return [x[0] for x in g.db.query(SubSubscription.sub).filter_by(user_id=self.id)] + return [x[0] for x in g.db.query(HoleFollow.hole).filter_by(user_id=self.id)] @lazy - def follows(self, sub): - return g.db.query(SubSubscription).filter_by(user_id=self.id, sub=sub).one_or_none() + def follows(self, hole): + return g.db.query(HoleFollow).filter_by(user_id=self.id, hole=hole).one_or_none() @lazy - def mod_date(self, sub): + def mod_date(self, hole): if self.admin_level >= PERMS['MODS_EVERY_HOLE']: return 1 - mod_ts = g.db.query(Mod.created_utc).filter_by(user_id=self.id, sub=sub).one_or_none() + mod_ts = g.db.query(Mod.created_utc).filter_by(user_id=self.id, hole=hole).one_or_none() if mod_ts is None: return None return mod_ts[0] @@ -737,8 +737,8 @@ class User(Base): @property @lazy - def followed_subs(self): - return [x[0] for x in g.db.query(SubSubscription.sub).filter_by(user_id=self.id)] + def followed_holes(self): + return [x[0] for x in g.db.query(HoleFollow.hole).filter_by(user_id=self.id)] @property @lazy @@ -796,7 +796,7 @@ class User(Base): return g.db.query(Post).filter( Post.created_utc > self.last_viewed_post_notifs, or_( - Post.sub.in_(self.followed_subs), + Post.hole.in_(self.followed_holes), and_( Post.author_id.in_(self.followed_users), Post.notify == True, @@ -808,7 +808,7 @@ class User(Base): Post.private == False, Post.author_id != self.id, Post.author_id.notin_(self.userblocks), - or_(Post.sub == None, Post.sub.notin_(self.sub_blocks)), + or_(Post.hole == None, Post.hole.notin_(self.hole_blocks)), ).count() @property @@ -830,11 +830,11 @@ class User(Base): return q.count() - if self.moderated_subs: - return g.db.query(SubAction).filter( - SubAction.created_utc > self.last_viewed_log_notifs, - SubAction.user_id != self.id, - SubAction.sub.in_(self.moderated_subs), + if self.moderated_holes: + return g.db.query(HoleAction).filter( + HoleAction.created_utc > self.last_viewed_log_notifs, + HoleAction.user_id != self.id, + HoleAction.hole.in_(self.moderated_holes), ).count() return 0 @@ -896,8 +896,8 @@ class User(Base): @property @lazy - def moderated_subs(self): - return [x[0] for x in g.db.query(Mod.sub).filter_by(user_id=self.id).order_by(Mod.sub)] + def moderated_holes(self): + return [x[0] for x in g.db.query(Mod.hole).filter_by(user_id=self.id).order_by(Mod.hole)] @property @lazy diff --git a/files/helpers/actions.py b/files/helpers/actions.py index b199a4995..efffe01f4 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -50,7 +50,7 @@ def snappy_report(post, reason): send_repeatable_notification(post.author_id, message) def execute_snappy(post, v): - if post.sub and g.db.query(Exile.user_id).filter_by(user_id=SNAPPY_ID, sub=post.sub).one_or_none(): + if post.hole and g.db.query(Exile.user_id).filter_by(user_id=SNAPPY_ID, hole=post.hole).one_or_none(): return ghost = post.ghost @@ -271,7 +271,7 @@ def execute_zozbot(c, level, post, v): posting_to_post = isinstance(post, Post) - if posting_to_post and post.sub and g.db.query(Exile.user_id).filter_by(user_id=ZOZBOT_ID, sub=post.sub).one_or_none(): + if posting_to_post and post.hole and g.db.query(Exile.user_id).filter_by(user_id=ZOZBOT_ID, hole=post.hole).one_or_none(): return c2 = Comment(author_id=ZOZBOT_ID, @@ -344,7 +344,7 @@ def execute_longpostbot(c, level, body, body_html, post, v): posting_to_post = isinstance(post, Post) - if posting_to_post and post.sub and g.db.query(Exile.user_id).filter_by(user_id=LONGPOSTBOT_ID, sub=post.sub).one_or_none(): + if posting_to_post and post.hole and g.db.query(Exile.user_id).filter_by(user_id=LONGPOSTBOT_ID, hole=post.hole).one_or_none(): return body = random.choice(LONGPOSTBOT_REPLIES) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 5be756c3f..c2b887bde 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -103,7 +103,7 @@ def notif_comment2(p): if existing: return existing[0], text else: - if p.sub: text += f" in /h/{p.sub}" + if p.hole: text += f" in /h/{p.hole}" text_html = sanitize(text, blackjack="notification", post_mention_notif=True) return create_comment(text_html), text diff --git a/files/helpers/can_see.py b/files/helpers/can_see.py index 49a272174..352733ec2 100644 --- a/files/helpers/can_see.py +++ b/files/helpers/can_see.py @@ -1,7 +1,7 @@ from .config.const import * from files.classes.post import Post from files.classes.comment import Comment -from files.classes.sub import Sub +from files.classes.hole import Hole from flask import request def can_see(user, other): @@ -9,7 +9,7 @@ def can_see(user, other): if not can_see(user, other.author): return False if user and user.id == other.author_id: return True if isinstance(other, Post): - if other.sub and not can_see(user, other.subr): + if other.hole and not can_see(user, other.hole_obj): return False if request.headers.get("Cf-Ipcountry") == 'NZ': if 'christchurch' in other.title.lower(): @@ -30,7 +30,7 @@ def can_see(user, other): return user.admin_level >= PERMS['VIEW_MODMAIL'] if other.sentto != user.id: return user.admin_level >= PERMS['BLACKJACK_NOTIFICATIONS'] - elif isinstance(other, Sub): + elif isinstance(other, Hole): if other.name == 'chudrama': return bool(user) and user.can_see_chudrama if other.name == 'countryclub': return bool(user) and user.can_see_countryclub if other.name == 'highrollerclub': return bool(user) and user.can_see_highrollerclub diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 5041a55c3..9ecff3571 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -292,13 +292,13 @@ POST_SORTS = COMMENT_SORTS | { ### COLUMN INFO ################################################################################ -SUB_NAME_COLUMN_LENGTH = 25 -SUB_SIDEBAR_COLUMN_LENGTH = 10000 -SUB_SIDEBAR_HTML_COLUMN_LENGTH = 20000 -SUB_SIDEBAR_URL_COLUMN_LENGTH = 60 -SUB_BANNER_URL_COLUMN_LENGTH = 60 -SUB_CSS_COLUMN_LENGTH = 6000 -SUB_MARSEY_URL_LENGTH = 60 +HOLE_NAME_COLUMN_LENGTH = 25 +HOLE_SIDEBAR_COLUMN_LENGTH = 10000 +HOLE_SIDEBAR_HTML_COLUMN_LENGTH = 20000 +HOLE_SIDEBAR_URL_COLUMN_LENGTH = 60 +HOLE_BANNER_URL_COLUMN_LENGTH = 60 +HOLE_CSS_COLUMN_LENGTH = 6000 +HOLE_MARSEY_URL_LENGTH = 60 ################################################################################ ### SITE SPECIFIC CONSTANTS @@ -487,7 +487,7 @@ COMMENT_MAX_DEPTH = 200 TRANSFER_MESSAGE_LENGTH_LIMIT = 200 # do not make larger than 10000 characters (comment limit) without altering the table MIN_REPOST_CHECK_URL_LENGTH = 9 # also change the constant in checkRepost() of submit.js CHAT_LENGTH_LIMIT = 1000 -SUB_BANNER_LIMIT = 10 +HOLE_BANNER_LIMIT = 10 BIO_FRIENDS_ENEMIES_LENGTH_LIMIT = 5000 # do not make larger than 5000 characters without altering the table BIO_FRIENDS_ENEMIES_HTML_LENGTH_LIMIT = 20000 # do not make larger than 20000 characters without altering the table @@ -706,7 +706,7 @@ elif SITE == 'watchpeopledie.tv': PERMS['MODS_EVERY_HOLE'] = 3 PERMS['IS_PERMA_PROGSTACKED'] = 4 - SUB_BANNER_LIMIT = 69420 + HOLE_BANNER_LIMIT = 69420 ERROR_TITLES.update({ 400: "Bad Request", @@ -800,7 +800,7 @@ else: # localhost or testing environment implied FEATURES['PRONOUNS'] = True FEATURES['HOUSES'] = True FEATURES['USERS_PERMANENT_WORD_FILTERS'] = True - SUB_BANNER_LIMIT = 69420 + HOLE_BANNER_LIMIT = 69420 HOUSES = ("None","Furry","Femboy","Vampire","Racist","Edgy") if FEATURES['HOUSES'] else ("None") diff --git a/files/helpers/config/subaction_types.py b/files/helpers/config/holeaction_types.py similarity index 97% rename from files/helpers/config/subaction_types.py rename to files/helpers/config/holeaction_types.py index 4d7dbefaa..c18a89a40 100644 --- a/files/helpers/config/subaction_types.py +++ b/files/helpers/config/holeaction_types.py @@ -1,4 +1,4 @@ -SUBACTION_TYPES = { +HOLEACTION_TYPES = { 'exile_user': { "str": 'exiled user {self.target_link}', "icon": 'fa-user-slash', @@ -116,4 +116,4 @@ SUBACTION_TYPES = { }, } -SUBACTION_TYPES = dict(sorted(SUBACTION_TYPES.items())) +HOLEACTION_TYPES = dict(sorted(HOLEACTION_TYPES.items())) diff --git a/files/helpers/const_stateful.py b/files/helpers/const_stateful.py index e73d0f1eb..abad9bbb6 100644 --- a/files/helpers/const_stateful.py +++ b/files/helpers/const_stateful.py @@ -1,6 +1,6 @@ from os import path -from files.classes import Emoji, Sub +from files.classes import Emoji, Hole from files.helpers.config.const import * SNAPPY_KONGS = [] @@ -32,7 +32,7 @@ def const_initialize(): SNAPPY_KONGS = db.query(Emoji.name).filter(Emoji.kind=="Donkey Kong", Emoji.submitter_id==None, Emoji.nsfw == False).all() SNAPPY_KONGS = [f':#{x[0]}:' for x in SNAPPY_KONGS] - STEALTH_HOLES = [x[0] for x in db.query(Sub.name).filter_by(stealth=True)] + STEALTH_HOLES = [x[0] for x in db.query(Hole.name).filter_by(stealth=True)] OVER_18_EMOJIS = [x[0] for x in db.query(Emoji.name).filter_by(nsfw=True)] diff --git a/files/helpers/cron.py b/files/helpers/cron.py index d98527d3a..beb164dac 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -70,7 +70,7 @@ def cron_fn(every_5m, every_1d, every_fri_12, every_fri_23, every_sat_00, every_ _leaderboard_task() g.db.commit() - _sub_inactive_purge_task() + _hole_inactive_purge_task() g.db.commit() stats.generate_charts_task(SITE) @@ -170,7 +170,7 @@ def _create_post(title, body, pin_hours): embed=None, title=title, title_html=title_html, - sub='countryclub', + hole='countryclub', ghost=False, chudded=False, rainbowed=False, @@ -248,29 +248,29 @@ def _grant_two_year_badges(): from users where created_utc < {two_years_ago} and id not in (select user_id from badges where badge_id=237);""") g.db.execute(_badge_query) -def _sub_inactive_purge_task(): +def _hole_inactive_purge_task(): if not HOLE_INACTIVITY_DELETION: return False one_week_ago = time.time() - 604800 - active_holes = [x[0] for x in g.db.query(Post.sub).distinct() \ - .filter(Post.sub != None, Post.created_utc > one_week_ago, + 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.deleted_utc == 0)] active_holes.extend(['changelog','countryclub','museumofrdrama','highrollerclub']) # holes immune from deletion - dead_holes = g.db.query(Sub).filter(Sub.name.notin_(active_holes)).all() + dead_holes = g.db.query(Hole).filter(Hole.name.notin_(active_holes)).all() names = [x.name for x in dead_holes] admins = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_HOLE_INACTIVITY_DELETION'])] - mods = g.db.query(Mod).filter(Mod.sub.in_(names)).all() + mods = g.db.query(Mod).filter(Mod.hole.in_(names)).all() for x in mods: if x.user_id in admins: continue - send_repeatable_notification(x.user_id, f":marseyrave: /h/{x.sub} has been deleted for inactivity after one week without new posts. All posts in it have been moved to the main feed :marseyrave:") + send_repeatable_notification(x.user_id, f":marseyrave: /h/{x.hole} has been deleted for inactivity after one week without new posts. All posts in it have been moved to the main feed :marseyrave:") for name in names: - first_mod_id = g.db.query(Mod.user_id).filter_by(sub=name).order_by(Mod.created_utc).first() + first_mod_id = g.db.query(Mod.user_id).filter_by(hole=name).order_by(Mod.created_utc).first() if first_mod_id: first_mod = get_account(first_mod_id[0]) badge_grant( @@ -282,22 +282,22 @@ def _sub_inactive_purge_task(): for admin in admins: send_repeatable_notification(admin, f":marseyrave: /h/{name} has been deleted for inactivity after one week without new posts. All posts in it have been moved to the main feed :marseyrave:") - posts = g.db.query(Post).filter(Post.sub.in_(names)).all() + posts = g.db.query(Post).filter(Post.hole.in_(names)).all() for post in posts: - if post.sub == 'programming': - post.sub = 'slackernews' + if post.hole == 'programming': + post.hole = 'slackernews' else: - post.sub = None + post.hole = None post.hole_pinned = None g.db.add(post) to_delete = mods \ - + g.db.query(Exile).filter(Exile.sub.in_(names)).all() \ - + g.db.query(SubBlock).filter(SubBlock.sub.in_(names)).all() \ - + g.db.query(SubJoin).filter(SubJoin.sub.in_(names)).all() \ - + g.db.query(SubSubscription).filter(SubSubscription.sub.in_(names)).all() \ - + g.db.query(SubAction).filter(SubAction.sub.in_(names)).all() + + g.db.query(Exile).filter(Exile.hole.in_(names)).all() \ + + g.db.query(HoleBlock).filter(HoleBlock.hole.in_(names)).all() \ + + g.db.query(StealthHoleUnblock).filter(StealthHoleUnblock.hole.in_(names)).all() \ + + g.db.query(HoleFollow).filter(HoleFollow.hole.in_(names)).all() \ + + g.db.query(HoleAction).filter(HoleAction.hole.in_(names)).all() for x in to_delete: g.db.delete(x) diff --git a/files/helpers/get.py b/files/helpers/get.py index 8deba9eb0..162fe6c44 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -3,7 +3,7 @@ from flask import * from sqlalchemy import and_, any_, or_ from sqlalchemy.orm import joinedload, Query, load_only -from files.classes import Comment, CommentVote, Hat, Sub, Post, User, UserBlock, Vote +from files.classes import Comment, CommentVote, Hat, Hole, Post, User, UserBlock, Vote from files.helpers.config.const import * from files.__main__ import cache @@ -321,16 +321,16 @@ def get_comments_v_properties(v, should_keep_func=None, *criterion): else: dump.append(comment) return (comments, output) -def get_sub_by_name(sub, v=None, graceful=False): - if not sub: +def get_hole(hole, v=None, graceful=False): + if not hole: if graceful: return None else: abort(404) - sub = sub.replace('/h/', '').replace('h/', '').strip().lower() - if not sub: + hole = hole.replace('/h/', '').replace('h/', '').strip().lower() + if not hole: if graceful: return None else: abort(404) - sub = g.db.get(Sub, sub) - if not sub: + hole = g.db.get(Hole, hole) + if not hole: if graceful: return None else: abort(404) return sub diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 3c64039d8..5b2df5e33 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -836,10 +836,10 @@ def complies_with_chud(obj): if isinstance(obj, Post): if obj.id in ADMIGGER_THREADS: return True - if obj.sub == "chudrama": return True + if obj.hole == "chudrama": return True elif obj.parent_post: if obj.parent_post in ADMIGGER_THREADS: return True - if obj.post.sub == "chudrama": return True + if obj.post.hole == "chudrama": return True #perserve old body_html to be used in checking for chud phrase old_body_html = obj.body_html diff --git a/files/routes/__init__.py b/files/routes/__init__.py index c718c313f..2c2b2c796 100644 --- a/files/routes/__init__.py +++ b/files/routes/__init__.py @@ -36,7 +36,7 @@ from .feeds import * if FEATURES['AWARDS']: from .awards import * from .giphy import * -from .subs import * +from .holes import * if FEATURES['GAMBLING']: from .lottery import * from .casino import * diff --git a/files/routes/admin.py b/files/routes/admin.py index 2270475b5..6c4070095 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1029,7 +1029,7 @@ def ban_user(fullname, v): except: abort(400) actual_reason = reason.split(str(post_id))[1].strip() post = get_post(post_id) - if post.sub != 'chudrama': + if post.hole != 'chudrama': post.bannedfor = f'{duration} by @{v.username}' if actual_reason: post.bannedfor += f' for "{actual_reason}"' @@ -1134,7 +1134,7 @@ def chud(fullname, v): try: post = int(reason.split("/post/")[1].split(None, 1)[0]) except: abort(400) post = get_post(post) - if post.sub == 'chudrama': + if post.hole == 'chudrama': abort(403, "You can't chud people in /h/chudrama") post.chuddedfor = f'{duration} by @{v.username}' g.db.add(post) @@ -1142,7 +1142,7 @@ def chud(fullname, v): try: comment = int(reason.split("/comment/")[1].split(None, 1)[0]) except: abort(400) comment = get_comment(comment) - if comment.post.sub == 'chudrama': + if comment.post.hole == 'chudrama': abort(403, "You can't chud people in /h/chudrama") comment.chuddedfor = f'{duration} by @{v.username}' g.db.add(comment) diff --git a/files/routes/awards.py b/files/routes/awards.py index 18b2a1b53..aa2ccf1f6 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -351,8 +351,8 @@ def award_thing(v, thing_type, id): thing.title_html = filter_emojis_only(thing.title, golden=False, obj=thing, author=author) elif kind == "chud": - if thing_type == 'post' and thing.sub == 'chudrama' \ - or thing_type == 'comment' and thing.post and thing.post.sub == 'chudrama': + if thing_type == 'post' and thing.hole == 'chudrama' \ + or thing_type == 'comment' and thing.post and thing.post.hole == 'chudrama': abort(403, "You can't give the chud award in /h/chudrama") if author.queen: diff --git a/files/routes/comments.py b/files/routes/comments.py index f0636f91d..d13f735a7 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -38,11 +38,11 @@ def _mark_comment_as_read(cid, vid): @app.get("/comment/") @app.get("/post///") -@app.get("/h//comment/") -@app.get("/h//post///") +@app.get("/h//comment/") +@app.get("/h//post///") @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @auth_desired_with_logingate -def post_pid_comment_cid(cid, v, pid=None, anything=None, sub=None): +def post_pid_comment_cid(cid, v, pid=None, anything=None, hole=None): comment = get_comment(cid, v=v) @@ -95,7 +95,7 @@ def post_pid_comment_cid(cid, v, pid=None, anything=None, sub=None): else: if post.is_banned and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or post.author_id == v.id)): template = "post_banned.html" else: template = "post.html" - return render_template(template, v=v, p=post, sort=sort, comment_info=comment_info, render_replies=True, sub=post.subr) + return render_template(template, v=v, p=post, sort=sort, comment_info=comment_info, render_replies=True, hole=post.hole_obj) @app.post("/comment") @limiter.limit('1/second', scope=rpath) @@ -158,10 +158,10 @@ def comment(v): abort(403, "You can't reply to deleted comments!") if posting_to_post: - sub = post_target.sub - if sub and v.exiler_username(sub): abort(403, f"You're exiled from /h/{sub}") - if sub in {'furry','vampire','racist','femboy','edgy'} and not v.client and not v.house.lower().startswith(sub): - abort(403, f"You need to be a member of House {sub.capitalize()} to comment in /h/{sub}") + hole = post_target.hole + if hole and v.exiler_username(hole): abort(403, f"You're exiled from /h/{hole}") + if hole in {'furry','vampire','racist','femboy','edgy'} and not v.client and not v.house.lower().startswith(hole): + abort(403, f"You need to be a member of House {hole.capitalize()} to comment in /h/{hole}") if level > COMMENT_MAX_DEPTH: abort(400, f"Max comment level is {COMMENT_MAX_DEPTH}") @@ -255,7 +255,7 @@ def comment(v): is_bot = v.client is not None and v.id not in BOT_SYMBOL_HIDDEN - chudded = v.chud and not (posting_to_post and post_target.sub == 'chudrama') + chudded = v.chud and not (posting_to_post and post_target.hole == 'chudrama') c = Comment(author_id=v.id, parent_post=post_target.id if posting_to_post else None, @@ -610,7 +610,7 @@ def diff_words(answer, guess): def toggle_comment_nsfw(cid, v): comment = get_comment(cid) - if comment.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION'] and not (comment.post.sub and v.mods(comment.post.sub)): + if comment.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION'] and not (comment.post.hole and v.mods(comment.post.hole)): abort(403) if comment.nsfw and v.is_permabanned: @@ -628,8 +628,8 @@ def toggle_comment_nsfw(cid, v): ) g.db.add(ma) else: - ma = SubAction( - sub = comment.post.sub, + ma = HoleAction( + hole = comment.post.hole, kind = "set_nsfw_comment" if comment.nsfw else "unset_nsfw_comment", user_id = v.id, target_comment_id = comment.id, diff --git a/files/routes/front.py b/files/routes/front.py index b681bd0bb..bd945fd1e 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -13,30 +13,30 @@ from files.routes.wrappers import * from files.__main__ import app, cache, limiter, redis_instance @app.get("/") -@app.get("/h/") +@app.get("/h/") @limiter.limit("30/minute;5000/hour;10000/day", deduct_when=lambda response: response.status_code < 400) @auth_desired_with_logingate -def front_all(v, sub=None): - if sub: - sub = get_sub_by_name(sub, graceful=True) - if sub and not can_see(v, sub): +def front_all(v, hole=None): + if hole: + hole = get_hole(hole, graceful=True) + if hole and not can_see(v, hole): abort(403) - if request.path.startswith('/h/') and not sub: + if request.path.startswith('/h/') and not hole: abort(404) page = get_page() if v: defaultsorting = v.defaultsorting - if sub or SITE_NAME != 'rDrama': defaulttime = 'all' + if hole or SITE_NAME != 'rDrama': defaulttime = 'all' else: defaulttime = v.defaulttime else: defaultsorting = "hot" - if sub or SITE_NAME != 'rDrama': defaulttime = 'all' + if hole or SITE_NAME != 'rDrama': defaulttime = 'all' else: defaulttime = DEFAULT_TIME_FILTER - if sub: defaultsorting = "new" + if hole: defaultsorting = "new" sort = request.values.get("sort", defaultsorting) t = request.values.get('t', defaulttime) @@ -53,10 +53,10 @@ def front_all(v, sub=None): if sort == 'hot': default = True else: default = False - pins = session.get(f'{sub}_{sort}', default) + pins = session.get(f'{hole}_{sort}', default) if not v: - result = cache.get(f'frontpage_{sort}_{t}_{page}_{sub}_{pins}') + result = cache.get(f'frontpage_{sort}_{t}_{page}_{hole}_{pins}') if result: calc_users() return result @@ -68,7 +68,7 @@ def front_all(v, sub=None): filter_words=v.filter_words if v else [], gt=gt, lt=lt, - sub=sub, + hole=hole, pins=pins, ) @@ -79,10 +79,10 @@ def front_all(v, sub=None): if v and v.client: return {"data": [x.json for x in posts], "total": total} - result = render_template("home.html", v=v, listing=posts, total=total, sort=sort, t=t, page=page, sub=sub, home=True, pins=pins, size=size) + result = render_template("home.html", v=v, listing=posts, total=total, sort=sort, t=t, page=page, hole=hole, home=True, pins=pins, size=size) if not v: - cache.set(f'frontpage_{sort}_{t}_{page}_{sub}_{pins}', result, timeout=900) + cache.set(f'frontpage_{sort}_{t}_{page}_{hole}_{pins}', result, timeout=900) return result @@ -92,7 +92,7 @@ LIMITED_WPD_HOLES = ('aftermath', 'fights', 'gore', 'medical', 'request', 'selfh 'countryclub', 'highrollerclub') @cache.memoize() -def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', gt=0, lt=0, sub=None, pins=True): +def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', gt=0, lt=0, hole=None, pins=True): posts = g.db.query(Post) if v and v.hidevotedon: @@ -100,13 +100,13 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' and_(Vote.post_id == Post.id, Vote.user_id == v.id) ).filter(Vote.post_id == None) - if sub: - posts = posts.filter(Post.sub == sub.name) + if hole: + posts = posts.filter(Post.hole == hole.name) elif v: - posts = posts.filter(or_(Post.sub == None, Post.sub.notin_(v.sub_blocks))) + posts = posts.filter(or_(Post.hole == None, Post.hole.notin_(v.hole_blocks))) else: - stealth = [x[0] for x in g.db.query(Sub.name).filter_by(stealth=True)] - posts = posts.filter(or_(Post.sub == None, Post.sub.notin_(stealth))) + stealth = [x[0] for x in g.db.query(Hole.name).filter_by(stealth=True)] + posts = posts.filter(or_(Post.hole == None, Post.hole.notin_(stealth))) if gt: posts = posts.filter(Post.created_utc > gt) if lt: posts = posts.filter(Post.created_utc < lt) @@ -121,7 +121,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 sub: posts = posts.filter(Post.hole_pinned == None) + if hole: posts = posts.filter(Post.hole_pinned == None) else: posts = posts.filter(Post.stickied == None) if v: @@ -141,28 +141,28 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' posts = posts.options(load_only(Post.id)).offset(size * (page - 1)) - if SITE_NAME == 'WPD' and sort == "hot" and sub == None: + if SITE_NAME == 'WPD' and sort == "hot" and hole == None: posts = posts.limit(200).all() to_remove = [] for h in LIMITED_WPD_HOLES: - to_remove += [x.id for x in posts if x.sub == h][1:] + to_remove += [x.id for x in posts if x.hole == h][1:] posts = [x for x in posts if x.id not in to_remove][:size] - elif SITE_NAME == 'WPD' and not v and sub == None: + elif SITE_NAME == 'WPD' and not v and hole == None: posts = posts.limit(200).all() - posts = [x for x in posts if x.sub not in {'pets','selfharm'}][:size] + posts = [x for x in posts if x.hole not in {'pets','selfharm'}][:size] else: posts = posts.limit(size).all() if pins and page == 1 and not gt and not lt: - if sub: - pins = g.db.query(Post).options(load_only(Post.id)).filter(Post.sub == sub.name, Post.hole_pinned != None) + 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) if v: - pins = pins.filter(or_(Post.sub == None, Post.sub.notin_(v.sub_blocks))) + pins = pins.filter(or_(Post.hole == None, Post.hole.notin_(v.hole_blocks))) if v: pins = pins.filter(Post.author_id.notin_(v.userblocks)) @@ -185,7 +185,7 @@ def random_post(v): Post.deleted_utc == 0, Post.is_banned == False, Post.private == False, - or_(Post.sub == None, Post.sub.notin_(v.sub_blocks)), + or_(Post.hole == None, Post.hole.notin_(v.hole_blocks)), ).order_by(func.random()).first() if p: p = p[0] diff --git a/files/routes/subs.py b/files/routes/holes.py similarity index 63% rename from files/routes/subs.py rename to files/routes/holes.py index d10ef5d21..a469b6834 100644 --- a/files/routes/subs.py +++ b/files/routes/holes.py @@ -16,23 +16,23 @@ from files.__main__ import app, cache, limiter @auth_required def exile_post(v, pid): p = get_post(pid) - sub = p.sub - if not sub: abort(400) + hole = p.hole + if not hole: abort(400) - if not v.mods(sub): abort(403) + if not v.mods(hole): abort(403) u = p.author - if u.mods(sub): abort(403) + if u.mods(hole): abort(403) - if not u.exiler_username(sub): - exile = Exile(user_id=u.id, sub=sub, exiler_id=v.id) + if not u.exiler_username(hole): + exile = Exile(user_id=u.id, hole=hole, exiler_id=v.id) g.db.add(exile) - send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{p.title}]({p.shortlink})") + send_notification(u.id, f"@{v.username} has exiled you from /h/{hole} for [{p.title}]({p.shortlink})") - ma = SubAction( - sub=sub, + ma = HoleAction( + hole=hole, kind='exile_user', user_id=v.id, target_user_id=u.id, @@ -40,7 +40,7 @@ def exile_post(v, pid): ) g.db.add(ma) - return {"message": f"@{u.username} has been exiled from /h/{sub} successfully!"} + return {"message": f"@{u.username} has been exiled from /h/{hole} successfully!"} @app.post("/exile/comment/") @limiter.limit('1/second', scope=rpath) @@ -50,23 +50,23 @@ def exile_post(v, pid): @auth_required def exile_comment(v, cid): c = get_comment(cid) - sub = c.post.sub - if not sub: abort(400) + hole = c.post.hole + if not hole: abort(400) - if not v.mods(sub): abort(403) + if not v.mods(hole): abort(403) u = c.author - if u.mods(sub): abort(403) + if u.mods(hole): abort(403) - if not u.exiler_username(sub): - exile = Exile(user_id=u.id, sub=sub, exiler_id=v.id) + if not u.exiler_username(hole): + exile = Exile(user_id=u.id, hole=hole, exiler_id=v.id) g.db.add(exile) - send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{c.permalink}]({c.shortlink})") + send_notification(u.id, f"@{v.username} has exiled you from /h/{hole} for [{c.permalink}]({c.shortlink})") - ma = SubAction( - sub=sub, + ma = HoleAction( + hole=hole, kind='exile_user', user_id=v.id, target_user_id=u.id, @@ -74,199 +74,199 @@ def exile_comment(v, cid): ) g.db.add(ma) - return {"message": f"@{u.username} has been exiled from /h/{sub} successfully!"} + return {"message": f"@{u.username} has been exiled from /h/{hole} successfully!"} -@app.post("/h//unexile/") +@app.post("/h//unexile/") @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) @auth_required -def unexile(v, sub, uid): +def unexile(v, hole, uid): u = get_account(uid) - if not v.mods(sub): abort(403) + if not v.mods(hole): abort(403) - if u.exiler_username(sub): - exile = g.db.query(Exile).filter_by(user_id=u.id, sub=sub).one_or_none() + if u.exiler_username(hole): + exile = g.db.query(Exile).filter_by(user_id=u.id, hole=hole).one_or_none() g.db.delete(exile) - send_notification(u.id, f"@{v.username} has revoked your exile from /h/{sub}") + send_notification(u.id, f"@{v.username} has revoked your exile from /h/{hole}") - ma = SubAction( - sub=sub, + ma = HoleAction( + hole=hole, kind='unexile_user', user_id=v.id, target_user_id=u.id ) g.db.add(ma) - return {"message": f"@{u.username} has been unexiled from /h/{sub} successfully!"} + return {"message": f"@{u.username} has been unexiled from /h/{hole} successfully!"} -@app.post("/h//block") +@app.post("/h//block") @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) @auth_required -def block_sub(v, sub): - sub = get_sub_by_name(sub).name - existing = g.db.query(SubBlock).filter_by(user_id=v.id, sub=sub).one_or_none() +def block_sub(v, hole): + hole = get_hole(hole).name + existing = g.db.query(HoleBlock).filter_by(user_id=v.id, hole=hole).one_or_none() if not existing: - block = SubBlock(user_id=v.id, sub=sub) + block = HoleBlock(user_id=v.id, hole=hole) g.db.add(block) cache.delete_memoized(frontlist) - return {"message": f"/h/{sub} blocked successfully!"} + return {"message": f"/h/{hole} blocked successfully!"} -@app.post("/h//unblock") +@app.post("/h//unblock") @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) @auth_required -def unblock_sub(v, sub): - sub = get_sub_by_name(sub) - if not can_see(v, sub): +def unblock_sub(v, hole): + hole = get_hole(hole) + if not can_see(v, hole): abort(403) - block = g.db.query(SubBlock).filter_by(user_id=v.id, sub=sub.name).one_or_none() + block = g.db.query(HoleBlock).filter_by(user_id=v.id, hole=hole.name).one_or_none() if block: g.db.delete(block) cache.delete_memoized(frontlist) - return {"message": f"/h/{sub.name} unblocked successfully!"} + return {"message": f"/h/{hole.name} unblocked successfully!"} -@app.post("/h//subscribe") +@app.post("/h//subscribe") @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) @auth_required -def subscribe_sub(v, sub): - sub = get_sub_by_name(sub).name - existing = g.db.query(SubJoin).filter_by(user_id=v.id, sub=sub).one_or_none() +def subscribe_sub(v, hole): + hole = get_hole(hole).name + existing = g.db.query(StealthHoleUnblock).filter_by(user_id=v.id, hole=hole).one_or_none() if not existing: - subscribe = SubJoin(user_id=v.id, sub=sub) + subscribe = StealthHoleUnblock(user_id=v.id, hole=hole) g.db.add(subscribe) cache.delete_memoized(frontlist) - return {"message": f"/h/{sub} unblocked successfully!"} + return {"message": f"/h/{hole} unblocked successfully!"} -@app.post("/h//unsubscribe") +@app.post("/h//unsubscribe") @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) @auth_required -def unsubscribe_sub(v, sub): - sub = get_sub_by_name(sub).name - subscribe = g.db.query(SubJoin).filter_by(user_id=v.id, sub=sub).one_or_none() +def unsubscribe_sub(v, hole): + hole = get_hole(hole).name + subscribe = g.db.query(StealthHoleUnblock).filter_by(user_id=v.id, hole=hole).one_or_none() if subscribe: g.db.delete(subscribe) cache.delete_memoized(frontlist) - return {"message": f"/h/{sub} blocked successfully!"} + return {"message": f"/h/{hole} blocked successfully!"} -@app.post("/h//follow") +@app.post("/h//follow") @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) @auth_required -def follow_sub(v, sub): - sub = get_sub_by_name(sub) - if not can_see(v, sub): +def follow_sub(v, hole): + hole = get_hole(hole) + if not can_see(v, hole): abort(403) - existing = g.db.query(SubSubscription).filter_by(user_id=v.id, sub=sub.name).one_or_none() + existing = g.db.query(HoleFollow).filter_by(user_id=v.id, hole=hole.name).one_or_none() if not existing: - subscription = SubSubscription(user_id=v.id, sub=sub.name) + subscription = HoleFollow(user_id=v.id, hole=hole.name) g.db.add(subscription) - return {"message": f"/h/{sub} followed successfully!"} + return {"message": f"/h/{hole} followed successfully!"} -@app.post("/h//unfollow") +@app.post("/h//unfollow") @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) @auth_required -def unfollow_sub(v, sub): - sub = get_sub_by_name(sub) - subscription = g.db.query(SubSubscription).filter_by(user_id=v.id, sub=sub.name).one_or_none() +def unfollow_sub(v, hole): + hole = get_hole(hole) + subscription = g.db.query(HoleFollow).filter_by(user_id=v.id, hole=hole.name).one_or_none() if subscription: g.db.delete(subscription) - return {"message": f"/h/{sub} unfollowed successfully!"} + return {"message": f"/h/{hole} unfollowed successfully!"} -@app.get("/h//mods") +@app.get("/h//mods") @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) @auth_required -def mods(v, sub): - sub = get_sub_by_name(sub) - if not can_see(v, sub): +def mods(v, hole): + hole = get_hole(hole) + if not can_see(v, hole): abort(403) - users = g.db.query(User, Mod).join(Mod).filter_by(sub=sub.name).order_by(Mod.created_utc).all() + users = g.db.query(User, Mod).join(Mod).filter_by(hole=hole.name).order_by(Mod.created_utc).all() - return render_template("sub/mods.html", v=v, sub=sub, users=users) + return render_template("hole/mods.html", v=v, hole=hole, users=users) -@app.get("/h//exilees") +@app.get("/h//exilees") @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) @auth_required -def sub_exilees(v, sub): - sub = get_sub_by_name(sub) - if not can_see(v, sub): +def hole_exilees(v, hole): + hole = get_hole(hole) + if not can_see(v, hole): abort(403) users = g.db.query(User, Exile).join(Exile, Exile.user_id==User.id) \ - .filter_by(sub=sub.name) \ + .filter_by(hole=hole.name) \ .order_by(Exile.created_utc.desc(), User.username).all() - return render_template("sub/exilees.html", v=v, sub=sub, users=users) + return render_template("hole/exilees.html", v=v, hole=hole, users=users) -@app.get("/h//blockers") +@app.get("/h//blockers") @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) @auth_required -def sub_blockers(v, sub): - sub = get_sub_by_name(sub) - if not can_see(v, sub): +def hole_blockers(v, hole): + hole = get_hole(hole) + if not can_see(v, hole): abort(403) - users = g.db.query(User, SubBlock).join(SubBlock) \ - .filter_by(sub=sub.name) \ - .order_by(SubBlock.created_utc.desc(), User.username).all() + users = g.db.query(User, HoleBlock).join(HoleBlock) \ + .filter_by(hole=hole.name) \ + .order_by(HoleBlock.created_utc.desc(), User.username).all() - return render_template("sub/blockers.html", - v=v, sub=sub, users=users, verb="blocking") + return render_template("hole/blockers.html", + v=v, hole=hole, users=users, verb="blocking") -@app.get("/h//followers") +@app.get("/h//followers") @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) @auth_required -def sub_followers(v, sub): - sub = get_sub_by_name(sub) - if not can_see(v, sub): +def hole_followers(v, hole): + hole = get_hole(hole) + if not can_see(v, hole): abort(403) - users = g.db.query(User, SubSubscription).join(SubSubscription) \ - .filter_by(sub=sub.name) \ - .order_by(SubSubscription.created_utc.desc(), User.username).all() + users = g.db.query(User, HoleFollow).join(HoleFollow) \ + .filter_by(hole=hole.name) \ + .order_by(HoleFollow.created_utc.desc(), User.username).all() - return render_template("sub/blockers.html", - v=v, sub=sub, users=users, verb="following") + return render_template("hole/blockers.html", + v=v, hole=hole, users=users, verb="following") -@app.post("/h//add_mod") +@app.post("/h//add_mod") @limiter.limit('1/second', scope=rpath) @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit("30/day", deduct_when=lambda response: response.status_code < 400) @limiter.limit("30/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required -def add_mod(v, sub): +def add_mod(v, hole): if SITE_NAME == 'WPD': abort(403) - sub = get_sub_by_name(sub).name - if not v.mods(sub): abort(403) + hole = get_hole(hole).name + if not v.mods(hole): abort(403) user = request.values.get('user') @@ -274,20 +274,20 @@ def add_mod(v, sub): user = get_user(user, v=v) - if sub in {'furry','vampire','racist','femboy','edgy'} and not v.client and not user.house.lower().startswith(sub): - abort(403, f"@{user.username} needs to be a member of House {sub.capitalize()} to be added as a mod there!") + if hole in {'furry','vampire','racist','femboy','edgy'} and not v.client and not user.house.lower().startswith(hole): + abort(403, f"@{user.username} needs to be a member of House {hole.capitalize()} to be added as a mod there!") - existing = g.db.query(Mod).filter_by(user_id=user.id, sub=sub).one_or_none() + existing = g.db.query(Mod).filter_by(user_id=user.id, hole=hole).one_or_none() if not existing: - mod = Mod(user_id=user.id, sub=sub) + mod = Mod(user_id=user.id, hole=hole) g.db.add(mod) if v.id != user.id: - send_repeatable_notification(user.id, f"@{v.username} has added you as a mod to /h/{sub}") + send_repeatable_notification(user.id, f"@{v.username} has added you as a mod to /h/{hole}") - ma = SubAction( - sub=sub, + ma = HoleAction( + hole=hole, kind='make_mod', user_id=v.id, target_user_id=user.id @@ -296,16 +296,16 @@ def add_mod(v, sub): return {"message": "Mod added successfully!"} -@app.post("/h//remove_mod") +@app.post("/h//remove_mod") @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) @auth_required -def remove_mod(v, sub): - sub = get_sub_by_name(sub).name +def remove_mod(v, hole): + hole = get_hole(hole).name - if not v.mods(sub): abort(403) + if not v.mods(hole): abort(403) uid = request.values.get('uid') @@ -318,18 +318,18 @@ def remove_mod(v, sub): if not user: abort(404) - mod = g.db.query(Mod).filter_by(user_id=user.id, sub=sub).one_or_none() + mod = g.db.query(Mod).filter_by(user_id=user.id, hole=hole).one_or_none() if not mod: abort(400) - if not (v.id == user.id or v.mod_date(sub) and v.mod_date(sub) < mod.created_utc): abort(403) + if not (v.id == user.id or v.mod_date(hole) and v.mod_date(hole) < mod.created_utc): abort(403) g.db.delete(mod) if v.id != user.id: - send_repeatable_notification(user.id, f"@{v.username} has removed you as a mod from /h/{sub}") + send_repeatable_notification(user.id, f"@{v.username} has removed you as a mod from /h/{hole}") - ma = SubAction( - sub=sub, + ma = HoleAction( + hole=hole, kind='remove_mod', user_id=v.id, target_user_id=user.id @@ -346,7 +346,7 @@ def create_sub(v): if not v.can_create_hole: abort(403) - return render_template("sub/create_hole.html", v=v, cost=HOLE_COST) + return render_template("hole/create_hole.html", v=v, cost=HOLE_COST) @app.post("/create_hole") @limiter.limit('1/second', scope=rpath) @@ -368,25 +368,25 @@ def create_sub2(v): if not v.charge_account('combined', HOLE_COST)[0]: abort(400, "You don't have enough coins or marseybux!") - sub = get_sub_by_name(name, graceful=True) + hole = get_hole(name, graceful=True) - if sub: - abort(400, f"/h/{sub} already exists!") + if hole: + abort(400, f"/h/{hole} already exists!") g.db.add(v) if v.shadowbanned: abort(500) - sub = Sub(name=name) - g.db.add(sub) + hole = Hole(name=name) + g.db.add(hole) g.db.flush() #Necessary, following statement errors out otherwise - mod = Mod(user_id=v.id, sub=sub.name) + mod = Mod(user_id=v.id, hole=hole.name) g.db.add(mod) admins = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_HOLE_CREATION'], User.id != v.id)] for admin in admins: - send_repeatable_notification(admin, f":!marseyparty: /h/{sub} has been created by @{v.username} :marseyparty:") + send_repeatable_notification(admin, f":!marseyparty: /h/{hole} has been created by @{v.username} :marseyparty:") - return redirect(f"/h/{sub}") + return redirect(f"/h/{hole}") @app.post("/kick/") @limiter.limit('1/second', scope=rpath) @@ -397,15 +397,15 @@ def create_sub2(v): def kick(v, pid): post = get_post(pid) - if not post.sub: abort(403) - if not v.mods(post.sub): abort(403) + if not post.hole: abort(403) + if not v.mods(post.hole): abort(403) - old = post.sub - post.sub = None + old = post.hole + post.hole = None post.hole_pinned = None - ma = SubAction( - sub=old, + ma = HoleAction( + hole=old, kind='kick_post', user_id=v.id, target_post_id=post.id @@ -422,38 +422,38 @@ def kick(v, pid): return {"message": f"Post kicked from /h/{old} successfully!"} -@app.get('/h//settings') +@app.get('/h//settings') @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) @auth_required -def sub_settings(v, sub): - sub = get_sub_by_name(sub) - if not v.mods(sub.name): abort(403) - return render_template('sub/settings.html', v=v, sidebar=sub.sidebar, sub=sub, css=sub.css) +def hole_settings(v, hole): + hole = get_hole(hole) + if not v.mods(hole.name): abort(403) + return render_template('hole/settings.html', v=v, sidebar=hole.sidebar, hole=hole, css=hole.css) -@app.post('/h//sidebar') +@app.post('/h//sidebar') @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) @auth_required -def post_sub_sidebar(v, sub): - sub = get_sub_by_name(sub) - if not v.mods(sub.name): abort(403) +def post_hole_sidebar(v, hole): + hole = get_hole(hole) + if not v.mods(hole.name): abort(403) if v.shadowbanned: abort(400) - sub.sidebar = request.values.get('sidebar', '')[:10000].strip() - sidebar_html = sanitize(sub.sidebar, blackjack=f"/h/{sub} sidebar") + hole.sidebar = request.values.get('sidebar', '')[:10000].strip() + sidebar_html = sanitize(hole.sidebar, blackjack=f"/h/{hole} sidebar") if len(sidebar_html) > 20000: abort(400, "Sidebar is too big! (max 20000 characters)") - sub.sidebar_html = sidebar_html - g.db.add(sub) + hole.sidebar_html = sidebar_html + g.db.add(hole) - ma = SubAction( - sub=sub.name, + ma = HoleAction( + hole=hole.name, kind='edit_sidebar', user_id=v.id ) @@ -462,18 +462,18 @@ def post_sub_sidebar(v, sub): return {"message": "Sidebar changed successfully!"} -@app.post('/h//css') +@app.post('/h//css') @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) @auth_required -def post_sub_css(v, sub): - sub = get_sub_by_name(sub) +def post_hole_css(v, hole): + hole = get_hole(hole) css = request.values.get('css', '').strip() - if not sub: abort(404) - if not v.mods(sub.name): abort(403) + if not hole: abort(404) + if not v.mods(hole.name): abort(403) if v.shadowbanned: abort(400) if len(css) > 6000: @@ -483,11 +483,11 @@ def post_sub_css(v, sub): if not valid: abort(400, error) - sub.css = css - g.db.add(sub) + hole.css = css + g.db.add(hole) - ma = SubAction( - sub=sub.name, + ma = HoleAction( + hole=hole.name, kind='edit_css', user_id=v.id ) @@ -495,26 +495,26 @@ def post_sub_css(v, sub): return {"message": "CSS changed successfully!"} -@app.get("/h//css") +@app.get("/h//css") @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) -def get_sub_css(sub): - sub = g.db.query(Sub.css).filter_by(name=sub.strip().lower()).one_or_none() - if not sub: abort(404) - resp = make_response(sub.css or "") +def get_hole_css(hole): + hole = g.db.query(Hole.css).filter_by(name=hole.strip().lower()).one_or_none() + if not hole: abort(404) + resp = make_response(hole.css or "") resp.headers.add("Content-Type", "text/css") return resp -@app.post("/h//settings/banners/") +@app.post("/h//settings/banners/") @limiter.limit('1/second', scope=rpath) @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit("50/day", deduct_when=lambda response: response.status_code < 400) @limiter.limit("50/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required -def upload_sub_banner(v, sub): +def upload_hole_banner(v, hole): if g.is_tor: abort(403, "Image uploads are not allowed through Tor") - sub = get_sub_by_name(sub) - if not v.mods(sub.name): abort(403) + hole = get_hole(hole) + if not v.mods(hole.name): abort(403) if v.shadowbanned: abort(500) file = request.files["banner"] @@ -523,86 +523,86 @@ def upload_sub_banner(v, sub): file.save(name) bannerurl = process_image(name, v, resize=1200) - sub.bannerurls.append(bannerurl) + hole.bannerurls.append(bannerurl) - g.db.add(sub) + g.db.add(hole) - ma = SubAction( - sub=sub.name, + ma = HoleAction( + hole=hole.name, kind='upload_banner', user_id=v.id ) g.db.add(ma) - return redirect(f'/h/{sub}/settings') + return redirect(f'/h/{hole}/settings') -@app.post("/h//settings/banners/delete/") +@app.post("/h//settings/banners/delete/") @limiter.limit("1/second;30/day", deduct_when=lambda response: response.status_code < 400) @limiter.limit("1/second;30/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required -def delete_sub_banner(v, sub, index): - sub = get_sub_by_name(sub) - if not v.mods(sub.name): abort(403) +def delete_hole_banner(v, hole, index): + hole = get_hole(hole) + if not v.mods(hole.name): abort(403) - if not sub.bannerurls: - abort(404, f"Banner not found (/h/{sub.name} has no banners)") - if index < 0 or index >= len(sub.bannerurls): - abort(404, f'Banner not found (banner index {index} is not between 0 and {len(sub.bannerurls)})') - banner = sub.bannerurls[index] + if not hole.bannerurls: + abort(404, f"Banner not found (/h/{hole.name} has no banners)") + if index < 0 or index >= len(hole.bannerurls): + abort(404, f'Banner not found (banner index {index} is not between 0 and {len(hole.bannerurls)})') + banner = hole.bannerurls[index] try: remove_media_using_link(banner) except FileNotFoundError: pass - del sub.bannerurls[index] - g.db.add(sub) + del hole.bannerurls[index] + g.db.add(hole) - ma = SubAction( - sub=sub.name, + ma = HoleAction( + hole=hole.name, kind='delete_banner', _note=index, user_id=v.id ) g.db.add(ma) - return {"message": f"Deleted banner {index} from /h/{sub} successfully"} + return {"message": f"Deleted banner {index} from /h/{hole} successfully"} -@app.post("/h//settings/banners/delete_all") +@app.post("/h//settings/banners/delete_all") @limiter.limit("1/10 second;30/day", deduct_when=lambda response: response.status_code < 400) @limiter.limit("1/10 second;30/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required -def delete_all_sub_banners(v, sub): - sub = get_sub_by_name(sub) - if not v.mods(sub.name): abort(403) +def delete_all_hole_banners(v, hole): + hole = get_hole(hole) + if not v.mods(hole.name): abort(403) - for banner in sub.banner_urls: + for banner in hole.banner_urls: try: remove_media_using_link(banner) except FileNotFoundError: pass - sub.bannerurls = [] - g.db.add(sub) + hole.bannerurls = [] + g.db.add(hole) - ma = SubAction( - sub=sub.name, + ma = HoleAction( + hole=hole.name, kind='delete_banner', _note='all', user_id=v.id ) g.db.add(ma) - return {"message": f"Deleted all banners from /h/{sub} successfully"} + return {"message": f"Deleted all banners from /h/{hole} successfully"} -@app.post("/h//sidebar_image") +@app.post("/h//sidebar_image") @limiter.limit('1/second', scope=rpath) @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400) @limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required -def sub_sidebar(v, sub): +def hole_sidebar(v, hole): if g.is_tor: abort(403, "Image uploads are not allowed through TOR!") - sub = get_sub_by_name(sub) - if not v.mods(sub.name): abort(403) + hole = get_hole(hole) + if not v.mods(hole.name): abort(403) if v.shadowbanned: abort(500) file = request.files["sidebar"] @@ -611,31 +611,31 @@ def sub_sidebar(v, sub): sidebarurl = process_image(name, v, resize=400) if sidebarurl: - if sub.sidebarurl: - remove_media_using_link(sub.sidebarurl) - sub.sidebarurl = sidebarurl - g.db.add(sub) + if hole.sidebarurl: + remove_media_using_link(hole.sidebarurl) + hole.sidebarurl = sidebarurl + g.db.add(hole) - ma = SubAction( - sub=sub.name, + ma = HoleAction( + hole=hole.name, kind='change_sidebar_image', user_id=v.id ) g.db.add(ma) - return redirect(f'/h/{sub}/settings') + return redirect(f'/h/{hole}/settings') -@app.post("/h//marsey_image") +@app.post("/h//marsey_image") @limiter.limit('1/second', scope=rpath) @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400) @limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required -def sub_marsey(v, sub): +def hole_marsey(v, hole): if g.is_tor: abort(403, "Image uploads are not allowed through TOR!") - sub = get_sub_by_name(sub) - if not v.mods(sub.name): abort(403) + hole = get_hole(hole) + if not v.mods(hole.name): abort(403) if v.shadowbanned: abort(500) file = request.files["marsey"] @@ -644,19 +644,19 @@ def sub_marsey(v, sub): marseyurl = process_image(name, v, resize=200) if marseyurl: - if sub.marseyurl: - remove_media_using_link(sub.marseyurl) - sub.marseyurl = marseyurl - g.db.add(sub) + if hole.marseyurl: + remove_media_using_link(hole.marseyurl) + hole.marseyurl = marseyurl + g.db.add(hole) - ma = SubAction( - sub=sub.name, + ma = HoleAction( + hole=hole.name, kind='change_marsey', user_id=v.id ) g.db.add(ma) - return redirect(f'/h/{sub}/settings') + return redirect(f'/h/{hole}/settings') @app.get("/flairs") @app.get("/holes") @@ -664,9 +664,9 @@ def sub_marsey(v, sub): @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required def subs(v): - subs = g.db.query(Sub, func.count(Post.sub)).outerjoin(Post, Sub.name == Post.sub).group_by(Sub.name).order_by(func.count(Post.sub).desc()).all() + subs = g.db.query(Hole, func.count(Post.hole)).outerjoin(Post, Hole.name == Post.hole).group_by(Hole.name).order_by(func.count(Post.hole).desc()).all() total_users = g.db.query(User).count() - return render_template('sub/subs.html', v=v, subs=subs, total_users=total_users) + return render_template('hole/holes.html', v=v, subs=subs, total_users=total_users) @app.post("/hole_pin/") @limiter.limit('1/second', scope=rpath) @@ -677,23 +677,23 @@ def subs(v): def hole_pin(v, pid): p = get_post(pid) - if not p.sub: abort(403) + if not p.hole: abort(403) - if not v.mods(p.sub): abort(403) + if not v.mods(p.hole): abort(403) - num = g.db.query(Post).filter(Post.sub == p.sub, Post.hole_pinned != None).count() + num = g.db.query(Post).filter(Post.hole == p.hole, Post.hole_pinned != None).count() if num >= 2: - abort(403, f"You can only pin 2 posts to /h/{p.sub}") + abort(403, f"You can only pin 2 posts to /h/{p.hole}") p.hole_pinned = v.username g.db.add(p) if v.id != p.author_id: - message = f"@{v.username} (a /h/{p.sub} mod) has pinned [{p.title}]({p.shortlink}) in /h/{p.sub}" + message = f"@{v.username} (a /h/{p.hole} mod) has pinned [{p.title}]({p.shortlink}) in /h/{p.hole}" send_repeatable_notification(p.author_id, message) - ma = SubAction( - sub=p.sub, + ma = HoleAction( + hole=p.hole, kind='pin_post', user_id=v.id, target_post_id=p.id @@ -702,7 +702,7 @@ def hole_pin(v, pid): cache.delete_memoized(frontlist) - return {"message": f"Post pinned to /h/{p.sub} successfully!"} + return {"message": f"Post pinned to /h/{p.hole} successfully!"} @app.post("/hole_unpin/") @limiter.limit('1/second', scope=rpath) @@ -713,19 +713,19 @@ def hole_pin(v, pid): def hole_unpin(v, pid): p = get_post(pid) - if not p.sub: abort(403) + if not p.hole: abort(403) - if not v.mods(p.sub): abort(403) + if not v.mods(p.hole): abort(403) p.hole_pinned = None g.db.add(p) if v.id != p.author_id: - message = f"@{v.username} (a /h/{p.sub} mod) has unpinned [{p.title}]({p.shortlink}) in /h/{p.sub}" + message = f"@{v.username} (a /h/{p.hole} mod) has unpinned [{p.title}]({p.shortlink}) in /h/{p.hole}" send_repeatable_notification(p.author_id, message) - ma = SubAction( - sub=p.sub, + ma = HoleAction( + hole=p.hole, kind='unpin_post', user_id=v.id, target_post_id=p.id @@ -734,42 +734,42 @@ def hole_unpin(v, pid): cache.delete_memoized(frontlist) - return {"message": f"Post unpinned from /h/{p.sub} successfully!"} + return {"message": f"Post unpinned from /h/{p.hole} successfully!"} -@app.post('/h//stealth') +@app.post('/h//stealth') @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) @auth_required -def sub_stealth(v, sub): - sub = get_sub_by_name(sub) - if sub.name in {'braincels','smuggies','mnn'} and v.admin_level < PERMS["MODS_EVERY_HOLE"]: +def hole_stealth(v, hole): + hole = get_hole(hole) + if hole.name in {'braincels','smuggies','mnn'} and v.admin_level < PERMS["MODS_EVERY_HOLE"]: abort(403) - if not v.mods(sub.name): abort(403) + if not v.mods(hole.name): abort(403) - sub.stealth = not sub.stealth - g.db.add(sub) + hole.stealth = not hole.stealth + g.db.add(hole) cache.delete_memoized(frontlist) - if sub.stealth: - ma = SubAction( - sub=sub.name, + if hole.stealth: + ma = HoleAction( + hole=hole.name, kind='enable_stealth', user_id=v.id ) g.db.add(ma) - return {"message": f"Stealth mode has been enabled for /h/{sub} successfully!"} + return {"message": f"Stealth mode has been enabled for /h/{hole} successfully!"} else: - ma = SubAction( - sub=sub.name, + ma = HoleAction( + hole=hole.name, kind='disable_stealth', user_id=v.id ) g.db.add(ma) - return {"message": f"Stealth mode has been disabled for /h/{sub} successfully!"} + return {"message": f"Stealth mode has been disabled for /h/{hole} successfully!"} @app.post("/pin_comment_mod/") @@ -784,14 +784,14 @@ def pin_comment_mod(cid, v): comment = get_comment(cid, v=v) if not comment.stickied: - if not (comment.post.sub and v.mods(comment.post.sub)): abort(403) + if not (comment.post.hole and v.mods(comment.post.hole)): abort(403) comment.stickied = v.username + " (Mod)" g.db.add(comment) - ma = SubAction( - sub=comment.post.sub, + ma = HoleAction( + hole=comment.post.hole, kind="pin_comment", user_id=v.id, target_comment_id=comment.id @@ -799,7 +799,7 @@ def pin_comment_mod(cid, v): g.db.add(ma) if v.id != comment.author_id: - message = f"@{v.username} (a /h/{comment.post.sub} mod) has pinned your [comment]({comment.shortlink})" + message = f"@{v.username} (a /h/{comment.post.hole} mod) has pinned your [comment]({comment.shortlink})" send_repeatable_notification(comment.author_id, message) return {"message": "Comment pinned!"} @@ -815,14 +815,14 @@ def unpin_comment_mod(cid, v): comment = get_comment(cid, v=v) if comment.stickied: - if not (comment.post.sub and v.mods(comment.post.sub)): abort(403) + if not (comment.post.hole and v.mods(comment.post.hole)): abort(403) comment.stickied = None comment.stickied_utc = None g.db.add(comment) - ma = SubAction( - sub=comment.post.sub, + ma = HoleAction( + hole=comment.post.hole, kind="unpin_comment", user_id=v.id, target_comment_id=comment.id @@ -830,19 +830,19 @@ def unpin_comment_mod(cid, v): g.db.add(ma) if v.id != comment.author_id: - message = f"@{v.username} (a /h/{comment.post.sub} mod) has unpinned your [comment]({comment.shortlink})" + message = f"@{v.username} (a /h/{comment.post.hole} mod) has unpinned your [comment]({comment.shortlink})" send_repeatable_notification(comment.author_id, message) return {"message": "Comment unpinned!"} -@app.get("/h//log") -@app.get("/h//modlog") +@app.get("/h//log") +@app.get("/h//modlog") @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) @auth_required -def hole_log(v, sub): - sub = get_sub_by_name(sub) - if not can_see(v, sub): +def hole_log(v, hole): + hole = get_hole(hole) + if not can_see(v, hole): abort(403) page = get_page() @@ -852,14 +852,14 @@ def hole_log(v, sub): kind = request.values.get("kind") - types = SUBACTION_TYPES + types = HOLEACTION_TYPES if kind and kind not in types: kind = None actions = [] total=0 else: - actions = g.db.query(SubAction).filter_by(sub=sub.name) + actions = g.db.query(HoleAction).filter_by(hole=hole.name) if mod_id: actions = actions.filter_by(user_id=mod_id) @@ -871,29 +871,29 @@ def hole_log(v, sub): types = types2 if kind: actions = actions.filter_by(kind=kind) total = actions.count() - actions = actions.order_by(SubAction.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all() + actions = actions.order_by(HoleAction.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all() - mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(sub=sub.name)] + mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(hole=hole.name)] mods = [x[0] for x in g.db.query(User.username).filter(User.id.in_(mods)).order_by(User.username)] - return render_template("log.html", v=v, admins=mods, types=types, admin=mod, type=kind, actions=actions, total=total, page=page, sub=sub, single_user_url='mod') + return render_template("log.html", v=v, admins=mods, types=types, admin=mod, type=kind, actions=actions, total=total, page=page, hole=hole, single_user_url='mod') -@app.get("/h//log/") +@app.get("/h//log/") @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) @auth_required -def hole_log_item(id, v, sub): - sub = get_sub_by_name(sub) - if not can_see(v, sub): +def hole_log_item(id, v, hole): + hole = get_hole(hole) + if not can_see(v, hole): abort(403) - action = g.db.get(SubAction, id) + action = g.db.get(HoleAction, id) if not action: abort(404) - mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(sub=sub.name)] + mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(hole=hole.name)] mods = [x[0] for x in g.db.query(User.username).filter(User.id.in_(mods)).order_by(User.username)] - types = SUBACTION_TYPES + types = HOLEACTION_TYPES - return render_template("log.html", v=v, actions=[action], total=1, page=1, action=action, admins=mods, types=types, sub=sub, single_user_url='mod') + return render_template("log.html", v=v, actions=[action], total=1, page=1, action=action, admins=mods, types=types, hole=hole, single_user_url='mod') diff --git a/files/routes/notifications.py b/files/routes/notifications.py index 435756e2f..997d167ab 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -4,7 +4,7 @@ from sqlalchemy.sql.expression import not_, and_, or_ from sqlalchemy.orm import load_only from files.classes.mod_logs import ModAction -from files.classes.sub_logs import SubAction +from files.classes.hole_logs import HoleAction from files.helpers.config.const import * from files.helpers.config.modaction_types import * from files.helpers.get import * @@ -167,7 +167,7 @@ def notifications_posts(v): listing = g.db.query(Post).filter( or_( - Post.sub.in_(v.followed_subs), + Post.hole.in_(v.followed_holes), and_( Post.author_id.in_(v.followed_users), Post.notify == True, @@ -179,7 +179,7 @@ def notifications_posts(v): Post.private == False, Post.author_id != v.id, Post.author_id.notin_(v.userblocks), - or_(Post.sub == None, Post.sub.notin_(v.sub_blocks)), + or_(Post.hole == None, Post.hole.notin_(v.hole_blocks)), ).options(load_only(Post.id)) total = listing.count() @@ -217,8 +217,8 @@ def notifications_modactions(v): if v.admin_level >= PERMS['NOTIFICATIONS_MODERATOR_ACTIONS']: cls = ModAction - elif v.moderated_subs: - cls = SubAction + elif v.moderated_holes: + cls = HoleAction else: abort(403) @@ -230,8 +230,8 @@ def notifications_modactions(v): if v.admin_level < PERMS['PROGSTACK']: listing = listing.filter(cls.kind.notin_(MODACTION_PRIVILEGED__TYPES)) - if cls == SubAction: - listing = listing.filter(cls.sub.in_(v.moderated_subs)) + if cls == HoleAction: + listing = listing.filter(cls.hole.in_(v.moderated_holes)) total = listing.count() listing = listing.order_by(cls.id.desc()) diff --git a/files/routes/polls.py b/files/routes/polls.py index 40a82419a..bf51e7953 100644 --- a/files/routes/polls.py +++ b/files/routes/polls.py @@ -18,10 +18,10 @@ def vote_option(option_id, v): abort(404) option = g.db.get(PostOption, option_id) if not option: abort(404) - sub = option.parent.sub + hole = option.parent.hole - if sub in {'furry','vampire','racist','femboy','edgy'} and not v.house.lower().startswith(sub): - abort(403, f"You need to be a member of House {sub.capitalize()} to vote on polls in /h/{sub}") + if hole in {'furry','vampire','racist','femboy','edgy'} and not v.house.lower().startswith(hole): + abort(403, f"You need to be a member of House {hole.capitalize()} to vote on polls in /h/{hole}") if option.exclusive == 2: if option.parent.total_bet_voted(v): @@ -72,12 +72,12 @@ def vote_option_comment(option_id, v): if not option: abort(404) if option.parent.parent_post: - sub = option.parent.post.sub + hole = option.parent.post.hole else: - sub = None + hole = None - if sub in {'furry','vampire','racist','femboy','edgy'} and not v.house.lower().startswith(sub): - abort(403, f"You need to be a member of House {sub.capitalize()} to vote on polls in /h/{sub}") + if hole in {'furry','vampire','racist','femboy','edgy'} and not v.house.lower().startswith(hole): + abort(403, f"You need to be a member of House {hole.capitalize()} to vote on polls in /h/{hole}") if option.exclusive == 2: if option.parent.total_bet_voted(v): diff --git a/files/routes/posts.py b/files/routes/posts.py index a85faadb6..d307521ee 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -79,25 +79,25 @@ def publish(pid, v): return {"message": "Post has been published successfully!"} @app.get("/submit") -@app.get("/h//submit") +@app.get("/h//submit") @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) @auth_required -def submit_get(v, sub=None): - sub = get_sub_by_name(sub, graceful=True) - if request.path.startswith('/h/') and not sub: abort(404) +def submit_get(v, hole=None): + hole = get_hole(hole, graceful=True) + if request.path.startswith('/h/') and not hole: abort(404) - SUBS = [x[0] for x in g.db.query(Sub.name).order_by(Sub.name)] + HOLES = [x[0] for x in g.db.query(Hole.name).order_by(Hole.name)] - return render_template("submit.html", SUBS=SUBS, v=v, sub=sub) + return render_template("submit.html", HOLES=HOLES, v=v, hole=hole) @app.get("/post/") @app.get("/post//") -@app.get("/h//post/") -@app.get("/h//post//") +@app.get("/h//post/") +@app.get("/h//post//") @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) @auth_desired_with_logingate -def post_id(pid, v, anything=None, sub=None): +def post_id(pid, v, anything=None, hole=None): p = get_post(pid, v=v) if not can_see(v, p): abort(403) @@ -192,7 +192,7 @@ def post_id(pid, v, anything=None, sub=None): template = "post_banned.html" result = render_template(template, v=v, p=p, ids=list(ids), - sort=sort, render_replies=True, offset=offset, sub=p.subr, + sort=sort, render_replies=True, offset=offset, hole=p.hole_obj, fart=get_setting('fart_mode')) if not v: @@ -426,13 +426,13 @@ def is_repost(v): else: return not_a_repost @app.post("/submit") -@app.post("/h//submit") +@app.post("/h//submit") @limiter.limit('1/second', scope=rpath) @limiter.limit('1/second', scope=rpath, key_func=get_ID) @limiter.limit('20/day', deduct_when=lambda response: response.status_code < 400) @limiter.limit('20/day', deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @is_not_banned -def submit_post(v, sub=None): +def submit_post(v, hole=None): url = request.values.get("url", "").strip() if '\\' in url: abort(400) @@ -446,35 +446,35 @@ def submit_post(v, sub=None): if not title: abort(400, "Please enter a better title!") - sub = request.values.get("sub", "").lower().replace('/h/','').strip() + hole = request.values.get("hole", "").lower().replace('/h/','').strip() if SITE == 'rdrama.net' and (v.chud == 1 or v.id == 253): - sub = 'chudrama' + hole = 'chudrama' if SITE == 'rdrama.net' and v.id == 10947: - sub = 'mnn' + hole = 'mnn' - if sub == 'changelog': + if hole == 'changelog': abort(400, "/h/changelog is archived") - if sub in {'furry','vampire','racist','femboy','edgy'} and not v.client and not v.house.lower().startswith(sub): - abort(400, f"You need to be a member of House {sub.capitalize()} to post in /h/{sub}") + if hole in {'furry','vampire','racist','femboy','edgy'} and not v.client and not v.house.lower().startswith(hole): + abort(400, f"You need to be a member of House {hole.capitalize()} to post in /h/{hole}") - if sub and sub != 'none': - sub_name = sub.strip().lower() - sub = g.db.query(Sub).options(load_only(Sub.name)).filter_by(name=sub_name).one_or_none() - if not sub: abort(400, f"/h/{sub_name} not found!") + if hole and hole != 'none': + hole_name = hole.strip().lower() + hole = g.db.query(Hole).options(load_only(Hole.name)).filter_by(name=hole_name).one_or_none() + if not hole: abort(400, f"/h/{hole_name} not found!") - if not can_see(v, sub): - if sub.name == 'highrollerclub': - abort(403, f"Only {patron}s can post in /h/{sub}") - abort(403, f"You're not allowed to post in /h/{sub}") + if not can_see(v, hole): + if hole.name == 'highrollerclub': + abort(403, f"Only {patron}s can post in /h/{hole}") + abort(403, f"You're not allowed to post in /h/{hole}") - sub = sub.name - if v.exiler_username(sub): abort(400, f"You're exiled from /h/{sub}") - else: sub = None + hole = hole.name + if v.exiler_username(hole): abort(400, f"You're exiled from /h/{hole}") + else: hole = None - if not sub and HOLE_REQUIRED: + if not hole and HOLE_REQUIRED: abort(400, f"You must choose a {HOLE_NAME} for your post!") if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')): @@ -536,7 +536,7 @@ def submit_post(v, sub=None): flag_private = request.values.get("private", False, bool) flag_ghost = request.values.get("ghost", False, bool) and v.can_post_in_ghost_threads - if flag_ghost: sub = None + if flag_ghost: hole = None if embed and len(embed) > 1500: embed = None if embed: embed = embed.strip() @@ -546,7 +546,7 @@ def submit_post(v, sub=None): if url == '': url = None - flag_chudded = v.chud and sub != 'chudrama' + flag_chudded = v.chud and hole != 'chudrama' p = Post( private=flag_private, @@ -560,7 +560,7 @@ def submit_post(v, sub=None): body=body, embed=embed, title=title, - sub=sub, + hole=hole, ghost=flag_ghost, chudded=flag_chudded, rainbowed=bool(v.rainbow), @@ -684,7 +684,7 @@ def submit_post(v, sub=None): if (SITE == 'rdrama.net' and v.id in {2008, 3336} - and not (p.sub and p.subr.stealth)) and p.sub != 'slavshit' and not p.ghost: + and not (p.hole and p.hole_obj.stealth)) and p.hole != 'slavshit' and not p.ghost: p.stickied_utc = int(time.time()) + 28800 p.stickied = "AutoJanny" @@ -766,7 +766,7 @@ def undelete_post_pid(pid, v): def mark_post_nsfw(pid, v): p = get_post(pid) - if p.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION'] and not (p.sub and v.mods(p.sub)): + if p.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION'] and not (p.hole and v.mods(p.hole)): abort(403) if p.nsfw and v.is_permabanned: @@ -784,8 +784,8 @@ def mark_post_nsfw(pid, v): ) g.db.add(ma) else: - ma = SubAction( - sub = p.sub, + ma = HoleAction( + hole = p.hole, kind = "set_nsfw", user_id = v.id, target_post_id = p.id, @@ -805,7 +805,7 @@ def mark_post_nsfw(pid, v): def unmark_post_nsfw(pid, v): p = get_post(pid) - if p.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION'] and not (p.sub and v.mods(p.sub)): + if p.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION'] and not (p.hole and v.mods(p.hole)): abort(403) if p.nsfw and v.is_permabanned: @@ -823,8 +823,8 @@ def unmark_post_nsfw(pid, v): ) g.db.add(ma) else: - ma = SubAction( - sub = p.sub, + ma = HoleAction( + hole = p.hole, kind = "unset_nsfw", user_id = v.id, target_post_id = p.id, diff --git a/files/routes/reporting.py b/files/routes/reporting.py index db6ad85be..3fad225bb 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -2,7 +2,7 @@ from flask import g from files.classes.reports import Report, CommentReport from files.classes.mod_logs import ModAction -from files.classes.sub_logs import SubAction +from files.classes.hole_logs import HoleAction from files.helpers.actions import * from files.helpers.alerts import * from files.helpers.get import * @@ -28,7 +28,7 @@ def report_post(pid, v): if len(reason_html) > 350: abort(400, "Report reason too long!") - if reason.startswith('!') and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or post.sub and v.mods(post.sub)): + if reason.startswith('!') and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or post.hole and v.mods(post.hole)): post.flair = reason_html[1:] g.db.add(post) if v.admin_level >= PERMS['POST_COMMENT_MODERATION']: @@ -41,15 +41,15 @@ def report_post(pid, v): g.db.add(ma) position = 'a site admin' else: - ma = SubAction( - sub=post.sub, + ma = HoleAction( + hole=post.hole, kind="flair_post", user_id=v.id, target_post_id=post.id, _note=f'"{post.flair}"' ) g.db.add(ma) - position = f'a /h/{post.sub} mod' + position = f'a /h/{post.hole} mod' if v.id != post.author_id: message = f'@{v.username} ({position}) has flaired [{post.title}]({post.shortlink}) with the flair: `"{og_flair}"`' @@ -156,75 +156,75 @@ def move_post(post, v, reason): if not reason.startswith('/h/') and not reason.startswith('h/'): return False - sub_from = post.sub - sub_to = get_sub_by_name(reason, graceful=True) - sub_to = sub_to.name if sub_to else None + hole_from = post.hole + hole_to = get_hole(reason, graceful=True) + hole_to = hole_to.name if hole_to else None - can_move_post = v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (post.sub and v.mods(sub_from)) - if sub_from != 'chudrama': # posts can only be moved out of /h/chudrama by admins + can_move_post = v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (post.hole and v.mods(hole_from)) + if hole_from != 'chudrama': # posts can only be moved out of /h/chudrama by admins can_move_post = can_move_post or post.author_id == v.id if not can_move_post: return False - if sub_to == None: + if hole_to == None: if HOLE_REQUIRED: abort(403, "All posts are required to be flaired!") - sub_to_in_notif = 'the main feed' + hole_to_in_notif = 'the main feed' else: - sub_to_in_notif = f'/h/{sub_to}' + hole_to_in_notif = f'/h/{hole_to}' - if sub_from == sub_to: abort(409, f"Post is already in {sub_to_in_notif}") + if hole_from == hole_to: abort(409, f"Post is already in {hole_to_in_notif}") - if post.author.exiler_username(sub_to): + if post.author.exiler_username(hole_to): abort(403, f"User is exiled from this {HOLE_NAME}!") - if sub_to == 'changelog': + if hole_to == 'changelog': abort(403, "/h/changelog is archived!") - if sub_to in {'furry','vampire','racist','femboy','edgy'} and not v.client and not post.author.house.lower().startswith(sub_to): + if hole_to in {'furry','vampire','racist','femboy','edgy'} and not v.client and not post.author.house.lower().startswith(hole_to): if v.id == post.author_id: - abort(403, f"You need to be a member of House {sub_to.capitalize()} to post in /h/{sub_to}") + abort(403, f"You need to be a member of House {hole_to.capitalize()} to post in /h/{hole_to}") else: - abort(403, f"@{post.author_name} needs to be a member of House {sub_to.capitalize()} for their post to be moved to /h/{sub_to}") + abort(403, f"@{post.author_name} needs to be a member of House {hole_to.capitalize()} for their post to be moved to /h/{hole_to}") - post.sub = sub_to + post.hole = hole_to post.hole_pinned = None g.db.add(post) if v.id != post.author_id: - sub_from_str = 'main feed' if sub_from is None else \ - f'/h/{sub_from}' - sub_to_str = 'main feed' if sub_to is None else \ - f'/h/{sub_to}' + hole_from_str = 'main feed' if hole_from is None else \ + f'/h/{hole_from}' + hole_to_str = 'main feed' if hole_to is None else \ + f'/h/{hole_to}' if v.admin_level >= PERMS['POST_COMMENT_MODERATION']: ma = ModAction( kind='move_hole', user_id=v.id, target_post_id=post.id, - _note=f'{sub_from_str} → {sub_to_str}', + _note=f'{hole_from_str} → {hole_to_str}', ) g.db.add(ma) else: - ma = SubAction( - sub=sub_from, + ma = HoleAction( + hole=hole_from, kind='move_hole', user_id=v.id, target_post_id=post.id, - _note=f'{sub_from_str} → {sub_to_str}', + _note=f'{hole_from_str} → {hole_to_str}', ) g.db.add(ma) if v.admin_level >= PERMS['POST_COMMENT_MODERATION']: position = 'a site admin' - else: position = f'a /h/{sub_from} mod' + else: position = f'a /h/{hole_from} mod' - if sub_from == None: - sub_from_in_notif = 'the main feed' + if hole_from == None: + hole_from_in_notif = 'the main feed' else: - sub_from_in_notif = f'/h/{sub_from}' + hole_from_in_notif = f'/h/{hole_from}' - message = f"@{v.username} ({position}) has moved [{post.title}]({post.shortlink}) from {sub_from_in_notif} to {sub_to_in_notif}" + message = f"@{v.username} ({position}) has moved [{post.title}]({post.shortlink}) from {hole_from_in_notif} to {hole_to_in_notif}" send_repeatable_notification(post.author_id, message) cache.delete_memoized(frontlist) - return f"Post moved to {sub_to_in_notif} successfully!" + return f"Post moved to {hole_to_in_notif} successfully!" diff --git a/files/routes/search.py b/files/routes/search.py index 32e19f83e..37d7d6201 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -140,7 +140,7 @@ def searchposts(v): if search_operator_hole in criteria: - posts = posts.filter(Post.sub == criteria[search_operator_hole]) + posts = posts.filter(Post.hole == criteria[search_operator_hole]) if 'after' in criteria: after = criteria['after'] @@ -239,7 +239,7 @@ def searchcomments(v): if 'nsfw' in criteria: comments = comments.filter(Comment.nsfw == True) if search_operator_hole in criteria: - comments = comments.filter(Post.sub == criteria[search_operator_hole]) + comments = comments.filter(Post.hole == criteria[search_operator_hole]) comments = apply_time_filter(t, comments, Comment) diff --git a/files/routes/users.py b/files/routes/users.py index ead2ea320..0228d88be 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1300,14 +1300,14 @@ def fp(v, fp): g.db.add(v) return '', 204 -@app.post("/toggle_pins//") +@app.post("/toggle_pins//") @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) -def toggle_pins(sub, sort): +def toggle_pins(hole, sort): if sort == 'hot': default = True else: default = False - pins = session.get(f'{sub}_{sort}', default) - session[f'{sub}_{sort}'] = not pins + pins = session.get(f'{hole}_{sort}', default) + session[f'{hole}_{sort}'] = not pins return {"message": "Pins toggled successfully!"} diff --git a/files/routes/votes.py b/files/routes/votes.py index 241f810ab..bc4e69e88 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -153,11 +153,11 @@ def vote_post_comment(target_id, new, v, cls, vote_cls): or 'forum' in target.domain or 'chan' in target.domain or 'lemmy' in target.domain or 'mastodon' in target.domain or (target.domain in BOOSTED_SITES and not target.url.startswith('/'))): mul = 2 - elif target.sub in STEALTH_HOLES or target.sub in {'countryclub', 'highrollerclub'}: + elif target.hole in STEALTH_HOLES or target.hole in {'countryclub', 'highrollerclub'}: mul = 2 elif 6 <= datetime.fromtimestamp(target.created_utc).hour <= 10: mul = 2 - elif target.sub in BOOSTED_HOLES: + elif target.hole in BOOSTED_HOLES: mul = 1.25 if target.body_html and target.author.id != 8768: diff --git a/files/templates/comments.html b/files/templates/comments.html index 9351edcb5..a069436e2 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -74,8 +74,8 @@ {{c.post.realtitle(v) | safe}} {% endif %} - {% if c.post.sub %} - in /h/{{c.post.sub}} + {% if c.post.hole %} + in /h/{{c.post.hole}} {% endif %} {% elif c.author_id==AUTOJANNY_ID %} Notification @@ -124,17 +124,17 @@ {% endfor %} {% if c.parent_post %} - {% set sub = c.post.sub %} - {% if sub and c.author.exiler_username(sub) %} - + {% set hole = c.post.hole %} + {% if hole and c.author.exiler_username(hole) %} + {% endif %} {% endif %} - {% if c.bannedfor and not (c.parent_post and c.post.sub == 'chudrama') %} + {% if c.bannedfor and not (c.parent_post and c.post.hole == 'chudrama') %} {% endif %} - {% if c.chuddedfor and not (c.parent_post and c.post.sub == 'chudrama') %} + {% if c.chuddedfor and not (c.parent_post and c.post.hole == 'chudrama') %} {% endif %} @@ -436,7 +436,7 @@ {% set url = "sticky_comment" %} {% elif v.id == c.post.author_id %} {% set url = "pin_comment" %} - {% elif c.post.sub and v.mods(c.post.sub) %} + {% elif c.post.hole and v.mods(c.post.hole) %} {% set url = "pin_comment_mod" %} {% endif %} @@ -466,10 +466,10 @@ {% endif %} {% if c.parent_post %} - {% set sub = c.post.sub %} - {% if sub and v.mods(sub) and not c.author.mods(sub) %} - - + {% set hole = c.post.hole %} + {% if hole and v.mods(hole) and not c.author.mods(hole) %} + + {% endif %} {% endif %} @@ -478,7 +478,7 @@ {% endif %} - {% if FEATURES['NSFW_MARKING'] and (c.parent_post or c.wall_user_id) and (c.author_id==v.id or v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (c.post.sub and v.mods(c.post.sub))) %} + {% if FEATURES['NSFW_MARKING'] and (c.parent_post or c.wall_user_id) and (c.author_id==v.id or v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or (c.post.hole and v.mods(c.post.hole))) %} {% endif %} @@ -636,7 +636,7 @@ {% endif %} {% endif %} - {% if FEATURES['NSFW_MARKING'] and (c.author_id == v.id or (c.post.sub and v.mods(c.post.sub))) %} + {% if FEATURES['NSFW_MARKING'] and (c.author_id == v.id or (c.post.hole and v.mods(c.post.hole))) %} @@ -646,17 +646,17 @@ {% if c.parent_post and v.id == c.post.author_id %} - {% elif c.post.sub and v.mods(c.post.sub) %} + {% elif c.post.hole and v.mods(c.post.hole) %} {% endif %} {% endif %} {% if c.parent_post %} - {% set sub = c.post.sub %} - {% if sub and v.mods(sub) and not c.author.mods(sub) %} - - + {% set hole = c.post.hole %} + {% if hole and v.mods(hole) and not c.author.mods(hole) %} + + {% endif %} {% endif %} {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index a953da5a7..c67327e47 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -9,17 +9,17 @@ {% block banner %} {% include "modals/expanded_image.html" %} {% if err or '@' not in request.path %} - {% if IS_FISTMAS() and not sub %} + {% if IS_FISTMAS() and not hole %} {% include 'events/fistmas/banner.html' %} - {% elif IS_HOMOWEEN() and not sub %} + {% elif IS_HOMOWEEN() and not hole %} {% include 'events/homoween/banner.html' %} {% else %} {% set path = "files/assets/images/" ~ SITE_NAME %} {% if err and SITE_NAME == 'rDrama' %} {% set src = "banner_error.webp" | asset_siteimg %} - {% elif sub and sub.has_banners %} - {% set src = sub.random_banner() %} + {% elif hole and hole.has_banners %} + {% set src = hole.random_banner() %} {% set alt = ['/h/', sub, 'banner']|join %} {% set class = 'site-banner-hole' %} {% elif get_orgy(v) and os_path.exists(path ~ "/orgy_banners") %} @@ -34,8 +34,8 @@ {% endif %} {% if SITE_NAME == "WPD" %} - {% if sub %} - {% set href = "/h/" ~ sub %} + {% if hole %} + {% set href = "/h/" ~ hole %} {% set expand = false %} {% else %} {% set href = "/" %} @@ -62,7 +62,7 @@ {{alt|default('site banner')}} {% endmacro %} - {% if sub and sub.has_banners %} + {% if hole and hole.has_banners %} {{img_element()}} {% else %}