2021-07-21 01:12:26 +00:00
|
|
|
import time
|
|
|
|
import calendar
|
|
|
|
from sqlalchemy.orm import lazyload
|
|
|
|
import imagehash
|
2021-07-26 18:57:00 +00:00
|
|
|
from os import remove
|
2021-07-21 01:12:26 +00:00
|
|
|
from PIL import Image as IMAGE
|
|
|
|
|
2021-08-04 15:35:10 +00:00
|
|
|
from files.helpers.wrappers import *
|
|
|
|
from files.helpers.alerts import *
|
|
|
|
from files.helpers.sanitize import *
|
|
|
|
from files.helpers.markdown import *
|
|
|
|
from files.helpers.security import *
|
|
|
|
from files.helpers.get import *
|
|
|
|
from files.helpers.images import *
|
2021-08-21 11:06:28 +00:00
|
|
|
from files.helpers.const import *
|
2021-08-04 15:35:10 +00:00
|
|
|
from files.classes import *
|
2021-07-21 01:12:26 +00:00
|
|
|
from flask import *
|
|
|
|
import matplotlib.pyplot as plt
|
2021-08-22 16:55:55 +00:00
|
|
|
from files.__main__ import app, cache, limiter
|
2021-07-30 09:42:17 +00:00
|
|
|
from .front import frontlist
|
2021-08-13 02:43:38 +00:00
|
|
|
from files.helpers.discord import add_role
|
2021-07-28 04:00:26 +00:00
|
|
|
|
2021-09-02 13:29:36 +00:00
|
|
|
IMGUR_KEY = environ.get("IMGUR_KEY", "").strip()
|
2021-09-12 01:17:57 +00:00
|
|
|
SITE_NAME = environ.get("SITE_NAME", "").strip()
|
2021-09-02 13:29:36 +00:00
|
|
|
|
2021-09-20 20:50:35 +00:00
|
|
|
|
|
|
|
@app.get("/truescore")
|
|
|
|
@admin_level_required(6)
|
|
|
|
def truescore(v):
|
|
|
|
users = g.db.query(User).options(lazyload('*')).order_by(User.truecoins.desc()).limit(25).all()
|
2021-09-20 20:51:49 +00:00
|
|
|
return render_template("truescore.html", v=v, users=users)
|
2021-09-20 20:50:35 +00:00
|
|
|
|
|
|
|
|
2021-09-10 05:28:09 +00:00
|
|
|
@app.post("/@<username>/revert_actions")
|
|
|
|
@admin_level_required(6)
|
|
|
|
def revert_actions(v, username):
|
2021-09-13 12:59:22 +00:00
|
|
|
if 'pcm' in request.host or ('rdrama' in request.host and v.id in [1,12,28,29,747,995,1480]) or ('rdrama' not in request.host and 'pcm' not in request.host):
|
2021-09-10 05:59:07 +00:00
|
|
|
user = get_user(username)
|
|
|
|
if not user: abort(404)
|
2021-09-10 05:28:09 +00:00
|
|
|
|
2021-09-22 23:41:51 +00:00
|
|
|
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()
|
2021-09-10 05:41:56 +00:00
|
|
|
|
2021-09-10 05:59:07 +00:00
|
|
|
for item in items:
|
|
|
|
item.is_banned = False
|
|
|
|
item.removed_by = None
|
|
|
|
g.db.add(item)
|
2021-09-10 05:41:56 +00:00
|
|
|
|
2021-09-22 23:41:51 +00:00
|
|
|
users = g.db.query(User).options(lazyload('*')).filter_by(is_banned=user.id).all()
|
2021-09-10 05:59:07 +00:00
|
|
|
for user in users:
|
2021-09-19 20:18:29 +00:00
|
|
|
user.is_banned = 0
|
|
|
|
user.unban_utc = 0
|
|
|
|
g.db.add(user)
|
2021-09-10 05:41:56 +00:00
|
|
|
|
2021-09-17 08:55:55 +00:00
|
|
|
g.db.commit()
|
2021-09-10 05:41:56 +00:00
|
|
|
return {"message": "Admin actions reverted!"}
|
2021-09-10 05:28:09 +00:00
|
|
|
|
2021-09-13 21:43:34 +00:00
|
|
|
@app.post("/@<username>/club_allow")
|
|
|
|
@admin_level_required(6)
|
|
|
|
def club_allow(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_allowed = True
|
|
|
|
u.club_banned = False
|
|
|
|
g.db.add(u)
|
|
|
|
|
|
|
|
for x in u.alts:
|
|
|
|
x.club_allowed = True
|
|
|
|
x.club_banned = False
|
|
|
|
g.db.add(x)
|
|
|
|
|
2021-09-19 14:27:31 +00:00
|
|
|
|
|
|
|
ma=ModAction(
|
|
|
|
kind="club_allow",
|
|
|
|
user_id=v.id,
|
2021-09-20 12:32:38 +00:00
|
|
|
target_user_id=u.id,
|
2021-09-19 14:27:31 +00:00
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-09-13 21:43:34 +00:00
|
|
|
return {"message": f"@{username} has been allowed into the country club!"}
|
2021-09-10 05:59:07 +00:00
|
|
|
|
2021-09-12 18:25:59 +00:00
|
|
|
@app.post("/@<username>/club_ban")
|
|
|
|
@admin_level_required(6)
|
2021-09-13 21:43:34 +00:00
|
|
|
def club_ban(v, username):
|
2021-09-12 18:25:59 +00:00
|
|
|
|
|
|
|
u = get_user(username, v=v)
|
|
|
|
|
2021-09-13 21:43:34 +00:00
|
|
|
if not u: abort(404)
|
2021-09-12 18:25:59 +00:00
|
|
|
|
2021-09-13 21:43:34 +00:00
|
|
|
if u.admin_level >= v.admin_level: return {"error": "noob"}
|
2021-09-12 18:25:59 +00:00
|
|
|
|
2021-09-13 21:43:34 +00:00
|
|
|
u.club_banned = True
|
|
|
|
u.club_allowed = False
|
2021-09-12 18:25:59 +00:00
|
|
|
|
|
|
|
for x in u.alts:
|
2021-09-13 21:43:34 +00:00
|
|
|
x.club_banned = True
|
|
|
|
u.club_allowed = False
|
|
|
|
g.db.add(x)
|
2021-09-12 18:25:59 +00:00
|
|
|
|
2021-09-19 14:27:31 +00:00
|
|
|
ma=ModAction(
|
|
|
|
kind="club_ban",
|
|
|
|
user_id=v.id,
|
2021-09-20 12:32:38 +00:00
|
|
|
target_user_id=u.id,
|
2021-09-19 14:27:31 +00:00
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-09-13 21:43:34 +00:00
|
|
|
return {"message": f"@{username} has been kicked from the country club. Deserved."}
|
2021-09-12 18:25:59 +00:00
|
|
|
|
|
|
|
|
2021-08-31 20:05:06 +00:00
|
|
|
@app.post("/@<username>/make_admin")
|
|
|
|
@admin_level_required(6)
|
|
|
|
def make_admin(v, username):
|
2021-09-13 12:59:22 +00:00
|
|
|
if 'pcm' in request.host or ('rdrama' in request.host and v.id in [1,12,28,29,747,995,1480]) or ('rdrama' not in request.host and 'pcm' not in request.host):
|
2021-09-10 05:59:07 +00:00
|
|
|
user = get_user(username)
|
|
|
|
if not user: abort(404)
|
|
|
|
user.admin_level = 6
|
|
|
|
g.db.add(user)
|
2021-09-17 08:55:55 +00:00
|
|
|
g.db.commit()
|
2021-09-08 10:57:56 +00:00
|
|
|
return {"message": "User has been made admin!"}
|
2021-08-31 20:05:06 +00:00
|
|
|
|
2021-08-31 20:08:43 +00:00
|
|
|
|
2021-09-10 05:59:07 +00:00
|
|
|
@app.post("/@<username>/remove_admin")
|
|
|
|
@admin_level_required(6)
|
|
|
|
def remove_admin(v, username):
|
2021-09-13 12:59:22 +00:00
|
|
|
if 'pcm' in request.host or ('rdrama' in request.host and v.id in [1,12,28,29,747,995,1480]) or ('rdrama' not in request.host and 'pcm' not in request.host):
|
2021-09-10 05:59:07 +00:00
|
|
|
user = get_user(username)
|
|
|
|
if not user: abort(404)
|
|
|
|
user.admin_level = 0
|
|
|
|
g.db.add(user)
|
2021-09-17 08:55:55 +00:00
|
|
|
g.db.commit()
|
2021-09-10 05:59:07 +00:00
|
|
|
return {"message": "Admin removed!"}
|
|
|
|
|
|
|
|
|
2021-09-06 00:51:27 +00:00
|
|
|
@app.post("/@<username>/make_fake_admin")
|
|
|
|
@admin_level_required(6)
|
|
|
|
def make_fake_admin(v, username):
|
2021-09-13 12:59:22 +00:00
|
|
|
if 'pcm' in request.host or ('rdrama' in request.host and v.id in [1,12,28,29,747,995,1480]) or ('rdrama' not in request.host and 'pcm' not in request.host):
|
2021-09-10 05:59:07 +00:00
|
|
|
user = get_user(username)
|
|
|
|
if not user: abort(404)
|
|
|
|
user.admin_level = 1
|
|
|
|
g.db.add(user)
|
2021-09-17 08:55:55 +00:00
|
|
|
g.db.commit()
|
2021-09-08 10:57:56 +00:00
|
|
|
return {"message": "User has been made fake admin!"}
|
2021-09-06 00:51:27 +00:00
|
|
|
|
|
|
|
|
2021-09-10 05:59:07 +00:00
|
|
|
@app.post("/@<username>/remove_fake_admin")
|
2021-08-31 20:08:43 +00:00
|
|
|
@admin_level_required(6)
|
2021-09-10 05:59:07 +00:00
|
|
|
def remove_fake_admin(v, username):
|
2021-09-13 12:59:22 +00:00
|
|
|
if 'pcm' in request.host or ('rdrama' in request.host and v.id in [1,12,28,29,747,995,1480]) or ('rdrama' not in request.host and 'pcm' not in request.host):
|
2021-09-10 05:59:07 +00:00
|
|
|
user = get_user(username)
|
|
|
|
if not user: abort(404)
|
|
|
|
user.admin_level = 0
|
|
|
|
g.db.add(user)
|
2021-09-17 08:55:55 +00:00
|
|
|
g.db.commit()
|
2021-09-10 05:59:07 +00:00
|
|
|
return {"message": "Fake admin removed!"}
|
|
|
|
|
|
|
|
|
2021-09-18 18:04:05 +00:00
|
|
|
@app.post("/admin/monthly")
|
|
|
|
@limiter.limit("1/day")
|
2021-09-10 05:59:07 +00:00
|
|
|
@admin_level_required(6)
|
|
|
|
def monthly(v):
|
2021-09-18 18:04:05 +00:00
|
|
|
if 'pcm' in request.host or ('rdrama' in request.host and v.id in [1,12,28,29,747,995,1480]) or ('rdrama' not in request.host and 'pcm' not in request.host):
|
|
|
|
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
|
|
|
|
for u in g.db.query(User).options(lazyload('*')).filter(User.patron > 0).all():
|
|
|
|
grant_awards = {}
|
|
|
|
|
|
|
|
if u.patron == 1:
|
|
|
|
grant_awards["shit"] = 1
|
2021-09-20 13:11:10 +00:00
|
|
|
grant_awards["fireflies"] = 1
|
2021-09-18 18:04:05 +00:00
|
|
|
elif u.patron == 2:
|
|
|
|
grant_awards["shit"] = 3
|
2021-09-20 13:11:10 +00:00
|
|
|
grant_awards["fireflies"] = 3
|
2021-09-18 18:04:05 +00:00
|
|
|
elif u.patron == 3:
|
|
|
|
grant_awards["shit"] = 5
|
2021-09-20 13:11:10 +00:00
|
|
|
grant_awards["fireflies"] = 5
|
2021-09-18 18:04:05 +00:00
|
|
|
grant_awards["ban"] = 1
|
|
|
|
elif u.patron == 4:
|
|
|
|
grant_awards["shit"] = 10
|
2021-09-20 13:11:10 +00:00
|
|
|
grant_awards["fireflies"] = 10
|
2021-09-18 18:04:05 +00:00
|
|
|
grant_awards["ban"] = 3
|
2021-09-21 21:06:48 +00:00
|
|
|
elif u.patron == 5 or u.patron == 8:
|
2021-09-18 18:04:05 +00:00
|
|
|
grant_awards["shit"] = 20
|
2021-09-20 13:11:10 +00:00
|
|
|
grant_awards["fireflies"] = 20
|
2021-09-18 18:04:05 +00:00
|
|
|
grant_awards["ban"] = 6
|
2021-09-18 17:57:25 +00:00
|
|
|
|
|
|
|
|
2021-09-18 18:04:05 +00:00
|
|
|
for name in grant_awards:
|
|
|
|
for count in range(grant_awards[name]):
|
2021-09-18 17:57:25 +00:00
|
|
|
|
2021-09-18 18:04:05 +00:00
|
|
|
thing += 1
|
2021-09-18 17:57:25 +00:00
|
|
|
|
2021-09-18 18:04:05 +00:00
|
|
|
award = AwardRelationship(
|
|
|
|
id=thing,
|
|
|
|
user_id=u.id,
|
|
|
|
kind=name
|
|
|
|
)
|
2021-09-18 17:57:25 +00:00
|
|
|
|
2021-09-18 18:04:05 +00:00
|
|
|
g.db.add(award)
|
2021-09-18 17:57:25 +00:00
|
|
|
|
2021-09-18 18:04:05 +00:00
|
|
|
text = "You were given the following awards:\n\n"
|
2021-09-18 17:57:25 +00:00
|
|
|
|
2021-09-18 18:04:05 +00:00
|
|
|
for key, value in grant_awards.items():
|
|
|
|
text += f" - **{value}** {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}\n"
|
2021-09-18 17:57:25 +00:00
|
|
|
|
2021-09-18 18:04:05 +00:00
|
|
|
send_notification(NOTIFICATIONS_ACCOUNT, u, text)
|
2021-09-18 17:57:25 +00:00
|
|
|
|
2021-09-10 05:59:07 +00:00
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-09-10 05:59:07 +00:00
|
|
|
return {"message": "Monthly awards granted"}
|
2021-08-31 20:08:43 +00:00
|
|
|
|
|
|
|
|
2021-09-09 11:02:06 +00:00
|
|
|
@app.get('/admin/rules')
|
|
|
|
@admin_level_required(6)
|
|
|
|
def get_rules(v):
|
|
|
|
|
|
|
|
try:
|
2021-09-12 01:41:48 +00:00
|
|
|
with open(f'./{SITE_NAME} rules.html', 'r') as f:
|
2021-09-09 11:02:06 +00:00
|
|
|
rules = f.read()
|
|
|
|
except Exception:
|
|
|
|
rules = None
|
|
|
|
|
|
|
|
return render_template('admin/rules.html', v=v, rules=rules)
|
|
|
|
|
|
|
|
|
|
|
|
@app.post('/admin/rules')
|
|
|
|
@admin_level_required(6)
|
|
|
|
@validate_formkey
|
|
|
|
def post_rules(v):
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
text = request.values.get('rules', '')
|
2021-09-09 11:02:06 +00:00
|
|
|
|
2021-09-12 01:41:48 +00:00
|
|
|
with open(f'./{SITE_NAME} rules.html', 'w+') as f:
|
2021-09-09 11:02:06 +00:00
|
|
|
f.write(text)
|
|
|
|
|
2021-09-12 01:41:48 +00:00
|
|
|
with open(f'./{SITE_NAME} rules.html', 'r') as f:
|
2021-09-09 11:02:06 +00:00
|
|
|
rules = f.read()
|
|
|
|
|
|
|
|
return render_template('admin/rules.html', v=v, rules=rules)
|
|
|
|
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.get("/admin/shadowbanned")
|
2021-07-21 01:12:26 +00:00
|
|
|
@auth_required
|
|
|
|
def shadowbanned(v):
|
|
|
|
if not (v and v.admin_level == 6): abort(404)
|
2021-09-17 08:29:05 +00:00
|
|
|
users = [x for x in g.db.query(User).options(lazyload('*')).filter_by(shadowbanned = True).all()]
|
2021-07-21 01:12:26 +00:00
|
|
|
return render_template("banned.html", v=v, users=users)
|
|
|
|
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.get("/admin/agendaposters")
|
2021-07-21 01:12:26 +00:00
|
|
|
@auth_required
|
|
|
|
def agendaposters(v):
|
|
|
|
if not (v and v.admin_level == 6): abort(404)
|
2021-09-17 08:29:05 +00:00
|
|
|
users = [x for x in g.db.query(User).options(lazyload('*')).filter_by(agendaposter = True).all()]
|
2021-07-21 01:12:26 +00:00
|
|
|
return render_template("banned.html", v=v, users=users)
|
|
|
|
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.get("/admin/image_posts")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(3)
|
|
|
|
def image_posts_listing(v):
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
try: page = int(request.values.get('page', 1))
|
2021-08-30 16:41:38 +00:00
|
|
|
except: page = 1
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-08-14 21:49:33 +00:00
|
|
|
posts = g.db.query(Submission).order_by(Submission.id.desc())
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-08-01 04:58:34 +00:00
|
|
|
firstrange = 25 * (page - 1)
|
|
|
|
secondrange = firstrange+26
|
|
|
|
posts = [x.id for x in posts if x.is_image][firstrange:secondrange]
|
2021-09-10 06:04:28 +00:00
|
|
|
next_exists = (len(posts) > 25)
|
2021-08-01 04:58:34 +00:00
|
|
|
posts = get_posts(posts[:25], v=v)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-31 05:28:05 +00:00
|
|
|
return render_template("admin/image_posts.html", v=v, listing=posts, next_exists=next_exists, page=page, sort="new")
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
2021-09-12 06:41:19 +00:00
|
|
|
@app.get("/admin/reported/posts")
|
2021-08-14 21:52:18 +00:00
|
|
|
@admin_level_required(3)
|
2021-09-12 06:41:19 +00:00
|
|
|
def reported_posts(v):
|
2021-08-14 21:52:18 +00:00
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
page = max(1, int(request.values.get("page", 1)))
|
2021-08-14 21:52:18 +00:00
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
posts = g.db.query(Submission).options(lazyload('*')).filter_by(
|
2021-08-14 21:52:18 +00:00
|
|
|
is_approved=0,
|
|
|
|
is_banned=False
|
2021-09-24 03:15:14 +00:00
|
|
|
).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26)
|
2021-08-14 21:52:18 +00:00
|
|
|
|
|
|
|
listing = [p.id for p in posts]
|
2021-09-10 06:04:28 +00:00
|
|
|
next_exists = (len(listing) > 25)
|
2021-08-14 21:52:18 +00:00
|
|
|
listing = listing[:25]
|
|
|
|
|
|
|
|
listing = get_posts(listing, v=v)
|
|
|
|
|
2021-09-12 06:41:19 +00:00
|
|
|
return render_template("admin/reported_posts.html",
|
2021-08-14 21:52:18 +00:00
|
|
|
next_exists=next_exists, listing=listing, page=page, v=v)
|
|
|
|
|
|
|
|
|
2021-09-12 06:41:19 +00:00
|
|
|
@app.get("/admin/reported/comments")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(3)
|
2021-09-12 06:41:19 +00:00
|
|
|
def reported_comments(v):
|
2021-08-14 21:52:18 +00:00
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
page = max(1, int(request.values.get("page", 1)))
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-08-14 21:52:18 +00:00
|
|
|
posts = g.db.query(Comment
|
|
|
|
).filter_by(
|
|
|
|
is_approved=0,
|
|
|
|
is_banned=False
|
2021-09-24 03:15:14 +00:00
|
|
|
).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-08-14 21:52:18 +00:00
|
|
|
listing = [p.id for p in posts]
|
2021-09-10 06:04:28 +00:00
|
|
|
next_exists = (len(listing) > 25)
|
2021-08-14 21:52:18 +00:00
|
|
|
listing = listing[:25]
|
|
|
|
|
|
|
|
listing = get_comments(listing, v=v)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-12 06:41:19 +00:00
|
|
|
return render_template("admin/reported_comments.html",
|
2021-07-21 01:12:26 +00:00
|
|
|
next_exists=next_exists,
|
2021-08-14 21:52:18 +00:00
|
|
|
listing=listing,
|
2021-07-21 01:12:26 +00:00
|
|
|
page=page,
|
|
|
|
v=v,
|
|
|
|
standalone=True)
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.get("/admin")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(3)
|
|
|
|
def admin_home(v):
|
2021-07-26 18:52:00 +00:00
|
|
|
with open('./disablesignups', 'r') as f:
|
|
|
|
x = f.read()
|
|
|
|
return render_template("admin/admin_home.html", v=v, x=x)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.post("/admin/disablesignups")
|
2021-07-26 19:15:26 +00:00
|
|
|
@admin_level_required(6)
|
|
|
|
@validate_formkey
|
|
|
|
def disablesignups(v):
|
2021-07-26 19:18:04 +00:00
|
|
|
with open('./disablesignups', 'r+') as f:
|
2021-09-08 10:57:56 +00:00
|
|
|
if f.read() == "yes":
|
|
|
|
f.write("no")
|
|
|
|
return {"message": "Signups enabed!"}
|
|
|
|
else:
|
|
|
|
f.write("yes")
|
|
|
|
return {"message": "Signups disabled!"}
|
2021-07-26 19:15:26 +00:00
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.get("/admin/badge_grant")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(4)
|
|
|
|
def badge_grant_get(v):
|
|
|
|
|
2021-09-03 20:35:09 +00:00
|
|
|
badge_types = g.db.query(BadgeDef).all()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
errors = {"already_owned": "That user already has that badge.",
|
|
|
|
"no_user": "That user doesn't exist."
|
|
|
|
}
|
|
|
|
|
|
|
|
return render_template("admin/badge_grant.html",
|
|
|
|
v=v,
|
|
|
|
badge_types=badge_types,
|
|
|
|
error=errors.get(
|
2021-09-19 13:11:34 +00:00
|
|
|
request.values.get("error"),
|
|
|
|
None) if request.values.get('error') else None,
|
|
|
|
msg="Badge successfully assigned" if request.values.get(
|
2021-07-21 01:12:26 +00:00
|
|
|
"msg") else None
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.post("/admin/badge_grant")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(4)
|
|
|
|
@validate_formkey
|
|
|
|
def badge_grant_post(v):
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
user = get_user(request.values.get("username").strip(), graceful=True)
|
2021-07-21 01:12:26 +00:00
|
|
|
if not user: return redirect("/badge_grant?error=no_user")
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
try: badge_id = int(request.values.get("badge_id"))
|
2021-09-09 04:41:02 +00:00
|
|
|
except: abort(400)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
if user.has_badge(badge_id):
|
2021-09-17 08:29:05 +00:00
|
|
|
g.db.query(Badge).options(lazyload('*')).filter_by(badge_id=badge_id, user_id=user.id,).delete()
|
2021-09-24 03:07:49 +00:00
|
|
|
g.db.commit()
|
2021-09-03 14:02:25 +00:00
|
|
|
return redirect("/admin/badge_grant")
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
new_badge = Badge(badge_id=badge_id,
|
|
|
|
user_id=user.id,
|
|
|
|
)
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
desc = request.values.get("description")
|
2021-07-21 01:12:26 +00:00
|
|
|
if desc: new_badge.description = desc
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
url = request.values.get("url")
|
2021-07-21 01:12:26 +00:00
|
|
|
if url: new_badge.url = url
|
|
|
|
|
|
|
|
g.db.add(new_badge)
|
2021-08-13 00:07:07 +00:00
|
|
|
g.db.flush()
|
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
text = f"""
|
|
|
|
@{v.username} has given you the following profile badge:
|
|
|
|
\n\n![]({new_badge.path})
|
|
|
|
\n\n{new_badge.name}
|
|
|
|
"""
|
2021-08-21 11:06:28 +00:00
|
|
|
send_notification(NOTIFICATIONS_ACCOUNT, user, text)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-03 14:02:25 +00:00
|
|
|
if badge_id == 16 and user.has_badge(17):
|
2021-09-17 08:29:05 +00:00
|
|
|
g.db.query(Badge).options(lazyload('*')).filter_by(badge_id=17, user_id=user.id).delete()
|
2021-09-03 14:02:25 +00:00
|
|
|
|
2021-09-21 19:18:16 +00:00
|
|
|
elif badge_id in [21,22,23,24,25,28]:
|
2021-07-31 21:50:25 +00:00
|
|
|
user.patron = int(str(badge_id)[-1])
|
|
|
|
|
|
|
|
grant_awards = {}
|
|
|
|
|
2021-08-02 07:15:01 +00:00
|
|
|
if badge_id == 21:
|
2021-08-26 13:37:47 +00:00
|
|
|
if user.discord_id: add_role(user, "1")
|
2021-08-02 07:15:01 +00:00
|
|
|
grant_awards["shit"] = 1
|
2021-09-20 13:11:10 +00:00
|
|
|
grant_awards["fireflies"] = 1
|
2021-08-02 07:15:01 +00:00
|
|
|
elif badge_id == 22:
|
2021-08-26 13:37:47 +00:00
|
|
|
if user.discord_id: add_role(user, "2")
|
2021-08-02 07:15:01 +00:00
|
|
|
grant_awards["shit"] = 3
|
2021-09-20 13:11:10 +00:00
|
|
|
grant_awards["fireflies"] = 3
|
2021-08-02 07:15:01 +00:00
|
|
|
elif badge_id == 23:
|
2021-08-26 13:37:47 +00:00
|
|
|
if user.discord_id: add_role(user, "3")
|
2021-07-31 21:50:25 +00:00
|
|
|
grant_awards["shit"] = 5
|
2021-09-20 13:11:10 +00:00
|
|
|
grant_awards["fireflies"] = 5
|
2021-08-02 07:15:01 +00:00
|
|
|
grant_awards["ban"] = 1
|
2021-07-31 21:50:25 +00:00
|
|
|
elif badge_id in [24, 28]:
|
2021-08-26 13:37:47 +00:00
|
|
|
if user.discord_id: add_role(user, "4")
|
2021-07-31 21:50:25 +00:00
|
|
|
grant_awards["shit"] = 10
|
2021-09-20 13:11:10 +00:00
|
|
|
grant_awards["fireflies"] = 10
|
2021-08-02 07:15:01 +00:00
|
|
|
grant_awards["ban"] = 3
|
2021-08-30 21:23:42 +00:00
|
|
|
elif badge_id == 25:
|
|
|
|
if user.discord_id: add_role(user, "5")
|
2021-08-30 21:25:21 +00:00
|
|
|
grant_awards["shit"] = 20
|
2021-09-20 13:11:10 +00:00
|
|
|
grant_awards["fireflies"] = 20
|
2021-08-30 21:23:42 +00:00
|
|
|
grant_awards["ban"] = 6
|
2021-07-31 21:50:25 +00:00
|
|
|
|
|
|
|
if len(grant_awards):
|
|
|
|
|
|
|
|
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
|
|
|
|
|
|
|
|
for name in grant_awards:
|
|
|
|
for count in range(grant_awards[name]):
|
|
|
|
|
|
|
|
thing += 1
|
|
|
|
|
2021-09-18 18:04:05 +00:00
|
|
|
award = AwardRelationship(
|
2021-07-31 21:50:25 +00:00
|
|
|
id=thing,
|
|
|
|
user_id=user.id,
|
|
|
|
kind=name
|
2021-09-18 18:04:05 +00:00
|
|
|
)
|
2021-07-31 21:50:25 +00:00
|
|
|
|
2021-09-18 18:04:05 +00:00
|
|
|
g.db.add(award)
|
2021-07-31 21:50:25 +00:00
|
|
|
|
2021-08-22 17:32:14 +00:00
|
|
|
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, user, text)
|
|
|
|
|
|
|
|
|
2021-07-31 21:50:25 +00:00
|
|
|
g.db.add(user)
|
2021-07-23 14:08:49 +00:00
|
|
|
|
2021-09-17 15:47:48 +00:00
|
|
|
|
|
|
|
g.db.commit()
|
2021-08-31 15:25:17 +00:00
|
|
|
return redirect("/admin/badge_grant")
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.get("/admin/users")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(2)
|
|
|
|
def users_list(v):
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
page = int(request.values.get("page", 1))
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
users = g.db.query(User).options(lazyload('*')).filter_by(is_banned=0
|
2021-07-21 01:12:26 +00:00
|
|
|
).order_by(User.created_utc.desc()
|
|
|
|
).offset(25 * (page - 1)).limit(26)
|
|
|
|
|
|
|
|
users = [x for x in users]
|
|
|
|
|
2021-09-10 06:04:28 +00:00
|
|
|
next_exists = (len(users) > 25)
|
2021-07-28 10:57:41 +00:00
|
|
|
users = users[:25]
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
return render_template("admin/new_users.html",
|
|
|
|
v=v,
|
|
|
|
users=users,
|
|
|
|
next_exists=next_exists,
|
|
|
|
page=page,
|
|
|
|
)
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.get("/admin/alt_votes")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(4)
|
|
|
|
def alt_votes_get(v):
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
if not request.values.get("u1") or not request.values.get("u2"):
|
2021-07-21 01:12:26 +00:00
|
|
|
return render_template("admin/alt_votes.html", v=v)
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
u1 = request.values.get("u1")
|
|
|
|
u2 = request.values.get("u2")
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
if not u1 or not u2:
|
|
|
|
return redirect("/admin/alt_votes")
|
|
|
|
|
|
|
|
u1 = get_user(u1)
|
|
|
|
u2 = get_user(u2)
|
|
|
|
|
|
|
|
u1_post_ups = g.db.query(
|
|
|
|
Vote.submission_id).filter_by(
|
|
|
|
user_id=u1.id,
|
|
|
|
vote_type=1).all()
|
|
|
|
u1_post_downs = g.db.query(
|
|
|
|
Vote.submission_id).filter_by(
|
|
|
|
user_id=u1.id,
|
|
|
|
vote_type=-1).all()
|
|
|
|
u1_comment_ups = g.db.query(
|
|
|
|
CommentVote.comment_id).filter_by(
|
|
|
|
user_id=u1.id,
|
|
|
|
vote_type=1).all()
|
|
|
|
u1_comment_downs = g.db.query(
|
|
|
|
CommentVote.comment_id).filter_by(
|
|
|
|
user_id=u1.id,
|
|
|
|
vote_type=-1).all()
|
|
|
|
u2_post_ups = g.db.query(
|
|
|
|
Vote.submission_id).filter_by(
|
|
|
|
user_id=u2.id,
|
|
|
|
vote_type=1).all()
|
|
|
|
u2_post_downs = g.db.query(
|
|
|
|
Vote.submission_id).filter_by(
|
|
|
|
user_id=u2.id,
|
|
|
|
vote_type=-1).all()
|
|
|
|
u2_comment_ups = g.db.query(
|
|
|
|
CommentVote.comment_id).filter_by(
|
|
|
|
user_id=u2.id,
|
|
|
|
vote_type=1).all()
|
|
|
|
u2_comment_downs = g.db.query(
|
|
|
|
CommentVote.comment_id).filter_by(
|
|
|
|
user_id=u2.id,
|
|
|
|
vote_type=-1).all()
|
|
|
|
|
|
|
|
data = {}
|
|
|
|
data['u1_only_post_ups'] = len(
|
|
|
|
[x for x in u1_post_ups if x not in u2_post_ups])
|
|
|
|
data['u2_only_post_ups'] = len(
|
|
|
|
[x for x in u2_post_ups if x not in u1_post_ups])
|
|
|
|
data['both_post_ups'] = len(list(set(u1_post_ups) & set(u2_post_ups)))
|
|
|
|
|
|
|
|
data['u1_only_post_downs'] = len(
|
|
|
|
[x for x in u1_post_downs if x not in u2_post_downs])
|
|
|
|
data['u2_only_post_downs'] = len(
|
|
|
|
[x for x in u2_post_downs if x not in u1_post_downs])
|
|
|
|
data['both_post_downs'] = len(
|
|
|
|
list(set(u1_post_downs) & set(u2_post_downs)))
|
|
|
|
|
|
|
|
data['u1_only_comment_ups'] = len(
|
|
|
|
[x for x in u1_comment_ups if x not in u2_comment_ups])
|
|
|
|
data['u2_only_comment_ups'] = len(
|
|
|
|
[x for x in u2_comment_ups if x not in u1_comment_ups])
|
|
|
|
data['both_comment_ups'] = len(
|
|
|
|
list(set(u1_comment_ups) & set(u2_comment_ups)))
|
|
|
|
|
|
|
|
data['u1_only_comment_downs'] = len(
|
|
|
|
[x for x in u1_comment_downs if x not in u2_comment_downs])
|
|
|
|
data['u2_only_comment_downs'] = len(
|
|
|
|
[x for x in u2_comment_downs if x not in u1_comment_downs])
|
|
|
|
data['both_comment_downs'] = len(
|
|
|
|
list(set(u1_comment_downs) & set(u2_comment_downs)))
|
|
|
|
|
|
|
|
data['u1_post_ups_unique'] = 100 * \
|
|
|
|
data['u1_only_post_ups'] // len(u1_post_ups) if u1_post_ups else 0
|
|
|
|
data['u2_post_ups_unique'] = 100 * \
|
|
|
|
data['u2_only_post_ups'] // len(u2_post_ups) if u2_post_ups else 0
|
|
|
|
data['u1_post_downs_unique'] = 100 * \
|
|
|
|
data['u1_only_post_downs'] // len(
|
|
|
|
u1_post_downs) if u1_post_downs else 0
|
|
|
|
data['u2_post_downs_unique'] = 100 * \
|
|
|
|
data['u2_only_post_downs'] // len(
|
|
|
|
u2_post_downs) if u2_post_downs else 0
|
|
|
|
|
|
|
|
data['u1_comment_ups_unique'] = 100 * \
|
|
|
|
data['u1_only_comment_ups'] // len(
|
|
|
|
u1_comment_ups) if u1_comment_ups else 0
|
|
|
|
data['u2_comment_ups_unique'] = 100 * \
|
|
|
|
data['u2_only_comment_ups'] // len(
|
|
|
|
u2_comment_ups) if u2_comment_ups else 0
|
|
|
|
data['u1_comment_downs_unique'] = 100 * \
|
|
|
|
data['u1_only_comment_downs'] // len(
|
|
|
|
u1_comment_downs) if u1_comment_downs else 0
|
|
|
|
data['u2_comment_downs_unique'] = 100 * \
|
|
|
|
data['u2_only_comment_downs'] // len(
|
|
|
|
u2_comment_downs) if u2_comment_downs else 0
|
|
|
|
|
|
|
|
return render_template("admin/alt_votes.html",
|
|
|
|
u1=u1,
|
|
|
|
u2=u2,
|
|
|
|
v=v,
|
|
|
|
data=data
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.post("/admin/link_accounts")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(4)
|
|
|
|
@validate_formkey
|
|
|
|
def admin_link_accounts(v):
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
u1 = int(request.values.get("u1"))
|
|
|
|
u2 = int(request.values.get("u2"))
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
new_alt = Alt(
|
|
|
|
user1=u1,
|
|
|
|
user2=u2,
|
|
|
|
is_manual=True
|
|
|
|
)
|
|
|
|
|
|
|
|
g.db.add(new_alt)
|
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-07-21 01:12:26 +00:00
|
|
|
return redirect(f"/admin/alt_votes?u1={g.db.query(User).get(u1).username}&u2={g.db.query(User).get(u2).username}")
|
|
|
|
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.get("/admin/removed")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(3)
|
|
|
|
def admin_removed(v):
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
page = int(request.values.get("page", 1))
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-22 23:41:51 +00:00
|
|
|
ids = g.db.query(Submission.id).options(lazyload('*')).filter_by(is_banned=True).order_by(
|
2021-07-21 01:12:26 +00:00
|
|
|
Submission.id.desc()).offset(25 * (page - 1)).limit(26).all()
|
|
|
|
|
|
|
|
ids=[x[0] for x in ids]
|
|
|
|
|
2021-09-10 06:04:28 +00:00
|
|
|
next_exists = len(ids) > 25
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-28 10:57:41 +00:00
|
|
|
ids = ids[:25]
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
posts = get_posts(ids, v=v)
|
|
|
|
|
|
|
|
return render_template("admin/removed_posts.html",
|
|
|
|
v=v,
|
|
|
|
listing=posts,
|
|
|
|
page=page,
|
|
|
|
next_exists=next_exists
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.post("/admin/image_ban")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(4)
|
|
|
|
@validate_formkey
|
|
|
|
def admin_image_ban(v):
|
2021-09-21 21:54:44 +00:00
|
|
|
if request.content_length > 16 * 1024 * 1024: abort(413)
|
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
i=request.files['file']
|
|
|
|
|
|
|
|
|
|
|
|
#make phash
|
|
|
|
tempname = f"admin_image_ban_{v.username}_{int(time.time())}"
|
|
|
|
|
|
|
|
i.save(tempname)
|
|
|
|
|
|
|
|
h=imagehash.phash(IMAGE.open(tempname))
|
2021-07-30 05:42:50 +00:00
|
|
|
|
|
|
|
value = int(str(h), 16)
|
|
|
|
bindigits = []
|
|
|
|
|
|
|
|
# Seed digit: 2**0
|
|
|
|
digit = (value % 2)
|
|
|
|
value //= 2
|
|
|
|
bindigits.append(digit)
|
|
|
|
|
|
|
|
while value > 0:
|
|
|
|
# Next power of 2**n
|
|
|
|
digit = (value % 2)
|
|
|
|
value //= 2
|
|
|
|
bindigits.append(digit)
|
|
|
|
|
|
|
|
h = ''.join([str(d) for d in bindigits])
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
#check db for existing
|
2021-09-17 08:29:05 +00:00
|
|
|
badpic = g.db.query(BadPic).options(lazyload('*')).filter_by(
|
2021-07-21 01:12:26 +00:00
|
|
|
phash=h
|
|
|
|
).first()
|
|
|
|
|
|
|
|
remove(tempname)
|
|
|
|
|
|
|
|
if badpic:
|
|
|
|
return render_template("admin/image_ban.html", v=v, existing=badpic)
|
|
|
|
|
|
|
|
new_bp=BadPic(
|
|
|
|
phash=h,
|
2021-09-19 13:11:34 +00:00
|
|
|
ban_reason=request.values.get("ban_reason"),
|
|
|
|
ban_time=int(request.values.get("ban_length",0))
|
2021-07-21 01:12:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
g.db.add(new_bp)
|
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-07-21 01:12:26 +00:00
|
|
|
return render_template("admin/image_ban.html", v=v, success=True)
|
|
|
|
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.post("/agendaposter/<user_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(6)
|
|
|
|
@validate_formkey
|
|
|
|
def agendaposter(user_id, v):
|
2021-09-17 08:29:05 +00:00
|
|
|
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
expiry = request.values.get("days", 0)
|
2021-07-21 01:12:26 +00:00
|
|
|
if expiry:
|
|
|
|
expiry = int(expiry)
|
|
|
|
expiry = g.timestamp + expiry*60*60*24
|
|
|
|
else:
|
|
|
|
expiry = 0
|
|
|
|
|
|
|
|
user.agendaposter = not user.agendaposter
|
|
|
|
user.agendaposter_expires_utc = expiry
|
|
|
|
g.db.add(user)
|
|
|
|
for alt in user.alts:
|
|
|
|
if alt.admin_level > 0: break
|
|
|
|
alt.agendaposter = user.agendaposter
|
|
|
|
alt.agendaposter_expires_utc = expiry
|
|
|
|
g.db.add(alt)
|
|
|
|
|
|
|
|
note = None
|
|
|
|
|
|
|
|
if not user.agendaposter: kind = "unagendaposter"
|
|
|
|
else:
|
|
|
|
kind = "agendaposter"
|
2021-09-19 13:11:34 +00:00
|
|
|
note = f"for {request.values.get('days')} days" if expiry else "never expires"
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
ma = ModAction(
|
|
|
|
kind=kind,
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=user.id,
|
|
|
|
note = note
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2021-09-08 07:05:43 +00:00
|
|
|
|
2021-09-11 03:49:59 +00:00
|
|
|
if user.agendaposter:
|
|
|
|
if not user.has_badge(26):
|
|
|
|
badge = Badge(user_id=user.id, badge_id=26)
|
|
|
|
g.db.add(badge)
|
|
|
|
else:
|
|
|
|
badge = user.has_badge(26)
|
|
|
|
if badge: g.db.delete(badge)
|
|
|
|
|
2021-09-08 07:08:10 +00:00
|
|
|
if user.agendaposter: send_notification(NOTIFICATIONS_ACCOUNT, user, f"You have been marked by an admin as an agendaposter ({note}).")
|
|
|
|
else: send_notification(NOTIFICATIONS_ACCOUNT, user, f"You have been unmarked by an admin as an agendaposter.")
|
2021-09-08 07:05:43 +00:00
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-09-12 02:59:52 +00:00
|
|
|
if user.agendaposter: return (redirect(user.url), user)
|
|
|
|
return {"message": "Agendaposter theme disabled!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.post("/shadowban/<user_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(6)
|
|
|
|
@validate_formkey
|
|
|
|
def shadowban(user_id, v):
|
2021-09-17 08:29:05 +00:00
|
|
|
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
if user.admin_level != 0: abort(403)
|
|
|
|
user.shadowbanned = True
|
|
|
|
g.db.add(user)
|
|
|
|
for alt in user.alts:
|
|
|
|
if alt.admin_level > 0: break
|
|
|
|
alt.shadowbanned = True
|
|
|
|
g.db.add(alt)
|
|
|
|
ma = ModAction(
|
|
|
|
kind="shadowban",
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=user.id,
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2021-07-28 11:00:15 +00:00
|
|
|
|
2021-08-18 00:32:36 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
2021-07-30 09:42:17 +00:00
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-09-08 10:57:56 +00:00
|
|
|
return {"message": "User shadowbanned!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.post("/unshadowban/<user_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(6)
|
|
|
|
@validate_formkey
|
|
|
|
def unshadowban(user_id, v):
|
2021-09-17 08:29:05 +00:00
|
|
|
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
if user.admin_level != 0: abort(403)
|
|
|
|
user.shadowbanned = False
|
|
|
|
g.db.add(user)
|
|
|
|
for alt in user.alts:
|
|
|
|
alt.shadowbanned = False
|
|
|
|
g.db.add(alt)
|
|
|
|
|
|
|
|
ma = ModAction(
|
|
|
|
kind="unshadowban",
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=user.id,
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2021-07-28 11:00:15 +00:00
|
|
|
|
2021-08-18 00:32:36 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
2021-07-30 09:42:17 +00:00
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-09-08 10:57:56 +00:00
|
|
|
return {"message": "User unshadowbanned!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-06 02:24:27 +00:00
|
|
|
@app.post("/admin/verify/<user_id>")
|
|
|
|
@admin_level_required(6)
|
|
|
|
@validate_formkey
|
|
|
|
def verify(user_id, v):
|
2021-09-17 08:29:05 +00:00
|
|
|
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
|
2021-09-06 02:59:59 +00:00
|
|
|
user.verified = "Verified"
|
2021-09-06 02:24:27 +00:00
|
|
|
g.db.add(user)
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-09-08 10:57:56 +00:00
|
|
|
return {"message": "User verfied!"}
|
2021-09-06 02:24:27 +00:00
|
|
|
|
|
|
|
@app.post("/admin/unverify/<user_id>")
|
|
|
|
@admin_level_required(6)
|
|
|
|
@validate_formkey
|
2021-09-06 02:48:53 +00:00
|
|
|
def unverify(user_id, v):
|
2021-09-17 08:29:05 +00:00
|
|
|
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
|
2021-09-06 02:59:59 +00:00
|
|
|
user.verified = None
|
2021-09-06 02:24:27 +00:00
|
|
|
g.db.add(user)
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-09-08 10:57:56 +00:00
|
|
|
return {"message": "User unverified!"}
|
2021-09-06 02:24:27 +00:00
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.post("/admin/title_change/<user_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(6)
|
|
|
|
@validate_formkey
|
|
|
|
def admin_title_change(user_id, v):
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
if user.admin_level != 0: abort(403)
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
new_name=request.values.get("title").strip()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
user.customtitleplain=new_name
|
2021-08-21 12:57:16 +00:00
|
|
|
new_name = sanitize(new_name)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-22 23:41:51 +00:00
|
|
|
user=g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=user.id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
user.customtitle=new_name
|
2021-09-19 13:11:34 +00:00
|
|
|
user.flairchanged = bool(request.values.get("locked"))
|
2021-07-21 01:12:26 +00:00
|
|
|
g.db.add(user)
|
|
|
|
|
|
|
|
if user.flairchanged: kind = "set_flair_locked"
|
|
|
|
else: kind = "set_flair_notlocked"
|
|
|
|
|
|
|
|
ma=ModAction(
|
|
|
|
kind=kind,
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=user.id,
|
|
|
|
note=f'"{new_name}"'
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-09-22 15:30:45 +00:00
|
|
|
|
|
|
|
if 'redir' in request.values: return (redirect(user.url), user)
|
|
|
|
else: return {"message": f"@{user.username} was unbanned!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/ban_user/<user_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(6)
|
|
|
|
@validate_formkey
|
|
|
|
def ban_user(user_id, v):
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-28 22:11:18 +00:00
|
|
|
if user.admin_level >= v.admin_level: abort(403)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
# check for number of days for suspension
|
2021-09-17 14:02:47 +00:00
|
|
|
if 'form' in request.values:
|
2021-09-22 15:33:49 +00:00
|
|
|
days = float(request.values.get("days")) if request.values.get('days') else 0
|
2021-09-19 13:11:34 +00:00
|
|
|
reason = sanitize(request.values.get("reason", ""))
|
|
|
|
message = request.values.get("reason", "")
|
2021-09-17 14:02:47 +00:00
|
|
|
else:
|
2021-09-22 15:33:49 +00:00
|
|
|
days = float(request.values.get("days")) if request.values.get('days') else 0
|
2021-09-17 14:02:47 +00:00
|
|
|
reason = sanitize(request.values.get("reason", ""))
|
|
|
|
message = request.values.get("reason", "")
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
if not user: abort(400)
|
|
|
|
|
|
|
|
if days > 0:
|
|
|
|
if message:
|
2021-08-04 16:00:57 +00:00
|
|
|
text = f"Your account has been suspended for {days} days for the following reason:\n\n> {message}"
|
2021-07-21 01:12:26 +00:00
|
|
|
else:
|
2021-08-04 16:00:57 +00:00
|
|
|
text = f"Your account has been suspended for {days} days."
|
2021-07-21 01:12:26 +00:00
|
|
|
user.ban(admin=v, reason=reason, days=days)
|
|
|
|
|
|
|
|
else:
|
|
|
|
if message:
|
2021-08-04 16:00:57 +00:00
|
|
|
text = f"Your account has been permanently suspended for the following reason:\n\n> {message}"
|
2021-07-21 01:12:26 +00:00
|
|
|
else:
|
2021-08-04 16:00:57 +00:00
|
|
|
text = "Your account has been permanently suspended."
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
user.ban(admin=v, reason=reason)
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
if request.values.get("alts", ""):
|
2021-07-29 21:01:22 +00:00
|
|
|
for x in user.alts:
|
|
|
|
if x.admin_level > 0: break
|
|
|
|
x.ban(admin=v, reason=reason)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-08-21 11:06:28 +00:00
|
|
|
send_notification(NOTIFICATIONS_ACCOUNT, user, text)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-29 21:01:22 +00:00
|
|
|
if days == 0: duration = "permanent"
|
2021-07-21 01:12:26 +00:00
|
|
|
elif days == 1: duration = "1 day"
|
|
|
|
else: duration = f"{days} days"
|
|
|
|
ma=ModAction(
|
2021-09-19 13:01:16 +00:00
|
|
|
kind="ban_user",
|
2021-07-21 01:12:26 +00:00
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=user.id,
|
2021-09-08 08:53:57 +00:00
|
|
|
note=f'reason: "{reason}", duration: {duration}'
|
2021-07-21 01:12:26 +00:00
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
if 'reason' in request.values:
|
2021-08-11 22:26:04 +00:00
|
|
|
if reason.startswith("/post/"):
|
2021-09-19 13:09:09 +00:00
|
|
|
post = reason.split("/post/")[1]
|
2021-08-11 22:26:04 +00:00
|
|
|
post = get_post(post)
|
|
|
|
post.bannedfor = True
|
|
|
|
g.db.add(post)
|
|
|
|
elif reason.startswith("/comment/"):
|
2021-09-19 13:09:09 +00:00
|
|
|
comment = reason.split("/comment/")[1]
|
2021-08-11 22:26:04 +00:00
|
|
|
comment = get_comment(comment)
|
|
|
|
comment.bannedfor = True
|
|
|
|
g.db.add(comment)
|
2021-09-22 15:30:45 +00:00
|
|
|
|
|
|
|
g.db.commit()
|
|
|
|
|
|
|
|
if 'redir' in request.values: return (redirect(user.url), user)
|
|
|
|
else: return {"message": f"@{user.username} was banned!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/unban_user/<user_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(6)
|
|
|
|
@validate_formkey
|
|
|
|
def unban_user(user_id, v):
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
if not user:
|
|
|
|
abort(400)
|
|
|
|
|
2021-09-19 20:18:29 +00:00
|
|
|
user.is_banned = 0
|
|
|
|
user.unban_utc = 0
|
|
|
|
g.db.add(user)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
if request.values.get("alts", ""):
|
2021-07-29 21:01:22 +00:00
|
|
|
for x in user.alts:
|
|
|
|
if x.admin_level == 0:
|
2021-09-19 20:18:29 +00:00
|
|
|
x.is_banned = 0
|
|
|
|
x.unban_utc = 0
|
|
|
|
g.db.add(x)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-08-21 11:06:28 +00:00
|
|
|
send_notification(NOTIFICATIONS_ACCOUNT, user,
|
2021-08-04 16:00:57 +00:00
|
|
|
"Your account has been reinstated. Please carefully review and abide by the [rules](/post/2510) to ensure that you don't get suspended again.")
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
ma=ModAction(
|
2021-09-19 13:01:16 +00:00
|
|
|
kind="unban_user",
|
2021-07-21 01:12:26 +00:00
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=user.id,
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2021-07-30 09:42:17 +00:00
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
|
|
|
|
2021-09-17 08:55:55 +00:00
|
|
|
if "@" in request.referrer: return redirect(user.url)
|
|
|
|
else: return {"message": f"@{user.username} was unbanned!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/ban_post/<post_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(3)
|
|
|
|
@validate_formkey
|
|
|
|
def ban_post(post_id, v):
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
if not post:
|
|
|
|
abort(400)
|
|
|
|
|
|
|
|
post.is_banned = True
|
|
|
|
post.is_approved = 0
|
2021-09-23 17:28:30 +00:00
|
|
|
post.stickied = None
|
2021-07-21 01:12:26 +00:00
|
|
|
post.is_pinned = False
|
2021-09-10 05:46:37 +00:00
|
|
|
post.removed_by = v.id
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
ban_reason=request.values.get("reason", "")
|
2021-09-13 11:45:03 +00:00
|
|
|
ban_reason = CustomRenderer().render(mistletoe.Document(ban_reason))
|
2021-08-21 12:57:16 +00:00
|
|
|
ban_reason = sanitize(ban_reason)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
post.ban_reason = ban_reason
|
|
|
|
|
|
|
|
g.db.add(post)
|
|
|
|
|
2021-07-28 11:00:15 +00:00
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
ma=ModAction(
|
|
|
|
kind="ban_post",
|
|
|
|
user_id=v.id,
|
|
|
|
target_submission_id=post.id,
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2021-07-30 09:42:17 +00:00
|
|
|
|
2021-08-18 00:32:36 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
2021-07-30 09:42:17 +00:00
|
|
|
|
2021-09-23 17:18:33 +00:00
|
|
|
v.coins += 1
|
|
|
|
g.db.add(v)
|
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
|
|
|
|
2021-09-08 10:57:56 +00:00
|
|
|
return {"message": "Post removed!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/unban_post/<post_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(3)
|
|
|
|
@validate_formkey
|
|
|
|
def unban_post(post_id, v):
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
if not post:
|
|
|
|
abort(400)
|
|
|
|
|
|
|
|
if post.is_banned:
|
|
|
|
ma=ModAction(
|
|
|
|
kind="unban_post",
|
|
|
|
user_id=v.id,
|
|
|
|
target_submission_id=post.id,
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
|
|
|
post.is_banned = False
|
|
|
|
post.is_approved = v.id
|
|
|
|
|
|
|
|
g.db.add(post)
|
|
|
|
|
2021-08-18 00:32:36 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-23 17:18:33 +00:00
|
|
|
v.coins -= 1
|
|
|
|
g.db.add(v)
|
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
|
|
|
|
2021-09-08 10:57:56 +00:00
|
|
|
return {"message": "Post approved!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/distinguish/<post_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(1)
|
|
|
|
@validate_formkey
|
|
|
|
def api_distinguish_post(post_id, v):
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
if not post:
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
if not post.author_id == v.id:
|
|
|
|
abort(403)
|
|
|
|
|
|
|
|
if post.distinguish_level:
|
|
|
|
post.distinguish_level = 0
|
|
|
|
else:
|
|
|
|
post.distinguish_level = v.admin_level
|
|
|
|
|
|
|
|
g.db.add(post)
|
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
|
|
|
|
2021-09-08 10:57:56 +00:00
|
|
|
return {"message": "Post distinguished!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/sticky/<post_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(3)
|
|
|
|
def api_sticky_post(post_id, v):
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
if post:
|
2021-09-23 17:28:30 +00:00
|
|
|
if post.stickied: post.stickied = None
|
|
|
|
else: post.stickied = v.username
|
2021-07-21 01:12:26 +00:00
|
|
|
g.db.add(post)
|
2021-08-27 21:19:08 +00:00
|
|
|
|
|
|
|
ma=ModAction(
|
2021-08-27 21:23:18 +00:00
|
|
|
kind="pin_post" if post.stickied else "unpin_post",
|
2021-08-27 21:19:08 +00:00
|
|
|
user_id=v.id,
|
2021-08-27 21:20:06 +00:00
|
|
|
target_submission_id=post.id
|
2021-08-27 21:19:08 +00:00
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
|
|
|
cache.delete_memoized(frontlist)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-09-08 10:57:56 +00:00
|
|
|
if post.stickied: return {"message": "Post pinned!"}
|
|
|
|
else: return {"message": "Post unpinned!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/pin/<post_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@auth_required
|
|
|
|
def api_pin_post(post_id, v):
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
if post:
|
|
|
|
post.is_pinned = not (post.is_pinned)
|
|
|
|
g.db.add(post)
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-08 10:57:56 +00:00
|
|
|
if post.is_pinned: return {"message": "Post pinned!"}
|
|
|
|
else: return {"message": "Post unpinned!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/ban_comment/<c_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(1)
|
|
|
|
def api_ban_comment(c_id, v):
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
comment = g.db.query(Comment).options(lazyload('*')).filter_by(id=c_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
if not comment:
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
comment.is_banned = True
|
|
|
|
comment.is_approved = 0
|
2021-09-10 05:46:37 +00:00
|
|
|
comment.removed_by = v.id
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
g.db.add(comment)
|
|
|
|
ma=ModAction(
|
|
|
|
kind="ban_comment",
|
|
|
|
user_id=v.id,
|
|
|
|
target_comment_id=comment.id,
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-09-08 10:57:56 +00:00
|
|
|
return {"message": "Comment removed!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/unban_comment/<c_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(1)
|
|
|
|
def api_unban_comment(c_id, v):
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
comment = g.db.query(Comment).options(lazyload('*')).filter_by(id=c_id).first()
|
2021-07-21 01:12:26 +00:00
|
|
|
if not comment:
|
|
|
|
abort(404)
|
|
|
|
g.db.add(comment)
|
|
|
|
|
|
|
|
if comment.is_banned:
|
|
|
|
ma=ModAction(
|
|
|
|
kind="unban_comment",
|
|
|
|
user_id=v.id,
|
|
|
|
target_comment_id=comment.id,
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
|
|
|
comment.is_banned = False
|
|
|
|
comment.is_approved = v.id
|
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-08 10:57:56 +00:00
|
|
|
return {"message": "Comment approved!"}
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
2021-07-31 04:48:47 +00:00
|
|
|
@app.post("/distinguish_comment/<c_id>")
|
2021-07-21 01:12:26 +00:00
|
|
|
@auth_required
|
|
|
|
def admin_distinguish_comment(c_id, v):
|
|
|
|
|
|
|
|
if v.admin_level == 0: abort(403)
|
|
|
|
|
|
|
|
comment = get_comment(c_id, v=v)
|
|
|
|
|
|
|
|
if comment.author_id != v.id:
|
|
|
|
abort(403)
|
|
|
|
|
|
|
|
comment.distinguish_level = 0 if comment.distinguish_level else v.admin_level
|
|
|
|
|
|
|
|
g.db.add(comment)
|
|
|
|
html=render_template(
|
|
|
|
"comments.html",
|
|
|
|
v=v,
|
|
|
|
comments=[comment],
|
|
|
|
)
|
|
|
|
|
2021-07-30 05:31:38 +00:00
|
|
|
html=str(BeautifulSoup(html, features="html.parser").find(id=f"comment-{comment.id}-only"))
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
|
|
|
|
2021-07-31 05:28:05 +00:00
|
|
|
return html
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.get("/admin/dump_cache")
|
2021-07-23 16:01:10 +00:00
|
|
|
@admin_level_required(6)
|
2021-07-23 15:57:38 +00:00
|
|
|
def admin_dump_cache(v):
|
|
|
|
cache.clear()
|
2021-07-31 05:28:05 +00:00
|
|
|
return {"message": "Internal cache cleared."}
|
2021-07-23 15:57:38 +00:00
|
|
|
|
|
|
|
|
2021-08-03 12:07:06 +00:00
|
|
|
@app.get("/admin/banned_domains/")
|
|
|
|
@admin_level_required(4)
|
|
|
|
def admin_banned_domains(v):
|
|
|
|
|
2021-08-03 12:16:57 +00:00
|
|
|
banned_domains = g.db.query(BannedDomain).all()
|
|
|
|
return render_template("admin/banned_domains.html", v=v, banned_domains=banned_domains)
|
2021-08-03 12:07:06 +00:00
|
|
|
|
2021-08-03 12:26:12 +00:00
|
|
|
@app.post("/admin/banned_domains")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(4)
|
|
|
|
@validate_formkey
|
2021-08-03 12:25:47 +00:00
|
|
|
def admin_toggle_ban_domain(v):
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
domain=request.values.get("domain", "").strip()
|
2021-08-01 04:24:46 +00:00
|
|
|
if not domain: abort(400)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
reason=request.values.get("reason", "").strip()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
d = g.db.query(BannedDomain).options(lazyload('*')).filter_by(domain=domain).first()
|
2021-08-03 12:23:10 +00:00
|
|
|
if d: g.db.delete(d)
|
|
|
|
else:
|
|
|
|
d = BannedDomain(domain=domain, reason=reason)
|
|
|
|
g.db.add(d)
|
2021-09-16 17:02:58 +00:00
|
|
|
|
|
|
|
g.db.commit()
|
|
|
|
|
2021-08-03 12:16:57 +00:00
|
|
|
return redirect("/admin/banned_domains/")
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.post("/admin/nuke_user")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(4)
|
|
|
|
@validate_formkey
|
|
|
|
def admin_nuke_user(v):
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
user=get_user(request.values.get("user"))
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
for post in g.db.query(Submission).options(lazyload('*')).filter_by(author_id=user.id).all():
|
2021-07-21 01:12:26 +00:00
|
|
|
if post.is_banned:
|
|
|
|
continue
|
|
|
|
|
|
|
|
post.is_banned=True
|
|
|
|
g.db.add(post)
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
for comment in g.db.query(Comment).options(lazyload('*')).filter_by(author_id=user.id).all():
|
2021-07-21 01:12:26 +00:00
|
|
|
if comment.is_banned:
|
|
|
|
continue
|
|
|
|
|
|
|
|
comment.is_banned=True
|
|
|
|
g.db.add(comment)
|
|
|
|
|
|
|
|
ma=ModAction(
|
|
|
|
kind="nuke_user",
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=user.id,
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
|
|
|
|
2021-07-27 00:05:58 +00:00
|
|
|
return redirect(user.url)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-27 22:31:28 +00:00
|
|
|
@app.post("/admin/unnuke_user")
|
2021-07-21 01:12:26 +00:00
|
|
|
@admin_level_required(4)
|
|
|
|
@validate_formkey
|
|
|
|
def admin_nunuke_user(v):
|
|
|
|
|
2021-09-19 13:11:34 +00:00
|
|
|
user=get_user(request.values.get("user"))
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
for post in g.db.query(Submission).options(lazyload('*')).filter_by(author_id=user.id).all():
|
2021-07-21 01:12:26 +00:00
|
|
|
if not post.is_banned:
|
|
|
|
continue
|
|
|
|
|
|
|
|
post.is_banned=False
|
|
|
|
g.db.add(post)
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
for comment in g.db.query(Comment).options(lazyload('*')).filter_by(author_id=user.id).all():
|
2021-07-21 01:12:26 +00:00
|
|
|
if not comment.is_banned:
|
|
|
|
continue
|
|
|
|
|
|
|
|
comment.is_banned=False
|
|
|
|
g.db.add(comment)
|
|
|
|
|
|
|
|
ma=ModAction(
|
|
|
|
kind="unnuke_user",
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=user.id,
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
2021-09-16 17:02:58 +00:00
|
|
|
g.db.commit()
|
|
|
|
|
2021-07-27 00:05:58 +00:00
|
|
|
return redirect(user.url)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-24 18:36:24 +00:00
|
|
|
|
2021-09-10 03:33:36 +00:00
|
|
|
@app.get("/chart")
|
|
|
|
@auth_required
|
|
|
|
def chart(v):
|
2021-09-24 18:36:24 +00:00
|
|
|
file = cached_chart()
|
|
|
|
return send_file(f"../{file}")
|
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-09-24 18:36:24 +00:00
|
|
|
@cache.memoize(timeout=86400)
|
|
|
|
def cached_chart():
|
2021-09-19 13:11:34 +00:00
|
|
|
days = int(request.values.get("days", 25))
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
now = time.gmtime()
|
|
|
|
midnight_this_morning = time.struct_time((now.tm_year,
|
|
|
|
now.tm_mon,
|
|
|
|
now.tm_mday,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
now.tm_wday,
|
|
|
|
now.tm_yday,
|
|
|
|
0)
|
|
|
|
)
|
|
|
|
today_cutoff = calendar.timegm(midnight_this_morning)
|
|
|
|
|
|
|
|
day = 3600 * 24
|
|
|
|
|
|
|
|
day_cutoffs = [today_cutoff - day * i for i in range(days)]
|
|
|
|
day_cutoffs.insert(0, calendar.timegm(now))
|
|
|
|
|
2021-09-10 03:49:47 +00:00
|
|
|
daily_times = [time.strftime("%d", time.gmtime(day_cutoffs[i + 1])) for i in range(len(day_cutoffs) - 1)][2:][::-1]
|
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
daily_signups = [g.db.query(User).options(lazyload('*')).filter(User.created_utc < day_cutoffs[i], User.created_utc > day_cutoffs[i + 1]).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
|
2021-09-10 03:47:14 +00:00
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
post_stats = [g.db.query(Submission).options(lazyload('*')).filter(Submission.created_utc < day_cutoffs[i], Submission.created_utc > day_cutoffs[i + 1], Submission.is_banned == False).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
|
2021-09-10 03:49:47 +00:00
|
|
|
|
2021-09-17 08:29:05 +00:00
|
|
|
comment_stats = [g.db.query(Comment).options(lazyload('*')).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.is_banned == False, Comment.author_id != 1).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
# create multiple charts
|
|
|
|
signup_chart = plt.subplot2grid((20, 4), (0, 0), rowspan=5, colspan=4)
|
2021-07-26 21:01:22 +00:00
|
|
|
posts_chart = plt.subplot2grid((20, 4), (7, 0), rowspan=5, colspan=4)
|
|
|
|
comments_chart = plt.subplot2grid((20, 4), (14, 0), rowspan=5, colspan=4)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-07-26 21:01:22 +00:00
|
|
|
signup_chart.grid(), posts_chart.grid(), comments_chart.grid()
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
signup_chart.plot(
|
2021-09-10 03:40:04 +00:00
|
|
|
daily_times,
|
|
|
|
daily_signups,
|
2021-07-21 01:12:26 +00:00
|
|
|
color='red')
|
|
|
|
posts_chart.plot(
|
2021-09-10 03:40:04 +00:00
|
|
|
daily_times,
|
|
|
|
post_stats,
|
2021-07-21 01:12:26 +00:00
|
|
|
color='green')
|
|
|
|
comments_chart.plot(
|
2021-09-10 03:40:04 +00:00
|
|
|
daily_times,
|
|
|
|
comment_stats,
|
2021-07-21 01:12:26 +00:00
|
|
|
color='gold')
|
|
|
|
|
|
|
|
signup_chart.set_ylabel("Signups")
|
|
|
|
posts_chart.set_ylabel("Posts")
|
|
|
|
comments_chart.set_ylabel("Comments")
|
|
|
|
comments_chart.set_xlabel("Time (UTC)")
|
|
|
|
|
|
|
|
signup_chart.legend(loc='upper left', frameon=True)
|
|
|
|
posts_chart.legend(loc='upper left', frameon=True)
|
|
|
|
comments_chart.legend(loc='upper left', frameon=True)
|
|
|
|
|
2021-09-24 18:36:24 +00:00
|
|
|
file = "chart.png"
|
|
|
|
plt.savefig(file)
|
2021-09-10 03:42:21 +00:00
|
|
|
plt.clf()
|
2021-09-24 18:36:24 +00:00
|
|
|
return file
|