add "offline mode"

pull/142/head
Aevann 2023-03-25 23:35:13 +02:00
parent 312abdee28
commit 33464589aa
6 changed files with 26 additions and 5 deletions

View File

@ -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,

View File

@ -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',

View File

@ -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,

View File

@ -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'

View File

@ -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

View File

@ -120,10 +120,12 @@
{% if v.admin_level >= PERMS['SITE_SETTINGS'] %}
{% for setting in SITE_SETTINGS.keys() %}
<div class="custom-control custom-switch{% if loop.index > 1 %} mt-1{% endif %}" id="settings-{{setting}}-container">
<input autocomplete="off" type="checkbox" class="custom-control-input" id="settings-{{setting}}-checkbox" {% if SITE_SETTINGS[setting] %}checked{% endif %} data-nonce="{{g.nonce}}" data-onchange="postToastSwitch(this, '/admin/site_settings/{{setting}}');">
<label class="custom-control-label" for="settings-{{setting}}-checkbox">{{setting.replace('_', ' ').title()}}</label>
</div>
{% if not (setting == "offline_mode" and v.admin_level < PERMS["SITE_OFFLINE_MODE"]) %}
<div class="custom-control custom-switch{% if loop.index > 1 %} mt-1{% endif %}" id="settings-{{setting}}-container">
<input autocomplete="off" type="checkbox" class="custom-control-input" id="settings-{{setting}}-checkbox" {% if SITE_SETTINGS[setting] %}checked{% endif %} data-nonce="{{g.nonce}}" data-onchange="postToastSwitch(this, '/admin/site_settings/{{setting}}');">
<label class="custom-control-label" for="settings-{{setting}}-checkbox">{{setting.replace('_', ' ').title()}}</label>
</div>
{% endif %}
{% endfor %}
{% endif %}