From fb3b5ea453f41dae790cdc68b63f0c21780b739e Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 12 Sep 2021 20:25:59 +0200 Subject: [PATCH] club ban --- files/classes/user.py | 1 + files/routes/admin.py | 22 ++++++++++++++++++++++ files/routes/comments.py | 6 +++++- files/routes/posts.py | 21 +++++++-------------- files/templates/submit.html | 4 ++-- files/templates/userpage.html | 13 +++++++++++++ 6 files changed, 50 insertions(+), 17 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 4a16ba17a8..f25bcca167 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -93,6 +93,7 @@ class User(Base, Stndrd, Age_times): is_banned = Column(Integer, default=0) unban_utc = Column(Integer, default=0) ban_reason = Column(String) + club_banned = Column(Boolean, default=False) login_nonce = Column(Integer, default=0) reserved = Column(String(256)) coins = Column(Integer, default=0) diff --git a/files/routes/admin.py b/files/routes/admin.py index 9d04b20b45..1a252cc761 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -45,6 +45,28 @@ def revert_actions(v, username): return {"message": "Admin actions reverted!"} +@app.post("/@/club_ban") +@admin_level_required(6) +def toggle_club_ban(v, username): + + u = get_user(username, v=v) + + if not u: + abort(404) + + if u.admin_level >= v.admin_level: + return {"error": "noob"} + + u.club_banned = not u.club_banned + + for x in u.alts: + x.club_banned = not x.club_banned + + return { + "message": f"@{username} has been kicked from the country club. Deserved." if u.club_banned else f"@{username}'s ban from club removed" + } + + @app.post("/@/make_admin") @admin_level_required(6) def make_admin(v, username): diff --git a/files/routes/comments.py b/files/routes/comments.py index 76db76bb3f..a890e0a616 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -41,7 +41,11 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None): comment = get_comment(cid, v=v) - if comment.post and comment.post.club and not (v and v.coins > 150): abort(403) + if comment.post and comment.post.club: + if not v: + abort(403) + elif v.admin_level < 3 and (v.coins < 750 or v.club_banned): + abort(403) if not comment.parent_submission and not (v and (comment.author.id == v.id or comment.sentto == v.id)) and not (v and v.admin_level == 6) : abort(403) diff --git a/files/routes/posts.py b/files/routes/posts.py index 218dfe3adc..0075c15dbf 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -33,7 +33,7 @@ def toggle_club(pid, v): post = get_post(pid) - if not post.author_id == v.id and not v.admin_level >= 3: abort(403) + if not (post.author_id == v.id and not v.club_banned) or not v.admin_level >= 3: abort(403) post.club = not post.club g.db.add(post) @@ -88,18 +88,6 @@ def post_id(pid, anything=None, v=None): if v: defaultsortingcomments = v.defaultsortingcomments else: defaultsortingcomments = "top" sort=request.args.get("sort", defaultsortingcomments) - - - - - - - - - - - - try: pid = int(pid) except: @@ -108,7 +96,12 @@ def post_id(pid, anything=None, v=None): post = get_post(pid, v=v) - if post.club and not (v and v.coins > 150): abort(403) + if post.club: + if not v: + abort(403) + elif v.admin_level < 3 and (v.coins < 750 or v.club_banned): + abort(403) + if v: votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() diff --git a/files/templates/submit.html b/files/templates/submit.html index d384415dc5..ae48219b61 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -375,10 +375,10 @@ - {% if v.admin_level == 6 or v.coins > 150 %} + {% if v.admin_level == 6 or (v.coins >= 750 and not v.club_banned) %}
- +
{% endif %}
diff --git a/files/templates/userpage.html b/files/templates/userpage.html
index efb5f67387..bc021696d0 100644
--- a/files/templates/userpage.html
+++ b/files/templates/userpage.html
@@ -327,6 +327,12 @@
 							
 							
 						
+
+						{% if u.club_banned %}
+						
+						{% else %}
+						
+						{% endif %}
 					{% endif %}
 					

 					

User ID: {{u.id}}

@@ -505,6 +511,13 @@ {% if v.admin_level > 1 %} + + {% if u.club_banned %} + + {% else %} + + {% endif %} +