add def can_see(v)

master
Aevann1 2022-08-20 00:36:28 +02:00
parent a88b9d59c4
commit e1e7258e7a
6 changed files with 27 additions and 4 deletions

View File

@ -84,6 +84,17 @@ class Comment(Base):
return f"<Comment(id={self.id})>"
@lazy
def can_see(self, v):
if not self.parent_submission: return True
if self.post.sub != 'chudrama': return True
if v:
if v.id == self.author_id: return True
if v.id == self.post.author_id: return True
if v and v.truecoins >= 20000: return True
return False
@property
@lazy
def top_comment(self):

View File

@ -77,6 +77,14 @@ class Submission(Base):
def __repr__(self):
return f"<Submission(id={self.id})>"
@lazy
def can_see(self, v):
if self.sub != 'chudrama': return True
if v:
if v.id == self.author_id: return True
if v and v.truecoins >= 20000: return True
return False
@property
@lazy
def controversial(self):

View File

@ -44,6 +44,8 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
except: abort(404)
comment = get_comment(cid, v=v)
if not comment.can_see(v): abort(403)
if comment.author.shadowbanned and not (v and v.shadowbanned) and not (v and v.admin_level >= 2):
abort(404)

View File

@ -118,6 +118,8 @@ def post_id(pid, anything=None, v=None, sub=None):
post = get_post(pid, v=v)
if not post.can_see(v): abort(403)
if post.over_18 and not (v and v.over_18) and session.get('over_18', 0) < int(time.time()):
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error":"Must be 18+ to view"}, 451
return render_template("errors/nsfw.html", v=v)

View File

@ -90,7 +90,7 @@
{% if render_replies %}
{% if level<9 or request.path.startswith('/notifications') or request.headers.get("xhr") %}
<div id="replies-of-{{c.fullname}}">
{% for reply in replies if not reply.parent_submission or reply.post.sub != 'chudrama' or (v and v.truecoins >= 20000) %}
{% for reply in replies %}
{{single_comment(reply, level=level+1)}}
{% endfor %}
</div>
@ -601,7 +601,7 @@
{% if render_replies %}
{% if level<9 or request.path.startswith('/notifications') or request.headers.get("xhr") %}
<div id="replies-of-{{c.fullname}}">
{% for reply in replies if not reply.parent_submission or reply.post.sub != 'chudrama' or (v and v.truecoins >= 20000) %}
{% for reply in replies %}
{{single_comment(reply, level=level+1)}}
{% endfor %}
</div>
@ -785,7 +785,7 @@
{% endmacro %}
{% for comment in comments if not comment.parent_submission or comment.post.sub != 'chudrama' or (v and v.truecoins >= 20000) %}
{% for comment in comments if comment.can_see(v) %}
{{single_comment(comment)}}

View File

@ -58,7 +58,7 @@
</div>
</div>
{% for p in listing if p.sub != 'chudrama' or (v and v.truecoins >= 20000) %}
{% for p in listing if p.can_see(v) %}
{% set ups=p.upvotes %}
{% set downs=p.downvotes %}