User.can_see -> v.can_see and other improvements
parent
27255696c8
commit
52325cc7c0
|
@ -203,34 +203,18 @@ class LoggedOutUser():
|
|||
@property
|
||||
@lazy
|
||||
def hat_active(self):
|
||||
if not FEATURES['HATS']:
|
||||
return ''
|
||||
|
||||
if self.is_cakeday:
|
||||
return '/i/hats/Cakeday.webp'
|
||||
|
||||
if self.forced_hat:
|
||||
return f'/i/hats/{self.forced_hat[0]}.webp'
|
||||
|
||||
if self.equipped_hat:
|
||||
return f'/i/hats/{self.equipped_hat.name}.webp'
|
||||
|
||||
if not FEATURES['HATS']: return ''
|
||||
if self.is_cakeday: return '/i/hats/Cakeday.webp'
|
||||
if self.forced_hat: return f'/i/hats/{self.forced_hat[0]}.webp'
|
||||
if self.equipped_hat: return f'/i/hats/{self.equipped_hat.name}.webp'
|
||||
return ''
|
||||
|
||||
@lazy
|
||||
def hat_tooltip(self, v):
|
||||
if not FEATURES['HATS']:
|
||||
return ''
|
||||
|
||||
if self.is_cakeday:
|
||||
return "I've spent another year rotting my brain with dramaposting, please ridicule me 🤓"
|
||||
|
||||
if self.forced_hat:
|
||||
return self.forced_hat[1]
|
||||
|
||||
if self.equipped_hat:
|
||||
return self.equipped_hat.name + ' - ' + self.equipped_hat.censored_description(v)
|
||||
|
||||
if not FEATURES['HATS']: return ''
|
||||
if self.is_cakeday: return "I've spent another year rotting my brain with dramaposting, please ridicule me 🤓"
|
||||
if self.forced_hat: return self.forced_hat[1]
|
||||
if self.equipped_hat: return self.equipped_hat.name + ' - ' + self.equipped_hat.censored_description(v)
|
||||
return ''
|
||||
|
||||
@property
|
||||
|
@ -355,7 +339,11 @@ class LoggedOutUser():
|
|||
def fullname(self) -> NoReturn:
|
||||
raise NotImplementedError()
|
||||
|
||||
# banned by, has badge
|
||||
# banned by
|
||||
|
||||
@lazy
|
||||
def has_badge(self, badge_id:int):
|
||||
return False
|
||||
|
||||
def verifyPass(self, password):
|
||||
if not self: return False
|
||||
|
@ -529,6 +517,36 @@ class LoggedOutUser():
|
|||
return 'Contributed at least $200'
|
||||
return ''
|
||||
|
||||
# lottery winnings
|
||||
|
||||
@lazy
|
||||
def show_sig(self, v):
|
||||
if not self.sig_html:
|
||||
return False
|
||||
|
||||
if not self.patron and SITE_NAME != 'WPD':
|
||||
return False
|
||||
|
||||
if v and (v.sigs_disabled or v.poor):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def user_name(self):
|
||||
if self.earlylife:
|
||||
expiry = int(self.earlylife - time.time())
|
||||
if expiry > 86400:
|
||||
name = self.username
|
||||
for i in range(int(expiry / 86400 + 1)):
|
||||
name = f'((({name})))'
|
||||
return name
|
||||
return f'((({self.username})))'
|
||||
return self.username
|
||||
|
||||
# capabilities
|
||||
|
||||
@lazy
|
||||
def can_see_content(self, other:Union[Submission, Comment, Sub]) -> bool:
|
||||
'''
|
||||
|
@ -574,7 +592,6 @@ class LoggedOutUser():
|
|||
return bool(self and self.id == other.id) or self.can_see_shadowbanned or not other.shadowbanned
|
||||
return True
|
||||
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def can_see_chudrama(self):
|
||||
|
@ -595,39 +612,46 @@ class LoggedOutUser():
|
|||
if self.truescore >= TRUESCORE_GHOST_LIMIT: return True
|
||||
if self.patron: return True
|
||||
return False
|
||||
|
||||
# lottery winnings
|
||||
|
||||
@lazy
|
||||
def show_sig(self, v):
|
||||
if not self.sig_html:
|
||||
return False
|
||||
|
||||
if not self.patron and SITE_NAME != 'WPD':
|
||||
return False
|
||||
|
||||
if v and (v.sigs_disabled or v.poor):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def user_name(self):
|
||||
if self.earlylife:
|
||||
expiry = int(self.earlylife - time.time())
|
||||
if expiry > 86400:
|
||||
name = self.username
|
||||
for i in range(int(expiry / 86400 + 1)):
|
||||
name = f'((({name})))'
|
||||
return name
|
||||
return f'((({self.username})))'
|
||||
return self.username
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def can_see_shadowbanned(self):
|
||||
return (self.admin_level >= PERMS['USER_SHADOWBAN']) or self.shadowbanned
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def unmutable(self):
|
||||
return self.has_badge(67)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def mute(self):
|
||||
return self.has_badge(68)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def eye(self):
|
||||
return self.has_badge(83)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def alt(self):
|
||||
return self.has_badge(84)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def unblockable(self):
|
||||
return self.has_badge(87)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def fish(self):
|
||||
return self.has_badge(90)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def offsitementions(self):
|
||||
return self.has_badge(140)
|
||||
|
||||
|
||||
class User(Base, LoggedOutUser):
|
||||
|
@ -752,7 +776,6 @@ class User(Base, LoggedOutUser):
|
|||
sub_exiles = relationship("Exile", primaryjoin="User.id == Exile.user_id", lazy="raise")
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
if "password" in kwargs:
|
||||
kwargs["passhash"] = hash_password(kwargs["password"])
|
||||
kwargs.pop("password")
|
||||
|
@ -1202,38 +1225,3 @@ class User(Base, LoggedOutUser):
|
|||
from_casino_value = from_casino or 0
|
||||
|
||||
return from_casino_value + self.total_lottery_winnings
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def unmutable(self):
|
||||
return self.has_badge(67)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def mute(self):
|
||||
return self.has_badge(68)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def eye(self):
|
||||
return self.has_badge(83)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def alt(self):
|
||||
return self.has_badge(84)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def unblockable(self):
|
||||
return self.has_badge(87)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def fish(self):
|
||||
return self.has_badge(90)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def offsitementions(self):
|
||||
return self.has_badge(140)
|
||||
|
|
|
@ -30,10 +30,10 @@ WORDLE_COLOR_MAPPINGS = {-1: "🟥", 0: "🟨", 1: "🟩"}
|
|||
@app.get("/h/<sub>/comment/<cid>")
|
||||
@app.get("/h/<sub>/post/<pid>/<anything>/<cid>")
|
||||
@auth_desired_with_logingate
|
||||
def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
|
||||
def post_pid_comment_cid(cid, pid=None, anything=None, v=LoggedOutUser(), sub=None):
|
||||
comment = get_comment(cid, v=v)
|
||||
if not User.can_see(v, comment): abort(404)
|
||||
if comment.post and comment.post.club and not User.can_see_content(v, comment): abort(403)
|
||||
if not v.can_see(comment): abort(404)
|
||||
if comment.post and comment.post.club and not v.can_see_content(comment): abort(403)
|
||||
|
||||
if v and request.values.get("read"):
|
||||
notif = g.db.query(Notification).filter_by(comment_id=cid, user_id=v.id, read=False).one_or_none()
|
||||
|
@ -113,7 +113,7 @@ def comment(v):
|
|||
|
||||
if parent_post.club and not (v and (v.paid_dues or v.id == parent_post.author_id)): abort(403)
|
||||
|
||||
if not User.can_see(v, parent): abort(404)
|
||||
if not v.can_see(parent): abort(404)
|
||||
if parent.deleted_utc != 0: abort(404)
|
||||
|
||||
if level > COMMENT_MAX_DEPTH: abort(400, f"Max comment level is {COMMENT_MAX_DEPTH}")
|
||||
|
|
|
@ -43,7 +43,7 @@ def front_all(v, sub=None, subdomain=None):
|
|||
#### WPD TEMP #### end special front logic
|
||||
if sub:
|
||||
sub = get_sub_by_name(sub, graceful=True)
|
||||
if sub and not User.can_see(v, sub): abort(403)
|
||||
if sub and not v.can_see(sub): abort(403)
|
||||
|
||||
if (request.path.startswith('/h/') or request.path.startswith('/s/')) and not sub: abort(404)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from os import environ, listdir, path
|
|||
|
||||
from jinja2 import pass_context
|
||||
|
||||
from files.classes.user import User
|
||||
from files.classes.user import LoggedOutUser
|
||||
from files.helpers.assetcache import assetcache_path
|
||||
from files.helpers.const import *
|
||||
from files.helpers.settings import get_settings
|
||||
|
@ -57,7 +57,7 @@ def inject_constants():
|
|||
"KOFI_TOKEN":KOFI_TOKEN, "KOFI_LINK":KOFI_LINK,
|
||||
"approved_embed_hosts":approved_embed_hosts,
|
||||
"site_settings":get_settings(), "EMAIL":EMAIL, "calc_users":calc_users,
|
||||
"max": max, "min": min, "user_can_see":User.can_see,
|
||||
"max": max, "min": min, "user_can_see":LoggedOutUser.can_see,
|
||||
"TELEGRAM_LINK":TELEGRAM_LINK, "EMAIL_REGEX_PATTERN":EMAIL_REGEX_PATTERN,
|
||||
"CONTENT_SECURITY_POLICY_DEFAULT":CONTENT_SECURITY_POLICY_DEFAULT,
|
||||
"CONTENT_SECURITY_POLICY_HOME":CONTENT_SECURITY_POLICY_HOME,
|
||||
|
|
|
@ -135,10 +135,10 @@ def submit_get(v, sub=None):
|
|||
@app.get("/h/<sub>/post/<pid>")
|
||||
@app.get("/h/<sub>/post/<pid>/<anything>")
|
||||
@auth_desired_with_logingate
|
||||
def post_id(pid, anything=None, v=None, sub=None):
|
||||
def post_id(pid, anything=None, v=LoggedOutUser(), sub=None):
|
||||
post = get_post(pid, v=v)
|
||||
if not User.can_see(v, post): abort(403)
|
||||
if not User.can_see_content(v, post) and post.club: abort(403)
|
||||
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 g.is_api_or_xhr: return {"error":"Must be 18+ to view"}, 451
|
||||
|
|
|
@ -54,7 +54,7 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
|
|||
else:
|
||||
abort(404)
|
||||
|
||||
if not User.can_see(v, target): abort(404)
|
||||
if not v.can_see(target): abort(404)
|
||||
|
||||
coin_delta = 1
|
||||
if v.id == target.author.id:
|
||||
|
|
Loading…
Reference in New Issue