From 03ba6c5fd2339ea1839fe88244c1420aa16c55c5 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 25 Jul 2021 04:14:52 +0200 Subject: [PATCH] fdf --- drama/classes/boards.py | 24 +---- drama/classes/comment.py | 12 --- drama/classes/submission.py | 13 --- drama/classes/user.py | 1 - drama/helpers/wrappers.py | 128 +----------------------- drama/routes/boards.py | 6 -- drama/routes/comments.py | 3 - drama/routes/login.py | 1 - drama/routes/posts.py | 5 - drama/routes/votes.py | 2 - drama/templates/submission.html | 4 +- drama/templates/submission_listing.html | 4 +- 12 files changed, 6 insertions(+), 197 deletions(-) diff --git a/drama/classes/boards.py b/drama/classes/boards.py index 6945b243a..322a95c39 100644 --- a/drama/classes/boards.py +++ b/drama/classes/boards.py @@ -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)) \ No newline at end of file + return [x.id for x in comments] \ No newline at end of file diff --git a/drama/classes/comment.py b/drama/classes/comment.py index 733b97952..651db176f 100644 --- a/drama/classes/comment.py +++ b/drama/classes/comment.py @@ -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) diff --git a/drama/classes/submission.py b/drama/classes/submission.py index 367e2284e..28702038a 100644 --- a/drama/classes/submission.py +++ b/drama/classes/submission.py @@ -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) diff --git a/drama/classes/user.py b/drama/classes/user.py index fb8c26d6d..525884971 100644 --- a/drama/classes/user.py +++ b/drama/classes/user.py @@ -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) diff --git a/drama/helpers/wrappers.py b/drama/helpers/wrappers.py index 9efcf94ef..a234f7127 100644 --- a/drama/helpers/wrappers.py +++ b/drama/helpers/wrappers.py @@ -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 \ No newline at end of file + return wrapper_maker \ No newline at end of file diff --git a/drama/routes/boards.py b/drama/routes/boards.py index 7830e0f25..8b95a714b 100644 --- a/drama/routes/boards.py +++ b/drama/routes/boards.py @@ -9,7 +9,6 @@ valid_board_regex = re.compile("^[a-zA-Z0-9][a-zA-Z0-9_]{2,24}$") @app.route("/mod/distinguish_post//", methods=["POST"]) @app.route("/api/v1/distinguish_post//", 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/", 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//rescind/", 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//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//remove/", 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): diff --git a/drama/routes/comments.py b/drama/routes/comments.py index 0b7356e8e..1fa859f4c 100644 --- a/drama/routes/comments.py +++ b/drama/routes/comments.py @@ -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): diff --git a/drama/routes/login.py b/drama/routes/login.py index 6b12792b8..8faedebe2 100644 --- a/drama/routes/login.py +++ b/drama/routes/login.py @@ -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])) ) diff --git a/drama/routes/posts.py b/drama/routes/posts.py index b697a2ae4..cbc3a6fa9 100644 --- a/drama/routes/posts.py +++ b/drama/routes/posts.py @@ -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/", 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): diff --git a/drama/routes/votes.py b/drama/routes/votes.py index 68039f870..7fe6adedc 100644 --- a/drama/routes/votes.py +++ b/drama/routes/votes.py @@ -8,7 +8,6 @@ from .users import leaderboard @app.route("/api/v1/vote/post//", methods=["POST"]) @app.route("/api/vote/post//", 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//", methods=["POST"]) @app.route("/api/vote/comment//", methods=["POST"]) @is_not_banned -@no_negative_balance("toast") @api("vote") @validate_formkey def api_vote_comment(comment_id, x, v): diff --git a/drama/templates/submission.html b/drama/templates/submission.html index 27ea3c3a6..178a981ae 100644 --- a/drama/templates/submission.html +++ b/drama/templates/submission.html @@ -152,7 +152,7 @@ {% 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 %} {% 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 %}
  • Toggle +18
  • diff --git a/drama/templates/submission_listing.html b/drama/templates/submission_listing.html index 4754d2387..d0af93fd4 100644 --- a/drama/templates/submission_listing.html +++ b/drama/templates/submission_listing.html @@ -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) %}
  • Toggle +18
  • @@ -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 %} {% endif %}