fsd
This commit is contained in:
parent
123cc81604
commit
d456aaa0c7
18 changed files with 119 additions and 119 deletions
|
@ -74,7 +74,7 @@ class Comment(Base):
|
||||||
@lazy
|
@lazy
|
||||||
def poll_voted(self, v):
|
def poll_voted(self, v):
|
||||||
if v:
|
if v:
|
||||||
vote = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=self.id).first()
|
vote = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=self.id).one_or_none()
|
||||||
if vote: return vote.vote_type
|
if vote: return vote.vote_type
|
||||||
else: return None
|
else: return None
|
||||||
else: return None
|
else: return None
|
||||||
|
|
|
@ -182,7 +182,7 @@ class User(Base):
|
||||||
return len(self.referrals)
|
return len(self.referrals)
|
||||||
|
|
||||||
def is_blocking(self, target):
|
def is_blocking(self, target):
|
||||||
return g.db.query(UserBlock).filter_by(user_id=self.id, target_id=target.id).first()
|
return g.db.query(UserBlock).filter_by(user_id=self.id, target_id=target.id).one_or_none()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
|
@ -193,7 +193,7 @@ class User(Base):
|
||||||
|
|
||||||
return g.db.query(UserBlock).filter(
|
return g.db.query(UserBlock).filter(
|
||||||
or_(and_(UserBlock.user_id == self.id, UserBlock.target_id == other.id), and_(
|
or_(and_(UserBlock.user_id == self.id, UserBlock.target_id == other.id), and_(
|
||||||
UserBlock.user_id == other.id, UserBlock.target_id == self.id))).first()
|
UserBlock.user_id == other.id, UserBlock.target_id == self.id))).one_or_none()
|
||||||
|
|
||||||
def validate_2fa(self, token):
|
def validate_2fa(self, token):
|
||||||
|
|
||||||
|
@ -287,10 +287,10 @@ class User(Base):
|
||||||
@lazy
|
@lazy
|
||||||
def banned_by(self):
|
def banned_by(self):
|
||||||
if not self.is_suspended: return None
|
if not self.is_suspended: return None
|
||||||
return g.db.query(User).filter_by(id=self.is_banned).first()
|
return g.db.query(User).filter_by(id=self.is_banned).one_or_none()
|
||||||
|
|
||||||
def has_badge(self, badge_id):
|
def has_badge(self, badge_id):
|
||||||
return g.db.query(Badge).filter_by(user_id=self.id, badge_id=badge_id).first()
|
return g.db.query(Badge).filter_by(user_id=self.id, badge_id=badge_id).one_or_none()
|
||||||
|
|
||||||
def hash_password(self, password):
|
def hash_password(self, password):
|
||||||
return generate_password_hash(
|
return generate_password_hash(
|
||||||
|
@ -422,7 +422,7 @@ class User(Base):
|
||||||
|
|
||||||
def has_follower(self, user):
|
def has_follower(self, user):
|
||||||
|
|
||||||
return g.db.query(Follow).filter_by(target_id=self.id, user_id=user.id).first()
|
return g.db.query(Follow).filter_by(target_id=self.id, user_id=user.id).one_or_none()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
|
|
|
@ -30,11 +30,11 @@ def send_repeatable_notification(uid, text, autojanny=False):
|
||||||
if autojanny: author_id = AUTOJANNY_ID
|
if autojanny: author_id = AUTOJANNY_ID
|
||||||
else: author_id = NOTIFICATIONS_ID
|
else: author_id = NOTIFICATIONS_ID
|
||||||
|
|
||||||
existing_comment = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body=text, created_utc=0).first()
|
existing_comment = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body=text, created_utc=0).one_or_none()
|
||||||
|
|
||||||
if existing_comment:
|
if existing_comment:
|
||||||
cid = existing_comment[0]
|
cid = existing_comment[0]
|
||||||
existing_notif = g.db.query(Notification.id).filter_by(user_id=uid, comment_id=cid).first()
|
existing_notif = g.db.query(Notification.id).filter_by(user_id=uid, comment_id=cid).one_or_none()
|
||||||
if existing_notif: cid = create_comment(text, autojanny)
|
if existing_notif: cid = create_comment(text, autojanny)
|
||||||
else: cid = create_comment(text, autojanny)
|
else: cid = create_comment(text, autojanny)
|
||||||
|
|
||||||
|
@ -53,14 +53,14 @@ def notif_comment(text, autojanny=False):
|
||||||
if autojanny: author_id = AUTOJANNY_ID
|
if autojanny: author_id = AUTOJANNY_ID
|
||||||
else: author_id = NOTIFICATIONS_ID
|
else: author_id = NOTIFICATIONS_ID
|
||||||
|
|
||||||
existing = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body=text, created_utc=0).first()
|
existing = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body=text, created_utc=0).one_or_none()
|
||||||
|
|
||||||
if existing: return existing[0]
|
if existing: return existing[0]
|
||||||
else: return create_comment(text, autojanny)
|
else: return create_comment(text, autojanny)
|
||||||
|
|
||||||
|
|
||||||
def add_notif(cid, uid):
|
def add_notif(cid, uid):
|
||||||
existing = g.db.query(Notification.id).filter_by(comment_id=cid, user_id=uid).first()
|
existing = g.db.query(Notification.id).filter_by(comment_id=cid, user_id=uid).one_or_none()
|
||||||
if not existing:
|
if not existing:
|
||||||
notif = Notification(comment_id=cid, user_id=uid)
|
notif = Notification(comment_id=cid, user_id=uid)
|
||||||
g.db.add(notif)
|
g.db.add(notif)
|
||||||
|
@ -96,7 +96,7 @@ def NOTIFY_USERS(text, v):
|
||||||
soup = BeautifulSoup(text, features="html.parser")
|
soup = BeautifulSoup(text, features="html.parser")
|
||||||
for mention in soup.find_all("a", href=re.compile("^/@(\w+)")):
|
for mention in soup.find_all("a", href=re.compile("^/@(\w+)")):
|
||||||
username = mention["href"].split("@")[1]
|
username = mention["href"].split("@")[1]
|
||||||
user = g.db.query(User).filter_by(username=username).first()
|
user = g.db.query(User).filter_by(username=username).one_or_none()
|
||||||
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
|
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
|
||||||
|
|
||||||
return notify_users
|
return notify_users
|
|
@ -15,7 +15,7 @@ def get_id(username, v=None, graceful=False):
|
||||||
User.username.ilike(username),
|
User.username.ilike(username),
|
||||||
User.original_username.ilike(username)
|
User.original_username.ilike(username)
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
if not graceful:
|
if not graceful:
|
||||||
|
@ -43,7 +43,7 @@ def get_user(username, v=None, graceful=False):
|
||||||
User.username.ilike(username),
|
User.username.ilike(username),
|
||||||
User.original_username.ilike(username)
|
User.original_username.ilike(username)
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
if not graceful: abort(404)
|
if not graceful: abort(404)
|
||||||
|
@ -60,7 +60,7 @@ def get_user(username, v=None, graceful=False):
|
||||||
UserBlock.target_id == v.id
|
UserBlock.target_id == v.id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
user.is_blocking = block and block.user_id == v.id
|
user.is_blocking = block and block.user_id == v.id
|
||||||
user.is_blocked = block and block.target_id == v.id
|
user.is_blocked = block and block.target_id == v.id
|
||||||
|
@ -69,12 +69,12 @@ def get_user(username, v=None, graceful=False):
|
||||||
|
|
||||||
def get_account(id, v=None):
|
def get_account(id, v=None):
|
||||||
|
|
||||||
user = g.db.query(User).filter_by(id = id).first()
|
user = g.db.query(User).filter_by(id = id).one_or_none()
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
try: id = int(str(id), 36)
|
try: id = int(str(id), 36)
|
||||||
except: abort(404)
|
except: abort(404)
|
||||||
user = g.db.query(User).filter_by(id = id).first()
|
user = g.db.query(User).filter_by(id = id).one_or_none()
|
||||||
if not user: abort(404)
|
if not user: abort(404)
|
||||||
|
|
||||||
if v:
|
if v:
|
||||||
|
@ -88,7 +88,7 @@ def get_account(id, v=None):
|
||||||
UserBlock.target_id == v.id
|
UserBlock.target_id == v.id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
user.is_blocking = block and block.user_id == v.id
|
user.is_blocking = block and block.user_id == v.id
|
||||||
user.is_blocked = block and block.target_id == v.id
|
user.is_blocked = block and block.target_id == v.id
|
||||||
|
@ -120,7 +120,7 @@ def get_post(i, v=None, graceful=False):
|
||||||
isouter=True
|
isouter=True
|
||||||
)
|
)
|
||||||
|
|
||||||
items=items.first()
|
items=items.one_or_none()
|
||||||
|
|
||||||
if not items and not graceful:
|
if not items and not graceful:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
@ -130,7 +130,7 @@ def get_post(i, v=None, graceful=False):
|
||||||
else:
|
else:
|
||||||
items = g.db.query(
|
items = g.db.query(
|
||||||
Submission
|
Submission
|
||||||
).filter(Submission.id == i).first()
|
).filter(Submission.id == i).one_or_none()
|
||||||
if not items and not graceful:
|
if not items and not graceful:
|
||||||
abort(404)
|
abort(404)
|
||||||
x=items
|
x=items
|
||||||
|
@ -201,16 +201,16 @@ def get_comment(i, v=None, graceful=False):
|
||||||
UserBlock.target_id == v.id
|
UserBlock.target_id == v.id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
vts = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id)
|
vts = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id)
|
||||||
vt = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).first()
|
vt = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
||||||
comment.is_blocking = block and block.user_id == v.id
|
comment.is_blocking = block and block.user_id == v.id
|
||||||
comment.is_blocked = block and block.target_id == v.id
|
comment.is_blocked = block and block.target_id == v.id
|
||||||
comment.voted = vt.vote_type if vt else 0
|
comment.voted = vt.vote_type if vt else 0
|
||||||
|
|
||||||
else:
|
else:
|
||||||
comment = g.db.query(Comment).filter(Comment.id == i).first()
|
comment = g.db.query(Comment).filter(Comment.id == i).one_or_none()
|
||||||
if not comment and not graceful:abort(404)
|
if not comment and not graceful:abort(404)
|
||||||
|
|
||||||
return comment
|
return comment
|
||||||
|
|
|
@ -69,7 +69,7 @@ def activate(v):
|
||||||
if not validate_hash(f"{email}+{id}+{timestamp}", token):
|
if not validate_hash(f"{email}+{id}+{timestamp}", token):
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
||||||
user = g.db.query(User).filter_by(id=id).first()
|
user = g.db.query(User).filter_by(id=id).one_or_none()
|
||||||
if not user:
|
if not user:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ def grassed(v):
|
||||||
def distribute(v, comment):
|
def distribute(v, comment):
|
||||||
try: comment = int(comment)
|
try: comment = int(comment)
|
||||||
except: abort(400)
|
except: abort(400)
|
||||||
post = g.db.query(Comment).filter_by(id=comment).first().post
|
post = g.db.query(Comment).filter_by(id=comment).one_or_none().post
|
||||||
|
|
||||||
pool = 0
|
pool = 0
|
||||||
for option in post.bet_options: pool += option.upvotes
|
for option in post.bet_options: pool += option.upvotes
|
||||||
|
@ -58,7 +58,7 @@ def distribute(v, comment):
|
||||||
u.coins += coinsperperson
|
u.coins += coinsperperson
|
||||||
add_notif(cid, u.id)
|
add_notif(cid, u.id)
|
||||||
|
|
||||||
autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).first()
|
autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).one_or_none()
|
||||||
autobetter.coins -= pool
|
autobetter.coins -= pool
|
||||||
if autobetter.coins < 0: return {"error": "Not enough coins in bool"}, 400
|
if autobetter.coins < 0: return {"error": "Not enough coins in bool"}, 400
|
||||||
g.db.add(autobetter)
|
g.db.add(autobetter)
|
||||||
|
@ -190,7 +190,7 @@ def remove_meme_admin(v, username):
|
||||||
def monthly(v):
|
def monthly(v):
|
||||||
if request.host == 'rdrama.net' and v.id != 1: abort (403)
|
if request.host == 'rdrama.net' and v.id != 1: abort (403)
|
||||||
|
|
||||||
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
|
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).one_or_none().id
|
||||||
|
|
||||||
data = {'access_token': GUMROAD_TOKEN}
|
data = {'access_token': GUMROAD_TOKEN}
|
||||||
|
|
||||||
|
@ -625,7 +625,7 @@ def admin_removed_comments(v):
|
||||||
@admin_level_required(2)
|
@admin_level_required(2)
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def agendaposter(user_id, v):
|
def agendaposter(user_id, v):
|
||||||
user = g.db.query(User).filter_by(id=user_id).first()
|
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||||
|
|
||||||
if user.username == '911roofer': abort(403)
|
if user.username == '911roofer': abort(403)
|
||||||
|
|
||||||
|
@ -682,7 +682,7 @@ def agendaposter(user_id, v):
|
||||||
@admin_level_required(2)
|
@admin_level_required(2)
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def shadowban(user_id, v):
|
def shadowban(user_id, v):
|
||||||
user = g.db.query(User).filter_by(id=user_id).first()
|
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||||
if user.admin_level != 0: abort(403)
|
if user.admin_level != 0: abort(403)
|
||||||
user.shadowbanned = v.username
|
user.shadowbanned = v.username
|
||||||
g.db.add(user)
|
g.db.add(user)
|
||||||
|
@ -708,7 +708,7 @@ def shadowban(user_id, v):
|
||||||
@admin_level_required(2)
|
@admin_level_required(2)
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def unshadowban(user_id, v):
|
def unshadowban(user_id, v):
|
||||||
user = g.db.query(User).filter_by(id=user_id).first()
|
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||||
if user.admin_level != 0: abort(403)
|
if user.admin_level != 0: abort(403)
|
||||||
user.shadowbanned = None
|
user.shadowbanned = None
|
||||||
user.ban_evade = 0
|
user.ban_evade = 0
|
||||||
|
@ -735,7 +735,7 @@ def unshadowban(user_id, v):
|
||||||
@admin_level_required(2)
|
@admin_level_required(2)
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def verify(user_id, v):
|
def verify(user_id, v):
|
||||||
user = g.db.query(User).filter_by(id=user_id).first()
|
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||||
user.verified = "Verified"
|
user.verified = "Verified"
|
||||||
g.db.add(user)
|
g.db.add(user)
|
||||||
|
|
||||||
|
@ -754,7 +754,7 @@ def verify(user_id, v):
|
||||||
@admin_level_required(2)
|
@admin_level_required(2)
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def unverify(user_id, v):
|
def unverify(user_id, v):
|
||||||
user = g.db.query(User).filter_by(id=user_id).first()
|
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||||
user.verified = None
|
user.verified = None
|
||||||
g.db.add(user)
|
g.db.add(user)
|
||||||
|
|
||||||
|
@ -775,7 +775,7 @@ def unverify(user_id, v):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def admin_title_change(user_id, v):
|
def admin_title_change(user_id, v):
|
||||||
|
|
||||||
user = g.db.query(User).filter_by(id=user_id).first()
|
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||||
|
|
||||||
if user.admin_level != 0: abort(403)
|
if user.admin_level != 0: abort(403)
|
||||||
|
|
||||||
|
@ -784,7 +784,7 @@ def admin_title_change(user_id, v):
|
||||||
user.customtitleplain=new_name
|
user.customtitleplain=new_name
|
||||||
new_name = sanitize(new_name)
|
new_name = sanitize(new_name)
|
||||||
|
|
||||||
user=g.db.query(User).with_for_update().filter_by(id=user.id).first()
|
user=g.db.query(User).with_for_update().filter_by(id=user.id).one_or_none()
|
||||||
user.customtitle=new_name
|
user.customtitle=new_name
|
||||||
if request.values.get("locked"): user.flairchanged = int(time.time()) + 2629746
|
if request.values.get("locked"): user.flairchanged = int(time.time()) + 2629746
|
||||||
g.db.add(user)
|
g.db.add(user)
|
||||||
|
@ -809,7 +809,7 @@ def admin_title_change(user_id, v):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def ban_user(user_id, v):
|
def ban_user(user_id, v):
|
||||||
|
|
||||||
user = g.db.query(User).filter_by(id=user_id).first()
|
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||||
|
|
||||||
if user.admin_level >= v.admin_level: abort(403)
|
if user.admin_level >= v.admin_level: abort(403)
|
||||||
|
|
||||||
|
@ -869,7 +869,7 @@ def ban_user(user_id, v):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def unban_user(user_id, v):
|
def unban_user(user_id, v):
|
||||||
|
|
||||||
user = g.db.query(User).filter_by(id=user_id).first()
|
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
abort(400)
|
abort(400)
|
||||||
|
@ -909,7 +909,7 @@ def unban_user(user_id, v):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def ban_post(post_id, v):
|
def ban_post(post_id, v):
|
||||||
|
|
||||||
post = g.db.query(Submission).filter_by(id=post_id).first()
|
post = g.db.query(Submission).filter_by(id=post_id).one_or_none()
|
||||||
|
|
||||||
if not post:
|
if not post:
|
||||||
abort(400)
|
abort(400)
|
||||||
|
@ -946,7 +946,7 @@ def ban_post(post_id, v):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def unban_post(post_id, v):
|
def unban_post(post_id, v):
|
||||||
|
|
||||||
post = g.db.query(Submission).filter_by(id=post_id).first()
|
post = g.db.query(Submission).filter_by(id=post_id).one_or_none()
|
||||||
|
|
||||||
if not post:
|
if not post:
|
||||||
abort(400)
|
abort(400)
|
||||||
|
@ -979,7 +979,7 @@ def unban_post(post_id, v):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def api_distinguish_post(post_id, v):
|
def api_distinguish_post(post_id, v):
|
||||||
|
|
||||||
post = g.db.query(Submission).filter_by(id=post_id).first()
|
post = g.db.query(Submission).filter_by(id=post_id).one_or_none()
|
||||||
|
|
||||||
if not post:
|
if not post:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
@ -1100,7 +1100,7 @@ def unsticky_comment(cid, v):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def api_ban_comment(c_id, v):
|
def api_ban_comment(c_id, v):
|
||||||
|
|
||||||
comment = g.db.query(Comment).filter_by(id=c_id).first()
|
comment = g.db.query(Comment).filter_by(id=c_id).one_or_none()
|
||||||
if not comment:
|
if not comment:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
@ -1124,7 +1124,7 @@ def api_ban_comment(c_id, v):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def api_unban_comment(c_id, v):
|
def api_unban_comment(c_id, v):
|
||||||
|
|
||||||
comment = g.db.query(Comment).filter_by(id=c_id).first()
|
comment = g.db.query(Comment).filter_by(id=c_id).one_or_none()
|
||||||
if not comment: abort(404)
|
if not comment: abort(404)
|
||||||
|
|
||||||
if comment.author.agendaposter and 'trans lives matters' not in comment.body.lower():
|
if comment.author.agendaposter and 'trans lives matters' not in comment.body.lower():
|
||||||
|
@ -1193,7 +1193,7 @@ def admin_toggle_ban_domain(v):
|
||||||
|
|
||||||
reason=request.values.get("reason", "").strip()
|
reason=request.values.get("reason", "").strip()
|
||||||
|
|
||||||
d = g.db.query(BannedDomain).filter_by(domain=domain).first()
|
d = g.db.query(BannedDomain).filter_by(domain=domain).one_or_none()
|
||||||
if d:
|
if d:
|
||||||
g.db.delete(d)
|
g.db.delete(d)
|
||||||
ma = ModAction(
|
ma = ModAction(
|
||||||
|
|
|
@ -146,7 +146,7 @@ def buy(v, award):
|
||||||
if award == "lootbox":
|
if award == "lootbox":
|
||||||
send_repeatable_notification(995, f"@{v.username} bought a lootbox!")
|
send_repeatable_notification(995, f"@{v.username} bought a lootbox!")
|
||||||
for i in [1,2,3,4,5]:
|
for i in [1,2,3,4,5]:
|
||||||
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
|
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).one_or_none().id
|
||||||
thing += 1
|
thing += 1
|
||||||
award = random.choice(["snow", "gingerbread", "lights", "candycane", "fireplace"])
|
award = random.choice(["snow", "gingerbread", "lights", "candycane", "fireplace"])
|
||||||
award = AwardRelationship(id=thing, user_id=v.id, kind=award)
|
award = AwardRelationship(id=thing, user_id=v.id, kind=award)
|
||||||
|
@ -167,7 +167,7 @@ def buy(v, award):
|
||||||
send_notification(v.id, f"@AutoJanny has given you the following profile badge:\n\n\n\n{new_badge.name}")
|
send_notification(v.id, f"@AutoJanny has given you the following profile badge:\n\n\n\n{new_badge.name}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
|
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).one_or_none().id
|
||||||
thing += 1
|
thing += 1
|
||||||
award = AwardRelationship(id=thing, user_id=v.id, kind=award)
|
award = AwardRelationship(id=thing, user_id=v.id, kind=award)
|
||||||
g.db.add(award)
|
g.db.add(award)
|
||||||
|
@ -200,12 +200,12 @@ def award_post(pid, v):
|
||||||
AwardRelationship.submission_id == None,
|
AwardRelationship.submission_id == None,
|
||||||
AwardRelationship.comment_id == None
|
AwardRelationship.comment_id == None
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
if not post_award:
|
if not post_award:
|
||||||
return {"error": "You don't have that award."}, 404
|
return {"error": "You don't have that award."}, 404
|
||||||
|
|
||||||
post = g.db.query(Submission).filter_by(id=pid).first()
|
post = g.db.query(Submission).filter_by(id=pid).one_or_none()
|
||||||
|
|
||||||
if not post:
|
if not post:
|
||||||
return {"error": "That post doesn't exist."}, 404
|
return {"error": "That post doesn't exist."}, 404
|
||||||
|
@ -216,7 +216,7 @@ def award_post(pid, v):
|
||||||
AwardRelationship.user_id == v.id,
|
AwardRelationship.user_id == v.id,
|
||||||
AwardRelationship.kind == kind
|
AwardRelationship.kind == kind
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
post_award.submission_id = post.id
|
post_award.submission_id = post.id
|
||||||
g.db.add(post_award)
|
g.db.add(post_award)
|
||||||
|
@ -374,12 +374,12 @@ def award_comment(cid, v):
|
||||||
AwardRelationship.submission_id == None,
|
AwardRelationship.submission_id == None,
|
||||||
AwardRelationship.comment_id == None
|
AwardRelationship.comment_id == None
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
if not comment_award:
|
if not comment_award:
|
||||||
return {"error": "You don't have that award."}, 404
|
return {"error": "You don't have that award."}, 404
|
||||||
|
|
||||||
c = g.db.query(Comment).filter_by(id=cid).first()
|
c = g.db.query(Comment).filter_by(id=cid).one_or_none()
|
||||||
|
|
||||||
if not c:
|
if not c:
|
||||||
return {"error": "That comment doesn't exist."}, 404
|
return {"error": "That comment doesn't exist."}, 404
|
||||||
|
@ -390,7 +390,7 @@ def award_comment(cid, v):
|
||||||
AwardRelationship.user_id == v.id,
|
AwardRelationship.user_id == v.id,
|
||||||
AwardRelationship.kind == kind
|
AwardRelationship.kind == kind
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
comment_award.comment_id = c.id
|
comment_award.comment_id = c.id
|
||||||
g.db.add(comment_award)
|
g.db.add(comment_award)
|
||||||
|
@ -547,7 +547,7 @@ def admin_userawards_post(v):
|
||||||
|
|
||||||
notify_awards = {}
|
notify_awards = {}
|
||||||
|
|
||||||
latest = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first()
|
latest = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).one_or_none()
|
||||||
thing = latest.id
|
thing = latest.id
|
||||||
|
|
||||||
for key, value in request.values.items():
|
for key, value in request.values.items():
|
||||||
|
|
|
@ -43,7 +43,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
||||||
comment = get_comment(cid, v=v)
|
comment = get_comment(cid, v=v)
|
||||||
|
|
||||||
if v and request.values.get("read"):
|
if v and request.values.get("read"):
|
||||||
notif = g.db.query(Notification).filter_by(comment_id=cid, user_id=v.id, read=False).first()
|
notif = g.db.query(Notification).filter_by(comment_id=cid, user_id=v.id, read=False).one_or_none()
|
||||||
if notif:
|
if notif:
|
||||||
notif.read = True
|
notif.read = True
|
||||||
g.db.add(notif)
|
g.db.add(notif)
|
||||||
|
@ -230,7 +230,7 @@ def api_comment(v):
|
||||||
Comment.parent_comment_id == parent_comment_id,
|
Comment.parent_comment_id == parent_comment_id,
|
||||||
Comment.parent_submission == parent_submission,
|
Comment.parent_submission == parent_submission,
|
||||||
Comment.body_html == body_html
|
Comment.body_html == body_html
|
||||||
).first()
|
).one_or_none()
|
||||||
if existing: return {"error": f"You already made that comment: /comment/{existing.id}"}, 409
|
if existing: return {"error": f"You already made that comment: /comment/{existing.id}"}, 409
|
||||||
|
|
||||||
if parent.author.any_block_exists(v) and v.admin_level < 2: return {"error": "You can't reply to users who have blocked you, or users you have blocked."}, 403
|
if parent.author.any_block_exists(v) and v.admin_level < 2: return {"error": "You can't reply to users who have blocked you, or users you have blocked."}, 403
|
||||||
|
@ -433,7 +433,7 @@ def api_comment(v):
|
||||||
|
|
||||||
g.db.add(c2)
|
g.db.add(c2)
|
||||||
|
|
||||||
longpostbot = g.db.query(User).filter_by(id = LONGPOSTBOT_ID).first()
|
longpostbot = g.db.query(User).filter_by(id = LONGPOSTBOT_ID).one_or_none()
|
||||||
longpostbot.comment_count += 1
|
longpostbot.comment_count += 1
|
||||||
longpostbot.coins += 1
|
longpostbot.coins += 1
|
||||||
g.db.add(longpostbot)
|
g.db.add(longpostbot)
|
||||||
|
@ -510,7 +510,7 @@ def api_comment(v):
|
||||||
|
|
||||||
g.db.add(c4)
|
g.db.add(c4)
|
||||||
|
|
||||||
zozbot = g.db.query(User).filter_by(id = ZOZBOT_ID).first()
|
zozbot = g.db.query(User).filter_by(id = ZOZBOT_ID).one_or_none()
|
||||||
zozbot.comment_count += 3
|
zozbot.comment_count += 3
|
||||||
zozbot.coins += 3
|
zozbot.coins += 3
|
||||||
g.db.add(zozbot)
|
g.db.add(zozbot)
|
||||||
|
@ -788,7 +788,7 @@ def edit_comment(cid, v):
|
||||||
notify_users = NOTIFY_USERS(body_html, v)
|
notify_users = NOTIFY_USERS(body_html, v)
|
||||||
|
|
||||||
for x in notify_users:
|
for x in notify_users:
|
||||||
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=x).first()
|
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=x).one_or_none()
|
||||||
if not notif:
|
if not notif:
|
||||||
n = Notification(comment_id=c.id, user_id=x)
|
n = Notification(comment_id=c.id, user_id=x)
|
||||||
g.db.add(n)
|
g.db.add(n)
|
||||||
|
@ -804,7 +804,7 @@ def edit_comment(cid, v):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def delete_comment(cid, v):
|
def delete_comment(cid, v):
|
||||||
|
|
||||||
c = g.db.query(Comment).filter_by(id=cid).first()
|
c = g.db.query(Comment).filter_by(id=cid).one_or_none()
|
||||||
|
|
||||||
if not c: abort(404)
|
if not c: abort(404)
|
||||||
|
|
||||||
|
@ -826,7 +826,7 @@ def delete_comment(cid, v):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def undelete_comment(cid, v):
|
def undelete_comment(cid, v):
|
||||||
|
|
||||||
c = g.db.query(Comment).filter_by(id=cid).first()
|
c = g.db.query(Comment).filter_by(id=cid).one_or_none()
|
||||||
|
|
||||||
if not c:
|
if not c:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
@ -895,7 +895,7 @@ def save_comment(cid, v):
|
||||||
|
|
||||||
comment=get_comment(cid)
|
comment=get_comment(cid)
|
||||||
|
|
||||||
save=g.db.query(SaveRelationship).filter_by(user_id=v.id, comment_id=comment.id, type=2).first()
|
save=g.db.query(SaveRelationship).filter_by(user_id=v.id, comment_id=comment.id, type=2).one_or_none()
|
||||||
|
|
||||||
if not save:
|
if not save:
|
||||||
new_save=SaveRelationship(user_id=v.id, comment_id=comment.id, type=2)
|
new_save=SaveRelationship(user_id=v.id, comment_id=comment.id, type=2)
|
||||||
|
@ -914,7 +914,7 @@ def unsave_comment(cid, v):
|
||||||
|
|
||||||
comment=get_comment(cid)
|
comment=get_comment(cid)
|
||||||
|
|
||||||
save=g.db.query(SaveRelationship).filter_by(user_id=v.id, comment_id=comment.id, type=2).first()
|
save=g.db.query(SaveRelationship).filter_by(user_id=v.id, comment_id=comment.id, type=2).one_or_none()
|
||||||
|
|
||||||
if save:
|
if save:
|
||||||
g.db.delete(save)
|
g.db.delete(save)
|
||||||
|
|
|
@ -97,7 +97,7 @@ def discord_redirect(v):
|
||||||
url=f"https://discord.com/api/guilds/{SERVER_ID}/members/{v.discord_id}"
|
url=f"https://discord.com/api/guilds/{SERVER_ID}/members/{v.discord_id}"
|
||||||
requests.delete(url, headers=headers, timeout=5)
|
requests.delete(url, headers=headers, timeout=5)
|
||||||
|
|
||||||
if g.db.query(User).filter(User.id!=v.id, User.discord_id==x["id"]).first():
|
if g.db.query(User).filter(User.id!=v.id, User.discord_id==x["id"]).one_or_none():
|
||||||
if not v or v.oldsite: template = ''
|
if not v or v.oldsite: template = ''
|
||||||
else: template = 'CHRISTMAS/'
|
else: template = 'CHRISTMAS/'
|
||||||
return render_template(f"{template}message.html", title="Discord account already linked.", error="That Discord account is already in use by another user.", v=v)
|
return render_template(f"{template}message.html", title="Discord account already linked.", error="That Discord account is already in use by another user.", v=v)
|
||||||
|
|
|
@ -389,7 +389,7 @@ def random_post(v):
|
||||||
total = x.count()
|
total = x.count()
|
||||||
n = random.randint(1, total - 2)
|
n = random.randint(1, total - 2)
|
||||||
|
|
||||||
post = x.offset(n).limit(1).first()
|
post = x.offset(n).limit(1).one_or_none()
|
||||||
return redirect(f"/post/{post.id}")
|
return redirect(f"/post/{post.id}")
|
||||||
|
|
||||||
@cache.memoize(timeout=86400)
|
@cache.memoize(timeout=86400)
|
||||||
|
|
|
@ -34,9 +34,9 @@ def check_for_alts(current_id):
|
||||||
if past_id == current_id: continue
|
if past_id == current_id: continue
|
||||||
|
|
||||||
check1 = g.db.query(Alt).filter_by(
|
check1 = g.db.query(Alt).filter_by(
|
||||||
user1=current_id, user2=past_id).first()
|
user1=current_id, user2=past_id).one_or_none()
|
||||||
check2 = g.db.query(Alt).filter_by(
|
check2 = g.db.query(Alt).filter_by(
|
||||||
user1=past_id, user2=current_id).first()
|
user1=past_id, user2=current_id).one_or_none()
|
||||||
|
|
||||||
if not check1 and not check2:
|
if not check1 and not check2:
|
||||||
|
|
||||||
|
@ -49,25 +49,25 @@ def check_for_alts(current_id):
|
||||||
alts = g.db.query(Alt)
|
alts = g.db.query(Alt)
|
||||||
otheralts = alts.filter(or_(Alt.user1 == past_id, Alt.user2 == past_id, Alt.user1 == current_id, Alt.user2 == current_id)).all()
|
otheralts = alts.filter(or_(Alt.user1 == past_id, Alt.user2 == past_id, Alt.user1 == current_id, Alt.user2 == current_id)).all()
|
||||||
for a in otheralts:
|
for a in otheralts:
|
||||||
existing = alts.filter_by(user1=a.user1, user2=past_id).first()
|
existing = alts.filter_by(user1=a.user1, user2=past_id).one_or_none()
|
||||||
if not existing:
|
if not existing:
|
||||||
new_alt = Alt(user1=a.user1, user2=past_id)
|
new_alt = Alt(user1=a.user1, user2=past_id)
|
||||||
g.db.add(new_alt)
|
g.db.add(new_alt)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
existing = alts.filter_by(user1=a.user1, user2=current_id).first()
|
existing = alts.filter_by(user1=a.user1, user2=current_id).one_or_none()
|
||||||
if not existing:
|
if not existing:
|
||||||
new_alt = Alt(user1=a.user1, user2=current_id)
|
new_alt = Alt(user1=a.user1, user2=current_id)
|
||||||
g.db.add(new_alt)
|
g.db.add(new_alt)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
existing = alts.filter_by(user1=a.user2, user2=past_id).first()
|
existing = alts.filter_by(user1=a.user2, user2=past_id).one_or_none()
|
||||||
if not existing:
|
if not existing:
|
||||||
new_alt = Alt(user1=a.user2, user2=past_id)
|
new_alt = Alt(user1=a.user2, user2=past_id)
|
||||||
g.db.add(new_alt)
|
g.db.add(new_alt)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
existing = alts.filter_by(user1=a.user2, user2=current_id).first()
|
existing = alts.filter_by(user1=a.user2, user2=current_id).one_or_none()
|
||||||
if not existing:
|
if not existing:
|
||||||
new_alt = Alt(user1=a.user2, user2=current_id)
|
new_alt = Alt(user1=a.user2, user2=current_id)
|
||||||
g.db.add(new_alt)
|
g.db.add(new_alt)
|
||||||
|
@ -85,7 +85,7 @@ def login_post():
|
||||||
if not username: abort(400)
|
if not username: abort(400)
|
||||||
if "@" in username:
|
if "@" in username:
|
||||||
account = g.db.query(User).filter(
|
account = g.db.query(User).filter(
|
||||||
User.email.ilike(username)).first()
|
User.email.ilike(username)).one_or_none()
|
||||||
else:
|
else:
|
||||||
account = get_user(username, graceful=True)
|
account = get_user(username, graceful=True)
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ def sign_up_get(v):
|
||||||
|
|
||||||
ref = request.values.get("ref", None)
|
ref = request.values.get("ref", None)
|
||||||
if ref:
|
if ref:
|
||||||
ref_user = g.db.query(User).filter(User.username.ilike(ref)).first()
|
ref_user = g.db.query(User).filter(User.username.ilike(ref)).one_or_none()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
ref_user = None
|
ref_user = None
|
||||||
|
@ -249,7 +249,7 @@ def sign_up_post(v):
|
||||||
args = {"error": error}
|
args = {"error": error}
|
||||||
if request.values.get("referred_by"):
|
if request.values.get("referred_by"):
|
||||||
user = g.db.query(User).filter_by(
|
user = g.db.query(User).filter_by(
|
||||||
id=request.values.get("referred_by")).first()
|
id=request.values.get("referred_by")).one_or_none()
|
||||||
if user:
|
if user:
|
||||||
args["ref"] = user.username
|
args["ref"] = user.username
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ def post_forgot():
|
||||||
|
|
||||||
user = g.db.query(User).filter(
|
user = g.db.query(User).filter(
|
||||||
User.username.ilike(username),
|
User.username.ilike(username),
|
||||||
User.email.ilike(email)).first()
|
User.email.ilike(email)).one_or_none()
|
||||||
|
|
||||||
if user:
|
if user:
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
|
@ -401,7 +401,7 @@ def get_reset():
|
||||||
title="Password reset link expired",
|
title="Password reset link expired",
|
||||||
error="That password reset link has expired.")
|
error="That password reset link has expired.")
|
||||||
|
|
||||||
user = g.db.query(User).filter_by(id=user_id).first()
|
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||||
|
|
||||||
if not validate_hash(f"{user_id}+{timestamp}+forgot+{user.login_nonce}", token):
|
if not validate_hash(f"{user_id}+{timestamp}+forgot+{user.login_nonce}", token):
|
||||||
abort(400)
|
abort(400)
|
||||||
|
@ -443,7 +443,7 @@ def post_reset(v):
|
||||||
title="Password reset expired",
|
title="Password reset expired",
|
||||||
error="That password reset form has expired.")
|
error="That password reset form has expired.")
|
||||||
|
|
||||||
user = g.db.query(User).filter_by(id=user_id).first()
|
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||||
|
|
||||||
if not validate_hash(f"{user_id}+{timestamp}+reset+{user.login_nonce}", token):
|
if not validate_hash(f"{user_id}+{timestamp}+reset+{user.login_nonce}", token):
|
||||||
abort(400)
|
abort(400)
|
||||||
|
|
|
@ -11,7 +11,7 @@ from sqlalchemy.orm import joinedload
|
||||||
@auth_required
|
@auth_required
|
||||||
def authorize_prompt(v):
|
def authorize_prompt(v):
|
||||||
client_id = request.values.get("client_id")
|
client_id = request.values.get("client_id")
|
||||||
application = g.db.query(OauthApp).filter_by(client_id=client_id).first()
|
application = g.db.query(OauthApp).filter_by(client_id=client_id).one_or_none()
|
||||||
if not application: return {"oauth_error": "Invalid `client_id`"}, 401
|
if not application: return {"oauth_error": "Invalid `client_id`"}, 401
|
||||||
if not v or v.oldsite: template = ''
|
if not v or v.oldsite: template = ''
|
||||||
else: template = 'CHRISTMAS/'
|
else: template = 'CHRISTMAS/'
|
||||||
|
@ -25,7 +25,7 @@ def authorize_prompt(v):
|
||||||
def authorize(v):
|
def authorize(v):
|
||||||
|
|
||||||
client_id = request.values.get("client_id")
|
client_id = request.values.get("client_id")
|
||||||
application = g.db.query(OauthApp).filter_by(client_id=client_id).first()
|
application = g.db.query(OauthApp).filter_by(client_id=client_id).one_or_none()
|
||||||
if not application: return {"oauth_error": "Invalid `client_id`"}, 401
|
if not application: return {"oauth_error": "Invalid `client_id`"}, 401
|
||||||
access_token = secrets.token_urlsafe(128)[:128]
|
access_token = secrets.token_urlsafe(128)[:128]
|
||||||
new_auth = ClientAuth(oauth_client = application.id, user_id = v.id, access_token=access_token)
|
new_auth = ClientAuth(oauth_client = application.id, user_id = v.id, access_token=access_token)
|
||||||
|
@ -66,7 +66,7 @@ def request_api_keys(v):
|
||||||
def delete_oauth_app(v, aid):
|
def delete_oauth_app(v, aid):
|
||||||
|
|
||||||
aid = int(aid)
|
aid = int(aid)
|
||||||
app = g.db.query(OauthApp).filter_by(id=aid).first()
|
app = g.db.query(OauthApp).filter_by(id=aid).one_or_none()
|
||||||
|
|
||||||
if app.author_id != v.id: abort(403)
|
if app.author_id != v.id: abort(403)
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ def delete_oauth_app(v, aid):
|
||||||
def edit_oauth_app(v, aid):
|
def edit_oauth_app(v, aid):
|
||||||
|
|
||||||
aid = int(aid)
|
aid = int(aid)
|
||||||
app = g.db.query(OauthApp).filter_by(id=aid).first()
|
app = g.db.query(OauthApp).filter_by(id=aid).one_or_none()
|
||||||
|
|
||||||
if app.author_id != v.id: abort(403)
|
if app.author_id != v.id: abort(403)
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ def edit_oauth_app(v, aid):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def admin_app_approve(v, aid):
|
def admin_app_approve(v, aid):
|
||||||
|
|
||||||
app = g.db.query(OauthApp).filter_by(id=aid).first()
|
app = g.db.query(OauthApp).filter_by(id=aid).one_or_none()
|
||||||
user = app.author
|
user = app.author
|
||||||
|
|
||||||
app.client_id = secrets.token_urlsafe(64)[:64]
|
app.client_id = secrets.token_urlsafe(64)[:64]
|
||||||
|
@ -143,7 +143,7 @@ def admin_app_approve(v, aid):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def admin_app_revoke(v, aid):
|
def admin_app_revoke(v, aid):
|
||||||
|
|
||||||
app = g.db.query(OauthApp).filter_by(id=aid).first()
|
app = g.db.query(OauthApp).filter_by(id=aid).one_or_none()
|
||||||
if app.id:
|
if app.id:
|
||||||
for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
|
for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ def admin_app_revoke(v, aid):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def admin_app_reject(v, aid):
|
def admin_app_reject(v, aid):
|
||||||
|
|
||||||
app = g.db.query(OauthApp).filter_by(id=aid).first()
|
app = g.db.query(OauthApp).filter_by(id=aid).one_or_none()
|
||||||
|
|
||||||
for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
|
for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ def admin_app_id(v, aid):
|
||||||
oauth = g.db.query(OauthApp).options(
|
oauth = g.db.query(OauthApp).options(
|
||||||
joinedload(
|
joinedload(
|
||||||
OauthApp.author)).filter_by(
|
OauthApp.author)).filter_by(
|
||||||
id=aid).first()
|
id=aid).one_or_none()
|
||||||
|
|
||||||
pids=oauth.idlist(page=int(request.values.get("page",1)),
|
pids=oauth.idlist(page=int(request.values.get("page",1)),
|
||||||
)
|
)
|
||||||
|
@ -226,7 +226,7 @@ def admin_app_id_comments(v, aid):
|
||||||
oauth = g.db.query(OauthApp).options(
|
oauth = g.db.query(OauthApp).options(
|
||||||
joinedload(
|
joinedload(
|
||||||
OauthApp.author)).filter_by(
|
OauthApp.author)).filter_by(
|
||||||
id=aid).first()
|
id=aid).one_or_none()
|
||||||
|
|
||||||
cids=oauth.comments_idlist(page=int(request.values.get("page",1)),
|
cids=oauth.comments_idlist(page=int(request.values.get("page",1)),
|
||||||
)
|
)
|
||||||
|
@ -267,7 +267,7 @@ def reroll_oauth_tokens(aid, v):
|
||||||
|
|
||||||
aid = aid
|
aid = aid
|
||||||
|
|
||||||
a = g.db.query(OauthApp).filter_by(id=aid).first()
|
a = g.db.query(OauthApp).filter_by(id=aid).one_or_none()
|
||||||
|
|
||||||
if a.author_id != v.id: abort(403)
|
if a.author_id != v.id: abort(403)
|
||||||
|
|
||||||
|
|
|
@ -383,7 +383,7 @@ def morecomments(v, cid):
|
||||||
else: dump.append(comment)
|
else: dump.append(comment)
|
||||||
comments = output
|
comments = output
|
||||||
else:
|
else:
|
||||||
c = g.db.query(Comment).filter_by(id=cid).first()
|
c = g.db.query(Comment).filter_by(id=cid).one_or_none()
|
||||||
comments = c.replies
|
comments = c.replies
|
||||||
|
|
||||||
if not v or v.oldsite: template = ''
|
if not v or v.oldsite: template = ''
|
||||||
|
@ -596,11 +596,11 @@ def thumbnail_thread(pid):
|
||||||
|
|
||||||
db = db_session()
|
db = db_session()
|
||||||
|
|
||||||
post = db.query(Submission).filter_by(id=pid).first()
|
post = db.query(Submission).filter_by(id=pid).one_or_none()
|
||||||
|
|
||||||
if not post or not post.url:
|
if not post or not post.url:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
post = db.query(Submission).filter_by(id=pid).first()
|
post = db.query(Submission).filter_by(id=pid).one_or_none()
|
||||||
|
|
||||||
if not post or not post.url: return
|
if not post or not post.url: return
|
||||||
|
|
||||||
|
@ -776,7 +776,7 @@ def submit_post(v):
|
||||||
Submission.url.ilike(url),
|
Submission.url.ilike(url),
|
||||||
Submission.deleted_utc == 0,
|
Submission.deleted_utc == 0,
|
||||||
Submission.is_banned == False
|
Submission.is_banned == False
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
if repost: return redirect(repost.permalink)
|
if repost: return redirect(repost.permalink)
|
||||||
|
|
||||||
|
@ -849,7 +849,7 @@ def submit_post(v):
|
||||||
Submission.title == title,
|
Submission.title == title,
|
||||||
Submission.url == url,
|
Submission.url == url,
|
||||||
Submission.body == body
|
Submission.body == body
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
if dup: return redirect(dup.permalink)
|
if dup: return redirect(dup.permalink)
|
||||||
|
|
||||||
|
@ -1167,7 +1167,7 @@ def submit_post(v):
|
||||||
|
|
||||||
g.db.add(c)
|
g.db.add(c)
|
||||||
|
|
||||||
snappy = g.db.query(User).filter_by(id = SNAPPY_ID).first()
|
snappy = g.db.query(User).filter_by(id = SNAPPY_ID).one_or_none()
|
||||||
snappy.comment_count += 1
|
snappy.comment_count += 1
|
||||||
snappy.coins += 1
|
snappy.coins += 1
|
||||||
g.db.add(snappy)
|
g.db.add(snappy)
|
||||||
|
@ -1238,7 +1238,7 @@ def undelete_post_pid(pid, v):
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def toggle_comment_nsfw(cid, v):
|
def toggle_comment_nsfw(cid, v):
|
||||||
|
|
||||||
comment = g.db.query(Comment).filter_by(id=cid).first()
|
comment = g.db.query(Comment).filter_by(id=cid).one_or_none()
|
||||||
if not comment.author_id == v.id and not v.admin_level > 1: abort(403)
|
if not comment.author_id == v.id and not v.admin_level > 1: abort(403)
|
||||||
comment.over_18 = not comment.over_18
|
comment.over_18 = not comment.over_18
|
||||||
g.db.add(comment)
|
g.db.add(comment)
|
||||||
|
@ -1282,7 +1282,7 @@ def save_post(pid, v):
|
||||||
|
|
||||||
post=get_post(pid)
|
post=get_post(pid)
|
||||||
|
|
||||||
save = g.db.query(SaveRelationship).filter_by(user_id=v.id, submission_id=post.id, type=1).first()
|
save = g.db.query(SaveRelationship).filter_by(user_id=v.id, submission_id=post.id, type=1).one_or_none()
|
||||||
|
|
||||||
if not save:
|
if not save:
|
||||||
new_save=SaveRelationship(user_id=v.id, submission_id=post.id, type=1)
|
new_save=SaveRelationship(user_id=v.id, submission_id=post.id, type=1)
|
||||||
|
@ -1299,7 +1299,7 @@ def unsave_post(pid, v):
|
||||||
|
|
||||||
post=get_post(pid)
|
post=get_post(pid)
|
||||||
|
|
||||||
save = g.db.query(SaveRelationship).filter_by(user_id=v.id, submission_id=post.id, type=1).first()
|
save = g.db.query(SaveRelationship).filter_by(user_id=v.id, submission_id=post.id, type=1).one_or_none()
|
||||||
|
|
||||||
if save:
|
if save:
|
||||||
g.db.delete(save)
|
g.db.delete(save)
|
||||||
|
@ -1311,7 +1311,7 @@ def unsave_post(pid, v):
|
||||||
@auth_required
|
@auth_required
|
||||||
def api_pin_post(post_id, v):
|
def api_pin_post(post_id, v):
|
||||||
|
|
||||||
post = g.db.query(Submission).filter_by(id=post_id).first()
|
post = g.db.query(Submission).filter_by(id=post_id).one_or_none()
|
||||||
if post:
|
if post:
|
||||||
if v.id != post.author_id: return {"error": "Only the post author's can do that!"}
|
if v.id != post.author_id: return {"error": "Only the post author's can do that!"}
|
||||||
post.is_pinned = not post.is_pinned
|
post.is_pinned = not post.is_pinned
|
||||||
|
|
|
@ -17,7 +17,7 @@ def api_flag_post(pid, v):
|
||||||
reason = request.values.get("reason", "").strip()[:100]
|
reason = request.values.get("reason", "").strip()[:100]
|
||||||
|
|
||||||
if not reason.startswith('!'):
|
if not reason.startswith('!'):
|
||||||
existing = g.db.query(Flag.id).filter_by(user_id=v.id, post_id=post.id).first()
|
existing = g.db.query(Flag.id).filter_by(user_id=v.id, post_id=post.id).one_or_none()
|
||||||
if existing: return "", 409
|
if existing: return "", 409
|
||||||
|
|
||||||
reason = filter_emojis_only(reason)
|
reason = filter_emojis_only(reason)
|
||||||
|
@ -45,7 +45,7 @@ def api_flag_comment(cid, v):
|
||||||
comment = get_comment(cid)
|
comment = get_comment(cid)
|
||||||
|
|
||||||
if not v.shadowbanned:
|
if not v.shadowbanned:
|
||||||
existing = g.db.query(CommentFlag.id).filter_by( user_id=v.id, comment_id=comment.id).first()
|
existing = g.db.query(CommentFlag.id).filter_by( user_id=v.id, comment_id=comment.id).one_or_none()
|
||||||
if existing: return "", 409
|
if existing: return "", 409
|
||||||
|
|
||||||
reason = request.values.get("reason", "").strip()[:100]
|
reason = request.values.get("reason", "").strip()[:100]
|
||||||
|
@ -68,9 +68,9 @@ def api_flag_comment(cid, v):
|
||||||
def remove_report(report_fn, v):
|
def remove_report(report_fn, v):
|
||||||
|
|
||||||
if report_fn.startswith('c'):
|
if report_fn.startswith('c'):
|
||||||
report = g.db.query(CommentFlag).filter_by(id=int(report_fn.lstrip('c'))).first()
|
report = g.db.query(CommentFlag).filter_by(id=int(report_fn.lstrip('c'))).one_or_none()
|
||||||
elif report_fn.startswith('p'):
|
elif report_fn.startswith('p'):
|
||||||
report = g.db.query(Flag).filter_by(id=int(report_fn.lstrip('p'))).first()
|
report = g.db.query(Flag).filter_by(id=int(report_fn.lstrip('p'))).one_or_none()
|
||||||
else:
|
else:
|
||||||
return {"error": "Invalid report ID"}, 400
|
return {"error": "Invalid report ID"}, 400
|
||||||
|
|
||||||
|
|
|
@ -603,7 +603,7 @@ def settings_security_post(v):
|
||||||
return render_template("settings_security.html", v=v, error="That email is already yours!")
|
return render_template("settings_security.html", v=v, error="That email is already yours!")
|
||||||
|
|
||||||
existing = g.db.query(User.id).filter(User.id != v.id,
|
existing = g.db.query(User.id).filter(User.id != v.id,
|
||||||
func.lower(User.email) == new_email.lower()).first()
|
func.lower(User.email) == new_email.lower()).one_or_none()
|
||||||
if existing:
|
if existing:
|
||||||
return render_template("settings_security.html", v=v, error="That email address is already in use.")
|
return render_template("settings_security.html", v=v, error="That email address is already in use.")
|
||||||
|
|
||||||
|
@ -960,7 +960,7 @@ def settings_name_change(v):
|
||||||
User.username.ilike(name),
|
User.username.ilike(name),
|
||||||
User.original_username.ilike(name)
|
User.original_username.ilike(name)
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
if x and x.id != v.id:
|
if x and x.id != v.id:
|
||||||
if not v or v.oldsite: template = ''
|
if not v or v.oldsite: template = ''
|
||||||
|
@ -969,7 +969,7 @@ def settings_name_change(v):
|
||||||
v=v,
|
v=v,
|
||||||
error=f"Username `{new_name}` is already in use.")
|
error=f"Username `{new_name}` is already in use.")
|
||||||
|
|
||||||
v=g.db.query(User).with_for_update().filter_by(id=v.id).first()
|
v=g.db.query(User).with_for_update().filter_by(id=v.id).one_or_none()
|
||||||
|
|
||||||
v.username=new_name
|
v.username=new_name
|
||||||
v.name_changed_utc=int(time.time())
|
v.name_changed_utc=int(time.time())
|
||||||
|
|
|
@ -98,7 +98,7 @@ def cached_chart(days):
|
||||||
today_cutoff = calendar.timegm(midnight_this_morning)
|
today_cutoff = calendar.timegm(midnight_this_morning)
|
||||||
|
|
||||||
if not days:
|
if not days:
|
||||||
firstsignup = g.db.query(User.created_utc).filter(User.created_utc != 0).order_by(User.created_utc).first()[0] - 86400
|
firstsignup = g.db.query(User.created_utc).filter(User.created_utc != 0).order_by(User.created_utc).one_or_none()[0] - 86400
|
||||||
nowstamp = int(time.time())
|
nowstamp = int(time.time())
|
||||||
days = int((nowstamp - firstsignup) / 86400)
|
days = int((nowstamp - firstsignup) / 86400)
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ def log_item(id, v):
|
||||||
try: id = int(id, 36)
|
try: id = int(id, 36)
|
||||||
except: abort(404)
|
except: abort(404)
|
||||||
|
|
||||||
action=g.db.query(ModAction).filter_by(id=id).first()
|
action=g.db.query(ModAction).filter_by(id=id).one_or_none()
|
||||||
|
|
||||||
if not action:
|
if not action:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
|
@ -206,7 +206,7 @@ def get_coins(v, username):
|
||||||
@is_not_banned
|
@is_not_banned
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def transfer_coins(v, username):
|
def transfer_coins(v, username):
|
||||||
receiver = g.db.query(User).filter_by(username=username).first()
|
receiver = g.db.query(User).filter_by(username=username).one_or_none()
|
||||||
|
|
||||||
if receiver is None: return {"error": "That user doesn't exist."}, 404
|
if receiver is None: return {"error": "That user doesn't exist."}, 404
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ def transfer_coins(v, username):
|
||||||
|
|
||||||
if not v.patron and not receiver.patron:
|
if not v.patron and not receiver.patron:
|
||||||
tax = math.ceil(amount*0.03)
|
tax = math.ceil(amount*0.03)
|
||||||
tax_receiver = g.db.query(User).filter_by(id=TAX_RECEIVER_ID).first()
|
tax_receiver = g.db.query(User).filter_by(id=TAX_RECEIVER_ID).one_or_none()
|
||||||
tax_receiver.coins += tax
|
tax_receiver.coins += tax
|
||||||
log_message = f"[@{v.username}]({v.url}) has transferred {amount} {app.config['COINS_NAME']} to [@{receiver.username}]({receiver.url})"
|
log_message = f"[@{v.username}]({v.url}) has transferred {amount} {app.config['COINS_NAME']} to [@{receiver.username}]({receiver.url})"
|
||||||
send_repeatable_notification(TAX_RECEIVER_ID, log_message)
|
send_repeatable_notification(TAX_RECEIVER_ID, log_message)
|
||||||
|
@ -244,7 +244,7 @@ def transfer_coins(v, username):
|
||||||
@is_not_banned
|
@is_not_banned
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def transfer_bux(v, username):
|
def transfer_bux(v, username):
|
||||||
receiver = g.db.query(User).filter_by(username=username).first()
|
receiver = g.db.query(User).filter_by(username=username).one_or_none()
|
||||||
|
|
||||||
if not receiver: return {"error": "That user doesn't exist."}, 404
|
if not receiver: return {"error": "That user doesn't exist."}, 404
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ def get_profilecss(username):
|
||||||
def songs(id):
|
def songs(id):
|
||||||
try: id = int(id)
|
try: id = int(id)
|
||||||
except: return "", 400
|
except: return "", 400
|
||||||
user = g.db.query(User).filter_by(id=id).first()
|
user = g.db.query(User).filter_by(id=id).one_or_none()
|
||||||
if user and user.song: return redirect(f"/static/song/{user.song}.mp3")
|
if user and user.song: return redirect(f"/static/song/{user.song}.mp3")
|
||||||
else: abort(404)
|
else: abort(404)
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ def subscribe(v, post_id):
|
||||||
@auth_required
|
@auth_required
|
||||||
@validate_formkey
|
@validate_formkey
|
||||||
def unsubscribe(v, post_id):
|
def unsubscribe(v, post_id):
|
||||||
sub=g.db.query(Subscription).filter_by(user_id=v.id, submission_id=post_id).first()
|
sub=g.db.query(Subscription).filter_by(user_id=v.id, submission_id=post_id).one_or_none()
|
||||||
if sub:
|
if sub:
|
||||||
g.db.delete(sub)
|
g.db.delete(sub)
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
@ -393,7 +393,7 @@ def message2(v, username):
|
||||||
existing = g.db.query(Comment.id).filter(Comment.author_id == v.id,
|
existing = g.db.query(Comment.id).filter(Comment.author_id == v.id,
|
||||||
Comment.sentto == user.id,
|
Comment.sentto == user.id,
|
||||||
Comment.body_html == text_html,
|
Comment.body_html == text_html,
|
||||||
).first()
|
).one_or_none()
|
||||||
if existing: return redirect('/notifications?messages=true')
|
if existing: return redirect('/notifications?messages=true')
|
||||||
|
|
||||||
new_comment = Comment(author_id=v.id,
|
new_comment = Comment(author_id=v.id,
|
||||||
|
@ -504,7 +504,7 @@ def api_is_available(name, v):
|
||||||
User.username.ilike(name2),
|
User.username.ilike(name2),
|
||||||
User.original_username.ilike(name2)
|
User.original_username.ilike(name2)
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
if x:
|
if x:
|
||||||
return {name: False}
|
return {name: False}
|
||||||
|
@ -584,7 +584,7 @@ def u_username(username, v=None):
|
||||||
ViewerRelationship.viewer_id == v.id,
|
ViewerRelationship.viewer_id == v.id,
|
||||||
ViewerRelationship.user_id == u.id
|
ViewerRelationship.user_id == u.id
|
||||||
)
|
)
|
||||||
).first()
|
).one_or_none()
|
||||||
|
|
||||||
if view:
|
if view:
|
||||||
view.last_view_utc = g.timestamp
|
view.last_view_utc = g.timestamp
|
||||||
|
@ -806,7 +806,7 @@ def follow_user(username, v):
|
||||||
|
|
||||||
if target.id==v.id: return {"error": "You can't follow yourself!"}, 400
|
if target.id==v.id: return {"error": "You can't follow yourself!"}, 400
|
||||||
|
|
||||||
if g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first(): return {"message": "User followed!"}
|
if g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).one_or_none(): return {"message": "User followed!"}
|
||||||
|
|
||||||
new_follow = Follow(user_id=v.id, target_id=target.id)
|
new_follow = Follow(user_id=v.id, target_id=target.id)
|
||||||
g.db.add(new_follow)
|
g.db.add(new_follow)
|
||||||
|
@ -831,7 +831,7 @@ def unfollow_user(username, v):
|
||||||
|
|
||||||
if target.fish: return {"error": "You can't unfollow this user!"}
|
if target.fish: return {"error": "You can't unfollow this user!"}
|
||||||
|
|
||||||
follow = g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first()
|
follow = g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).one_or_none()
|
||||||
|
|
||||||
if follow:
|
if follow:
|
||||||
g.db.delete(follow)
|
g.db.delete(follow)
|
||||||
|
@ -853,7 +853,7 @@ def unfollow_user(username, v):
|
||||||
def remove_follow(username, v):
|
def remove_follow(username, v):
|
||||||
target = get_user(username)
|
target = get_user(username)
|
||||||
|
|
||||||
follow = g.db.query(Follow).filter_by(user_id=target.id, target_id=v.id).first()
|
follow = g.db.query(Follow).filter_by(user_id=target.id, target_id=v.id).one_or_none()
|
||||||
|
|
||||||
if not follow: return {"message": "Follower removed!"}
|
if not follow: return {"message": "Follower removed!"}
|
||||||
|
|
||||||
|
@ -953,7 +953,7 @@ def fp(v, fp):
|
||||||
users += g.db.query(User).filter(User.email == v.email, User.is_activated, User.id != v.id).all()
|
users += g.db.query(User).filter(User.email == v.email, User.is_activated, User.id != v.id).all()
|
||||||
for u in users:
|
for u in users:
|
||||||
li = [v.id, u.id]
|
li = [v.id, u.id]
|
||||||
existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).first()
|
existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none()
|
||||||
if existing: continue
|
if existing: continue
|
||||||
new_alt = Alt(user1=v.id, user2=u.id)
|
new_alt = Alt(user1=v.id, user2=u.id)
|
||||||
g.db.add(new_alt)
|
g.db.add(new_alt)
|
||||||
|
|
|
@ -81,7 +81,7 @@ def api_vote_post(post_id, new, v):
|
||||||
|
|
||||||
post = get_post(post_id)
|
post = get_post(post_id)
|
||||||
|
|
||||||
existing = g.db.query(Vote).filter_by(user_id=v.id, submission_id=post.id).first()
|
existing = g.db.query(Vote).filter_by(user_id=v.id, submission_id=post.id).one_or_none()
|
||||||
|
|
||||||
if existing and existing.vote_type == new: return "", 204
|
if existing and existing.vote_type == new: return "", 204
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ def api_vote_comment(comment_id, new, v):
|
||||||
|
|
||||||
if comment.author_id == AUTOBETTER_ID: return {"error": "forbidden."}, 403
|
if comment.author_id == AUTOBETTER_ID: return {"error": "forbidden."}, 403
|
||||||
|
|
||||||
existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).first()
|
existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
||||||
|
|
||||||
if existing and existing.vote_type == new: return "", 204
|
if existing and existing.vote_type == new: return "", 204
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ def api_vote_poll(comment_id, v):
|
||||||
comment_id = int(comment_id)
|
comment_id = int(comment_id)
|
||||||
comment = get_comment(comment_id)
|
comment = get_comment(comment_id)
|
||||||
|
|
||||||
existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).first()
|
existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
||||||
|
|
||||||
if existing and existing.vote_type == new: return "", 204
|
if existing and existing.vote_type == new: return "", 204
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ def bet(comment_id, v):
|
||||||
comment_id = int(comment_id)
|
comment_id = int(comment_id)
|
||||||
comment = get_comment(comment_id)
|
comment = get_comment(comment_id)
|
||||||
|
|
||||||
existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).first()
|
existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
||||||
if existing: return "", 204
|
if existing: return "", 204
|
||||||
|
|
||||||
vote = CommentVote(user_id=v.id, vote_type=1, comment_id=comment.id)
|
vote = CommentVote(user_id=v.id, vote_type=1, comment_id=comment.id)
|
||||||
|
@ -250,7 +250,7 @@ def bet(comment_id, v):
|
||||||
|
|
||||||
v.coins -= 200
|
v.coins -= 200
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).first()
|
autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).one_or_none()
|
||||||
autobetter.coins += 200
|
autobetter.coins += 200
|
||||||
g.db.add(autobetter)
|
g.db.add(autobetter)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue