forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2022-04-15 18:28:08 +02:00
parent d198cd603d
commit 99cb01d9fc
12 changed files with 120 additions and 75 deletions

View File

@ -72,10 +72,14 @@ class Comment(Base):
def top_comment(self):
return g.db.query(Comment).filter_by(id=self.top_comment_id).one_or_none()
@property
@lazy
def flags(self):
return g.db.query(CommentFlag).filter_by(comment_id=self.id).order_by(CommentFlag.created_utc)
def flags(self, v):
flags = g.db.query(CommentFlag).filter_by(comment_id=self.id).order_by(CommentFlag.created_utc).all()
if not (v and (v.shadowbanned or v.admin_level > 2)):
for flag in flags:
if flag.user.shadowbanned:
flags.remove(flag)
return flags
@lazy
def poll_voted(self, v):
@ -256,7 +260,7 @@ class Comment(Base):
@lazy
def json_raw(self):
flags = {}
for f in self.flags: flags[f.user.username] = f.reason
for f in self.flags(None): flags[f.user.username] = f.reason
data= {
'id': self.id,
@ -434,10 +438,9 @@ class Comment(Base):
@lazy
def is_op(self): return self.author_id==self.post.author_id
@property
@lazy
def active_flags(self): return self.flags.count()
def active_flags(self, v): return len(self.flags(v))
@lazy
def wordle_html(self, v):
if not self.wordle_result: return ''

View File

@ -76,11 +76,15 @@ class Submission(Base):
if self.downvotes > 5 and 0.25 < self.upvotes / self.downvotes < 4: return True
return False
@property
@lazy
def flags(self):
return g.db.query(Flag).filter_by(post_id=self.id).order_by(Flag.created_utc)
def flags(self, v):
flags = g.db.query(Flag).filter_by(post_id=self.id).order_by(Flag.created_utc).all()
if not (v and (v.shadowbanned or v.admin_level > 2)):
for flag in flags:
if flag.user.shadowbanned:
flags.remove(flag)
return flags
@property
@lazy
def options(self):
@ -261,7 +265,7 @@ class Submission(Base):
@lazy
def json_raw(self):
flags = {}
for f in self.flags: flags[f.user.username] = f.reason
for f in self.flags(None): flags[f.user.username] = f.reason
data = {'author_name': self.author_name if self.author else '',
'permalink': self.permalink,
@ -477,6 +481,5 @@ class Submission(Base):
if self.url: return self.url.lower().endswith('.webp') or self.url.lower().endswith('.jpg') or self.url.lower().endswith('.png') or self.url.lower().endswith('.gif') or self.url.lower().endswith('.jpeg') or self.url.lower().endswith('?maxwidth=9999') or self.url.lower().endswith('&fidelity=high')
else: return False
@property
@lazy
def active_flags(self): return self.flags.count()
def active_flags(self, v): return len(self.flags(v))

View File

@ -422,7 +422,12 @@ class User(Base):
@property
@lazy
def notifications_count(self):
return g.db.query(Notification.user_id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0).count()
notifs = g.db.query(Notification.user_id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0)
if not self.shadowbanned and self.admin_level < 3:
notifs = notifs.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
return notifs.count()
@property
@lazy
@ -516,8 +521,8 @@ class User(Base):
'bannerurl': self.banner_url,
'bio_html': self.bio_html_eager,
'coins': self.coins,
'post_count': 0 if self.shadowbanned and not (v and (v.shadowbanned or v.admin_level)) else self.post_count,
'comment_count': 0 if self.shadowbanned and not (v and (v.shadowbanned or v.admin_level)) else self.comment_count,
'post_count': 0 if self.shadowbanned and not (v and (v.shadowbanned or v.admin_level > 2)) else self.post_count,
'comment_count': 0 if self.shadowbanned and not (v and (v.shadowbanned or v.admin_level > 2)) else self.comment_count,
'badges': [x.path for x in self.badges],
}

View File

@ -231,7 +231,7 @@ def get_comments(cids, v=None, load_parent=False):
blocked.c.target_id,
).filter(Comment.id.in_(cids))
if not (v and (v.shadowbanned or v.admin_level > 1)):
if not (v and (v.shadowbanned or v.admin_level > 2)):
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
comments = comments.join(

View File

@ -125,7 +125,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
blocked.c.target_id,
)
if not (v and v.shadowbanned) and not (v and v.admin_level > 1):
if not (v and v.shadowbanned) and not (v and v.admin_level > 2):
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
comments=comments.filter(

View File

@ -49,7 +49,11 @@ def notifications(v):
next_exists = (len(comments) > 25)
listing = comments[:25]
elif messages:
comments = g.db.query(Comment).filter(Comment.sentto != None, or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None, Comment.level == 1).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all()
if v and (v.shadowbanned or v.admin_level > 2):
comments = g.db.query(Comment).filter(Comment.sentto != None, or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None, Comment.level == 1).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all()
else:
comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.sentto != None, or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None, Comment.level == 1).order_by(Comment.id.desc()).offset(25*(page-1)).limit(26).all()
next_exists = (len(comments) > 25)
listing = comments[:25]
elif posts:
@ -112,7 +116,7 @@ def notifications(v):
Comment.body_html.notlike('<html><body><p>New site mention: <a href="https://old.reddit.com/r/%')
).order_by(Comment.top_comment_id.desc(), Notification.created_utc.desc()).subquery()
if v and (v.shadowbanned or v.admin_level > 1):
if v and (v.shadowbanned or v.admin_level > 2):
comments = g.db.query(Comment).join(sq, sq.c.id == Comment.id).order_by(sq.c.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()
else:
comments = g.db.query(Comment).join(sq, sq.c.id == Comment.id).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None).order_by(sq.c.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()

View File

@ -149,7 +149,7 @@ def post_id(pid, anything=None, v=None, sub=None):
blocked.c.target_id,
)
if not (v and v.shadowbanned) and not (v and v.admin_level > 1):
if not (v and v.shadowbanned) and not (v and v.admin_level > 2):
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
comments=comments.filter(Comment.parent_submission == post.id, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID))).join(
@ -284,7 +284,7 @@ def viewmore(v, pid, sort, offset):
blocked.c.target_id,
).filter(Comment.parent_submission == pid, Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID)), Comment.is_pinned == None, Comment.id.notin_(ids))
if not (v and v.shadowbanned) and not (v and v.admin_level > 1):
if not (v and v.shadowbanned) and not (v and v.admin_level > 2):
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
comments=comments.join(

View File

@ -12,32 +12,37 @@ def api_flag_post(pid, v):
post = get_post(pid)
if not v.shadowbanned:
reason = request.values.get("reason", "").strip()[:100]
reason = request.values.get("reason", "").strip()
if not reason.startswith('!'):
existing = g.db.query(Flag.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none()
if existing: return "", 409
if blackjack and blackjack in reason.lower():
v.shadowbanned = 'AutoJanny'
send_repeatable_notification(CARP_ID, f"reports on {post.permalink}")
reason = filter_emojis_only(reason)
reason = reason[:100]
if len(reason) > 350: return {"error": "Too long."}
if not reason.startswith('!'):
existing = g.db.query(Flag.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none()
if existing: return "", 409
if reason.startswith('!') and v.admin_level > 1:
post.flair = reason[1:]
g.db.add(post)
ma=ModAction(
kind="flair_post",
user_id=v.id,
target_submission_id=post.id,
_note=f'"{post.flair}"'
)
g.db.add(ma)
else:
flag = Flag(post_id=post.id, user_id=v.id, reason=reason)
g.db.add(flag)
reason = filter_emojis_only(reason)
g.db.commit()
if len(reason) > 350: return {"error": "Too long."}
if reason.startswith('!') and v.admin_level > 1:
post.flair = reason[1:]
g.db.add(post)
ma=ModAction(
kind="flair_post",
user_id=v.id,
target_submission_id=post.id,
_note=f'"{post.flair}"'
)
g.db.add(ma)
else:
flag = Flag(post_id=post.id, user_id=v.id, reason=reason)
g.db.add(flag)
g.db.commit()
return {"message": "Post reported!"}
@ -49,19 +54,25 @@ def api_flag_comment(cid, v):
comment = get_comment(cid)
if not v.shadowbanned:
existing = g.db.query(CommentFlag.comment_id).filter_by( user_id=v.id, comment_id=comment.id).one_or_none()
if existing: return "", 409
existing = g.db.query(CommentFlag.comment_id).filter_by( user_id=v.id, comment_id=comment.id).one_or_none()
if existing: return "", 409
reason = request.values.get("reason", "").strip()[:100]
reason = filter_emojis_only(reason)
reason = request.values.get("reason", "").strip()
if len(reason) > 350: return {"error": "Too long."}
if blackjack and blackjack in reason.lower():
v.shadowbanned = 'AutoJanny'
send_repeatable_notification(CARP_ID, f"reports on {comment.permalink}")
flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason)
reason = reason[:100]
g.db.add(flag)
g.db.commit()
reason = filter_emojis_only(reason)
if len(reason) > 350: return {"error": "Too long."}
flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason)
g.db.add(flag)
g.db.commit()
return {"message": "Comment reported!"}

View File

@ -600,8 +600,6 @@ def message2(v, username):
if v.admin_level <= 1 and hasattr(user, 'is_blocked') and user.is_blocked:
return {"error": "This user is blocking you."}, 403
if v.shadowbanned and user.admin_level < 2: return {"message": "Message sent!"}
message = request.values.get("message", "").strip()[:10000].strip()
if not message: return {"error": "Message is empty!"}
@ -629,11 +627,21 @@ def message2(v, username):
g.db.flush()
if blackjack and blackjack in c.body_html.lower():
v.shadowbanned = 'AutoJanny'
g.db.add(v)
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=CARP_ID).one_or_none()
if not notif:
notif = Notification(comment_id=c.id, user_id=CARP_ID)
g.db.add(notif)
g.db.flush()
c.top_comment_id = c.id
notif = Notification(comment_id=c.id, user_id=user.id)
g.db.add(notif)
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=user.id).one_or_none()
if not notif:
notif = Notification(comment_id=c.id, user_id=user.id)
g.db.add(notif)
g.db.commit()
@ -688,7 +696,7 @@ def messagereply(v):
else: return {"error": "Image/Video files only"}, 400
new_comment = Comment(author_id=v.id,
c = Comment(author_id=v.id,
parent_submission=None,
parent_comment_id=id,
top_comment_id=parent.top_comment_id,
@ -696,12 +704,23 @@ def messagereply(v):
sentto=user_id,
body_html=body_html,
)
g.db.add(new_comment)
g.db.add(c)
g.db.flush()
if blackjack and blackjack in c.body_html.lower():
v.shadowbanned = 'AutoJanny'
g.db.add(v)
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=CARP_ID).one_or_none()
if not notif:
notif = Notification(comment_id=c.id, user_id=CARP_ID)
g.db.add(notif)
g.db.flush()
if user_id and user_id != v.id and user_id != 2:
notif = Notification(comment_id=new_comment.id, user_id=user_id)
g.db.add(notif)
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=user_id).one_or_none()
if not notif:
notif = Notification(comment_id=c.id, user_id=user_id)
g.db.add(notif)
if PUSHER_ID != 'blahblahblah':
if len(message) > 500: notifbody = message[:500] + '...'
@ -731,14 +750,14 @@ def messagereply(v):
)
if new_comment.top_comment.sentto == 2:
if c.top_comment.sentto == 2:
admins = g.db.query(User).filter(User.admin_level > 2, User.id != v.id).all()
for admin in admins:
notif = Notification(comment_id=new_comment.id, user_id=admin.id)
notif = Notification(comment_id=c.id, user_id=admin.id)
g.db.add(notif)
g.db.commit()
return {"comment": render_template("comments.html", v=v, comments=[new_comment], ajax=True)}
return {"comment": render_template("comments.html", v=v, comments=[c], ajax=True)}
@app.get("/2faqr/<secret>")
@auth_required

