make API message better

also make unchecking the box hide the permalink
master
justcool393 2022-11-06 20:11:59 -06:00
parent 57df202cfa
commit 7de3bb064c
2 changed files with 22 additions and 6 deletions

View File

@ -51,14 +51,14 @@ def settings_personal_post(v):
return True
return False
def update_flag_with_permanence(column_name:str, request_name:str, friendly_name:str, badge_id:Optional[int]):
def update_potentially_permanent_flag(column_name:str, request_name:str, friendly_name:str, badge_id:Optional[int]):
if not request.values.get(request_name): return False
current_value = getattr(v, column_name)
if FEATURES['USERS_PERMANENT_WORD_FILTERS'] and current_value > 1:
abort(403, f"Cannot change the {friendly_name} setting after you've already set it permanently!")
request_flag = int(request.values.get(request_name, '') == 'true')
if current_value and request_flag and request.values.get("permanent", '') == 'true' and request.values.get("username") == v.username:
if v.client: abort(403, "Cannot set filters permanently from the API")
if v.client: abort(403, f"Cannot set {friendly_name} permanently from the API")
request_flag = int(time.time())
setattr(v, column_name, request_flag)
if badge_id: badge_grant(v, badge_id)
@ -80,14 +80,14 @@ def settings_personal_post(v):
updated = True
session['poor'] = v.poor
slur_filter_updated = updated or update_flag_with_permanence("slurreplacer", "slurreplacer", "slur replacer", 192)
slur_filter_updated = updated or update_potentially_permanent_flag("slurreplacer", "slurreplacer", "slur replacer", 192)
if isinstance(slur_filter_updated, bool):
updated = slur_filter_updated
else:
g.db.add(v)
return slur_filter_updated
profanity_filter_updated = updated or update_flag_with_permanence("profanityreplacer", "profanityreplacer", "profanity replacer", 190)
profanity_filter_updated = updated or update_potentially_permanent_flag("profanityreplacer", "profanityreplacer", "profanity replacer", 190)
if isinstance(profanity_filter_updated, bool):
updated = profanity_filter_updated
else:

View File

@ -220,14 +220,14 @@
{% set ns = namespace(slurtext='Enable if you would like to automatically replace slurs.', profanitytext='Enable if you would like to automatically replace slurs.') %}
{% if FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.slurreplacer %}
{% if v.slurreplacer == 1 %}
{% set ns.slurtext = 'Enable if you would like to automatically replace slurs. <a href="#" class="text-primary" data-bs-toggle="modal" data-bs-target="#modal-slurreplacer">Make filter permanent for a badge!</a>' %}
{% set ns.slurtext = 'Enable if you would like to automatically replace slurs. <a id="slurreplacer-perma-link" href="#" class="text-primary" data-bs-toggle="modal" data-bs-target="#modal-slurreplacer">Make filter permanent for a badge!</a>' %}
{% else %}
{% set ns.slurttext = "You've enabled the slur replacer permanently! ✊🏿" %}
{% endif %}
{% endif %}
{% if FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.profanityreplacer %}
{% if v.profanityreplacer == 1 %}
{% set ns.profanitytext = 'Enable if you would like to automatically replace profanities. <a href="#" class="text-primary" data-bs-toggle="modal" data-bs-target="#modal-profanityreplacer">Make filter permanent for a badge!</a>' %}
{% set ns.profanitytext = 'Enable if you would like to automatically replace profanities. <a id="profanityreplacer-perma-link" href="#" class="text-primary" data-bs-toggle="modal" data-bs-target="#modal-profanityreplacer">Make filter permanent for a badge!</a>' %}
{% else %}
{% set ns.profanitytext = "You've enabled the profanity replacer permanently! 😇" %}
{% endif %}
@ -306,4 +306,20 @@
{% if v.profanityreplacer == 1 -%}
{{permanent_filter_modal('profanityreplacer', '/settings/personal', 'profanityreplacer', 'Profanity Replacer', 'Soapy-Mouthed Angel')}}
{%- endif %}
{% if FEATURES['PERMANENT_WORD_FILTERS'] -%}
<script>
document.addEventListener("DOMContentLoaded", function (event) {
const sr_toggle = document.getElementById("slurreplacer");
const sr_link = document.getElementById('slurreplacer-perma-link');
const pr_toggle = document.getElementById("profanityreplacer");
const pr_link = document.getElementById('profanityreplacer-perma-link');
sr_toggle.addEventListener('change', function (event) {
sr_link.hidden = !sr_toggle.checked;
});
pr_toggle.addEventListener('change', function (event) {
pr_link.hidden = !pr_toggle.checked;
});
});
</script>
{% endif %}
{% endblock %}