forked from MarseyWorld/MarseyWorld
Refactor profile views condition to deduplicate.
parent
e301fb458f
commit
86bea72484
|
@ -774,3 +774,14 @@ class User(Base):
|
||||||
@lazy
|
@lazy
|
||||||
def can_create_hole(self):
|
def can_create_hole(self):
|
||||||
return self.admin_level >= PERMS['HOLE_CREATE']
|
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
|
||||||
|
|
|
@ -887,7 +887,7 @@ def following(username, v):
|
||||||
@app.get("/views")
|
@app.get("/views")
|
||||||
@auth_required
|
@auth_required
|
||||||
def visitors(v):
|
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)
|
return render_template("errors/patron.html", v=v)
|
||||||
viewers=sorted(v.viewers, key = lambda x: x.last_view_utc, reverse=True)
|
viewers=sorted(v.viewers, key = lambda x: x.last_view_utc, reverse=True)
|
||||||
return render_template("viewers.html", v=v, viewers=viewers)
|
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):
|
if u.shadowbanned and not (v and v.admin_level >= 2) and not (v and v.id == u.id):
|
||||||
abort(404)
|
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()
|
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())
|
if view: view.last_view_utc = int(time.time())
|
||||||
|
|
Loading…
Reference in New Issue