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 *
|
2023-10-05 10:09:58 +00:00
|
|
|
from files.helpers.can_see 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)
|
2024-02-15 21:34:09 +00:00
|
|
|
hole = p.hole_obj
|
2023-10-07 17:55:50 +00:00
|
|
|
if not hole: abort(400)
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2024-02-15 21:34:09 +00:00
|
|
|
if hole.public_use:
|
|
|
|
abort(403, "You can't exile users while Public Use mode is enabled!")
|
|
|
|
|
|
|
|
hole = hole.name
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2024-02-15 21:34:09 +00:00
|
|
|
if not v.mods_hole(hole): abort(403)
|
2024-02-12 14:43:54 +00:00
|
|
|
|
2022-02-16 04:33:13 +00:00
|
|
|
u = p.author
|
|
|
|
|
2024-01-12 07:18:04 +00:00
|
|
|
if u.mods_hole(hole): abort(403)
|
2022-03-05 19:46:47 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if not u.exiler_username(hole):
|
|
|
|
exile = Exile(user_id=u.id, hole=hole, exiler_id=v.id)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(exile)
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2024-02-20 00:00:21 +00:00
|
|
|
send_notification(u.id, f"@{v.username} has exiled you from /h/{hole} for {p.textlink}")
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='exile_user',
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=u.id,
|
2024-03-02 21:01:29 +00:00
|
|
|
_note=f'for <a href="{p.permalink}">{p.title_html}</a>'
|
2022-09-29 09:39:37 +00:00
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"@{u.username} has been exiled from /h/{hole} 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)
|
2024-02-15 21:34:09 +00:00
|
|
|
hole = c.post.hole_obj
|
2023-10-07 17:55:50 +00:00
|
|
|
if not hole: abort(400)
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2024-02-15 21:34:09 +00:00
|
|
|
if hole.public_use:
|
|
|
|
abort(403, "You can't exile users while Public Use mode is enabled!")
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2024-02-15 21:34:09 +00:00
|
|
|
hole = hole.name
|
|
|
|
|
|
|
|
if not v.mods_hole(hole): abort(403)
|
2024-02-12 14:43:54 +00:00
|
|
|
|
2022-02-16 04:33:13 +00:00
|
|
|
u = c.author
|
|
|
|
|
2024-01-12 07:18:04 +00:00
|
|
|
if u.mods_hole(hole): abort(403)
|
2022-03-05 19:46:47 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if not u.exiler_username(hole):
|
|
|
|
exile = Exile(user_id=u.id, hole=hole, exiler_id=v.id)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(exile)
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2024-02-20 00:00:21 +00:00
|
|
|
send_notification(u.id, f"@{v.username} has exiled you from /h/{hole} for {c.textlink}")
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='exile_user',
|
|
|
|
user_id=v.id,
|
|
|
|
target_user_id=u.id,
|
2024-03-02 21:01:29 +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
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"@{u.username} has been exiled from /h/{hole} successfully!"}
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def unexile(v, hole, uid):
|
2022-03-09 01:44:53 +00:00
|
|
|
u = get_account(uid)
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole): abort(403)
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if u.exiler_username(hole):
|
|
|
|
exile = g.db.query(Exile).filter_by(user_id=u.id, hole=hole).one_or_none()
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.delete(exile)
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
send_notification(u.id, f"@{v.username} has revoked your exile from /h/{hole}")
|
2022-02-16 04:33:13 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole,
|
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-10-07 17:55:50 +00:00
|
|
|
return {"message": f"@{u.username} has been unexiled from /h/{hole} successfully!"}
|
2022-03-09 01:44:53 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def block_sub(v, hole):
|
2024-02-15 21:34:09 +00:00
|
|
|
hole = get_hole(hole)
|
|
|
|
|
|
|
|
if hole.public_use:
|
|
|
|
abort(403, f"/h/{hole} has Public Use mode enabled and is unblockable!")
|
|
|
|
|
|
|
|
hole = hole.name
|
2024-02-11 07:04:09 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
existing = g.db.query(HoleBlock).filter_by(user_id=v.id, hole=hole).one_or_none()
|
2022-02-14 01:22:26 +00:00
|
|
|
if not existing:
|
2023-10-07 17:55:50 +00:00
|
|
|
block = HoleBlock(user_id=v.id, hole=hole)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(block)
|
2022-02-14 01:22:26 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"/h/{hole} blocked successfully!"}
|
2022-02-14 01:22:26 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def unblock_sub(v, hole):
|
|
|
|
hole = get_hole(hole)
|
|
|
|
if not can_see(v, hole):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
block = g.db.query(HoleBlock).filter_by(user_id=v.id, hole=hole.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)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"/h/{hole.name} unblocked successfully!"}
|
2022-08-19 21:31:26 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def subscribe_sub(v, hole):
|
|
|
|
hole = get_hole(hole).name
|
|
|
|
existing = g.db.query(StealthHoleUnblock).filter_by(user_id=v.id, hole=hole).one_or_none()
|
2022-08-19 21:31:26 +00:00
|
|
|
if not existing:
|
2023-10-07 17:55:50 +00:00
|
|
|
subscribe = StealthHoleUnblock(user_id=v.id, hole=hole)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(subscribe)
|
2022-08-19 21:31:26 +00:00
|
|
|
cache.delete_memoized(frontlist)
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"/h/{hole} unblocked successfully!"}
|
2022-08-19 21:31:26 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def unsubscribe_sub(v, hole):
|
|
|
|
hole = get_hole(hole).name
|
|
|
|
subscribe = g.db.query(StealthHoleUnblock).filter_by(user_id=v.id, hole=hole).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)
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"/h/{hole} blocked successfully!"}
|
2022-02-14 01:22:26 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def follow_sub(v, hole):
|
|
|
|
hole = get_hole(hole)
|
|
|
|
if not can_see(v, hole):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2023-10-07 17:55:50 +00:00
|
|
|
existing = g.db.query(HoleFollow).filter_by(user_id=v.id, hole=hole.name).one_or_none()
|
2022-06-09 20:24:24 +00:00
|
|
|
if not existing:
|
2023-10-07 17:55:50 +00:00
|
|
|
subscription = HoleFollow(user_id=v.id, hole=hole.name)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(subscription)
|
2022-06-09 20:24:24 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"/h/{hole} followed successfully!"}
|
2022-06-09 20:24:24 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def unfollow_sub(v, hole):
|
|
|
|
hole = get_hole(hole)
|
|
|
|
subscription = g.db.query(HoleFollow).filter_by(user_id=v.id, hole=hole.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
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"/h/{hole} unfollowed successfully!"}
|
2022-06-09 20:24:24 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.get("/h/<hole>/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
|
2024-01-12 07:18:04 +00:00
|
|
|
def mods_hole(v, hole):
|
2023-10-29 13:01:52 +00:00
|
|
|
if hole == 'test':
|
|
|
|
return redirect('/users')
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
hole = get_hole(hole)
|
|
|
|
if not can_see(v, hole):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2023-10-07 17:55:50 +00:00
|
|
|
users = g.db.query(User, Mod).join(Mod).filter_by(hole=hole.name).order_by(Mod.created_utc).all()
|
2022-02-11 23:32:14 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return render_template("hole/mods.html", v=v, hole=hole, users=users)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.get("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def hole_exilees(v, hole):
|
|
|
|
hole = get_hole(hole)
|
|
|
|
if not can_see(v, hole):
|
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) \
|
2023-10-07 17:55:50 +00:00
|
|
|
.filter_by(hole=hole.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
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return render_template("hole/exilees.html", v=v, hole=hole, users=users)
|
2022-02-21 06:45:01 +00:00
|
|
|
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.get("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def hole_blockers(v, hole):
|
|
|
|
hole = get_hole(hole)
|
2024-02-28 21:01:25 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if not can_see(v, hole):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2024-02-28 21:01:25 +00:00
|
|
|
|
|
|
|
if hole.public_use:
|
|
|
|
users = []
|
|
|
|
else:
|
|
|
|
users = g.db.query(User, HoleBlock).join(HoleBlock) \
|
|
|
|
.filter_by(hole=hole.name) \
|
|
|
|
.order_by(HoleBlock.created_utc.desc(), User.username).all()
|
2022-02-21 06:45:01 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return render_template("hole/blockers.html",
|
|
|
|
v=v, hole=hole, users=users, verb="blocking")
|
2022-06-09 20:24:24 +00:00
|
|
|
|
2022-09-24 18:11:48 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.get("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def hole_followers(v, hole):
|
|
|
|
hole = get_hole(hole)
|
|
|
|
if not can_see(v, hole):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2023-10-07 17:55:50 +00:00
|
|
|
users = g.db.query(User, HoleFollow).join(HoleFollow) \
|
|
|
|
.filter_by(hole=hole.name) \
|
|
|
|
.order_by(HoleFollow.created_utc.desc(), User.username).all()
|
2022-02-21 06:45:01 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return render_template("hole/blockers.html",
|
|
|
|
v=v, hole=hole, users=users, verb="following")
|
2022-02-21 06:45:01 +00:00
|
|
|
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def add_mod(v, hole):
|
2022-09-01 23:54:05 +00:00
|
|
|
if SITE_NAME == 'WPD': abort(403)
|
2023-10-29 13:01:52 +00:00
|
|
|
|
|
|
|
if hole == 'test':
|
|
|
|
abort(403, "Everyone is already a mod of this hole!")
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
hole = get_hole(hole).name
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole): abort(403)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
|
|
|
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-10-07 17:55:50 +00:00
|
|
|
if hole in {'furry','vampire','racist','femboy','edgy'} and not v.client and not user.house.lower().startswith(hole):
|
|
|
|
abort(403, f"@{user.username} needs to be a member of House {hole.capitalize()} to be added as a mod there!")
|
2022-08-21 16:02:01 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
existing = g.db.query(Mod).filter_by(user_id=user.id, hole=hole).one_or_none()
|
2022-02-11 23:32:14 +00:00
|
|
|
|
|
|
|
if not existing:
|
2023-10-07 17:55:50 +00:00
|
|
|
mod = Mod(user_id=user.id, hole=hole)
|
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:
|
2023-10-07 17:55:50 +00:00
|
|
|
send_repeatable_notification(user.id, f"@{v.username} has added you as a mod to /h/{hole}")
|
2022-02-11 23:32:14 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole,
|
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
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def remove_mod(v, hole):
|
|
|
|
hole = get_hole(hole).name
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole): abort(403)
|
2022-02-11 23:32:14 +00:00
|
|
|
|
|
|
|
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-10-07 17:55:50 +00:00
|
|
|
mod = g.db.query(Mod).filter_by(user_id=user.id, hole=hole).one_or_none()
|
2022-02-11 23:32:14 +00:00
|
|
|
if not mod: abort(400)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if not (v.id == user.id or v.mod_date(hole) and v.mod_date(hole) < 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:
|
2023-10-07 17:55:50 +00:00
|
|
|
send_repeatable_notification(user.id, f"@{v.username} has removed you as a mod from /h/{hole}")
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole,
|
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-10-07 17:55:50 +00:00
|
|
|
return render_template("hole/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
|
|
|
|
2024-03-06 02:04:25 +00:00
|
|
|
charge_reason = f'Cost of creating <a href="/h/{name}">/h/{name}</a>'
|
2024-03-09 12:19:38 +00:00
|
|
|
if not v.charge_account('coins/marseybux', HOLE_COST, charge_reason):
|
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
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
hole = get_hole(name, graceful=True)
|
2022-03-01 21:19:51 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if hole:
|
|
|
|
abort(400, f"/h/{hole} 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)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
hole = Hole(name=name)
|
|
|
|
g.db.add(hole)
|
2023-07-25 21:42:47 +00:00
|
|
|
g.db.flush() #Necessary, following statement errors out otherwise
|
2023-10-07 17:55:50 +00:00
|
|
|
mod = Mod(user_id=v.id, hole=hole.name)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(mod)
|
2022-03-01 21:19:51 +00:00
|
|
|
|
2024-01-14 09:41:45 +00:00
|
|
|
text = f":!marseyparty: /h/{hole} has been created by @{v.username} :marseyparty:"
|
2024-02-10 15:34:45 +00:00
|
|
|
alert_active_users(text, v.id, User.hole_creation_notifs == True)
|
2024-01-14 09:00:11 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return redirect(f"/h/{hole}")
|
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)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if not post.hole: abort(403)
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(post.hole): abort(403)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
old = post.hole
|
|
|
|
post.hole = None
|
2022-11-18 19:58:12 +00:00
|
|
|
post.hole_pinned = None
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=old,
|
2022-11-03 19:23:37 +00:00
|
|
|
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:
|
2024-02-20 00:00:21 +00:00
|
|
|
message = f"@{v.username} (a /h/{old} mod) has moved {post.textlink} 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
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.get('/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def hole_settings(v, hole):
|
|
|
|
hole = get_hole(hole)
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole.name): abort(403)
|
2024-02-11 10:26:54 +00:00
|
|
|
return render_template('hole/settings.html', v=v, sidebar=hole.sidebar, hole=hole, css=hole.css, snappy_quotes=hole.snappy_quotes)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post('/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def post_hole_sidebar(v, hole):
|
|
|
|
hole = get_hole(hole)
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole.name): abort(403)
|
2023-08-11 21:50:23 +00:00
|
|
|
if v.shadowbanned: abort(400)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2024-01-03 21:20:53 +00:00
|
|
|
sidebar = request.values.get('sidebar', '').strip()
|
2024-01-02 18:54:08 +00:00
|
|
|
|
|
|
|
if len(sidebar) > 10000:
|
|
|
|
abort(400, "New sidebar is too long (max 10000 characters)")
|
|
|
|
|
2024-01-03 21:20:53 +00:00
|
|
|
sidebar_html = sanitize(sidebar, blackjack=f"/h/{hole} sidebar")
|
2022-02-11 23:32:14 +00:00
|
|
|
|
2023-07-14 12:12:13 +00:00
|
|
|
if len(sidebar_html) > 20000:
|
2024-01-02 18:54:08 +00:00
|
|
|
abort(400, "New rendered sidebar is too long!")
|
2023-07-14 12:12:13 +00:00
|
|
|
|
2024-01-03 21:20:53 +00:00
|
|
|
hole.sidebar = sidebar
|
2023-10-07 17:55:50 +00:00
|
|
|
hole.sidebar_html = sidebar_html
|
|
|
|
g.db.add(hole)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.name,
|
2022-09-29 10:18:27 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post('/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def post_hole_css(v, hole):
|
|
|
|
hole = get_hole(hole)
|
2022-05-03 19:07:15 +00:00
|
|
|
css = request.values.get('css', '').strip()
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if not hole: abort(404)
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole.name): abort(403)
|
2023-08-11 21:50:23 +00:00
|
|
|
if v.shadowbanned: abort(400)
|
2022-08-12 23:07:49 +00:00
|
|
|
|
2023-12-24 21:53:49 +00:00
|
|
|
if len(css) > CSS_LENGTH_LIMIT:
|
|
|
|
abort(400, f"Hole CSS is too long (max {CSS_LENGTH_LIMIT} 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
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
hole.css = css
|
|
|
|
g.db.add(hole)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.name,
|
2022-09-29 10:18:27 +00:00
|
|
|
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
|
|
|
|
2024-02-11 10:13:47 +00:00
|
|
|
return {"message": "CSS edited successfully!"}
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.get("/h/<hole>/css")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
2023-10-07 17:55:50 +00:00
|
|
|
def get_hole_css(hole):
|
|
|
|
hole = g.db.query(Hole.css).filter_by(name=hole.strip().lower()).one_or_none()
|
|
|
|
if not hole: abort(404)
|
|
|
|
resp = make_response(hole.css or "")
|
2022-06-26 05:07:28 +00:00
|
|
|
resp.headers.add("Content-Type", "text/css")
|
|
|
|
return resp
|
|
|
|
|
2024-03-06 03:31:45 +00:00
|
|
|
@app.post("/h/<hole>/settings/sidebars")
|
2023-11-04 22:03:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
|
|
|
@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)
|
|
|
|
@auth_required
|
|
|
|
def upload_hole_sidebar(v, hole):
|
2024-02-28 22:34:26 +00:00
|
|
|
if g.is_tor: abort(403, "File uploads are not allowed through TOR")
|
2023-11-04 22:03:26 +00:00
|
|
|
|
|
|
|
hole = get_hole(hole)
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole.name): abort(403)
|
2023-11-04 22:03:26 +00:00
|
|
|
if v.shadowbanned: abort(500)
|
|
|
|
|
2024-03-06 03:31:45 +00:00
|
|
|
file = request.files["image"]
|
2023-11-04 22:03:26 +00:00
|
|
|
|
|
|
|
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
|
|
|
file.save(name)
|
2024-02-10 15:06:00 +00:00
|
|
|
sidebarurl = process_image(name, v, resize=600)
|
2023-11-04 22:03:26 +00:00
|
|
|
|
|
|
|
hole.sidebarurls.append(sidebarurl)
|
|
|
|
|
|
|
|
g.db.add(hole)
|
|
|
|
|
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.name,
|
2023-11-04 22:17:23 +00:00
|
|
|
kind='upload_sidebar_image',
|
2024-03-02 21:07:05 +00:00
|
|
|
_note=f'<a href="{sidebarurl}">{sidebarurl}</a>',
|
2023-11-04 22:03:26 +00:00
|
|
|
user_id=v.id
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
2024-03-06 03:31:45 +00:00
|
|
|
return {"message": "Sidebar image uploaded successfully!", "url": sidebarurl}
|
2023-11-04 22:03:26 +00:00
|
|
|
|
2024-03-06 03:31:45 +00:00
|
|
|
@app.post("/h/<hole>/settings/sidebars/delete")
|
2023-11-25 23:36:03 +00:00
|
|
|
@limiter.limit("1/second", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("1/second", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-11-04 22:03:26 +00:00
|
|
|
@auth_required
|
2024-03-06 03:31:45 +00:00
|
|
|
def delete_hole_sidebar(v, hole):
|
2023-11-04 22:03:26 +00:00
|
|
|
hole = get_hole(hole)
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole.name): abort(403)
|
2023-11-04 22:03:26 +00:00
|
|
|
|
|
|
|
if not hole.sidebarurls:
|
|
|
|
abort(404, f"Sidebar image not found (/h/{hole.name} has no sidebar images)")
|
2024-03-06 03:31:45 +00:00
|
|
|
|
|
|
|
sidebar = request.values["url"]
|
|
|
|
|
|
|
|
if sidebar not in hole.sidebarurls:
|
|
|
|
abort(404, "Sidebar image not found!")
|
|
|
|
|
|
|
|
try: remove_media_using_link(sidebar)
|
|
|
|
except FileNotFoundError: pass
|
|
|
|
|
|
|
|
hole.sidebarurls.remove(sidebar)
|
2023-11-04 22:03:26 +00:00
|
|
|
g.db.add(hole)
|
|
|
|
|
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.name,
|
2023-11-04 22:17:23 +00:00
|
|
|
kind='delete_sidebar_image',
|
2024-03-02 21:07:05 +00:00
|
|
|
_note=f'<a href="{sidebar}">{sidebar}</a>',
|
2023-11-04 22:03:26 +00:00
|
|
|
user_id=v.id
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
2024-03-06 03:31:45 +00:00
|
|
|
return {"message": "Sidebar image deleted successfully!"}
|
2023-11-04 22:03:26 +00:00
|
|
|
|
2024-03-06 03:31:45 +00:00
|
|
|
@app.post("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def upload_hole_banner(v, hole):
|
2024-02-28 22:34:26 +00:00
|
|
|
if g.is_tor: abort(403, "File uploads are not allowed through TOR")
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
hole = get_hole(hole)
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole.name): abort(403)
|
2023-10-05 08:32:51 +00:00
|
|
|
if v.shadowbanned: abort(500)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2024-03-06 03:31:45 +00:00
|
|
|
file = request.files["image"]
|
2022-02-10 20:35:16 +00:00
|
|
|
|
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)
|
2023-10-27 13:17:38 +00:00
|
|
|
bannerurl = process_image(name, v, resize=1600)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
hole.bannerurls.append(bannerurl)
|
2022-12-11 23:44:34 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
g.db.add(hole)
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.name,
|
2022-12-11 23:44:34 +00:00
|
|
|
kind='upload_banner',
|
2024-03-02 21:07:05 +00:00
|
|
|
_note=f'<a href="{bannerurl}">{bannerurl}</a>',
|
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
|
|
|
|
2024-03-06 03:31:45 +00:00
|
|
|
return {"message": "Banner uploaded successfully!", "url": bannerurl}
|
2022-02-10 20:35:16 +00:00
|
|
|
|
2024-03-06 03:31:45 +00:00
|
|
|
@app.post("/h/<hole>/settings/banners/delete")
|
2023-11-25 23:36:03 +00:00
|
|
|
@limiter.limit("1/second", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("1/second", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2024-03-06 03:31:45 +00:00
|
|
|
def delete_hole_banner(v, hole):
|
2023-10-07 17:55:50 +00:00
|
|
|
hole = get_hole(hole)
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole.name): abort(403)
|
2022-12-11 23:44:34 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if not hole.bannerurls:
|
2024-03-06 03:31:45 +00:00
|
|
|
abort(404, f"Banner not found (/h/{hole.name} has no banner images)")
|
|
|
|
|
|
|
|
banner = request.values["url"]
|
|
|
|
|
|
|
|
if banner not in hole.bannerurls:
|
|
|
|
abort(404, "Banner not found!")
|
|
|
|
|
|
|
|
try: remove_media_using_link(banner)
|
|
|
|
except FileNotFoundError: pass
|
|
|
|
|
|
|
|
hole.bannerurls.remove(banner)
|
2023-10-07 17:55:50 +00:00
|
|
|
g.db.add(hole)
|
2022-12-11 23:44:34 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.name,
|
2024-03-24 14:36:02 +00:00
|
|
|
kind='delete_banner',
|
2024-03-02 21:07:05 +00:00
|
|
|
_note=f'<a href="{banner}">{banner}</a>',
|
2022-12-11 23:44:34 +00:00
|
|
|
user_id=v.id
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-12-11 23:44:34 +00:00
|
|
|
|
2024-03-06 03:31:45 +00:00
|
|
|
return {"message": "Banner deleted successfully!"}
|
2022-12-11 23:44:34 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post("/h/<hole>/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)
|
2024-02-24 23:45:09 +00:00
|
|
|
@limiter.limit("5/minute;50/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("5/minute;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-10-07 17:55:50 +00:00
|
|
|
def hole_marsey(v, hole):
|
2024-02-28 22:34:26 +00:00
|
|
|
if g.is_tor: abort(403, "File uploads are not allowed through TOR!")
|
2022-08-24 22:22:44 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
hole = get_hole(hole)
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole.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:
|
2023-10-07 17:55:50 +00:00
|
|
|
if hole.marseyurl:
|
|
|
|
remove_media_using_link(hole.marseyurl)
|
|
|
|
hole.marseyurl = marseyurl
|
|
|
|
g.db.add(hole)
|
2022-08-24 22:22:44 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.name,
|
2022-09-29 09:39:37 +00:00
|
|
|
kind='change_marsey',
|
2024-03-02 21:07:05 +00:00
|
|
|
_note=f'<a href="{hole.marseyurl}">{hole.marseyurl}</a>',
|
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-10-07 17:55:50 +00:00
|
|
|
return redirect(f'/h/{hole}/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):
|
2024-02-07 04:16:17 +00:00
|
|
|
holes = g.db.query(Hole, func.count(Post.hole)).outerjoin(Post, Hole.name == Post.hole).group_by(Hole.name).order_by(Hole.created_utc).all()
|
2023-03-16 06:27:58 +00:00
|
|
|
total_users = g.db.query(User).count()
|
2024-02-07 04:09:10 +00:00
|
|
|
return render_template('hole/holes.html', v=v, holes=holes, 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)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if not p.hole: abort(403)
|
2022-07-01 23:11:48 +00:00
|
|
|
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(p.hole): abort(403)
|
2022-07-01 23:11:48 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
num = g.db.query(Post).filter(Post.hole == p.hole, Post.hole_pinned != None).count()
|
2023-03-15 06:24:48 +00:00
|
|
|
if num >= 2:
|
2023-10-07 17:55:50 +00:00
|
|
|
abort(403, f"You can only pin 2 posts to /h/{p.hole}")
|
2023-03-15 06:24:48 +00:00
|
|
|
|
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:
|
2024-02-20 00:00:21 +00:00
|
|
|
message = f"@{v.username} (a /h/{p.hole} mod) has pinned {p.textlink} in /h/{p.hole}"
|
2022-08-13 07:08:32 +00:00
|
|
|
send_repeatable_notification(p.author_id, message)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=p.hole,
|
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)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"Post pinned to /h/{p.hole} 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)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if not p.hole: abort(403)
|
2022-07-01 23:11:48 +00:00
|
|
|
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(p.hole): abort(403)
|
2022-07-01 23:11:48 +00:00
|
|
|
|
|
|
|
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:
|
2024-02-20 00:00:21 +00:00
|
|
|
message = f"@{v.username} (a /h/{p.hole} mod) has unpinned {p.textlink} in /h/{p.hole}"
|
2022-08-13 07:08:32 +00:00
|
|
|
send_repeatable_notification(p.author_id, message)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=p.hole,
|
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)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"Post unpinned from /h/{p.hole} successfully!"}
|
2022-08-19 21:31:26 +00:00
|
|
|
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.post('/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def hole_stealth(v, hole):
|
|
|
|
hole = get_hole(hole)
|
2024-02-10 18:23:10 +00:00
|
|
|
if hole.name in {'braincels','smuggies','mnn','glory','racist'} and v.admin_level < PERMS["MODS_EVERY_HOLE"]:
|
2023-01-20 05:15:08 +00:00
|
|
|
abort(403)
|
2024-01-12 07:18:04 +00:00
|
|
|
if not v.mods_hole(hole.name): abort(403)
|
2022-08-19 21:31:26 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
hole.stealth = not hole.stealth
|
|
|
|
g.db.add(hole)
|
2022-08-19 21:31:26 +00:00
|
|
|
|
|
|
|
cache.delete_memoized(frontlist)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if hole.stealth:
|
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.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)
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"Stealth mode has been enabled for /h/{hole} successfully!"}
|
2022-08-19 21:31:26 +00:00
|
|
|
else:
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.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)
|
2023-10-07 17:55:50 +00:00
|
|
|
return {"message": f"Stealth mode has been disabled for /h/{hole} successfully!"}
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2024-02-15 21:34:09 +00:00
|
|
|
@app.post('/h/<hole>/public_use')
|
|
|
|
@limiter.limit('1/second', scope=rpath)
|
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
|
|
|
@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)
|
|
|
|
@auth_required
|
|
|
|
def hole_public_use(v, hole):
|
|
|
|
hole = get_hole(hole)
|
|
|
|
|
|
|
|
if not v.mods_hole(hole.name): abort(403)
|
|
|
|
|
2024-03-30 21:59:54 +00:00
|
|
|
if hole in {'furry','vampire','racist','femboy','edgy'}:
|
2024-03-30 22:00:03 +00:00
|
|
|
abort(400, "House holes can't have Public Use mode enabled.")
|
2024-03-30 21:59:54 +00:00
|
|
|
|
2024-02-15 21:34:09 +00:00
|
|
|
hole.public_use = not hole.public_use
|
|
|
|
g.db.add(hole)
|
|
|
|
|
|
|
|
exiles = g.db.query(Exile).filter_by(hole=hole.name)
|
|
|
|
for exile in exiles:
|
|
|
|
send_repeatable_notification(exile.user_id, f"Your exile from /h/{exile.hole} has been revoked due to its jannies enabling Public Use mode!")
|
|
|
|
g.db.delete(exile)
|
|
|
|
|
|
|
|
if hole.public_use:
|
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.name,
|
|
|
|
kind='enable_public_use',
|
|
|
|
user_id=v.id
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
return {"message": f"Public Use mode has been enabled for /h/{hole} successfully!"}
|
|
|
|
else:
|
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.name,
|
|
|
|
kind='disable_public_use',
|
|
|
|
user_id=v.id
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
return {"message": f"Public Use mode has been disabled for /h/{hole} 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
|
|
|
|
2024-02-18 15:29:53 +00:00
|
|
|
if not comment.pinned:
|
2024-02-16 12:36:45 +00:00
|
|
|
if not v.mods_hole(comment.post.hole): abort(403)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2024-02-18 15:29:53 +00:00
|
|
|
comment.pinned = v.username + " (Mod)"
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(comment)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-12-03 22:41:16 +00:00
|
|
|
comment.pin_parents()
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=comment.post.hole,
|
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:
|
2024-02-20 00:00:21 +00:00
|
|
|
message = f"@{v.username} (a /h/{comment.post.hole} mod) has pinned {comment.textlink}"
|
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
|
|
|
|
2024-02-18 15:29:53 +00:00
|
|
|
if comment.pinned:
|
2024-02-16 12:36:45 +00:00
|
|
|
if not v.mods_hole(comment.post.hole): abort(403)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2024-02-18 15:29:53 +00:00
|
|
|
comment.pinned = None
|
|
|
|
comment.pinned_utc = None
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(comment)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-12-03 22:41:16 +00:00
|
|
|
comment.unpin_parents()
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole=comment.post.hole,
|
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:
|
2024-02-20 00:00:21 +00:00
|
|
|
message = f"@{v.username} (a /h/{comment.post.hole} mod) has unpinned {comment.textlink}"
|
2022-09-29 09:39:37 +00:00
|
|
|
send_repeatable_notification(comment.author_id, message)
|
|
|
|
return {"message": "Comment unpinned!"}
|
|
|
|
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.get("/h/<hole>/log")
|
|
|
|
@app.get("/h/<hole>/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-10-07 17:55:50 +00:00
|
|
|
def hole_log(v, hole):
|
|
|
|
hole = get_hole(hole)
|
|
|
|
if not can_see(v, hole):
|
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")
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
types = HOLEACTION_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-10-07 17:55:50 +00:00
|
|
|
actions = g.db.query(HoleAction).filter_by(hole=hole.name)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
if mod_id:
|
|
|
|
actions = actions.filter_by(user_id=mod_id)
|
2024-02-15 23:12:53 +00:00
|
|
|
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-10-07 17:55:50 +00:00
|
|
|
actions = actions.order_by(HoleAction.id.desc()).offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(hole=hole.name)]
|
2023-08-11 13:15:34 +00:00
|
|
|
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-10-07 17:55:50 +00:00
|
|
|
return render_template("log.html", v=v, admins=mods, types=types, admin=mod, type=kind, actions=actions, total=total, page=page, hole=hole, single_user_url='mod')
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.get("/h/<hole>/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
|
2023-10-07 17:55:50 +00:00
|
|
|
def hole_log_item(id, v, hole):
|
|
|
|
hole = get_hole(hole)
|
|
|
|
if not can_see(v, hole):
|
2022-12-04 18:39:06 +00:00
|
|
|
abort(403)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
action = g.db.get(HoleAction, id)
|
2022-09-29 09:39:37 +00:00
|
|
|
|
|
|
|
if not action: abort(404)
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
mods = [x[0] for x in g.db.query(Mod.user_id).filter_by(hole=hole.name)]
|
2023-08-11 13:15:34 +00:00
|
|
|
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-10-07 17:55:50 +00:00
|
|
|
types = HOLEACTION_TYPES
|
2022-09-29 09:39:37 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
return render_template("log.html", v=v, actions=[action], total=1, page=1, action=action, admins=mods, types=types, hole=hole, single_user_url='mod')
|
2024-02-11 10:26:54 +00:00
|
|
|
|
|
|
|
@app.post('/h/<hole>/snappy_quotes')
|
|
|
|
@limiter.limit('1/second', scope=rpath)
|
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
|
|
|
@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)
|
|
|
|
@auth_required
|
|
|
|
def post_hole_snappy_quotes(v, hole):
|
|
|
|
hole = get_hole(hole)
|
|
|
|
snappy_quotes = request.values.get('snappy_quotes', '').strip()
|
|
|
|
|
|
|
|
if not hole: abort(404)
|
|
|
|
if not v.mods_hole(hole.name): abort(403)
|
|
|
|
if v.shadowbanned: abort(400)
|
|
|
|
|
2024-02-15 22:24:38 +00:00
|
|
|
if snappy_quotes.endswith('[para]'):
|
|
|
|
snappy_quotes = snappy_quotes[:-6].strip()
|
|
|
|
|
2024-02-11 10:26:54 +00:00
|
|
|
if len(snappy_quotes) > HOLE_SNAPPY_QUOTES_LENGTH:
|
2024-02-14 09:34:49 +00:00
|
|
|
abort(400, f"Quotes are too long (max {HOLE_SNAPPY_QUOTES_LENGTH} characters)")
|
2024-02-11 10:26:54 +00:00
|
|
|
|
|
|
|
hole.snappy_quotes = snappy_quotes
|
|
|
|
g.db.add(hole)
|
|
|
|
|
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole.name,
|
|
|
|
kind='edit_snappy_quotes',
|
|
|
|
user_id=v.id
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
|
|
|
return {"message": "Snappy quotes edited successfully!"}
|
2024-02-14 12:49:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.post("/change_hole/<int:pid>")
|
|
|
|
@limiter.limit('1/second', scope=rpath)
|
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
|
|
|
@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)
|
|
|
|
@auth_required
|
|
|
|
def change_hole(pid, v):
|
|
|
|
post = get_post(pid)
|
|
|
|
|
|
|
|
if post.ghost:
|
|
|
|
abort(403, "You can't move ghost posts into holes!")
|
|
|
|
|
|
|
|
hole_from = post.hole
|
|
|
|
|
|
|
|
hole_to = request.values.get("hole_to", "").strip()
|
|
|
|
hole_to = get_hole(hole_to, graceful=True)
|
|
|
|
hole_to = hole_to.name if hole_to else None
|
|
|
|
|
|
|
|
if not post.hole_changable(v):
|
2024-02-18 20:06:36 +00:00
|
|
|
abort(403, "You can't change the hole of this post!")
|
2024-02-14 12:49:29 +00:00
|
|
|
|
|
|
|
if hole_to == None:
|
|
|
|
if HOLE_REQUIRED:
|
|
|
|
abort(403, "All posts are required to be in holes!")
|
|
|
|
hole_to_in_notif = 'the main feed'
|
|
|
|
else:
|
|
|
|
hole_to_in_notif = f'/h/{hole_to}'
|
|
|
|
|
|
|
|
if hole_from == hole_to:
|
|
|
|
abort(409, f"Post is already in {hole_to_in_notif}")
|
|
|
|
|
|
|
|
if post.author.exiler_username(hole_to):
|
|
|
|
abort(403, f"User is exiled from this hole!")
|
|
|
|
|
|
|
|
if hole_to == 'changelog':
|
|
|
|
abort(403, "/h/changelog is archived!")
|
|
|
|
|
|
|
|
if hole_to in {'furry','vampire','racist','femboy','edgy'} and not v.client and not post.author.house.lower().startswith(hole_to):
|
|
|
|
if v.id == post.author_id:
|
|
|
|
abort(403, f"You need to be a member of House {hole_to.capitalize()} to post in /h/{hole_to}")
|
|
|
|
else:
|
|
|
|
abort(403, f"@{post.author_name} needs to be a member of House {hole_to.capitalize()} for their post to be moved to /h/{hole_to}")
|
|
|
|
|
|
|
|
post.hole = hole_to
|
|
|
|
post.hole_pinned = None
|
|
|
|
|
|
|
|
if hole_to == 'chudrama':
|
|
|
|
post.bannedfor = None
|
|
|
|
post.chuddedfor = None
|
|
|
|
for c in post.comments:
|
|
|
|
c.bannedfor = None
|
|
|
|
c.chuddedfor = None
|
|
|
|
g.db.add(c)
|
|
|
|
|
|
|
|
g.db.add(post)
|
|
|
|
|
|
|
|
if v.id != post.author_id:
|
|
|
|
hole_from_str = 'main feed' if hole_from is None else \
|
|
|
|
f'<a href="/h/{hole_from}">/h/{hole_from}</a>'
|
|
|
|
hole_to_str = 'main feed' if hole_to is None else \
|
|
|
|
f'<a href="/h/{hole_to}">/h/{hole_to}</a>'
|
|
|
|
|
|
|
|
if v.admin_level >= PERMS['POST_COMMENT_MODERATION']:
|
|
|
|
ma = ModAction(
|
|
|
|
kind='change_hole',
|
|
|
|
user_id=v.id,
|
|
|
|
target_post_id=post.id,
|
2024-03-02 21:01:29 +00:00
|
|
|
_note=f'{hole_from_str} → {hole_to_str}',
|
2024-02-14 12:49:29 +00:00
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2024-02-18 16:10:24 +00:00
|
|
|
position = 'a site admin'
|
2024-02-14 12:49:29 +00:00
|
|
|
else:
|
|
|
|
ma = HoleAction(
|
|
|
|
hole=hole_from,
|
|
|
|
kind='change_hole',
|
|
|
|
user_id=v.id,
|
|
|
|
target_post_id=post.id,
|
2024-03-02 21:01:29 +00:00
|
|
|
_note=f'{hole_from_str} → {hole_to_str}',
|
2024-02-14 12:49:29 +00:00
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2024-02-18 16:10:24 +00:00
|
|
|
position = f'a /h/{hole_from} mod'
|
2024-02-14 12:49:29 +00:00
|
|
|
|
|
|
|
if hole_from == None:
|
|
|
|
hole_from_in_notif = 'the main feed'
|
|
|
|
else:
|
|
|
|
hole_from_in_notif = f'/h/{hole_from}'
|
|
|
|
|
2024-02-20 00:00:21 +00:00
|
|
|
message = f"@{v.username} ({position}) has moved {post.textlink} from {hole_from_in_notif} to {hole_to_in_notif}"
|
2024-02-14 12:49:29 +00:00
|
|
|
send_repeatable_notification(post.author_id, message)
|
|
|
|
|
|
|
|
cache.delete_memoized(frontlist)
|
|
|
|
|
|
|
|
return {"message": f"Post moved to {hole_to_in_notif} successfully!"}
|