2022-11-15 09:19:08 +00:00
|
|
|
from files.classes import *
|
2022-02-10 20:35:16 +00:00
|
|
|
from files.helpers.alerts import *
|
2022-06-24 13:19:53 +00:00
|
|
|
from files.helpers.get import *
|
2022-06-24 14:30:59 +00:00
|
|
|
from files.helpers.regex import *
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.routes.wrappers import *
|
|
|
|
|
2022-02-10 20:35:16 +00:00
|
|
|
from .front import frontlist
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.__main__ import app, cache, limiter
|
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/exile/post/<int:pid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def exile_post(v, pid):
|
2022-02-16 04:33:13 +00:00
|
|
|
p = get_post(pid)
|
|
|
|
sub = p.sub
|
|
|
|
if not sub: abort(400)
|
|
|
|
|
|
|
|
if not v.mods(sub): abort(403)
|
|
|
|
|
|
|
|
u = p.author
|
|
|
|
|
2022-03-05 19:46:47 +00:00
|
|
|
if u.mods(sub): abort(403)
|
|
|
|
|
2023-08-08 17:01:58 +00:00
|
|
|
if not u.exiler_username(sub):
|
2022-02-22 12:39:02 +00:00
|
|
|
exile = Exile(user_id=u.id, sub=sub, exiler_id=v.id)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(exile)
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{p.title}]({p.shortlink})")
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='exile_user',
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=u.id,
|
|
|
|
_note=f'for <a href="{p.permalink}">{p.title_html}</a>'
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-09-12 05:25:04 +00:00
|
|
|
return {"message": f"@{u.username} has been exiled from /h/{sub} successfully!"}
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/exile/comment/<int:cid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def exile_comment(v, cid):
|
2022-02-16 04:33:13 +00:00
|
|
|
c = get_comment(cid)
|
|
|
|
sub = c.post.sub
|
|
|
|
if not sub: abort(400)
|
|
|
|
|
|
|
|
if not v.mods(sub): abort(403)
|
|
|
|
|
|
|
|
u = c.author
|
|
|
|
|
2022-11-03 19:23:37 +00:00
|
|
|
if u.mods(sub): abort(403)
|
2022-03-05 19:46:47 +00:00
|
|
|
|
2023-08-08 17:01:58 +00:00
|
|
|
if not u.exiler_username(sub):
|
2022-02-22 12:39:02 +00:00
|
|
|
exile = Exile(user_id=u.id, sub=sub, exiler_id=v.id)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(exile)
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
send_notification(u.id, f"@{v.username} has exiled you from /h/{sub} for [{c.permalink}]({c.shortlink})")
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='exile_user',
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=u.id,
|
2022-12-24 19:19:47 +00:00
|
|
|
_note=f'for <a href="/comment/{c.id}#context">comment</a>'
|
2022-09-29 09:39:37 +00:00
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2022-09-12 05:25:04 +00:00
|
|
|
return {"message": f"@{u.username} has been exiled from /h/{sub} successfully!"}
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/h/<sub>/unexile/<int:uid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def unexile(v, sub, uid):
|
2022-03-09 01:44:53 +00:00
|
|
|
u = get_account(uid)
|
2022-02-16 04:33:13 +00:00
|
|
|
|
|
|
|
if not v.mods(sub): abort(403)
|
|
|
|
|
2023-08-08 17:01:58 +00:00
|
|
|
if u.exiler_username(sub):
|
2023-03-16 06:27:58 +00:00
|
|
|
exile = g.db.query(Exile).filter_by(user_id=u.id, sub=sub).one_or_none()
|
|
|
|
g.db.delete(exile)
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
send_notification(u.id, f"@{v.username} has revoked your exile from /h/{sub}")
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='unexile_user',
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=u.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2023-08-11 21:50:23 +00:00
|
|
|
return {"message": f"@{u.username} has been unexiled from /h/{sub} successfully!"}
|
2022-03-09 01:44:53 +00:00
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.post("/h/<sub>/block")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-02-14 01:22:26 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def block_sub(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub).name
|
2023-03-16 06:27:58 +00:00
|
|
|
existing = g.db.query(SubBlock).filter_by(user_id=v.id, sub=sub).one_or_none()
|
2022-02-14 01:22:26 +00:00
|
|
|
if not existing:
|
|
|
|
block = SubBlock(user_id=v.id, sub=sub)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(block)
|
2022-02-14 01:22:26 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
2022-09-12 05:25:04 +00:00
|
|
|
return {"message": f"/h/{sub} blocked successfully!"}
|
2022-02-14 01:22:26 +00:00
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.post("/h/<sub>/unblock")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-02-14 01:22:26 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def unblock_sub(v, sub):
|
2022-12-04 18:39:06 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2023-10-05 09:22:05 +00:00
|
|
|
if not v.can_see(sub):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
block = g.db.query(SubBlock).filter_by(user_id=v.id, sub=sub.name).one_or_none()
|
2022-02-14 01:22:26 +00:00
|
|
|
|
|
|
|
if block:
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.delete(block)
|
2022-02-14 01:22:26 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
|
|
|
|
2022-12-04 18:39:06 +00:00
|
|
|
return {"message": f"/h/{sub.name} unblocked successfully!"}
|
2022-08-19 21:31:26 +00:00
|
|
|
|
|
|
|
@app.post("/h/<sub>/subscribe")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-08-19 21:31:26 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def subscribe_sub(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub).name
|
2023-03-16 06:27:58 +00:00
|
|
|
existing = g.db.query(SubJoin).filter_by(user_id=v.id, sub=sub).one_or_none()
|
2022-08-19 21:31:26 +00:00
|
|
|
if not existing:
|
|
|
|
subscribe = SubJoin(user_id=v.id, sub=sub)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(subscribe)
|
2022-08-19 21:31:26 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
2022-09-12 05:25:04 +00:00
|
|
|
return {"message": f"/h/{sub} unblocked successfully!"}
|
2022-08-19 21:31:26 +00:00
|
|
|
|
|
|
|
@app.post("/h/<sub>/unsubscribe")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-08-19 21:31:26 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def unsubscribe_sub(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub).name
|
2023-03-16 06:27:58 +00:00
|
|
|
subscribe = g.db.query(SubJoin).filter_by(user_id=v.id, sub=sub).one_or_none()
|
2022-08-19 21:31:26 +00:00
|
|
|
if subscribe:
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.delete(subscribe)
|
2022-08-19 21:31:26 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
2022-09-12 05:25:04 +00:00
|
|
|
return {"message": f"/h/{sub} blocked successfully!"}
|
2022-02-14 01:22:26 +00:00
|
|
|
|
2022-06-09 20:24:24 +00:00
|
|
|
@app.post("/h/<sub>/follow")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-06-09 20:24:24 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def follow_sub(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2023-10-05 09:22:05 +00:00
|
|
|
if not v.can_see(sub):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2023-03-16 06:27:58 +00:00
|
|
|
existing = g.db.query(SubSubscription).filter_by(user_id=v.id, sub=sub.name).one_or_none()
|
2022-06-09 20:24:24 +00:00
|
|
|
if not existing:
|
|
|
|
subscription = SubSubscription(user_id=v.id, sub=sub.name)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(subscription)
|
2022-06-09 20:24:24 +00:00
|
|
|
|
2022-09-12 05:25:04 +00:00
|
|
|
return {"message": f"/h/{sub} followed successfully!"}
|
2022-06-09 20:24:24 +00:00
|
|
|
|
|
|
|
@app.post("/h/<sub>/unfollow")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-06-09 20:24:24 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def unfollow_sub(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2023-03-16 06:27:58 +00:00
|
|
|
subscription = g.db.query(SubSubscription).filter_by(user_id=v.id, sub=sub.name).one_or_none()
|
2022-06-09 20:24:24 +00:00
|
|
|
if subscription:
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.delete(subscription)
|
2022-06-09 20:24:24 +00:00
|
|
|
|
2022-09-12 05:25:04 +00:00
|
|
|
return {"message": f"/h/{sub} unfollowed successfully!"}
|
2022-06-09 20:24:24 +00:00
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.get("/h/<sub>/mods")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-02-21 06:45:01 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def mods(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2023-10-05 09:22:05 +00:00
|
|
|
if not v.can_see(sub):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2023-03-16 06:27:58 +00:00
|
|
|
users = g.db.query(User, Mod).join(Mod).filter_by(sub=sub.name).order_by(Mod.created_utc).all()
|
2022-02-11 23:32:14 +00:00
|
|
|
|
2022-02-10 20:35:16 +00:00
|
|
|
return render_template("sub/mods.html", v=v, sub=sub, users=users)
|
|
|
|
|
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.get("/h/<sub>/exilees")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-02-21 06:45:01 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def sub_exilees(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2023-10-05 09:22:05 +00:00
|
|
|
if not v.can_see(sub):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2023-03-16 06:27:58 +00:00
|
|
|
users = g.db.query(User, Exile).join(Exile, Exile.user_id==User.id) \
|
2022-09-24 18:11:48 +00:00
|
|
|
.filter_by(sub=sub.name) \
|
2023-01-28 08:25:19 +00:00
|
|
|
.order_by(Exile.created_utc.desc(), User.username).all()
|
2022-02-21 06:45:01 +00:00
|
|
|
|
|
|
|
return render_template("sub/exilees.html", v=v, sub=sub, users=users)
|
|
|
|
|
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.get("/h/<sub>/blockers")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-02-21 06:45:01 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def sub_blockers(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2023-10-05 09:22:05 +00:00
|
|
|
if not v.can_see(sub):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2023-03-16 06:27:58 +00:00
|
|
|
users = g.db.query(User, SubBlock).join(SubBlock) \
|
2022-09-24 18:11:48 +00:00
|
|
|
.filter_by(sub=sub.name) \
|
2023-01-28 08:25:19 +00:00
|
|
|
.order_by(SubBlock.created_utc.desc(), User.username).all()
|
2022-02-21 06:45:01 +00:00
|
|
|
|
2023-01-01 11:36:20 +00:00
|
|
|
return render_template("sub/blockers.html",
|
2022-06-09 20:24:24 +00:00
|
|
|
v=v, sub=sub, users=users, verb="blocking")
|
|
|
|
|
2022-09-24 18:11:48 +00:00
|
|
|
|
2022-06-09 20:24:24 +00:00
|
|
|
@app.get("/h/<sub>/followers")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-06-09 20:24:24 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def sub_followers(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2023-10-05 09:22:05 +00:00
|
|
|
if not v.can_see(sub):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2023-03-16 06:27:58 +00:00
|
|
|
users = g.db.query(User, SubSubscription).join(SubSubscription) \
|
2022-09-24 18:11:48 +00:00
|
|
|
.filter_by(sub=sub.name) \
|
2023-01-28 08:25:19 +00:00
|
|
|
.order_by(SubSubscription.created_utc.desc(), User.username).all()
|
2022-02-21 06:45:01 +00:00
|
|
|
|
2023-01-01 11:36:20 +00:00
|
|
|
return render_template("sub/blockers.html",
|
2022-06-09 20:24:24 +00:00
|
|
|
v=v, sub=sub, users=users, verb="following")
|
2022-02-21 06:45:01 +00:00
|
|
|
|
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.post("/h/<sub>/add_mod")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit("30/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("30/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def add_mod(v, sub):
|
2022-09-01 23:54:05 +00:00
|
|
|
if SITE_NAME == 'WPD': abort(403)
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub).name
|
2022-02-10 20:35:16 +00:00
|
|
|
if not v.mods(sub): abort(403)
|
|
|
|
|
|
|
|
user = request.values.get('user')
|
|
|
|
|
|
|
|
if not user: abort(400)
|
|
|
|
|
2023-02-27 15:38:12 +00:00
|
|
|
user = get_user(user, v=v)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-06-26 15:05:27 +00:00
|
|
|
if sub in {'furry','vampire','racist','femboy','edgy'} and not v.client and not user.house.lower().startswith(sub):
|
2022-10-11 13:01:39 +00:00
|
|
|
abort(403, f"@{user.username} needs to be a member of House {sub.capitalize()} to be added as a mod there!")
|
2022-08-21 16:02:01 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
existing = g.db.query(Mod).filter_by(user_id=user.id, sub=sub).one_or_none()
|
2022-02-11 23:32:14 +00:00
|
|
|
|
|
|
|
if not existing:
|
2022-02-14 21:07:31 +00:00
|
|
|
mod = Mod(user_id=user.id, sub=sub)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(mod)
|
2022-02-11 23:32:14 +00:00
|
|
|
|
2022-03-02 04:27:53 +00:00
|
|
|
if v.id != user.id:
|
2022-03-09 02:04:37 +00:00
|
|
|
send_repeatable_notification(user.id, f"@{v.username} has added you as a mod to /h/{sub}")
|
2022-02-11 23:32:14 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='make_mod',
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=user.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-08-11 21:50:23 +00:00
|
|
|
return {"message": "Mod added successfully!"}
|
2022-02-11 23:32:14 +00:00
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.post("/h/<sub>/remove_mod")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def remove_mod(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub).name
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-02-11 23:32:14 +00:00
|
|
|
if not v.mods(sub): abort(403)
|
|
|
|
|
|
|
|
uid = request.values.get('uid')
|
|
|
|
|
|
|
|
if not uid: abort(400)
|
|
|
|
|
|
|
|
try: uid = int(uid)
|
|
|
|
except: abort(400)
|
|
|
|
|
2022-06-24 13:19:53 +00:00
|
|
|
user = get_account(uid)
|
2022-02-12 19:33:34 +00:00
|
|
|
|
|
|
|
if not user: abort(404)
|
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
mod = g.db.query(Mod).filter_by(user_id=user.id, sub=sub).one_or_none()
|
2022-02-11 23:32:14 +00:00
|
|
|
if not mod: abort(400)
|
|
|
|
|
2022-02-25 12:46:33 +00:00
|
|
|
if not (v.id == user.id or v.mod_date(sub) and v.mod_date(sub) < mod.created_utc): abort(403)
|
2022-02-12 19:33:34 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.delete(mod)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-03-02 04:27:53 +00:00
|
|
|
if v.id != user.id:
|
2022-03-09 02:04:37 +00:00
|
|
|
send_repeatable_notification(user.id, f"@{v.username} has removed you as a mod from /h/{sub}")
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='remove_mod',
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=user.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2022-11-07 06:32:30 +00:00
|
|
|
return {"message": f"@{user.username} has been removed as a mod!"}
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-06-09 22:29:45 +00:00
|
|
|
@app.get("/create_hole")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2022-05-09 02:16:28 +00:00
|
|
|
def create_sub(v):
|
2022-06-21 05:20:21 +00:00
|
|
|
if not v.can_create_hole:
|
|
|
|
abort(403)
|
2022-03-01 21:19:51 +00:00
|
|
|
|
2023-08-11 21:50:23 +00:00
|
|
|
return render_template("sub/create_hole.html", v=v, cost=HOLE_COST)
|
2022-03-01 21:19:51 +00:00
|
|
|
|
2022-06-09 22:29:45 +00:00
|
|
|
@app.post("/create_hole")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2022-03-02 04:24:36 +00:00
|
|
|
def create_sub2(v):
|
2022-06-21 05:20:21 +00:00
|
|
|
if not v.can_create_hole:
|
|
|
|
abort(403)
|
|
|
|
|
2022-03-02 04:24:36 +00:00
|
|
|
name = request.values.get('name')
|
|
|
|
if not name: abort(400)
|
|
|
|
name = name.strip().lower()
|
2022-03-01 21:19:51 +00:00
|
|
|
|
2023-09-08 22:31:18 +00:00
|
|
|
if not hole_group_name_regex.fullmatch(name):
|
2023-08-11 21:50:23 +00:00
|
|
|
abort(400, "Name does not match the required format!")
|
2022-03-01 21:19:51 +00:00
|
|
|
|
2023-04-24 15:08:40 +00:00
|
|
|
if not v.charge_account('combined', HOLE_COST)[0]:
|
2023-08-11 21:50:23 +00:00
|
|
|
abort(400, "You don't have enough coins or marseybux!")
|
2023-03-07 14:28:57 +00:00
|
|
|
|
2022-10-08 01:25:43 +00:00
|
|
|
sub = get_sub_by_name(name, graceful=True)
|
2022-03-01 21:19:51 +00:00
|
|
|
|
2023-03-07 14:28:57 +00:00
|
|
|
if sub:
|
2023-08-11 21:50:23 +00:00
|
|
|
abort(400, f"/h/{sub} already exists!")
|
2022-03-02 04:24:36 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(v)
|
2023-03-07 14:28:57 +00:00
|
|
|
if v.shadowbanned: abort(500)
|
|
|
|
|
|
|
|
sub = Sub(name=name)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(sub)
|
2023-07-25 21:42:47 +00:00
|
|
|
g.db.flush() #Necessary, following statement errors out otherwise
|
2023-03-07 14:28:57 +00:00
|
|
|
mod = Mod(user_id=v.id, sub=sub.name)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(mod)
|
2022-03-01 21:19:51 +00:00
|
|
|
|
2023-08-11 13:15:34 +00:00
|
|
|
admins = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_HOLE_CREATION'], User.id != v.id)]
|
2023-03-07 14:28:57 +00:00
|
|
|
for admin in admins:
|
|
|
|
send_repeatable_notification(admin, f":!marseyparty: /h/{sub} has been created by @{v.username} :marseyparty:")
|
2022-08-11 13:25:56 +00:00
|
|
|
|
2023-10-04 12:20:55 +00:00
|
|
|
return redirect(f"/h/{sub}")
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/kick/<int:pid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def kick(v, pid):
|
2022-02-10 20:35:16 +00:00
|
|
|
post = get_post(pid)
|
|
|
|
|
|
|
|
if not post.sub: abort(403)
|
|
|
|
if not v.mods(post.sub): abort(403)
|
|
|
|
|
2022-09-11 14:32:00 +00:00
|
|
|
old = post.sub
|
2022-03-06 19:13:11 +00:00
|
|
|
post.sub = None
|
2022-11-18 19:58:12 +00:00
|
|
|
post.hole_pinned = None
|
|
|
|
|
2022-11-03 19:23:37 +00:00
|
|
|
ma = SubAction(
|
|
|
|
sub=old,
|
|
|
|
kind='kick_post',
|
|
|
|
user_id=v.id,
|
2023-06-07 23:26:32 +00:00
|
|
|
target_post_id=post.id
|
2022-11-03 19:23:37 +00:00
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 06:05:42 +00:00
|
|
|
|
|
|
|
if v.id != post.author_id:
|
2022-12-13 17:11:26 +00:00
|
|
|
message = f"@{v.username} (a /h/{old} mod) has moved [{post.title}]({post.shortlink}) from /h/{old} to the main feed!"
|
2022-09-29 06:05:42 +00:00
|
|
|
send_repeatable_notification(post.author_id, message)
|
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(post)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
|
|
|
cache.delete_memoized(frontlist)
|
|
|
|
|
2022-09-11 14:32:00 +00:00
|
|
|
return {"message": f"Post kicked from /h/{old} successfully!"}
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.get('/h/<sub>/settings')
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def sub_settings(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2022-02-10 20:35:16 +00:00
|
|
|
if not v.mods(sub.name): abort(403)
|
2023-01-27 09:49:29 +00:00
|
|
|
return render_template('sub/settings.html', v=v, sidebar=sub.sidebar, sub=sub, css=sub.css)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.post('/h/<sub>/sidebar')
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def post_sub_sidebar(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2022-02-10 20:35:16 +00:00
|
|
|
if not v.mods(sub.name): abort(403)
|
2023-08-11 21:50:23 +00:00
|
|
|
if v.shadowbanned: abort(400)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-07-30 06:20:02 +00:00
|
|
|
sub.sidebar = request.values.get('sidebar', '')[:10000].strip()
|
2023-07-14 12:12:13 +00:00
|
|
|
sidebar_html = sanitize(sub.sidebar, blackjack=f"/h/{sub} sidebar")
|
2022-02-11 23:32:14 +00:00
|
|
|
|
2023-07-14 12:12:13 +00:00
|
|
|
if len(sidebar_html) > 20000:
|
2023-08-11 21:50:23 +00:00
|
|
|
abort(400, "Sidebar is too big! (max 20000 characters)")
|
2023-07-14 12:12:13 +00:00
|
|
|
|
|
|
|
sub.sidebar_html = sidebar_html
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(sub)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub.name,
|
|
|
|
kind='edit_sidebar',
|
2022-09-29 09:39:37 +00:00
|
|
|
user_id=v.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-02-11 23:32:14 +00:00
|
|
|
|
2023-08-11 21:50:23 +00:00
|
|
|
return {"message": "Sidebar changed successfully!"}
|
2022-02-11 23:32:14 +00:00
|
|
|
|
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.post('/h/<sub>/css')
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def post_sub_css(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2022-05-03 19:07:15 +00:00
|
|
|
css = request.values.get('css', '').strip()
|
|
|
|
|
2022-08-12 23:07:49 +00:00
|
|
|
if not sub: abort(404)
|
|
|
|
if not v.mods(sub.name): abort(403)
|
2023-08-11 21:50:23 +00:00
|
|
|
if v.shadowbanned: abort(400)
|
2022-08-12 23:07:49 +00:00
|
|
|
|
|
|
|
if len(css) > 6000:
|
2023-08-11 21:50:23 +00:00
|
|
|
abort(400, "CSS is too long (max 6000 characters)")
|
2022-05-03 19:07:15 +00:00
|
|
|
|
2022-08-05 17:09:41 +00:00
|
|
|
valid, error = validate_css(css)
|
|
|
|
if not valid:
|
2023-08-11 21:50:23 +00:00
|
|
|
abort(400, error)
|
2022-05-03 19:07:15 +00:00
|
|
|
|
|
|
|
sub.css = css
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(sub)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub.name,
|
|
|
|
kind='edit_css',
|
2022-09-29 09:39:37 +00:00
|
|
|
user_id=v.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-08-11 21:50:23 +00:00
|
|
|
return {"message": "CSS changed successfully!"}
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-06-26 05:07:28 +00:00
|
|
|
@app.get("/h/<sub>/css")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
2022-06-26 05:07:28 +00:00
|
|
|
def get_sub_css(sub):
|
2023-03-16 06:27:58 +00:00
|
|
|
sub = g.db.query(Sub.css).filter_by(name=sub.strip().lower()).one_or_none()
|
2022-06-26 05:07:28 +00:00
|
|
|
if not sub: abort(404)
|
2023-08-23 21:57:39 +00:00
|
|
|
resp = make_response(sub.css or "")
|
2022-06-26 05:07:28 +00:00
|
|
|
resp.headers.add("Content-Type", "text/css")
|
|
|
|
return resp
|
|
|
|
|
2022-12-11 23:44:34 +00:00
|
|
|
@app.post("/h/<sub>/settings/banners/")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit("50/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("50/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def upload_sub_banner(v, sub):
|
2022-12-11 23:44:34 +00:00
|
|
|
if g.is_tor: abort(403, "Image uploads are not allowed through Tor")
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2022-02-10 20:35:16 +00:00
|
|
|
if not v.mods(sub.name): abort(403)
|
2023-10-05 08:32:51 +00:00
|
|
|
if v.shadowbanned: abort(500)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
|
|
|
file = request.files["banner"]
|
|
|
|
|
2022-03-25 22:30:15 +00:00
|
|
|
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
2022-02-10 20:35:16 +00:00
|
|
|
file.save(name)
|
2022-11-15 09:19:08 +00:00
|
|
|
bannerurl = process_image(name, v, resize=1200)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-12-11 23:44:34 +00:00
|
|
|
sub.bannerurls.append(bannerurl)
|
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(sub)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub.name,
|
2022-12-11 23:44:34 +00:00
|
|
|
kind='upload_banner',
|
2022-09-29 09:39:37 +00:00
|
|
|
user_id=v.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2022-09-12 05:25:04 +00:00
|
|
|
return redirect(f'/h/{sub}/settings')
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-08-12 14:56:39 +00:00
|
|
|
@app.post("/h/<sub>/settings/banners/delete/<int:index>")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit("1/second;30/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("1/second;30/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def delete_sub_banner(v, sub, index):
|
2022-12-11 23:44:34 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
|
|
|
if not v.mods(sub.name): abort(403)
|
|
|
|
|
|
|
|
if not sub.bannerurls:
|
|
|
|
abort(404, f"Banner not found (/h/{sub.name} has no banners)")
|
|
|
|
if index < 0 or index >= len(sub.bannerurls):
|
|
|
|
abort(404, f'Banner not found (banner index {index} is not between 0 and {len(sub.bannerurls)})')
|
|
|
|
banner = sub.bannerurls[index]
|
|
|
|
try:
|
2023-03-17 10:25:49 +00:00
|
|
|
remove_media_using_link(banner)
|
2022-12-11 23:44:34 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
del sub.bannerurls[index]
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(sub)
|
2022-12-11 23:44:34 +00:00
|
|
|
|
|
|
|
ma = SubAction(
|
|
|
|
sub=sub.name,
|
|
|
|
kind='delete_banner',
|
|
|
|
_note=index,
|
|
|
|
user_id=v.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-12-11 23:44:34 +00:00
|
|
|
|
|
|
|
return {"message": f"Deleted banner {index} from /h/{sub} successfully"}
|
|
|
|
|
2023-08-12 14:56:39 +00:00
|
|
|
@app.post("/h/<sub>/settings/banners/delete_all")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit("1/10 second;30/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("1/10 second;30/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def delete_all_sub_banners(v, sub):
|
2022-12-11 23:44:34 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
|
|
|
if not v.mods(sub.name): abort(403)
|
2023-10-05 08:32:51 +00:00
|
|
|
|
2022-12-11 23:44:34 +00:00
|
|
|
for banner in sub.banner_urls:
|
|
|
|
try:
|
2023-03-17 10:25:49 +00:00
|
|
|
remove_media_using_link(banner)
|
2022-12-11 23:44:34 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
sub.bannerurls = []
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(sub)
|
2022-12-11 23:44:34 +00:00
|
|
|
|
|
|
|
ma = SubAction(
|
|
|
|
sub=sub.name,
|
|
|
|
kind='delete_banner',
|
|
|
|
_note='all',
|
|
|
|
user_id=v.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-12-11 23:44:34 +00:00
|
|
|
|
|
|
|
return {"message": f"Deleted all banners from /h/{sub} successfully"}
|
|
|
|
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.post("/h/<sub>/sidebar_image")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def sub_sidebar(v, sub):
|
2023-01-27 11:57:29 +00:00
|
|
|
if g.is_tor: abort(403, "Image uploads are not allowed through TOR!")
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2022-02-10 20:35:16 +00:00
|
|
|
if not v.mods(sub.name): abort(403)
|
2023-10-05 08:32:51 +00:00
|
|
|
if v.shadowbanned: abort(500)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-02-10 20:35:16 +00:00
|
|
|
file = request.files["sidebar"]
|
2022-03-25 22:30:15 +00:00
|
|
|
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
2022-02-10 20:35:16 +00:00
|
|
|
file.save(name)
|
2022-11-15 09:19:08 +00:00
|
|
|
sidebarurl = process_image(name, v, resize=400)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
|
|
|
if sidebarurl:
|
2022-12-05 15:10:15 +00:00
|
|
|
if sub.sidebarurl:
|
2023-03-17 10:25:49 +00:00
|
|
|
remove_media_using_link(sub.sidebarurl)
|
2022-02-10 20:35:16 +00:00
|
|
|
sub.sidebarurl = sidebarurl
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(sub)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub.name,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='change_sidebar_image',
|
|
|
|
user_id=v.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2022-09-12 05:25:04 +00:00
|
|
|
return redirect(f'/h/{sub}/settings')
|
2022-02-24 12:03:28 +00:00
|
|
|
|
2022-08-24 22:22:44 +00:00
|
|
|
@app.post("/h/<sub>/marsey_image")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def sub_marsey(v, sub):
|
2023-01-27 11:57:29 +00:00
|
|
|
if g.is_tor: abort(403, "Image uploads are not allowed through TOR!")
|
2022-08-24 22:22:44 +00:00
|
|
|
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2022-08-24 22:22:44 +00:00
|
|
|
if not v.mods(sub.name): abort(403)
|
2023-10-05 08:32:51 +00:00
|
|
|
if v.shadowbanned: abort(500)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-08-24 22:22:44 +00:00
|
|
|
file = request.files["marsey"]
|
|
|
|
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
|
|
|
file.save(name)
|
2022-11-15 09:19:08 +00:00
|
|
|
marseyurl = process_image(name, v, resize=200)
|
2022-08-24 22:22:44 +00:00
|
|
|
|
|
|
|
if marseyurl:
|
2022-12-05 15:10:15 +00:00
|
|
|
if sub.marseyurl:
|
2023-03-17 10:25:49 +00:00
|
|
|
remove_media_using_link(sub.marseyurl)
|
2022-08-24 22:22:44 +00:00
|
|
|
sub.marseyurl = marseyurl
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(sub)
|
2022-08-24 22:22:44 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub.name,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='change_marsey',
|
|
|
|
user_id=v.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2022-09-12 05:25:04 +00:00
|
|
|
return redirect(f'/h/{sub}/settings')
|
2022-08-24 22:22:44 +00:00
|
|
|
|
2023-02-20 14:40:00 +00:00
|
|
|
@app.get("/flairs")
|
2022-03-09 02:04:37 +00:00
|
|
|
@app.get("/holes")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-09-20 00:54:10 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def subs(v):
|
2023-06-07 23:26:32 +00:00
|
|
|
subs = g.db.query(Sub, func.count(Post.sub)).outerjoin(Post, Sub.name == Post.sub).group_by(Sub.name).order_by(func.count(Post.sub).desc()).all()
|
2023-03-16 06:27:58 +00:00
|
|
|
total_users = g.db.query(User).count()
|
2022-11-11 15:00:56 +00:00
|
|
|
return render_template('sub/subs.html', v=v, subs=subs, total_users=total_users)
|
2022-06-10 09:47:41 +00:00
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/hole_pin/<int:pid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def hole_pin(v, pid):
|
2022-07-01 23:11:48 +00:00
|
|
|
p = get_post(pid)
|
|
|
|
|
|
|
|
if not p.sub: abort(403)
|
|
|
|
|
|
|
|
if not v.mods(p.sub): abort(403)
|
|
|
|
|
2023-06-07 23:26:32 +00:00
|
|
|
num = g.db.query(Post).filter(Post.sub == p.sub, Post.hole_pinned != None).count()
|
2023-03-15 06:24:48 +00:00
|
|
|
if num >= 2:
|
|
|
|
abort(403, f"You can only pin 2 posts to /h/{p.sub}")
|
|
|
|
|
2022-07-01 23:11:48 +00:00
|
|
|
p.hole_pinned = v.username
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(p)
|
2022-07-01 23:11:48 +00:00
|
|
|
|
2022-08-13 07:08:32 +00:00
|
|
|
if v.id != p.author_id:
|
2022-12-13 17:11:26 +00:00
|
|
|
message = f"@{v.username} (a /h/{p.sub} mod) has pinned [{p.title}]({p.shortlink}) in /h/{p.sub}"
|
2022-08-13 07:08:32 +00:00
|
|
|
send_repeatable_notification(p.author_id, message)
|
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=p.sub,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='pin_post',
|
|
|
|
user_id=v.id,
|
2023-06-07 23:26:32 +00:00
|
|
|
target_post_id=p.id
|
2022-09-29 09:39:37 +00:00
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2022-12-22 22:39:59 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
|
|
|
|
2022-09-11 14:32:00 +00:00
|
|
|
return {"message": f"Post pinned to /h/{p.sub} successfully!"}
|
2022-07-01 23:11:48 +00:00
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/hole_unpin/<int:pid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def hole_unpin(v, pid):
|
2022-07-01 23:11:48 +00:00
|
|
|
p = get_post(pid)
|
|
|
|
|
|
|
|
if not p.sub: abort(403)
|
|
|
|
|
|
|
|
if not v.mods(p.sub): abort(403)
|
|
|
|
|
|
|
|
p.hole_pinned = None
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(p)
|
2022-07-01 23:11:48 +00:00
|
|
|
|
2022-08-13 07:08:32 +00:00
|
|
|
if v.id != p.author_id:
|
2022-12-13 17:11:26 +00:00
|
|
|
message = f"@{v.username} (a /h/{p.sub} mod) has unpinned [{p.title}]({p.shortlink}) in /h/{p.sub}"
|
2022-08-13 07:08:32 +00:00
|
|
|
send_repeatable_notification(p.author_id, message)
|
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=p.sub,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='unpin_post',
|
|
|
|
user_id=v.id,
|
2023-06-07 23:26:32 +00:00
|
|
|
target_post_id=p.id
|
2022-09-29 09:39:37 +00:00
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2022-12-22 22:39:59 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
|
|
|
|
2022-09-11 14:32:00 +00:00
|
|
|
return {"message": f"Post unpinned from /h/{p.sub} successfully!"}
|
2022-08-19 21:31:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.post('/h/<sub>/stealth')
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def sub_stealth(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2023-04-02 17:30:55 +00:00
|
|
|
if sub.name in {'braincels','smuggies','mnn'} and v.admin_level < PERMS["MODS_EVERY_HOLE"]:
|
2023-01-20 05:15:08 +00:00
|
|
|
abort(403)
|
2022-08-19 21:31:26 +00:00
|
|
|
if not v.mods(sub.name): abort(403)
|
|
|
|
|
|
|
|
sub.stealth = not sub.stealth
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(sub)
|
2022-08-19 21:31:26 +00:00
|
|
|
|
|
|
|
cache.delete_memoized(frontlist)
|
|
|
|
|
|
|
|
if sub.stealth:
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub.name,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='enable_stealth',
|
|
|
|
user_id=v.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-12 05:25:04 +00:00
|
|
|
return {"message": f"Stealth mode has been enabled for /h/{sub} successfully!"}
|
2022-08-19 21:31:26 +00:00
|
|
|
else:
|
2022-09-29 09:39:37 +00:00
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=sub.name,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='disable_stealth',
|
|
|
|
user_id=v.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-27 22:09:08 +00:00
|
|
|
return {"message": f"Stealth mode has been disabled for /h/{sub} successfully!"}
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
|
2023-07-23 00:10:05 +00:00
|
|
|
@app.post("/pin_comment_mod/<int:cid>")
|
2022-10-11 07:29:24 +00:00
|
|
|
@feature_required('PINS')
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-23 00:10:05 +00:00
|
|
|
def pin_comment_mod(cid, v):
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
comment = get_comment(cid, v=v)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
if not comment.stickied:
|
|
|
|
if not (comment.post.sub and v.mods(comment.post.sub)): abort(403)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
comment.stickied = v.username + " (Mod)"
|
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(comment)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=comment.post.sub,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind="pin_comment",
|
|
|
|
user_id=v.id,
|
|
|
|
target_comment_id=comment.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
if v.id != comment.author_id:
|
2022-12-13 17:11:26 +00:00
|
|
|
message = f"@{v.username} (a /h/{comment.post.sub} mod) has pinned your [comment]({comment.shortlink})"
|
2022-09-29 09:39:37 +00:00
|
|
|
send_repeatable_notification(comment.author_id, message)
|
|
|
|
|
|
|
|
return {"message": "Comment pinned!"}
|
|
|
|
|
2023-07-23 00:10:05 +00:00
|
|
|
@app.post("/unpin_comment_mod/<int:cid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2023-07-23 00:10:05 +00:00
|
|
|
def unpin_comment_mod(cid, v):
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
comment = get_comment(cid, v=v)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-09-29 09:39:37 +00:00
|
|
|
if comment.stickied:
|
|
|
|
if not (comment.post.sub and v.mods(comment.post.sub)): abort(403)
|
|
|
|
|
|
|
|
comment.stickied = None
|
2023-09-29 01:24:36 +00:00
|
|
|
comment.stickied_utc = None
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(comment)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
ma = SubAction(
|
2022-09-29 10:18:27 +00:00
|
|
|
sub=comment.post.sub,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind="unpin_comment",
|
|
|
|
user_id=v.id,
|
|
|
|
target_comment_id=comment.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
if v.id != comment.author_id:
|
2022-12-13 17:11:26 +00:00
|
|
|
message = f"@{v.username} (a /h/{comment.post.sub} mod) has unpinned your [comment]({comment.shortlink})"
|
2022-09-29 09:39:37 +00:00
|
|
|
send_repeatable_notification(comment.author_id, message)
|
|
|
|
return {"message": "Comment unpinned!"}
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/h/<sub>/log")
|
|
|
|
@app.get("/h/<sub>/modlog")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-09-29 09:39:37 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def hole_log(v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2023-10-05 09:22:05 +00:00
|
|
|
if not v.can_see(sub):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2023-05-05 05:23:59 +00:00
|
|
|
page = get_page()
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
mod = request.values.get("mod")
|
2023-09-15 23:48:33 +00:00
|
|
|
if mod: mod_id = get_user(mod, attributes=[User.id]).id
|
2022-09-29 09:39:37 +00:00
|
|
|
else: mod_id = 0
|
|
|
|
|
|
|
|
kind = request.values.get("kind")
|
|
|
|
|
2022-12-11 23:44:34 +00:00
|
|
|
types = SUBACTION_TYPES
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
if kind and kind not in types:
|
|
|
|
kind = None
|
|
|
|
actions = []
|
2023-05-05 21:44:24 +00:00
|
|
|
total=0
|
2022-09-29 09:39:37 +00:00
|
|
|
else:
|
2023-03-16 06:27:58 +00:00
|
|
|
actions = g.db.query(SubAction).filter_by(sub=sub.name)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
if mod_id:
|
|
|
|
actions = actions.filter_by(user_id=mod_id)
|
|
|
|
kinds = set([x.kind for x in actions])
|
2023-10-02 05:07:30 +00:00
|
|
|
if kind: kinds.add(kind)
|
2022-09-29 09:39:37 +00:00
|
|
|
types2 = {}
|
|
|
|
for k,val in types.items():
|
|
|
|
if k in kinds: types2[k] = val
|
|
|
|
types = types2
|
|
|
|
if kind: actions = actions.filter_by(kind=kind)
|
2023-05-05 21:44:24 +00:00
|
|
|
total = actions.count()
|
2023-05-05 00:54:55 +00:00
|
|
|
actions = actions.order_by(SubAction.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-08-11 13:15:34 +00:00
|
|
|
mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(sub=sub.name)]
|
|
|
|
mods = [x[0] for x in g.db.query(User.username).filter(User.id.in_(mods)).order_by(User.username)]
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-05-05 21:44:24 +00:00
|
|
|
return render_template("log.html", v=v, admins=mods, types=types, admin=mod, type=kind, actions=actions, total=total, page=page, sub=sub, single_user_url='mod')
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.get("/h/<sub>/log/<int:id>")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-09-29 09:39:37 +00:00
|
|
|
@auth_required
|
|
|
|
def hole_log_item(id, v, sub):
|
2022-10-05 10:30:44 +00:00
|
|
|
sub = get_sub_by_name(sub)
|
2023-10-05 09:22:05 +00:00
|
|
|
if not v.can_see(sub):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-08-23 21:57:39 +00:00
|
|
|
action = g.db.get(SubAction, id)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
if not action: abort(404)
|
|
|
|
|
2023-08-11 13:15:34 +00:00
|
|
|
mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(sub=sub.name)]
|
|
|
|
mods = [x[0] for x in g.db.query(User.username).filter(User.id.in_(mods)).order_by(User.username)]
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2022-12-11 23:44:34 +00:00
|
|
|
types = SUBACTION_TYPES
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-05-05 21:44:24 +00:00
|
|
|
return render_template("log.html", v=v, actions=[action], total=1, page=1, action=action, admins=mods, types=types, sub=sub, single_user_url='mod')
|