From 86bea724840a6592a614a2850297eba07b30e995 Mon Sep 17 00:00:00 2001 From: TLSM Date: Mon, 15 Aug 2022 05:32:29 -0400 Subject: [PATCH] Refactor profile views condition to deduplicate. --- files/classes/user.py | 11 +++++++++++ files/routes/users.py | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index a116e954b..7bae16015 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -774,3 +774,14 @@ class User(Base): @lazy def can_create_hole(self): return self.admin_level >= PERMS['HOLE_CREATE'] + + @property + @lazy + def viewers_recorded(self): + if SITE_NAME == 'WPD': # WPD gets profile views + return True + elif self.admin_level >= 2: # Admins get profile views + return True + elif self.patron: # Patrons get profile views as a perk + return True + return False diff --git a/files/routes/users.py b/files/routes/users.py index 0f712ccff..f75bf6479 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -887,7 +887,7 @@ def following(username, v): @app.get("/views") @auth_required def visitors(v): - if v.admin_level < 2 and (not v.patron and SITE_NAME != 'WPD'): + if not v.viewers_recorded: return render_template("errors/patron.html", v=v) viewers=sorted(v.viewers, key = lambda x: x.last_view_utc, reverse=True) return render_template("viewers.html", v=v, viewers=viewers) @@ -925,7 +925,7 @@ def u_username(username, v=None): if u.shadowbanned and not (v and v.admin_level >= 2) and not (v and v.id == u.id): abort(404) - if v and v.id not in (u.id, DAD_ID) and (u.patron or u.admin_level > 1): + if v and v.id not in (u.id, DAD_ID) and u.viewers_recorded: view = g.db.query(ViewerRelationship).filter_by(viewer_id=v.id, user_id=u.id).one_or_none() if view: view.last_view_utc = int(time.time())