fdf
This commit is contained in:
parent
cefd63908a
commit
03ba6c5fd2
12 changed files with 6 additions and 197 deletions
|
@ -390,25 +390,3 @@ class Board(Base, Stndrd, Age_times):
|
|||
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))
|
|
@ -458,18 +458,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)
|
||||
|
|
|
@ -498,19 +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)
|
||||
|
|
|
@ -88,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)
|
||||
|
|
|
@ -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):
|
||||
|
@ -533,25 +429,3 @@ def api(*scopes, no_ban=False):
|
|||
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
|
|
@ -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):
|
||||
|
|
|
@ -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]))
|
||||
)
|
||||
|
|
|
@ -90,7 +90,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")
|
||||
|
||||
|
@ -144,7 +143,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):
|
||||
|
||||
|
@ -281,7 +279,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)
|
||||
|
@ -461,8 +458,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):
|
||||
|
|
|
@ -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):
|
||||
|
@ -79,7 +78,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):
|
||||
|
|
|
@ -152,7 +152,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 %}
|
||||
|
@ -363,7 +363,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>
|
||||
|
|
|
@ -229,7 +229,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>
|
||||
|
||||
|
@ -412,7 +412,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…
Add table
Add a link
Reference in a new issue