View File

@ -54,7 +54,7 @@
{% set downs=c.downvotes %}
{% set score=ups-downs %}
{% if v and (v.shadowbanned or v.admin_level > 1) %}
{% if v and (v.shadowbanned or v.admin_level > 2) %}
{% set replies=c.replies3 %}
{% else %}
{% set replies=c.replies %}
@ -185,7 +185,7 @@
{% if c.bannedfor %}
<a role="button"><i class="fas fa-gavel text-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="User was banned for this comment{% if c.author.banned_by %} by @{{c.author.banned_by.username}}{% endif %}"></i></a>
{% endif %}
{% if c.active_flags %}<a class="btn btn-primary" style="padding:1px 5px; font-size:10px"role="button" onclick="document.getElementById('flaggers-{{c.id}}').classList.toggle('d-none')">{{c.active_flags}} Reports</a>{% endif %}
{% if c.active_flags(v) %}<a class="btn btn-primary" style="padding:1px 5px; font-size:10px"role="button" onclick="document.getElementById('flaggers-{{c.id}}').classList.toggle('d-none')">{{c.active_flags(v)}} Reports</a>{% endif %}
{% if c.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %}
{% if v and v.admin_level > 1 and c.author.shadowbanned %}<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Shadowbanned by @{{c.author.shadowbanned}}"></i>{% endif %}
{% if c.is_pinned %}
@ -246,12 +246,12 @@
{{c.wordle_html(v) | safe}}
{% endif %}
</div>
{% if c.active_flags %}
{% if c.active_flags(v) %}
<div id="flaggers-{{c.id}}" class="flaggers d-none">
<strong><i class="far fa-fw fa-flag"></i> Reported by:</strong>
<pre></pre>
<ul style="padding-left:20px; margin-bottom: 0;word-wrap:break-word">
{% for f in c.flags %}
{% for f in c.flags(v) %}
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a role="button" onclick="post_toast(this,'/del_report/comment/{{f.comment_id}}/{{f.user_id}}')">[remove]</a>{% endif %}</li>
{% endfor %}
</ul>

