From c751739a2061cae29a615bebca6ae3af172501d8 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Sat, 19 Nov 2022 03:25:16 -0600 Subject: [PATCH] more changes! loggedinlets are JL-1 now remove many redundant v and v. checks --- files/classes/user.py | 4 +- files/helpers/const.py | 2 +- files/routes/posts.py | 8 +-- files/routes/static.py | 7 ++- files/routes/users.py | 2 +- files/routes/votes.py | 4 +- files/templates/admin/apps.html | 2 +- .../templates/admin/shadowbanned_tooltip.html | 2 +- files/templates/comments.html | 18 ++----- files/templates/default.html | 2 +- files/templates/mobile_navigation_bar.html | 2 +- files/templates/popover.html | 2 +- files/templates/settings.html | 2 +- files/templates/settings/personal.html | 4 +- files/templates/settings2.html | 4 +- files/templates/sub/settings.html | 49 ++----------------- files/templates/submission.html | 10 ++-- files/templates/submission_banned.html | 2 +- files/templates/submission_listing.html | 20 +++----- files/templates/submit.html | 2 +- files/templates/userpage.html | 10 ++-- 21 files changed, 51 insertions(+), 107 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index a4cd2a5d4..1a4fd2ddf 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -69,7 +69,7 @@ class LoggedOutUser(): comment_count = 0 received_award_count = 0 created_utc = 0 - admin_level = 0 + admin_level = -1 last_active = 0 coins_spent = 0 coins_spent_on_hats = 0 @@ -375,7 +375,7 @@ class LoggedOutUser(): # moderated subs @lazy def has_follower(self, user): - if not user or self.id == user.id: return False # users can't follow themselves + if not self or not user or self.id == user.id: return False # users can't follow themselves return g.db.query(Follow).filter_by(target_id=self.id, user_id=user.id).one_or_none() @lazy diff --git a/files/helpers/const.py b/files/helpers/const.py index 2e9f0d991..6130b2b04 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -214,7 +214,7 @@ PERMS = { # Minimum admin_level to perform action. 'FLAGS_REMOVE': 2, 'VOTES_VISIBLE': 0, 'USER_BLOCKS_VISIBLE': 0, - 'USER_FOLLOWS_VISIBLE': 0, + 'USER_FOLLOWS_VISIBLE': -1, 'USER_VOTERS_VISIBLE': 0, 'POST_COMMENT_INFINITE_PINGS': 1, 'POST_COMMENT_MODERATION': 2, diff --git a/files/routes/posts.py b/files/routes/posts.py index 5a5ccc503..d8a4cd39a 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -140,7 +140,7 @@ def post_id(v, pid, anything=None, sub=None): if not v.can_see(post): abort(403) if not v.can_see_content(post) and post.club: abort(403) - if post.over_18 and not (v and v.over_18) and session.get('over_18', 0) < int(time.time()): + if post.over_18 and not v.over_18 and session.get('over_18', 0) < int(time.time()): if g.is_api_or_xhr: return {"error":"Must be 18+ to view"}, 451 return render_template("errors/nsfw.html", v=v) @@ -348,7 +348,7 @@ def edit_post(pid, v): body = body.strip()[:POST_BODY_LENGTH_LIMIT] # process_files() may be adding stuff to the body if body != p.body: - if v and v.admin_level >= PERMS['POST_BETS']: + if v.admin_level >= PERMS['POST_BETS']: for i in bet_regex.finditer(body): body = body.replace(i.group(0), "") body_html = filter_emojis_only(i.group(1)) @@ -750,7 +750,7 @@ def submit_post(v, sub=None): return error("There's a 2048 character limit for URLs.") bets = [] - if v and v.admin_level >= PERMS['POST_BETS']: + if v.admin_level >= PERMS['POST_BETS']: for i in bet_regex.finditer(body): bets.append(i.group(1)) body = body.replace(i.group(0), "") @@ -818,7 +818,7 @@ def submit_post(v, sub=None): for text in [post.body, post.title, post.url]: if not execute_blackjack(v, post, text, 'submission'): break - if v and v.admin_level >= PERMS['POST_BETS']: + if v.admin_level >= PERMS['POST_BETS']: for bet in bets: body_html = filter_emojis_only(bet) if len(body_html) > 500: abort(400, "Bet option too long!") diff --git a/files/routes/static.py b/files/routes/static.py index 65f34bd77..72f14d56a 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -127,7 +127,6 @@ def admins(v): @app.get("/modlog") @auth_required def log(v): - try: page = max(int(request.values.get("page", 1)), 1) except: page = 1 @@ -137,7 +136,7 @@ def log(v): kind = request.values.get("kind") - if v and v.admin_level >= PERMS['USER_SHADOWBAN']: types = ACTIONTYPES + if v.admin_level >= PERMS['USER_SHADOWBAN']: types = ACTIONTYPES else: types = ACTIONTYPES2 if kind and kind not in types: @@ -145,7 +144,7 @@ def log(v): actions = [] else: actions = g.db.query(ModAction) - if not (v and v.admin_level >= PERMS['USER_SHADOWBAN']): + if not (v.admin_level >= PERMS['USER_SHADOWBAN']): actions = actions.filter(ModAction.kind.notin_([ "shadowban","unshadowban", "mod_mute_user","mod_unmute_user", @@ -182,7 +181,7 @@ def log_item(id, v): admins = [x[0] for x in g.db.query(User.username).filter(User.admin_level >= PERMS['ADMIN_MOP_VISIBLE']).all()] - if v and v.admin_level >= PERMS['USER_SHADOWBAN']: types = ACTIONTYPES + if v.admin_level >= PERMS['USER_SHADOWBAN']: types = ACTIONTYPES else: types = ACTIONTYPES2 return render_template("log.html", v=v, actions=[action], next_exists=False, page=1, action=action, admins=admins, types=types, single_user_url='admin') diff --git a/files/routes/users.py b/files/routes/users.py index 38ae39d9d..423d8aa9d 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -675,7 +675,7 @@ def userpagelisting(user:User, site=None, v=None, page:int=1, sort="new", t="all if not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == user.id)): posts = posts.filter_by(is_banned=False, private=False, ghost=False, deleted_utc=0) posts = apply_time_filter(t, posts, Submission) - posts = sort_objects(sort, posts, Submission, include_shadowbanned=v and v.can_see_shadowbanned) + posts = sort_objects(sort, posts, Submission, include_shadowbanned=v.can_see_shadowbanned) posts = posts.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE+1).all() return [x[0] for x in posts] diff --git a/files/routes/votes.py b/files/routes/votes.py index f0de3c476..f0ae336ee 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -17,7 +17,7 @@ def vote_info_get(v, link): if thing.ghost and v.id != AEVANN_ID: abort(403) if isinstance(thing, Submission): - if thing.author.shadowbanned and not (v and v.admin_level >= PERMS['USER_SHADOWBAN']): + if thing.author.shadowbanned and not v.admin_level >= PERMS['USER_SHADOWBAN']: thing_id = g.db.query(Submission.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Submission.id).first()[0] else: thing_id = thing.id @@ -25,7 +25,7 @@ def vote_info_get(v, link): downs = g.db.query(Vote).filter_by(submission_id=thing_id, vote_type=-1).order_by(Vote.created_utc).all() elif isinstance(thing, Comment): - if thing.author.shadowbanned and not (v and v.admin_level >= PERMS['USER_SHADOWBAN']): + if thing.author.shadowbanned and not v.admin_level >= PERMS['USER_SHADOWBAN']: thing_id = g.db.query(Comment.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Comment.id).first()[0] else: thing_id = thing.id diff --git a/files/templates/admin/apps.html b/files/templates/admin/apps.html index 5e6d3bbed..c85099d6f 100644 --- a/files/templates/admin/apps.html +++ b/files/templates/admin/apps.html @@ -14,7 +14,7 @@
diff --git a/files/templates/admin/shadowbanned_tooltip.html b/files/templates/admin/shadowbanned_tooltip.html index 5b21b5bac..6b10b3978 100644 --- a/files/templates/admin/shadowbanned_tooltip.html +++ b/files/templates/admin/shadowbanned_tooltip.html @@ -1 +1 @@ -{% if v and v.admin_level >= PERMS['USER_SHADOWBAN'] and user.shadowbanned %}{% endif %} +{% if v.admin_level >= PERMS['USER_SHADOWBAN'] and user.shadowbanned %}{% endif %} diff --git a/files/templates/comments.html b/files/templates/comments.html index 061ecef05..e994611e5 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -24,7 +24,7 @@ {% set replies=c.replies(sort=sort, v=v, db=g.db) %} {% endif %} -{% if c.is_blocking and not c.ghost or (c.is_banned or c.deleted_utc) and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id==c.author_id) %} +{% if c.is_blocking and not c.ghost or (c.is_banned or c.deleted_utc) and not v.admin_level >= PERMS['POST_COMMENT_MODERATION'] and not (v and v.id==c.author_id) %}
@@ -88,7 +88,7 @@ {% endif %} {% if c.post.sub %} - in /h/{{c.post.sub}} + in /h/{{c.post.sub}} {% endif %} {% elif c.author_id==AUTOJANNY_ID %} Notification @@ -141,7 +141,7 @@ {% if c.active_flags(v) %}{% endif %} {% if c.over_18 %}+18{% endif %} - {% if v and v.admin_level >= PERMS['USER_SHADOWBAN'] and c.author.shadowbanned %}{% endif %} + {% if v.admin_level >= PERMS['USER_SHADOWBAN'] and c.author.shadowbanned %}{% endif %} {% if c.stickied %} {% endif %} @@ -291,7 +291,7 @@
- +
{% endif %}
@@ -361,14 +361,6 @@
- - - - - - - -
  • {% if v and request.path.startswith('/@') and v.admin_level < PERMS['VIEW_VOTE_BUTTONS_ON_USER_PAGE'] %} {% if voted==1 %} @@ -540,7 +532,7 @@
    - +
