forked from MarseyWorld/MarseyWorld
Merge remote-tracking branch 'origin/master'
# Conflicts: # drama/classes/__init__.py # drama/classes/user.py # drama/helpers/get.py # drama/templates/errors/402.html # drama/templates/errors/451.htmlmaster
commit
363d9f7f7a
|
@ -260,9 +260,6 @@ def before_request():
|
|||
|
||||
g.db = db_session()
|
||||
|
||||
if g.db.query(IP).filter_by(addr=request.remote_addr).first():
|
||||
abort(503)
|
||||
|
||||
g.timestamp = int(time.time())
|
||||
|
||||
session.permanent = True
|
||||
|
|
|
@ -4,7 +4,6 @@ from .boards import *
|
|||
from .board_relationships import *
|
||||
from .clients import *
|
||||
from .comment import *
|
||||
from .custom_errors import *
|
||||
from .domains import Domain
|
||||
from .flags import *
|
||||
from .user import *
|
||||
|
@ -16,5 +15,5 @@ from .domains import *
|
|||
from .subscriptions import *
|
||||
from .ips import *
|
||||
from .titles import *
|
||||
from .award import *
|
||||
from .lolwtf import *
|
||||
from .mod_logs import *
|
|
@ -389,26 +389,4 @@ class Board(Base, Stndrd, Age_times):
|
|||
comments = comments.order_by(Comment.created_utc.desc()).offset(
|
||||
25 * (page - 1)).limit(26).all()
|
||||
|
||||
return [x.id for x in comments]
|
||||
|
||||
|
||||
def user_guild_rep(self, user):
|
||||
|
||||
return user.guild_rep(self)
|
||||
|
||||
def is_guildmaster(self, perm=None):
|
||||
mod=self.__dict__.get('_is_guildmaster', False)
|
||||
if not mod:
|
||||
return False
|
||||
if not perm:
|
||||
return True
|
||||
|
||||
return mod.__dict__[f"perm_{perm}"]
|
||||
|
||||
|
||||
@property
|
||||
def siege_rep_requirement(self):
|
||||
|
||||
now=int(time.time())
|
||||
|
||||
return self.stored_subscriber_count//10 + min(180, (now-self.created_utc)//(60*60*24))
|
||||
return [x.id for x in comments]
|
|
@ -82,7 +82,7 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
parent_comment = relationship("Comment", remote_side=[id])
|
||||
child_comments = relationship("Comment", remote_side=[parent_comment_id])
|
||||
|
||||
awards = relationship("AwardRelationship", lazy="joined")
|
||||
#awards = relationship("AwardRelationship", lazy="joined")
|
||||
|
||||
# These are virtual properties handled as postgres functions server-side
|
||||
# There is no difference to SQLAlchemy, but they cannot be written to
|
||||
|
@ -266,7 +266,7 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
'score': self.score_fuzzed,
|
||||
'upvotes': self.upvotes_fuzzed,
|
||||
'downvotes': self.downvotes_fuzzed,
|
||||
'award_count': self.award_count,
|
||||
#'award_count': self.award_count,
|
||||
'is_bot': self.is_bot
|
||||
}
|
||||
|
||||
|
@ -345,10 +345,6 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
x = 0
|
||||
return x
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
return self.__dict__.get("_title", self.author.title)
|
||||
|
||||
@property
|
||||
def is_blocking(self):
|
||||
return self.__dict__.get('_is_blocking', 0)
|
||||
|
@ -395,9 +391,9 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
def flag_count(self):
|
||||
return len(self.flags)
|
||||
|
||||
@property
|
||||
def award_count(self):
|
||||
return len(self.awards)
|
||||
#@property
|
||||
#def award_count(self):
|
||||
#return len(self.awards)
|
||||
|
||||
def collapse_for_user(self, v):
|
||||
|
||||
|
@ -458,18 +454,6 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
|
||||
return data
|
||||
|
||||
def is_guildmaster(self, perm=None):
|
||||
mod=self.__dict__.get('_is_guildmaster', False)
|
||||
|
||||
if not mod:
|
||||
return False
|
||||
elif not perm:
|
||||
return True
|
||||
else:
|
||||
return mod.perm_full or mod.__dict__[f"perm_{perm}"]
|
||||
|
||||
return output
|
||||
|
||||
@property
|
||||
def is_exiled_for(self):
|
||||
return self.__dict__.get('_is_exiled_for', None)
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
class PaymentRequired(Exception):
|
||||
status_code=402
|
||||
def __init__(self):
|
||||
Exception.__init__(self)
|
||||
self.status_code=402
|
|
@ -1,18 +1,6 @@
|
|||
from sqlalchemy import *
|
||||
from drama.__main__ import Base
|
||||
|
||||
|
||||
class IP(Base):
|
||||
|
||||
__tablename__ = "ips"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
addr = Column(String(64))
|
||||
reason = Column(String(256), default="")
|
||||
banned_by = Column(Integer, ForeignKey("users.id"), default=True)
|
||||
until_utc=Column(Integer, default=None)
|
||||
|
||||
|
||||
class Agent(Base):
|
||||
|
||||
__tablename__ = "useragents"
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
from drama.__main__ import Base, app
|
|
@ -117,7 +117,7 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
comment_count = Column(Integer, server_default=FetchedValue())
|
||||
score = deferred(Column(Float, server_default=FetchedValue()))
|
||||
|
||||
awards = relationship("AwardRelationship", lazy="joined")
|
||||
#awards = relationship("AwardRelationship", lazy="joined")
|
||||
|
||||
rank_hot = deferred(Column(Float, server_default=FetchedValue()))
|
||||
rank_fiery = deferred(Column(Float, server_default=FetchedValue()))
|
||||
|
@ -330,7 +330,7 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
'score': self.score_fuzzed,
|
||||
'upvotes': self.upvotes_fuzzed,
|
||||
'downvotes': self.downvotes_fuzzed,
|
||||
'award_count': self.award_count,
|
||||
#'award_count': self.award_count,
|
||||
'is_offensive': self.is_offensive,
|
||||
'meta_title': self.meta_title,
|
||||
'meta_description': self.meta_description,
|
||||
|
@ -498,23 +498,6 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
self.submission_aux.meta_description=x
|
||||
g.db.add(self.submission_aux)
|
||||
|
||||
|
||||
def is_guildmaster(self, perm=None):
|
||||
mod=self.__dict__.get('_is_guildmaster', False)
|
||||
|
||||
if not mod:
|
||||
return False
|
||||
elif not perm:
|
||||
return True
|
||||
else:
|
||||
return mod.perm_full or mod.__dict__[f"perm_{perm}"]
|
||||
|
||||
return output
|
||||
|
||||
@property
|
||||
def is_blocking_guild(self):
|
||||
return self.__dict__.get('_is_blocking_guild', False)
|
||||
|
||||
@property
|
||||
def is_blocked(self):
|
||||
return self.__dict__.get('_is_blocked', False)
|
||||
|
@ -523,10 +506,6 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
def is_blocking(self):
|
||||
return self.__dict__.get('_is_blocking', False)
|
||||
|
||||
@property
|
||||
def is_subscribed(self):
|
||||
return self.__dict__.get('_is_subscribed', False)
|
||||
|
||||
@property
|
||||
def is_public(self):
|
||||
return self.post_public or not self.board.is_private
|
||||
|
@ -539,9 +518,9 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
def report_count(self):
|
||||
return len(self.reports)
|
||||
|
||||
@property
|
||||
def award_count(self):
|
||||
return len(self.awards)
|
||||
#@property
|
||||
#def award_count(self):
|
||||
#return len(self.awards)
|
||||
|
||||
@property
|
||||
def embed_template(self):
|
||||
|
|
|
@ -38,7 +38,6 @@ class User(Base, Stndrd, Age_times):
|
|||
passhash = deferred(Column(String, default=None))
|
||||
banawards = Column(Integer, default=0)
|
||||
created_utc = Column(Integer, default=0)
|
||||
suicide_utc = Column(Integer, default=0)
|
||||
admin_level = Column(Integer, default=0)
|
||||
resized = Column(Boolean, default=True)
|
||||
agendaposter = Column(Boolean, default=False)
|
||||
|
@ -89,7 +88,6 @@ class User(Base, Stndrd, Age_times):
|
|||
has_banner = Column(Boolean, default=False)
|
||||
reserved = Column(String(256), default=None)
|
||||
is_nsfw = Column(Boolean, default=False)
|
||||
tos_agreed_utc = Column(Integer, default=0)
|
||||
profile_nonce = Column(Integer, default=0)
|
||||
banner_nonce = Column(Integer, default=0)
|
||||
last_siege_utc = Column(Integer, default=0)
|
||||
|
@ -155,11 +153,6 @@ class User(Base, Stndrd, Age_times):
|
|||
lazy="dynamic",
|
||||
primaryjoin="User.id==SaveRelationship.user_id")
|
||||
|
||||
awards = relationship(
|
||||
"AwardRelationship",
|
||||
primaryjoin="User.id==AwardRelationship.user_id"
|
||||
)
|
||||
|
||||
# properties defined as SQL server-side functions
|
||||
referral_count = deferred(Column(Integer, server_default=FetchedValue()))
|
||||
follower_count = deferred(Column(Integer, server_default=FetchedValue()))
|
||||
|
@ -201,11 +194,6 @@ class User(Base, Stndrd, Age_times):
|
|||
or_(and_(UserBlock.user_id == self.id, UserBlock.target_id == other.id), and_(
|
||||
UserBlock.user_id == other.id, UserBlock.target_id == self.id))).first()
|
||||
|
||||
def has_blocked_guild(self, board):
|
||||
|
||||
return g.db.query(BoardBlock).filter_by(
|
||||
user_id=self.id, board_id=board.id).first()
|
||||
|
||||
def validate_2fa(self, token):
|
||||
|
||||
x = pyotp.TOTP(self.mfa_secret)
|
||||
|
@ -388,7 +376,8 @@ class User(Base, Stndrd, Age_times):
|
|||
@property
|
||||
def formkey(self):
|
||||
|
||||
if "session_id" not in session: session["session_id"] = token_hex(16)
|
||||
if "session_id" not in session:
|
||||
session["session_id"] = token_hex(16)
|
||||
|
||||
msg = f"{session['session_id']}+{self.id}+{self.login_nonce}"
|
||||
|
||||
|
@ -623,9 +612,6 @@ class User(Base, Stndrd, Age_times):
|
|||
pic = random.randint(1, 50)
|
||||
return f"/assets/images/defaultpictures/{pic}.png"
|
||||
|
||||
def has_award(self, kind):
|
||||
return bool(len([x for x in self.awards if x.kind == kind]))
|
||||
|
||||
@property
|
||||
def profile_url(self):
|
||||
if self.has_profile and self.profileurl:
|
||||
|
@ -784,8 +770,8 @@ class User(Base, Stndrd, Age_times):
|
|||
|
||||
# Takes care of all functions needed for account reinstatement.
|
||||
|
||||
self.is_banned = 0
|
||||
self.unban_utc = 0
|
||||
self.is_banned = None
|
||||
self.unban_utc = None
|
||||
|
||||
g.db.add(self)
|
||||
|
||||
|
@ -885,6 +871,34 @@ class User(Base, Stndrd, Age_times):
|
|||
|
||||
return [x[0] for x in comments.offset(25 * (page - 1)).limit(26).all()]
|
||||
|
||||
def guild_rep(self, guild, recent=0):
|
||||
|
||||
posts = g.db.query(Submission.score).filter_by(
|
||||
is_banned=False,
|
||||
original_board_id=guild.id)
|
||||
|
||||
if recent:
|
||||
cutoff = int(time.time()) - 60 * 60 * 24 * recent
|
||||
posts = posts.filter(Submission.created_utc > cutoff)
|
||||
|
||||
posts = posts.all()
|
||||
|
||||
post_rep = sum([x[0] for x in posts]) - len(list(sum([x[0] for x in posts])))
|
||||
|
||||
comments = g.db.query(Comment.score).filter_by(
|
||||
is_banned=False,
|
||||
original_board_id=guild.id)
|
||||
|
||||
if recent:
|
||||
cutoff = int(time.time()) - 60 * 60 * 24 * recent
|
||||
comments = comments.filter(Comment.created_utc > cutoff)
|
||||
|
||||
comments = comments.all()
|
||||
|
||||
comment_rep = sum([x[0] for x in comments]) - len(list(sum([x[0] for x in comments])))
|
||||
|
||||
return int(post_rep + comment_rep)
|
||||
|
||||
@property
|
||||
def has_premium(self):
|
||||
|
||||
|
@ -1016,4 +1030,4 @@ class ViewerRelationship(Base):
|
|||
return f"{months}mo ago"
|
||||
else:
|
||||
years = int(months / 12)
|
||||
return f"{years}yr ago"
|
||||
return f"{years}yr ago"
|
|
@ -46,6 +46,7 @@ def get_user(username, v=None, graceful=False):
|
|||
|
||||
def get_account(base36id, v=None, graceful=False):
|
||||
|
||||
|
||||
if isinstance(base36id, str): id = base36decode(base36id)
|
||||
else: id = base36id
|
||||
|
||||
|
@ -120,9 +121,7 @@ def get_post(pid, v=None, graceful=False, **kwargs):
|
|||
|
||||
else:
|
||||
items = g.db.query(
|
||||
Submission,
|
||||
).options(
|
||||
joinedload(Submission.author).joinedload(User.title)
|
||||
Submission
|
||||
).filter(Submission.id == i).first()
|
||||
|
||||
if not items and not graceful:
|
||||
|
@ -133,7 +132,7 @@ def get_post(pid, v=None, graceful=False, **kwargs):
|
|||
return x
|
||||
|
||||
|
||||
def get_posts(pids, sort="hot", v=None):
|
||||
def get_posts(pids, v=None):
|
||||
|
||||
if not pids:
|
||||
return []
|
||||
|
@ -166,20 +165,18 @@ def get_posts(pids, sort="hot", v=None):
|
|||
blocked,
|
||||
blocked.c.user_id == Submission.author_id,
|
||||
isouter=True
|
||||
)
|
||||
).all()
|
||||
|
||||
output = [p[0] for p in query]
|
||||
for i in range(len(output)):
|
||||
output[i]._voted = query[i][1] or 0
|
||||
output[i]._is_blocking = query[i][2] or 0
|
||||
output[i]._is_blocked = query[i][3] or 0
|
||||
|
||||
else:
|
||||
output = g.db.query(
|
||||
Submission
|
||||
Submission,
|
||||
).filter(Submission.id.in_(pids)
|
||||
).order_by(Submission.id.desc()).all()
|
||||
|
||||
).all()
|
||||
|
||||
return sorted(output, key=lambda x: pids.index(x.id))
|
||||
|
||||
|
@ -200,8 +197,6 @@ def get_post_with_comments(pid, sort="top", v=None):
|
|||
votes.c.vote_type,
|
||||
blocking.c.id,
|
||||
blocked.c.id,
|
||||
).options(
|
||||
joinedload(Comment.author)
|
||||
)
|
||||
if v.admin_level >=4:
|
||||
comms=comms.options(joinedload(Comment.oauth_app))
|
||||
|
@ -252,8 +247,6 @@ def get_post_with_comments(pid, sort="top", v=None):
|
|||
else:
|
||||
comms = g.db.query(
|
||||
Comment
|
||||
).options(
|
||||
joinedload(Comment.author).joinedload(User.title)
|
||||
).filter(
|
||||
Comment.parent_submission == post.id
|
||||
)
|
||||
|
@ -300,13 +293,6 @@ def get_comment(cid, v=None, graceful=False, **kwargs):
|
|||
else:
|
||||
i = cid
|
||||
|
||||
exile = g.db.query(ModAction
|
||||
).options(
|
||||
lazyload('*')
|
||||
).filter_by(
|
||||
kind="exile_user"
|
||||
).subquery()
|
||||
|
||||
if v:
|
||||
blocking = v.blocking.subquery()
|
||||
blocked = v.blocked.subquery()
|
||||
|
@ -314,20 +300,9 @@ def get_comment(cid, v=None, graceful=False, **kwargs):
|
|||
CommentVote.user_id == v.id,
|
||||
CommentVote.comment_id == i).subquery()
|
||||
|
||||
mod=g.db.query(ModRelationship
|
||||
).filter_by(
|
||||
user_id=v.id,
|
||||
accepted=True
|
||||
).subquery()
|
||||
|
||||
|
||||
items = g.db.query(
|
||||
Comment,
|
||||
vt.c.vote_type,
|
||||
aliased(ModRelationship, alias=mod),
|
||||
aliased(ModAction, alias=exile)
|
||||
).options(
|
||||
joinedload(Comment.author).joinedload(User.title)
|
||||
)
|
||||
|
||||
if v.admin_level >=4:
|
||||
|
@ -342,14 +317,6 @@ def get_comment(cid, v=None, graceful=False, **kwargs):
|
|||
).join(
|
||||
Comment.post,
|
||||
isouter=True
|
||||
).join(
|
||||
mod,
|
||||
mod.c.board_id==Submission.board_id,
|
||||
isouter=True
|
||||
).join(
|
||||
exile,
|
||||
and_(exile.c.target_comment_id==Comment.id, exile.c.board_id==Comment.original_board_id),
|
||||
isouter=True
|
||||
).first()
|
||||
|
||||
if not items and not graceful:
|
||||
|
@ -357,8 +324,6 @@ def get_comment(cid, v=None, graceful=False, **kwargs):
|
|||
|
||||
x = items[0]
|
||||
x._voted = items[1] or 0
|
||||
x._is_guildmaster=items[2] or 0
|
||||
x._is_exiled_for=items[3] or 0
|
||||
|
||||
block = g.db.query(UserBlock).filter(
|
||||
or_(
|
||||
|
@ -376,31 +341,21 @@ def get_comment(cid, v=None, graceful=False, **kwargs):
|
|||
x._is_blocked = block and block.target_id == v.id
|
||||
|
||||
else:
|
||||
q = g.db.query(
|
||||
x = g.db.query(
|
||||
Comment,
|
||||
aliased(ModAction, alias=exile)
|
||||
).options(
|
||||
joinedload(Comment.author).joinedload(User.title)
|
||||
).join(
|
||||
exile,
|
||||
and_(exile.c.target_comment_id==Comment.id, exile.c.board_id==Comment.original_board_id),
|
||||
isouter=True
|
||||
).filter(Comment.id == i).first()
|
||||
|
||||
if not q and not graceful:
|
||||
if not x and not graceful:
|
||||
abort(404)
|
||||
|
||||
x=q[0]
|
||||
x._is_exiled_for=q[1]
|
||||
|
||||
|
||||
return x
|
||||
|
||||
|
||||
def get_comments(cids, v=None, sort="new",
|
||||
load_parent=False, **kwargs):
|
||||
def get_comments(cids, v=None, load_parent=False, **kwargs):
|
||||
|
||||
if not cids: return []
|
||||
if not cids:
|
||||
return []
|
||||
|
||||
cids=tuple(cids)
|
||||
|
||||
|
@ -434,17 +389,26 @@ def get_comments(cids, v=None, sort="new",
|
|||
isouter=True
|
||||
).filter(
|
||||
Comment.id.in_(cids)
|
||||
).order_by(Comment.id.desc()).all()
|
||||
)
|
||||
|
||||
|
||||
output = [x[0] for x in query]
|
||||
for i in range(len(output)): output[i]._voted = query[i][1].vote_type if query[i][1] else 0
|
||||
for i in range(len(output)):
|
||||
output[i]._voted = query[i][1].vote_type if query[i][1] else 0
|
||||
|
||||
|
||||
else:
|
||||
output = g.db.query(Comment).options().filter(Comment.id.in_(cids)).order_by(Comment.id.desc()).all()
|
||||
query = g.db.query(
|
||||
Comment,
|
||||
).filter(
|
||||
Comment.id.in_(cids)
|
||||
).all()
|
||||
|
||||
output=[x for x in query]
|
||||
|
||||
return sorted(output, key=lambda x: cids.index(x.id))
|
||||
output = sorted(output, key=lambda x: cids.index(x.id))
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def get_board(bid, graceful=False):
|
||||
|
@ -484,27 +448,6 @@ def get_domain(s):
|
|||
return doms[0]
|
||||
|
||||
|
||||
def get_title(x):
|
||||
|
||||
title = g.db.query(Title).filter_by(id=x).first()
|
||||
|
||||
if not title:
|
||||
abort(400)
|
||||
|
||||
else:
|
||||
return title
|
||||
|
||||
|
||||
def get_mod(uid, bid):
|
||||
|
||||
mod = g.db.query(ModRelationship).filter_by(board_id=bid,
|
||||
user_id=uid,
|
||||
accepted=True,
|
||||
invite_rescinded=False).first()
|
||||
|
||||
return mod
|
||||
|
||||
|
||||
def get_application(client_id, graceful=False):
|
||||
|
||||
application = g.db.query(OauthApp).filter_by(client_id=client_id).first()
|
||||
|
@ -541,57 +484,4 @@ def get_from_permalink(link, v=None):
|
|||
return get_comment(int(comment_id), v=v)
|
||||
|
||||
else:
|
||||
return get_post(int(post_id), v=v)
|
||||
|
||||
|
||||
def get_from_fullname(fullname, v=None, graceful=False):
|
||||
|
||||
parts = fullname.split('_')
|
||||
|
||||
if len(parts) != 2:
|
||||
if graceful:
|
||||
return None
|
||||
else:
|
||||
abort(400)
|
||||
|
||||
kind = parts[0]
|
||||
b36 = parts[1]
|
||||
|
||||
if kind == 't1':
|
||||
return get_account(b36, v=v, graceful=graceful)
|
||||
elif kind == 't2':
|
||||
return get_post(b36, v=v, graceful=graceful)
|
||||
elif kind == 't3':
|
||||
return get_comment(b36, v=v, graceful=graceful)
|
||||
elif kind == 't4':
|
||||
return get_board(b36, graceful=graceful)
|
||||
|
||||
def get_txn(paypal_id):
|
||||
|
||||
txn= g.db.query(PayPalTxn).filter_by(paypal_id=paypal_id).first()
|
||||
|
||||
if not txn:
|
||||
abort(404)
|
||||
|
||||
return txn
|
||||
|
||||
def get_txid(txid):
|
||||
|
||||
txn= g.db.query(PayPalTxn).filter_by(id=base36decode(txid)).first()
|
||||
|
||||
if not txn:
|
||||
abort(404)
|
||||
elif txn.status==1:
|
||||
abort(404)
|
||||
|
||||
return txn
|
||||
|
||||
|
||||
def get_promocode(code):
|
||||
|
||||
code = code.replace('\\', '')
|
||||
code = code.replace("_", "\_")
|
||||
|
||||
code = g.db.query(PromoCode).filter(PromoCode.code.ilike(code)).first()
|
||||
|
||||
return code
|
||||
return get_post(int(post_id), v=v)
|
|
@ -47,37 +47,6 @@ def js_str_escape(s):
|
|||
return s
|
||||
|
||||
|
||||
@app.template_filter("is_mod")
|
||||
@cache.memoize(60)
|
||||
def jinja_is_mod(uid, bid):
|
||||
|
||||
return bool(get_mod(uid, bid))
|
||||
|
||||
@app.template_filter("coin_goal")
|
||||
@cache.cached(timeout=600, key_prefix="premium_coin_goal")
|
||||
def coin_goal(x):
|
||||
|
||||
now = time.gmtime()
|
||||
midnight_month_start = time.struct_time((now.tm_year,
|
||||
now.tm_mon,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
now.tm_wday,
|
||||
now.tm_yday,
|
||||
0)
|
||||
)
|
||||
cutoff = calendar.timegm(midnight_month_start)
|
||||
|
||||
coins=g.db.query(func.sum(PayPalTxn.coin_count)).filter(
|
||||
PayPalTxn.created_utc>cutoff,
|
||||
PayPalTxn.status==3).all()[0][0] or 0
|
||||
|
||||
|
||||
return int(100*coins/1000)
|
||||
|
||||
|
||||
@app.template_filter("app_config")
|
||||
def app_config(x):
|
||||
return app.config.get(x)
|
||||
|
|
|
@ -221,110 +221,6 @@ def is_not_banned(f):
|
|||
wrapper.__name__ = f.__name__
|
||||
return wrapper
|
||||
|
||||
# Require tos agreement
|
||||
|
||||
|
||||
def tos_agreed(f):
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
|
||||
v = kwargs['v']
|
||||
|
||||
cutoff = int(environ.get("tos_cutoff", 0))
|
||||
|
||||
if v.tos_agreed_utc > cutoff:
|
||||
return f(*args, **kwargs)
|
||||
else:
|
||||
return redirect("/terms#agreebox")
|
||||
|
||||
wrapper.__name__ = f.__name__
|
||||
return wrapper
|
||||
|
||||
def premium_required(f):
|
||||
|
||||
#decorator that enforces valid premium status
|
||||
#use under auth_required or is_not_banned
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
|
||||
v=kwargs["v"]
|
||||
|
||||
if not v.has_premium:
|
||||
abort(403)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
wrapper.__name__=f.__name__
|
||||
return wrapper
|
||||
|
||||
|
||||
def no_negative_balance(s):
|
||||
|
||||
def wrapper_maker(f):
|
||||
|
||||
#decorator that enforces valid premium status
|
||||
#use under auth_required or is_not_banned
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
|
||||
v=kwargs["v"]
|
||||
|
||||
if v.negative_balance_cents:
|
||||
if s=="toast":
|
||||
return jsonify({"error":"You can't do that while your account balance is negative. Visit your account settings to bring your balance up to zero."}), 402
|
||||
elif s=="html":
|
||||
raise(PaymentRequired)
|
||||
else:
|
||||
raise(PaymentRequired)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
wrapper.__name__=f.__name__
|
||||
return wrapper
|
||||
|
||||
return wrapper_maker
|
||||
|
||||
def is_guildmaster(*perms):
|
||||
# decorator that enforces guildmaster status and verifies permissions
|
||||
# use under auth_required
|
||||
def wrapper_maker(f):
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
|
||||
v = kwargs["v"]
|
||||
boardname = kwargs.get("boardname")
|
||||
board_id = kwargs.get("bid")
|
||||
bid=request.values.get("bid", request.values.get("board_id"))
|
||||
|
||||
if boardname:
|
||||
board = get_guild(boardname)
|
||||
elif board_id:
|
||||
board = get_board(board_id)
|
||||
elif bid:
|
||||
board = get_board(bid)
|
||||
else:
|
||||
return jsonify({"error": f"no guild specified"}), 400
|
||||
|
||||
m=board.has_mod(v)
|
||||
if not m:
|
||||
return jsonify({"error":f"You aren't a guildmaster of +{board.name}"}), 403
|
||||
|
||||
if perms:
|
||||
for perm in perms:
|
||||
if not m.__dict__.get(f"perm_{perm}") and not m.perm_full:
|
||||
return jsonify({"error":f"Permission `{perm}` required"}), 403
|
||||
|
||||
|
||||
if v.is_banned and not v.unban_utc:
|
||||
abort(403)
|
||||
|
||||
return f(*args, board=board, **kwargs)
|
||||
|
||||
wrapper.__name__ = f.__name__
|
||||
return wrapper
|
||||
|
||||
return wrapper_maker
|
||||
|
||||
|
||||
# this wrapper takes args and is a bit more complicated
|
||||
def admin_level_required(x):
|
||||
|
@ -529,26 +425,4 @@ def api(*scopes, no_ban=False):
|
|||
wrapper.__name__ = f.__name__
|
||||
return wrapper
|
||||
|
||||
return wrapper_maker
|
||||
|
||||
|
||||
SANCTIONS=[
|
||||
"CU", #Cuba
|
||||
"IR", #Iran
|
||||
"KP", #North Korea
|
||||
"SY", #Syria
|
||||
"TR", #Turkey
|
||||
"VE", #Venezuela
|
||||
]
|
||||
|
||||
def no_sanctions(f):
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
|
||||
if request.headers.get("cf-ipcountry","") in SANCTIONS:
|
||||
abort(451)
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
wrapper.__name__=f.__name__
|
||||
return wrapper
|
||||
return wrapper_maker
|
|
@ -9,7 +9,6 @@ valid_board_regex = re.compile("^[a-zA-Z0-9][a-zA-Z0-9_]{2,24}$")
|
|||
@app.route("/mod/distinguish_post/<bid>/<pid>", methods=["POST"])
|
||||
@app.route("/api/v1/distinguish_post/<bid>/<pid>", methods=["POST"])
|
||||
@auth_required
|
||||
@is_guildmaster("content")
|
||||
@api("guildmaster")
|
||||
def mod_distinguish_post(bid, pid, board, v):
|
||||
|
||||
|
@ -41,7 +40,6 @@ def mod_distinguish_post(bid, pid, board, v):
|
|||
|
||||
@app.route("/mod/invite_mod/<bid>", methods=["POST"])
|
||||
@auth_required
|
||||
@is_guildmaster("full")
|
||||
@validate_formkey
|
||||
def mod_invite_username(bid, board, v):
|
||||
|
||||
|
@ -99,7 +97,6 @@ def mod_invite_username(bid, board, v):
|
|||
|
||||
@app.route("/mod/<bid>/rescind/<username>", methods=["POST"])
|
||||
@auth_required
|
||||
@is_guildmaster("full")
|
||||
@validate_formkey
|
||||
def mod_rescind_bid_username(bid, username, board, v):
|
||||
|
||||
|
@ -158,7 +155,6 @@ def mod_accept_board(bid, v):
|
|||
|
||||
@app.route("/mod/<bid>/step_down", methods=["POST"])
|
||||
@auth_required
|
||||
@is_guildmaster()
|
||||
@validate_formkey
|
||||
def mod_step_down(bid, board, v):
|
||||
|
||||
|
@ -184,7 +180,6 @@ def mod_step_down(bid, board, v):
|
|||
|
||||
@app.route("/mod/<bid>/remove/<username>", methods=["POST"])
|
||||
@auth_required
|
||||
@is_guildmaster("full")
|
||||
@validate_formkey
|
||||
def mod_remove_username(bid, username, board, v):
|
||||
|
||||
|
@ -284,7 +279,6 @@ def mod_log_item(aid, v):
|
|||
|
||||
@app.route("/mod/edit_perms", methods=["POST"])
|
||||
@auth_required
|
||||
@is_guildmaster("full")
|
||||
@validate_formkey
|
||||
def board_mod_perms_change(boardname, board, v):
|
||||
|
||||
|
|
|
@ -190,7 +190,6 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
|||
comment._voted = c[1] or 0
|
||||
comment._is_blocking = c[2] or 0
|
||||
comment._is_blocked = c[3] or 0
|
||||
comment._is_guildmaster=top_comment._is_guildmaster
|
||||
comment._is_exiled_for=c[4] or 0
|
||||
output.append(comment)
|
||||
else:
|
||||
|
@ -247,8 +246,6 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
|||
@app.route("/api/v1/comment", methods=["POST"])
|
||||
@limiter.limit("6/minute")
|
||||
@is_not_banned
|
||||
@no_negative_balance('toast')
|
||||
@tos_agreed
|
||||
@validate_formkey
|
||||
@api("create")
|
||||
def api_comment(v):
|
||||
|
|
|
@ -2,12 +2,10 @@ import jinja2.exceptions
|
|||
|
||||
from drama.helpers.wrappers import *
|
||||
from drama.helpers.session import *
|
||||
from drama.classes.custom_errors import *
|
||||
from flask import *
|
||||
from urllib.parse import quote, urlencode
|
||||
import time
|
||||
from drama.__main__ import app, r, cache, db_session
|
||||
import gevent
|
||||
from drama.__main__ import app
|
||||
|
||||
# Errors
|
||||
|
||||
|
@ -27,14 +25,6 @@ def error_401(e):
|
|||
else:
|
||||
return redirect(output)
|
||||
|
||||
@app.errorhandler(PaymentRequired)
|
||||
@auth_desired
|
||||
@api()
|
||||
def error_402(e, v):
|
||||
return{"html": lambda: (render_template('errors/402.html', v=v), 402),
|
||||
"api": lambda: (jsonify({"error": "402 Payment Required"}), 402)
|
||||
}
|
||||
|
||||
@app.errorhandler(403)
|
||||
@auth_desired
|
||||
@api()
|
||||
|
|
|
@ -211,7 +211,7 @@ def front_all(v):
|
|||
ids = ids[0:25]
|
||||
|
||||
# check if ids exist
|
||||
posts = get_posts(ids, sort=sort, v=v)
|
||||
posts = get_posts(ids, v=v)
|
||||
|
||||
if request.path == "/": return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page)
|
||||
else: return jsonify({"data": [x.json for x in posts], "next_exists": next_exists})
|
||||
|
@ -313,7 +313,7 @@ def changelog(v):
|
|||
ids = ids[0:25]
|
||||
|
||||
# check if ids exist
|
||||
posts = get_posts(ids, sort=sort, v=v)
|
||||
posts = get_posts(ids, v=v)
|
||||
|
||||
return {'html': lambda: render_template("changelog.html",
|
||||
v=v,
|
||||
|
|
|
@ -358,7 +358,6 @@ def sign_up_post(v):
|
|||
created_utc=int(time.time()),
|
||||
creation_ip=request.remote_addr,
|
||||
referred_by=ref_id or None,
|
||||
tos_agreed_utc=int(time.time()),
|
||||
creation_region=request.headers.get("cf-ipcountry"),
|
||||
ban_evade = int(any([x.is_banned for x in g.db.query(User).filter(User.id.in_(tuple(session.get("history", [])))).all() if x]))
|
||||
)
|
||||
|
|
|
@ -89,7 +89,6 @@ def publish(pid, v):
|
|||
|
||||
@app.route("/submit", methods=["GET"])
|
||||
@auth_required
|
||||
@no_negative_balance("html")
|
||||
def submit_get(v):
|
||||
if v and v.is_banned and not v.unban_utc: return render_template("seized.html")
|
||||
|
||||
|
@ -143,7 +142,6 @@ def post_base36id(pid, anything=None, v=None):
|
|||
|
||||
@app.route("/edit_post/<pid>", methods=["POST"])
|
||||
@is_not_banned
|
||||
@no_negative_balance("html")
|
||||
@validate_formkey
|
||||
def edit_post(pid, v):
|
||||
|
||||
|
@ -278,7 +276,6 @@ def edit_post(pid, v):
|
|||
@app.route("/submit/title", methods=['GET'])
|
||||
@limiter.limit("6/minute")
|
||||
@is_not_banned
|
||||
@no_negative_balance("html")
|
||||
def get_post_title(v):
|
||||
|
||||
url = request.args.get("url", None)
|
||||
|
@ -458,8 +455,6 @@ def archiveorg(url):
|
|||
@app.route("/api/vue/submit", methods=["POST"])
|
||||
@limiter.limit("6/minute")
|
||||
@is_not_banned
|
||||
@no_negative_balance('html')
|
||||
@tos_agreed
|
||||
@validate_formkey
|
||||
@api("create")
|
||||
def submit_post(v):
|
||||
|
|
|
@ -127,22 +127,6 @@ def settings_profile_post(v):
|
|||
|
||||
|
||||
|
||||
x = request.values.get("title_id", None)
|
||||
if x:
|
||||
x = int(x)
|
||||
if x == 0:
|
||||
v.title_id = None
|
||||
updated = True
|
||||
elif x > 0:
|
||||
title = get_title(x)
|
||||
if bool(eval(title.qualification_expr)):
|
||||
v.title_id = title.id
|
||||
updated = True
|
||||
else:
|
||||
return jsonify({"error": f"You don't meet the requirements for title `{title.text}`."}), 403
|
||||
else:
|
||||
abort(400)
|
||||
|
||||
defaultsortingcomments = request.values.get("defaultsortingcomments")
|
||||
if defaultsortingcomments:
|
||||
if defaultsortingcomments in ["new", "old", "controversial", "top", "bottom", "random"]:
|
||||
|
|
|
@ -317,7 +317,7 @@ def u_username(username, v=None):
|
|||
for p in sticky:
|
||||
ids = [p.id] + ids
|
||||
|
||||
listing = get_posts(ids, v=v, sort="new")
|
||||
listing = get_posts(ids, v=v)
|
||||
|
||||
if u.unban_utc:
|
||||
unban = datetime.fromtimestamp(u.unban_utc).strftime('%c')
|
||||
|
@ -516,7 +516,7 @@ def saved_posts(v, username):
|
|||
|
||||
ids=ids[0:25]
|
||||
|
||||
listing = get_posts(ids, v=v, sort="new")
|
||||
listing = get_posts(ids, v=v)
|
||||
|
||||
return {'html': lambda: render_template("userpage.html",
|
||||
u=v,
|
||||
|
|
|
@ -8,7 +8,6 @@ from .users import leaderboard
|
|||
@app.route("/api/v1/vote/post/<post_id>/<x>", methods=["POST"])
|
||||
@app.route("/api/vote/post/<post_id>/<x>", methods=["POST"])
|
||||
@is_not_banned
|
||||
@no_negative_balance("toast")
|
||||
@api("vote")
|
||||
@validate_formkey
|
||||
def api_vote_post(post_id, x, v):
|
||||
|
@ -63,7 +62,6 @@ def api_vote_post(post_id, x, v):
|
|||
@app.route("/api/v1/vote/comment/<comment_id>/<x>", methods=["POST"])
|
||||
@app.route("/api/vote/comment/<comment_id>/<x>", methods=["POST"])
|
||||
@is_not_banned
|
||||
@no_negative_balance("toast")
|
||||
@api("vote")
|
||||
@validate_formkey
|
||||
def api_vote_comment(comment_id, x, v):
|
||||
|
|
|
@ -20,4 +20,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
|
@ -1,20 +0,0 @@
|
|||
{% extends "errors/default.html" %}
|
||||
|
||||
{% block title %}
|
||||
<title>402 Payment Required</title>
|
||||
{% endblock %}
|
||||
|
||||
{% block pagetype %}error-402{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-10 col-md-5">
|
||||
<div class="text-center px-3 my-8">
|
||||
<i class="fad fa-sack-dollar text-muted mb-5" style="font-size: 5rem;"></i>
|
||||
<h1 class="h5">402 Payment Required</h1>
|
||||
<p class="text-muted mb-5">You should NEVER SEE THIS PAGE. It's about Ruqqus microtransactions. But no one deleted it from the github thing so I assume it has to continue existing for a reason. If you do see this page, you did something wrong.</p>
|
||||
<div><a href="/settings/premium" class="btn btn-primary">Go to Coin settings</a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -13,8 +13,8 @@
|
|||
<i class="fad fa-balance-scale text-muted mb-5" style="font-size: 5rem;"></i>
|
||||
<h1 class="h5">451 Unavailable For Legal Reasons</h1>
|
||||
|
||||
<p class="text-muted mb-5"><img src="https://i.imgur.com/ykKSTmq.jpg" width=500><BR><BR>fool.</p>
|
||||
<p class="text-muted mb-5"><img src=https://i.imgur.com/ykKSTmq.jpg width=500><BR><BR>fool.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
|
@ -123,4 +123,4 @@
|
|||
|
||||
<script src="https://ajax.cloudflare.com/cdn-cgi/scripts/7089c43e/cloudflare-static/rocket-loader.min.js" data-cf-settings="37cef32129ec2b1bc32e9226-|49" defer=""></script></body>
|
||||
|
||||
</html>
|
||||
</html>
|
|
@ -4,7 +4,7 @@
|
|||
<title>403 Unauthorized</title>
|
||||
{% endblock %}
|
||||
|
||||
{% block pagetype %}error-405{% endblock %}
|
||||
{% block pagetype %}error-403{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row justify-content-center">
|
||||
|
|
|
@ -35,4 +35,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -35,4 +35,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -150,7 +150,7 @@
|
|||
<button class="btn btn-link btn-block btn-lg text-left text-muted"><a href="javascript:void(0)" onclick="post('/save_post/{{p.base36id}}', function(){window.location.reload(true);})"><i class="fas fa-save text-center text-muted mr-3"></i>Save</a></button>
|
||||
{% endif %}
|
||||
|
||||
{% if v and (v.id==p.author_id or v.admin_level>=3 or p.is_guildmaster('content')) %}
|
||||
{% if v and (v.id==p.author_id or v.admin_level>=3) %}
|
||||
{% if not p.board.over_18 %}
|
||||
<button class="btn btn-link btn-block btn-lg text-left text-muted" onclick="post('/api/toggle_post_nsfw/{{p.base36id}}', function(){window.location.reload(true);})"><i class="far fa-eye-evil text-center text-muted mr-3"></i>Toggle +18</button>
|
||||
{% endif %}
|
||||
|
@ -361,7 +361,7 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if v and (v.id==p.author_id or v.admin_level>=3 or p.is_guildmaster('content')) %}
|
||||
{% if v and (v.id==p.author_id or v.admin_level>=3) %}
|
||||
|
||||
{% if not p.board.over_18 %}
|
||||
<li class="list-inline-item"><a href="javascript:void(0)" onclick="post('/api/toggle_post_nsfw/{{p.base36id}}', function(){window.location.reload(true);})"><i class="fas fa-eye-evil"></i>Toggle +18</a></li>
|
||||
|
|
|
@ -203,7 +203,7 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if v and (v.id==p.author_id or v.admin_level>=3 or p.is_guildmaster('content')) %}
|
||||
{% if v and (v.id==p.author_id or v.admin_level>=3) %}
|
||||
|
||||
<li class="list-inline-item"><a href="javascript:void(0)" onclick="post('/api/toggle_post_nsfw/{{p.base36id}}', function(){window.location.reload(true);})"><i class="fas fa-eye-evil"></i>Toggle +18</a></li>
|
||||
|
||||
|
@ -386,7 +386,7 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if v and (v.id==p.author_id or v.admin_level>=3 or p.is_guildmaster('content')) %}
|
||||
{% if v and (v.id==p.author_id or v.admin_level>=3) %}
|
||||
{% if not p.board.over_18 %}
|
||||
<button class="btn btn-link btn-block btn-lg text-left text-muted" onclick="post('/api/toggle_post_nsfw/{{p.base36id}}', function(){window.location.reload(true);})"><i class="far fa-eye-evil text-center text-muted mr-3"></i>Toggle +18</button>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in New Issue