diff --git a/files/routes/admin.py b/files/routes/admin.py index 805132c265..51f5bc7968 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -26,52 +26,121 @@ IMGUR_KEY = environ.get("IMGUR_KEY", "").strip() @app.post("/@/revert_actions") @admin_level_required(6) def revert_actions(v, username): - user = get_user(username) - if not user: abort(404) + if 'pcm' in request.host or ('rdrama' in request.host and v.id in [12,28,29,747,995]) or ('rdrama' not in request.host and 'pcm' not in request.host): + user = get_user(username) + if not user: abort(404) - items = g.db.query(Submission).options(lazyload('*')).filter_by(removed_by=user.id).all() + g.db.query(Comment).options(lazyload('*')).filter_by(removed_by=user.id).all() + items = g.db.query(Submission).options(lazyload('*')).filter_by(removed_by=user.id).all() + g.db.query(Comment).options(lazyload('*')).filter_by(removed_by=user.id).all() - for item in items: - item.is_banned = False - item.removed_by = None - g.db.add(item) + for item in items: + item.is_banned = False + item.removed_by = None + g.db.add(item) - users = g.db.query(User).options(lazyload('*')).filter_by(is_banned=user.id).all() - for user in users: - user.unban() + users = g.db.query(User).options(lazyload('*')).filter_by(is_banned=user.id).all() + for user in users: + user.unban() return {"message": "Admin actions reverted!"} + @app.post("/@/make_admin") @admin_level_required(6) def make_admin(v, username): - user = get_user(username) - if not user: abort(404) - user.admin_level = 6 - g.db.add(user) + if 'pcm' in request.host or ('rdrama' in request.host and v.id in [12,28,29,747,995]) or ('rdrama' not in request.host and 'pcm' not in request.host): + user = get_user(username) + if not user: abort(404) + user.admin_level = 6 + g.db.add(user) return {"message": "User has been made admin!"} -@app.post("/@/make_fake_admin") -@admin_level_required(6) -def make_fake_admin(v, username): - user = get_user(username) - if not user: abort(404) - user.admin_level = 1 - g.db.add(user) - return {"message": "User has been made fake admin!"} - - @app.post("/@/remove_admin") @admin_level_required(6) def remove_admin(v, username): - user = get_user(username) - if not user: abort(404) - user.admin_level = 0 - g.db.add(user) + if 'pcm' in request.host or ('rdrama' in request.host and v.id in [12,28,29,747,995]) or ('rdrama' not in request.host and 'pcm' not in request.host): + user = get_user(username) + if not user: abort(404) + user.admin_level = 0 + g.db.add(user) return {"message": "Admin removed!"} +@app.post("/@/make_fake_admin") +@admin_level_required(6) +def make_fake_admin(v, username): + if 'pcm' in request.host or ('rdrama' in request.host and v.id in [12,28,29,747,995]) or ('rdrama' not in request.host and 'pcm' not in request.host): + user = get_user(username) + if not user: abort(404) + user.admin_level = 1 + g.db.add(user) + return {"message": "User has been made fake admin!"} + + +@app.post("/@/remove_fake_admin") +@admin_level_required(6) +def remove_fake_admin(v, username): + if 'pcm' in request.host or ('rdrama' in request.host and v.id in [12,28,29,747,995]) or ('rdrama' not in request.host and 'pcm' not in request.host): + user = get_user(username) + if not user: abort(404) + user.admin_level = 0 + g.db.add(user) + return {"message": "Fake admin removed!"} + + +@app.post("/admin/monthly") +@limiter.limit("1/day") +@admin_level_required(6) +def monthly(v): + if 'pcm' in request.host or ('rdrama' in request.host and v.id in [12,28,29,747,995]) or ('rdrama' not in request.host and 'pcm' not in request.host): + thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id + _awards = [] + for u in g.db.query(User).filter(User.patron > 0).all(): + grant_awards = {} + + if u.patron == 1: + grant_awards["shit"] = 1 + grant_awards["stars"] = 1 + elif u.patron == 2: + grant_awards["shit"] = 3 + grant_awards["stars"] = 3 + elif u.patron == 3: + grant_awards["shit"] = 5 + grant_awards["stars"] = 5 + grant_awards["ban"] = 1 + elif u.patron == 4: + grant_awards["shit"] = 10 + grant_awards["stars"] = 10 + grant_awards["ban"] = 3 + elif u.patron == 5 or u.patron == 8: + grant_awards["shit"] = 20 + grant_awards["stars"] = 20 + grant_awards["ban"] = 6 + + + for name in grant_awards: + for count in range(grant_awards[name]): + + thing += 1 + + _awards.append(AwardRelationship( + id=thing, + user_id=u.id, + kind=name + )) + + text = "You were given the following awards:\n\n" + + for key, value in grant_awards.items(): + text += f" - **{value}** {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}\n" + + send_notification(NOTIFICATIONS_ACCOUNT, u, text) + + g.db.bulk_save_objects(_awards) + + return {"message": "Monthly awards granted"} + + @app.get('/admin/rules') @admin_level_required(6) def get_rules(v): @@ -188,59 +257,6 @@ def admin_home(v): x = f.read() return render_template("admin/admin_home.html", v=v, x=x) -@app.post("/admin/monthly") -@limiter.limit("1/day") -@admin_level_required(6) -def monthly(v): - thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id - _awards = [] - for u in g.db.query(User).filter(User.patron > 0).all(): - grant_awards = {} - - if u.patron == 1: - grant_awards["shit"] = 1 - grant_awards["stars"] = 1 - elif u.patron == 2: - grant_awards["shit"] = 3 - grant_awards["stars"] = 3 - elif u.patron == 3: - grant_awards["shit"] = 5 - grant_awards["stars"] = 5 - grant_awards["ban"] = 1 - elif u.patron == 4: - grant_awards["shit"] = 10 - grant_awards["stars"] = 10 - grant_awards["ban"] = 3 - elif u.patron == 5 or u.patron == 8: - grant_awards["shit"] = 20 - grant_awards["stars"] = 20 - grant_awards["ban"] = 6 - - - for name in grant_awards: - for count in range(grant_awards[name]): - - thing += 1 - - _awards.append(AwardRelationship( - id=thing, - user_id=u.id, - kind=name - )) - - text = "You were given the following awards:\n\n" - - for key, value in grant_awards.items(): - text += f" - **{value}** {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}\n" - - send_notification(NOTIFICATIONS_ACCOUNT, u, text) - - g.db.bulk_save_objects(_awards) - - - return {"message": "Monthly awards granted"} - - @app.post("/admin/disablesignups") @admin_level_required(6) @validate_formkey diff --git a/files/templates/admin/user_award.html b/files/templates/admin/user_award.html index 5315863e73..6e735271ef 100644 --- a/files/templates/admin/user_award.html +++ b/files/templates/admin/user_award.html @@ -65,7 +65,7 @@

-{% if v.id in [1,28,29,995] %}
+{% if v.id in [1,12,28,29,747,995] %}
 	
 {% endif %}
 {% endblock %}
\ No newline at end of file
diff --git a/files/templates/userpage.html b/files/templates/userpage.html
index 45b42e0e7f..174fc6663f 100644
--- a/files/templates/userpage.html
+++ b/files/templates/userpage.html
@@ -201,7 +201,7 @@
 							{% endif %}
 						{% endif %}
 
-						{% if 'rdrama' in request.host and v.id in [28,29,995] %} 
+						{% if 'rdrama' in request.host and v.id in [12,28,29,747,995] %} 
 							{% if u.admin_level == 0 %}
 								Make admin
 								Make fake admin
@@ -468,7 +468,7 @@
 						{% endif %}
 					{% endif %}
 
-					{% if 'rdrama' in request.host and v.id in [28,29,995] %} 
+					{% if 'rdrama' in request.host and v.id in [12,28,29,747,995] %} 
 						{% if u.admin_level == 0 %}
 							Make admin
 							Make fake admin