diff --git a/files/templates/default.html b/files/templates/default.html index cf4e281d0..0ac7f2706 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -107,7 +107,7 @@ -{% if v and v.spider %} +{% if v.spider %} {% endif %} diff --git a/files/templates/mobile_navigation_bar.html b/files/templates/mobile_navigation_bar.html index 8656206be..666054609 100644 --- a/files/templates/mobile_navigation_bar.html +++ b/files/templates/mobile_navigation_bar.html @@ -11,7 +11,7 @@
-{% if v and v.defaultsorting == 'new' %} +{% if v.defaultsorting == 'new' %}
-
Formatting help
+
Formatting help
{% endif %} @@ -298,7 +298,7 @@
{% else %}
diff --git a/files/templates/submission_banned.html b/files/templates/submission_banned.html index d6cf9dbb4..ed9772c26 100644 --- a/files/templates/submission_banned.html +++ b/files/templates/submission_banned.html @@ -43,7 +43,7 @@
- {% if v and v.admin_level >= PERMS['POST_COMMENT_MODERATION'] and p.body_html %} + {% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] and p.body_html %}
{{p.body_html | safe}}
diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index a7a56700c..b8745bd6a 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -26,11 +26,7 @@ {% set downs=p.downvotes %} {% set score=ups-downs %} -{% if v %} - {% set voted= p.voted %} -{% else %} - {% set voted=-2 %} -{% endif %} +{% set voted = p.voted if v else -2 %} {% set v_forbid_deleted = (p.deleted_utc != 0 or p.is_banned) and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == p.author_id) %} @@ -82,7 +78,7 @@ {% if p.club and not (v and (v.paid_dues or v.id == p.author_id)) %} post thumnail {% elif not p.url %} - + post thumnail {% elif p.is_image %} @@ -138,7 +134,7 @@ {% endfor %} - {% if v and v.admin_level >= PERMS['USER_SHADOWBAN'] and p.author.shadowbanned %} + {% if v.admin_level >= PERMS['USER_SHADOWBAN'] and p.author.shadowbanned %} {% endif %} @@ -190,7 +186,7 @@ {% endif %}  {{p.age_string}}   - ({% if p.is_image %}image post{% elif p.is_video %}video post{% elif p.is_audio %}audio post{% elif p.domain %}{{p.domain|truncate(50, True)}}{% else %}text post{% endif %}) + ({% if p.is_image %}image post{% elif p.is_video %}video post{% elif p.is_audio %}audio post{% elif p.domain %}{{p.domain|truncate(50, True)}}{% else %}text post{% endif %}) {% if p.edited_utc %} Edited {{p.edited_string}} {% endif %} @@ -199,7 +195,7 @@
- + {% if p.club %}{{CC}}{% endif %} {% if p.flair %}{{p.flair | safe}}{% endif %} {{p.realtitle(v) | safe}} @@ -213,7 +209,7 @@ {% if p.realbody(v, listing=True) %} {% endif %} - + {{p.comment_count}} @@ -225,7 +221,7 @@