View File

@ -636,7 +636,7 @@
{% if p.is_bot %} <i class="fas fa-robot text-info" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Bot"></i>{% endif %}
{% if p.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %}
{% if p.private %}<span class="badge border-warning border-1 text-small-extra">Draft</span>{% endif %}
{% if p.active_flags %}<a class="btn btn-primary" role="button" style="padding:1px 5px; font-size:10px"onclick="document.getElementById('flaggers').classList.toggle('d-none')">{{p.active_flags}} Reports</a>{% endif %}
{% if p.active_flags(v) %}<a class="btn btn-primary" role="button" style="padding:1px 5px; font-size:10px"onclick="document.getElementById('flaggers').classList.toggle('d-none')">{{p.active_flags(v)}} Reports</a>{% endif %}
{% if not p.author %}
{{p.print()}}
@ -661,12 +661,12 @@
{% endif %}
&nbsp;&nbsp;{{p.views}} thread views
</div>
{% if p.active_flags %}
{% if p.active_flags(v) %}
<div id="flaggers" class="flaggers d-none">
<strong><i class="far fa-fw fa-flag"></i> Reported by:</strong>
<pre></pre>
<ul style="padding-left:20px; margin-bottom: 0;word-wrap:break-word">
{% for f in p.flags %}
{% for f in p.flags(v) %}
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a role="button" onclick="post_toast(this,'/del_report/post/{{f.post_id}}/{{f.user_id}}')">[remove]</a>{% endif %}</li>
{% endfor %}
</ul>

