fdf
This commit is contained in:
parent
cefd63908a
commit
03ba6c5fd2
12 changed files with 6 additions and 197 deletions
|
@ -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):
|
||||
|
@ -532,26 +428,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
|
Loading…
Add table
Add a link
Reference in a new issue