From 6ad935e12a6a2d0dcf1a19dc35183b4e239ee3b1 Mon Sep 17 00:00:00 2001 From: TLSM Date: Wed, 6 Jul 2022 23:45:33 -0400 Subject: [PATCH] Permission flags UI visibility; start PERMS dict. Original work started for WPD and LGB, who wish to restrict flags visibility in the UI based on admin_level. To support this change and upcoming changes, `const.PERMS: string -> int` was created. Potentially targetting a future design where Permissions is a proper business object integrated with the User model; however, for now just looking toward getting admin_level magic numbers centralized. This commit applies PERMS to: create_hole, flags visibility in UI, flag removal in UI & backend. Flag visibility in Comment & Submission json_raw methods is unaffected to avoid needing a user object to build the JSON. --- files/classes/user.py | 2 +- files/helpers/const.py | 18 ++++++++++++++---- files/helpers/jinja2.py | 2 +- files/routes/reporting.py | 4 ++-- files/templates/comments.html | 6 +++--- files/templates/submission.html | 6 +++--- files/templates/submission_listing.html | 6 +++--- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index c136a1720..58f9c2cd2 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -735,4 +735,4 @@ class User(Base): @property @lazy def can_create_hole(self): - return self.admin_level >= HOLE_CREATE_JL_MIN + return self.admin_level >= PERMS['HOLE_CREATE'] diff --git a/files/helpers/const.py b/files/helpers/const.py index 95c702419..3a39a69c7 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -143,8 +143,15 @@ HOLE_NAME = 'hole' HOLE_STYLE_FLAIR = False HOLE_REQUIRED = False HOLE_COST = 0 -HOLE_CREATE_JL_MIN = 0 HOLE_INACTIVITY_DELETION = False + +PERMS = { # Minimum admin_level to perform action. + 'HOLE_CREATE': 0, + 'FLAGS_VISIBLE': 0, + 'FLAGS_VISIBLE_REPORTER': 0, + 'FLAGS_REMOVE': 2, +} + PIN_ENABLED = True PIN_LIMIT = 3 POST_RATE_LIMIT = '1/second;2/minute;10/hour;50/day' @@ -285,7 +292,9 @@ elif SITE == 'watchpeopledie.co': HOLE_NAME = 'flair' HOLE_STYLE_FLAIR = True HOLE_REQUIRED = True - HOLE_CREATE_JL_MIN = 2 + + PERMS['HOLE_CREATE'] = 2 + PERMS['FLAGS_VISIBLE'] = 2 GIFT_NOTIF_ID = 13 CARP_ID = 13 @@ -294,8 +303,10 @@ elif SITE == 'watchpeopledie.co': PROCOINS_ENABLED = False elif SITE == 'lgbdropthet.com': - HOLE_CREATE_JL_MIN = 3 + PERMS['HOLE_CREATE'] = 3 + PERMS['FLAGS_VISIBLE_REPORTER'] = 2 + AEVANN_ID = 10 SNAKES_ID = 9 PROCOINS_ENABLED = False @@ -796,7 +807,6 @@ if SITE != 'localhost': REDDIT_NOTIFS_SITE = [SITE] if SITE_NAME == 'rDrama': - REDDIT_NOTIFS_JL_MIN = 1 REDDIT_NOTIFS_SITE.append(['rdrama', 'marsey',]) REDDIT_NOTIFS_USERS = { 'idio3': IDIO_ID, diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index a53676c4a..7aa0a6d12 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -57,5 +57,5 @@ def inject_constants(): "COLORS":COLORS, "ADMIGGERS":ADMIGGERS, "datetime":datetime, "time":time, "HOLE_NAME": HOLE_NAME, "HOLE_STYLE_FLAIR": HOLE_STYLE_FLAIR, "HOLE_REQUIRED": HOLE_REQUIRED, "LOTTERY_ENABLED": LOTTERY_ENABLED, "GUMROAD_LINK": GUMROAD_LINK, - "DEFAULT_THEME": DEFAULT_THEME, "DESCRIPTION": DESCRIPTION, + "DEFAULT_THEME": DEFAULT_THEME, "DESCRIPTION": DESCRIPTION, "PERMS": PERMS, "PROCOINS_ENABLED": PROCOINS_ENABLED, "has_sidebar": has_sidebar, "has_logo": has_logo} diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 67eb89d91..eb295f2de 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -107,7 +107,7 @@ def api_flag_comment(cid, v): @app.post('/del_report/post//') @limiter.limit("1/second;30/minute;200/hour;1000/day") -@admin_level_required(2) +@admin_level_required(PERMS['FLAGS_REMOVE']) def remove_report_post(v, pid, uid): try: @@ -134,7 +134,7 @@ def remove_report_post(v, pid, uid): @app.post('/del_report/comment//') @limiter.limit("1/second;30/minute;200/hour;1000/day") -@admin_level_required(2) +@admin_level_required(PERMS['FLAGS_REMOVE']) def remove_report_comment(v, cid, uid): cid = int(cid) diff --git a/files/templates/comments.html b/files/templates/comments.html index 6a7b90966..de9b02665 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -188,7 +188,7 @@ {% if c.bannedfor %} {% endif %} - {% if c.active_flags %}{{c.active_flags}} Report{{ help.plural(c.active_flags) }}{% endif %} + {% if c.active_flags and (v and v.admin_level >= PERMS['FLAGS_VISIBLE']) %}{{c.active_flags}} Report{{ help.plural(c.active_flags) }}{% endif %} {% if c.over_18 %}+18{% endif %} {% if v and v.admin_level > 1 and c.author.shadowbanned %}{% endif %} {% if c.stickied %} @@ -259,13 +259,13 @@ {{c.wordle_html(v) | safe}} {% endif %} - {% if c.active_flags %} + {% if c.active_flags and (v and v.admin_level >= PERMS['FLAGS_VISIBLE']) %}
Reported by:

 				
    {% for f in c.flags %} -
  • {% if not c.ghost %}{{f.user.username}}{% else %}👻{% endif %}{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}[remove]{% endif %}
  • +
  • {% if v and v.admin_level >= PERMS['FLAGS_VISIBLE_REPORTER'] %}{% if not c.ghost %}{{f.user.username}}{% else %}👻{% endif %}{% else %}User{% endif %}{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level >= PERMS['FLAGS_REMOVE'] %}[remove]{% endif %}
  • {% endfor %}
diff --git a/files/templates/submission.html b/files/templates/submission.html index da48eb681..8ba7c8e96 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -739,7 +739,7 @@ {% if p.is_bot %} {% endif %} {% if p.over_18 %}+18{% endif %} {% if p.private %}Draft{% endif %} - {% if p.active_flags %}{{p.active_flags}} Report{{ help.plural(p.active_flags) }}{% endif %} + {% if p.active_flags and (v and v.admin_level >= PERMS['FLAGS_VISIBLE']) %}{{p.active_flags}} Report{{ help.plural(p.active_flags) }}{% endif %} {% if p.ghost %} 👻 @@ -769,13 +769,13 @@ {% endif %}   {{p.views}} thread views - {% if p.active_flags %} + {% if p.active_flags and (v and v.admin_level >= PERMS['FLAGS_VISIBLE']) %}
Reported by:

 						
    {% for f in p.flags %} -
  • {{f.user.username}}{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}[remove]{% endif %}
  • +
  • {% if v and v.admin_level >= PERMS['FLAGS_VISIBLE_REPORTER'] %}{{f.user.username}}{% else %}User{% endif %}{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level >= PERMS['FLAGS_REMOVE'] %}[remove]{% endif %}
  • {% endfor %}
diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index b5be6a694..ea551c1fd 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -67,13 +67,13 @@ {% set v_forbid_deleted = (p.deleted_utc != 0 or p.is_banned) and not (v and v.admin_level >= 2) and not (v and v.id == p.author_id) %} -{% if p.active_flags %} +{% if p.active_flags and (v and v.admin_level >= PERMS['FLAGS_VISIBLE']) %}
Reported by:

 		
    {% for f in p.flags %} -
  • {{f.user.username}}{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}[remove]{% endif %}
  • +
  • {% if v and v.admin_level >= PERMS['FLAGS_VISIBLE_REPORTER'] %}{{f.user.username}}{% else %}User{% endif %}{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level >= PERMS['FLAGS_REMOVE'] %}[remove]{% endif %}
  • {% endfor %}
@@ -189,7 +189,7 @@ {% if p.is_blocking %}{% endif %} {% if p.is_blocked %}{% endif %} {% if p.private %}Draft{% endif %} - {% if p.active_flags %}{{p.active_flags}} Report{{ help.plural(p.active_flags) }}{% endif %} + {% if p.active_flags and (v and v.admin_level >= PERMS['FLAGS_VISIBLE']) %}{{p.active_flags}} Report{{ help.plural(p.active_flags) }}{% endif %} {% if p.ghost %} 👻