View File

@ -62,12 +62,12 @@
{% set voted=-2 %}
{% endif %}
{% if p.active_flags %}
{% if p.active_flags(v) %}
<div id="flaggers-{{p.id}}" class="flaggers d-none">
<strong><i class="far fa-fw fa-flag"></i> Reported by:</strong>
<pre></pre>
<ul style="padding-left:20px; margin-bottom: 0;word-wrap:break-word">
{% for f in p.flags %}
{% for f in p.flags(v) %}
<li><a style="font-weight:bold" href="{{f.user.url}}">{{f.user.username}}</a>{% if f.reason %}: {{f.realreason(v) | safe}}{% endif %} {% if v and v.admin_level > 1 %}<a role="button" onclick="post_toast(this,'/del_report/post/{{f.post_id}}/{{f.user_id}}')">[remove]</a>{% endif %}</li>
{% endfor %}
</ul>
@ -179,7 +179,7 @@
{% if p.is_blocking %}<i class="fas fa-user-minus text-warning" data-bs-toggle="tooltip" data-bs-placement="bottom" title="You're blocking this user, but you can see this post because you're an admin."></i>{% endif %}
{% if p.is_blocked %}<i class="fas fa-user-minus text-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="This user is blocking you."></i>{% endif %}
{% if p.private %}<span class="badge border-warning border-1 text-small-extra">Draft</span>{% endif %}
{% if p.active_flags %}<a class="btn btn-primary" role="button" style="padding:1px 5px; font-size:10px"onclick="document.getElementById('flaggers-{{p.id}}').classList.toggle('d-none')">{{p.active_flags}} Reports</a>{% endif %}
{% if p.active_flags(v) %}<a class="btn btn-primary" role="button" style="padding:1px 5px; font-size:10px"onclick="document.getElementById('flaggers-{{p.id}}').classList.toggle('d-none')">{{p.active_flags(v)}} Reports</a>{% endif %}
{% if not p.author %}
{{p.print()}}