settings: implement front end for perma-filters

remotes/1693176582716663532/tmp_refs/heads/watchparty
justcool393 2022-11-06 04:27:44 -06:00
parent 3a989356dd
commit 72da55fd61
4 changed files with 54 additions and 4 deletions

View File

@ -312,6 +312,7 @@ FEATURES = {
'USERS_PROFILE_BANNER': True,
'USERS_PROFILE_BODYTEXT': True,
'USERS_PROFILE_SONG': True,
'USERS_PERMANENT_WORD_FILTERS': False,
'USERS_SUICIDE': True,
'MARKUP_COMMANDS': True,
'REPOST_DETECTION': True,
@ -473,6 +474,7 @@ HOUSE_SWITCH_COST = 2000
if SITE.startswith('rdrama.'):
FEATURES['PRONOUNS'] = True
FEATURES['HOUSES'] = True
FEATURES['USERS_PERMANENT_WORD_FILTERS'] = True
PERMS['ADMIN_ADD'] = 4
SIDEBAR_THREAD = 37696

View File

@ -21,7 +21,6 @@ import requests
def settings(v):
return redirect("/settings/personal")
@app.get("/settings/personal")
@auth_required
def settings_personal(v):

View File

@ -1,15 +1,15 @@
{% macro toggle_section(title, id, name, flag, below_text) %}
{% macro toggle_section(title, id, name, flag, below_text, disabled) %}
<div class="d-lg-flex border-bottom">
<div class="title w-lg-25">
<label for="{{id}}">{{title}}</label>
</div>
<div class="body w-lg-100">
<div class="custom-control custom-switch">
<input autocomplete="off" type="checkbox" class="custom-control-input" id="{{id}}" name="{{name}}"{% if flag %} checked{% endif %} onchange="postToastSwitch(this,'/settings/profile?{{name}}='+document.getElementById('{{id}}').checked)">
<input autocomplete="off" type="checkbox" class="custom-control-input" id="{{id}}" name="{{name}}"{% if flag %} checked{% endif %} {% if disabled %}disabled=""{% else %}onchange="postToastSwitch(this,'/settings/profile?{{name}}='+document.getElementById('{{id}}').checked)"{% endif %}>
<label class="custom-control-label" for="{{id}}"></label>
</div>
{% if below_text %}
<span class="text-small text-muted">{{below_text}}</span>
<span class="text-small text-muted">{{below_text|safe}}</span>
{% endif %}
</div>
</div>

View File

@ -211,6 +211,19 @@
<section id="site-settings-filters-section" class="settings-section-section">
<h5>Filters</h5>
<div class="settings-section rounded" id="site-settings-filters">
{# toggle_section(title, id, name, flag, below_text, disabled) #}
{% if FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.slurreplacer %}
{% set slurtext = 'Enable if you would like to automatically replace slurs. <a class="danger" data-bs-toggle="modal" data-bs-target="#modal-slurreplacer">Make filter permanent for a badge!</a>' %}
{% else %}
{% set slurtext = 'Enable if you would like to automatically replace slurs.' %}
{% endif %}
{% if FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.profanityreplacer %}
{% set slurtext = 'Enable if you would like to automatically replace profanities. <a class="danger" data-bs-toggle="modal" data-bs-target="#modal-profanityreplacer">Make filter permanent for a badge!</a>' %}
{% else %}
{% set profanitytext = 'Enable if you would like to automatically replace profanities.' %}
{% endif %}
{{toggle_section("Slur Replacer", "slurreplacer", v.slurreplacer, slurtext, FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.slurreplacer > 1)}}
{{toggle_section("Profanity Replacer", "profanityreplacer", v.slurreplacer, profanitytext, FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.profanityreplacer > 1)}}
{# profanity filter toggle (and lock?) #}
{# slur filter toggle (and lock?) #}
</div>
@ -249,4 +262,40 @@
{% endif %}
<script defer src="{{'js/settings_profile.js' | asset}}"></script>
{% macro permanent_filter_modal(id, form_action, field, friendly_name, badge_name) %}
{% if FEATURES['USERS_PERMANENT_WORD_FILTERS'] -%}
<div class="modal fade" id="modal-{{id}}" tabindex="-1" role="dialog" aria-labelledby="{{id}}modal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<form class="m-auto" action="{{form_action}}" id="exile-form" method="post" onsubmit="return false;">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Make {{friendly_name}} Permanent</h5>
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Cancel">
<span aria-hidden="true"><i class="far fa-times"></i></span>
</button>
</div>
<div class="modal-body">
<input type="hidden" name="{{field}}" value="true">
<input type="hidden" name="permanent" value="true">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<p>This form will permanently enable the filter for you. You will receive the {{badge_name}} badge and will not be able to disable the filter.<br>Type your username to continue.</p>
<input autocomplete="off" type="text" name="username" placeholder="Enter your username" id="username-{{id}}" class="form-control" pattern="{{v.username}}" required>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-link text-muted" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" id="submit-{{id}}-form">Make Permanent</button>
</div>
</div>
</form>
</div>
</div>
{%- endif %}
{% endmacro %}
{% if v.slurreplacer and v.slurreplacer == 1 %}
{{permanent_filter_modal('slurreplacer', '/settings/profile', 'slurreplacer', 'Slur Replacer', 'Social Justice Berserker')}}
{% endif %}
{% if v.profanityreplacer and v.profanityreplacer == 1 %}
{{permanent_filter_modal('profanityreplacer', '/settings/profile', 'profanityreplacer', 'Profanity Replacer', 'Soapy-Mouthed Angel')}}
{% endif %}
{% endblock %}