From 33464589aa3be63c0f4077421793e06dc73604dc Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 25 Mar 2023 23:35:13 +0200 Subject: [PATCH] add "offline mode" --- files/helpers/config/const.py | 1 + files/helpers/config/modaction_types.py | 10 ++++++++++ files/helpers/settings.py | 1 + files/routes/admin.py | 4 ++++ files/routes/wrappers.py | 5 ++++- files/templates/admin/admin_home.html | 10 ++++++---- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 9f398b316..6b77d4e97 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -504,6 +504,7 @@ PERMS = { # Minimum admin_level to perform action. 'IGNORE_BADGE_BLACKLIST': 5, 'ENABLE_DM_IMAGES': 5, 'SEE_GHOST_VOTES': 5, + 'SITE_OFFLINE_MODE': 5, 'MODS_EVERY_HOLE': 6, 'MODS_EVERY_GROUP': 6, diff --git a/files/helpers/config/modaction_types.py b/files/helpers/config/modaction_types.py index 3e7197ce7..2ecac9a66 100644 --- a/files/helpers/config/modaction_types.py +++ b/files/helpers/config/modaction_types.py @@ -66,6 +66,11 @@ MODACTION_TYPES = { "icon": 'fa-gas-pump-slash', "color": 'bg-danger' }, + 'disable_offline_mode': { + "str": 'disabled offline mode', + "icon": 'fa-lock-open', + "color": 'bg-success' + }, 'disable_read_only_mode': { "str": 'disabled read only mode', "icon": 'fa-book', @@ -136,6 +141,11 @@ MODACTION_TYPES = { "icon": 'fa-gas-pump', "color": 'bg-success' }, + 'enable_offline_mode': { + "str": 'enabled offline mode', + "icon": 'fa-lock', + "color": 'bg-danger' + }, 'enable_read_only_mode': { "str": 'enabled read only mode', "icon": 'fa-book', diff --git a/files/helpers/settings.py b/files/helpers/settings.py index c3135bfca..2419f2f22 100644 --- a/files/helpers/settings.py +++ b/files/helpers/settings.py @@ -10,6 +10,7 @@ _SETTINGS = { "bots": True, "fart_mode": False, "read_only_mode": False, + "offline_mode": False, "signups": True, "login_required": False, "under_siege": False, diff --git a/files/routes/admin.py b/files/routes/admin.py index ab6030e46..3be6e38cb 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -376,6 +376,10 @@ def change_settings(v:User, setting): if setting not in get_settings().keys(): abort(404, f"Setting '{setting}' not found") + + if setting == "offline_mode" and v.admin_level < PERMS["SITE_OFFLINE_MODE"]: + abort(403, "You can't change this setting!") + val = toggle_setting(setting) if val: word = 'enable' else: word = 'disable' diff --git a/files/routes/wrappers.py b/files/routes/wrappers.py index e7a64c45d..094d34f50 100644 --- a/files/routes/wrappers.py +++ b/files/routes/wrappers.py @@ -55,7 +55,10 @@ def get_logged_in_user(): session.pop("lo_user") if request.method.lower() != "get" and get_setting('read_only_mode') and not (v and v.admin_level >= PERMS['SITE_BYPASS_READ_ONLY_MODE']): - abort(403) + abort(403, "Site is in read-only mode right now. It will be back shortly!") + + if get_setting('offline_mode') and not (v and v.admin_level >= PERMS['SITE_OFFLINE_MODE']): + abort(403, "Site is in offline mode right now. It will be back shortly!") g.v = v diff --git a/files/templates/admin/admin_home.html b/files/templates/admin/admin_home.html index 6724f58d4..e9ce11322 100644 --- a/files/templates/admin/admin_home.html +++ b/files/templates/admin/admin_home.html @@ -120,10 +120,12 @@ {% if v.admin_level >= PERMS['SITE_SETTINGS'] %} {% for setting in SITE_SETTINGS.keys() %} -
- - -
+ {% if not (setting == "offline_mode" and v.admin_level < PERMS["SITE_OFFLINE_MODE"]) %} +
+ + +
+ {% endif %} {% endfor %} {% endif %}