From 775169b2abbc9cbda09532712d47af865fcf6353 Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 15 Feb 2024 23:34:09 +0200 Subject: [PATCH] add public use mode --- files/classes/hole.py | 1 + files/helpers/config/holeaction_types.py | 10 ++++ files/routes/holes.py | 64 +++++++++++++++++---- files/templates/hole/settings.html | 13 +++++ migrations/20240215-add-public-use-mode.sql | 2 + 5 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 migrations/20240215-add-public-use-mode.sql diff --git a/files/classes/hole.py b/files/classes/hole.py index 0cfa9d530..a84b38212 100644 --- a/files/classes/hole.py +++ b/files/classes/hole.py @@ -23,6 +23,7 @@ class Hole(Base): marseyurl = Column(VARCHAR(HOLE_MARSEY_URL_LENGTH)) css = deferred(Column(VARCHAR(CSS_LENGTH_LIMIT))) stealth = Column(Boolean, default=False) + public_use = Column(Boolean, default=False) created_utc = Column(Integer) if SITE_NAME == 'WPD': snappy_quotes = None diff --git a/files/helpers/config/holeaction_types.py b/files/helpers/config/holeaction_types.py index 374258155..ca8bcab2c 100644 --- a/files/helpers/config/holeaction_types.py +++ b/files/helpers/config/holeaction_types.py @@ -94,6 +94,16 @@ HOLEACTION_TYPES = { "icon": 'fa-thumbtack fa-rotate--45', "color": 'bg-muted' }, + 'enable_public_use': { + "str": 'enabled public use mode', + "icon": 'fa-users', + "color": 'bg-primary' + }, + 'disable_public_use': { + "str": 'disabled public use mode', + "icon": 'fa-users', + "color": 'bg-muted' + }, 'enable_stealth': { "str": 'enabled stealth mode', "icon": 'fa-user-ninja', diff --git a/files/routes/holes.py b/files/routes/holes.py index c34ddfbf6..580c92d11 100644 --- a/files/routes/holes.py +++ b/files/routes/holes.py @@ -16,13 +16,15 @@ from files.__main__ import app, cache, limiter @auth_required def exile_post(v, pid): p = get_post(pid) - hole = p.hole + hole = p.hole_obj if not hole: abort(400) - if not v.mods_hole(hole): abort(403) + if hole.public_use: + abort(403, "You can't exile users while Public Use mode is enabled!") - if hole in {'atheism', 'dioceseofrdrama', 'truth'}: - abort(403, f"/h/{hole} has the exiling feature disabled due to being unblockable.") + hole = hole.name + + if not v.mods_hole(hole): abort(403) u = p.author @@ -53,13 +55,15 @@ def exile_post(v, pid): @auth_required def exile_comment(v, cid): c = get_comment(cid) - hole = c.post.hole + hole = c.post.hole_obj if not hole: abort(400) - if not v.mods_hole(hole): abort(403) + if hole.public_use: + abort(403, "You can't exile users while Public Use mode is enabled!") - if hole in {'atheism', 'dioceseofrdrama', 'truth'}: - abort(403, f"/h/{hole} has the exiling feature disabled due to being unblockable.") + hole = hole.name + + if not v.mods_hole(hole): abort(403) u = c.author @@ -116,10 +120,13 @@ def unexile(v, hole, uid): @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) @auth_required def block_sub(v, hole): - if hole in {'atheism', 'dioceseofrdrama', 'truth'}: - abort(403, f"/h/{hole} is unblockable!") + hole = get_hole(hole) + + if hole.public_use: + abort(403, f"/h/{hole} has Public Use mode enabled and is unblockable!") + + hole = hole.name - hole = get_hole(hole).name existing = g.db.query(HoleBlock).filter_by(user_id=v.id, hole=hole).one_or_none() if not existing: block = HoleBlock(user_id=v.id, hole=hole) @@ -846,6 +853,41 @@ def hole_stealth(v, hole): g.db.add(ma) return {"message": f"Stealth mode has been disabled for /h/{hole} successfully!"} +@app.post('/h//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) + + 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!"} @app.post("/pin_comment_mod/") @feature_required('PINS') diff --git a/files/templates/hole/settings.html b/files/templates/hole/settings.html index a0b05d296..6970b20f0 100644 --- a/files/templates/hole/settings.html +++ b/files/templates/hole/settings.html @@ -15,6 +15,19 @@ +
+ +
+
+
+ + +
+ + Make this hole unblockable and can't be exiled from. + +
+
Marsey
sub marsey picture diff --git a/migrations/20240215-add-public-use-mode.sql b/migrations/20240215-add-public-use-mode.sql new file mode 100644 index 000000000..4f583ece4 --- /dev/null +++ b/migrations/20240215-add-public-use-mode.sql @@ -0,0 +1,2 @@ +alter table holes add column public_use bool default false not null; +alter table holes alter column public_use drop default;