rename flags to reports

pull/157/head
Aevann 2023-06-23 19:49:23 +03:00
parent 955f29c7be
commit 5e8f04b2ac
20 changed files with 81 additions and 67 deletions

View File

@ -4512,7 +4512,7 @@ small, .small {
height: 60px;
}
}
.post-actions .comments, .post-actions .share, .post-actions .flag {
.post-actions .comments, .post-actions .share, .post-actions .report {
margin-right: 0.5rem;
vertical-align: top;
}
@ -5304,7 +5304,7 @@ span.green {
.btn-primary:focus, .btn-primary.focus {
box-shadow: none !important;
}
.flaggers {
.reports {
margin: 7px;
border: 1px solid var(--primary);
padding: 10px;

View File

@ -14,6 +14,6 @@
background-color: rgb(var(--background)) !important;
}
.App-side, .flaggers, .comment-section {
.App-side, .reports, .comment-section {
background: transparent !important;
}

View File

@ -98,7 +98,7 @@ blockquote {
color: #000 !important
}
.flaggers {
.reports {
background-color: var(--white) !important;
}

View File

@ -8,7 +8,7 @@ function removePost(t,post_id,button1,button2,cls) {
() => {
if (location.pathname == '/admin/reported/posts')
{
document.getElementById("flaggers-"+post_id).remove()
document.getElementById("reports-"+post_id).remove()
document.getElementById("post-"+post_id).remove()
}
else
@ -30,7 +30,7 @@ function approvePost(t,post_id,button1,button2,cls) {
() => {
if (location.pathname == '/admin/reported/posts')
{
document.getElementById("flaggers-"+post_id).remove()
document.getElementById("reports-"+post_id).remove()
document.getElementById("post-"+post_id).remove()
}
else

View File

@ -27,8 +27,8 @@ function collapse_comment(id) {
window.scrollBy(0, - 100)
}
const flags = document.getElementById(`flaggers-${id}`)
if (flags) flags.classList.add('d-none')
const reports = document.getElementById(`reports-${id}`)
if (reports) reports.classList.add('d-none')
vids = element.getElementsByTagName('video')
for (let i=0; i < vids.length; i++)

View File

@ -6,7 +6,7 @@ function delete_postModal(t, id) {
() => {
if (location.pathname == '/admin/reported/posts')
{
document.getElementById("flaggers-"+id).remove()
document.getElementById("reports-"+id).remove()
document.getElementById("post-"+id).remove()
}
else

View File

@ -7,7 +7,7 @@ from .alts import *
from .clients import *
from .comment import *
from .domains import *
from .flags import *
from .reports import *
from .user import *
from .badges import *
from .userblock import *

View File

@ -145,7 +145,7 @@ class Comment(Base):
senttouser = relationship("User", primaryjoin="User.id==Comment.sentto")
parent_comment = relationship("Comment", remote_side=[id])
awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", back_populates="comment")
flags = relationship("CommentFlag", order_by="CommentFlag.created_utc")
reports = relationship("CommentReport", order_by="CommentReport.created_utc")
options = relationship("CommentOption", order_by="CommentOption.id")
casino_game = relationship("CasinoGame")
wall_user = relationship("User", primaryjoin="User.id==Comment.wall_user_id")
@ -279,8 +279,9 @@ class Comment(Base):
'parent': self.parent_fullname
}
else:
flags = {}
for f in self.flags: flags[f.user.username] = f.reason
reports = {}
for r in self.reports:
reports[r.user.username] = r.reason
data = {
'id': self.id,
@ -302,7 +303,7 @@ class Comment(Base):
'upvotes': self.upvotes,
'downvotes': self.downvotes,
'is_bot': self.is_bot,
'flags': flags,
'reports': reports,
'author': '👻' if self.ghost else self.author.json,
# 'replies': [x.json for x in self.replies(sort="old", v=None)] # WORKER TIMEOUTS ON BUGTHREAD
}
@ -399,12 +400,12 @@ class Comment(Base):
def is_op(self): return self.author_id==self.post.author_id
@lazy
def filtered_flags(self, v):
return [f for f in self.flags if not f.user.shadowbanned or (v and v.id == f.user_id) or (v and v.admin_level)]
def filtered_reports(self, v):
return [r for r in self.reports if not r.user.shadowbanned or (v and v.id == r.user_id) or (v and v.admin_level)]
@lazy
def active_flags(self, v):
return len(self.filtered_flags(v))
def active_reports(self, v):
return len(self.filtered_reports(v))
@property
@lazy

View File

@ -65,7 +65,7 @@ class Post(Base):
oauth_app = relationship("OauthApp")
approved_by = relationship("User", uselist=False, primaryjoin="Post.is_approved==User.id")
awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", back_populates="post")
flags = relationship("Flag", order_by="Flag.created_utc")
reports = relationship("Report", order_by="Report.created_utc")
comments = relationship("Comment", primaryjoin="Comment.parent_post==Post.id", back_populates="post")
subr = relationship("Sub", primaryjoin="foreign(Post.sub)==remote(Sub.name)")
options = relationship("PostOption", order_by="PostOption.id")
@ -203,8 +203,9 @@ class Post(Base):
'permalink': self.permalink,
}
flags = {}
for f in self.flags: flags[f.user.username] = f.reason
reports = {}
for r in self.reports:
reports[r.user.username] = r.reason
data = {'author_name': self.author_name if self.author else '',
'permalink': self.permalink,
@ -231,7 +232,7 @@ class Post(Base):
'private' : self.private,
'distinguish_level': self.distinguish_level,
'voted': self.voted if hasattr(self, 'voted') else 0,
'flags': flags,
'reports': reports,
'author': '👻' if self.ghost else self.author.json
}
@ -364,12 +365,12 @@ class Post(Base):
return self.url and any((str(self.url).lower().split('?')[0].endswith(f'.{x}') for x in IMAGE_FORMATS)) and is_safe_url(self.url)
@lazy
def filtered_flags(self, v):
return [f for f in self.flags if not f.user.shadowbanned or (v and v.id == f.user_id) or (v and v.admin_level)]
def filtered_reports(self, v):
return [r for r in self.reports if not r.user.shadowbanned or (v and v.id == r.user_id) or (v and v.admin_level)]
@lazy
def active_flags(self, v):
return len(self.filtered_flags(v))
def active_reports(self, v):
return len(self.filtered_reports(v))
@property
@lazy

View File

@ -8,15 +8,15 @@ from files.classes import Base
from files.helpers.lazy import lazy
from files.helpers.regex import censor_slurs
class Flag(Base):
__tablename__ = "flags"
class Report(Base):
__tablename__ = "reports"
post_id = Column(Integer, ForeignKey("posts.id"), primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
reason = Column(String)
created_utc = Column(Integer)
user = relationship("User", primaryjoin = "Flag.user_id == User.id", uselist = False)
user = relationship("User", primaryjoin = "Report.user_id == User.id", uselist = False)
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
@ -36,15 +36,15 @@ class Flag(Base):
return self.post_id
class CommentFlag(Base):
__tablename__ = "commentflags"
class CommentReport(Base):
__tablename__ = "commentreports"
comment_id = Column(Integer, ForeignKey("comments.id"), primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
reason = Column(String)
created_utc = Column(Integer)
user = relationship("User", primaryjoin = "CommentFlag.user_id == User.id", uselist = False)
user = relationship("User", primaryjoin = "CommentReport.user_id == User.id", uselist = False)
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())

View File

@ -7,7 +7,7 @@ import gevent
import requests
from flask import g
from files.classes.flags import Flag
from files.classes.reports import Report
from files.classes.mod_logs import ModAction
from files.classes.notifications import Notification
from files.classes.polls import CommentOption, PostOption
@ -46,8 +46,8 @@ def archive_url(url):
gevent.spawn(_archiveorg, url)
def snappy_report(post, reason):
flag = Flag(post_id=post.id, user_id=SNAPPY_ID, reason=reason)
g.db.add(flag)
report = Report(post_id=post.id, user_id=SNAPPY_ID, reason=reason)
g.db.add(report)
message = f'@Snappy reported [{post.title}]({post.shortlink})\n\n> {reason}'
send_repeatable_notification(post.author_id, message)

View File

@ -466,7 +466,7 @@ PERMS = { # Minimum admin_level to perform action.
'MESSAGE_BLOCKED_USERS': 1,
'ADMIN_MOP_VISIBLE': 1,
'ADMIN_HOME_VISIBLE': 1,
'FLAGS_REMOVE': 1,
'REPORTS_REMOVE': 1,
'POST_COMMENT_MODERATION': 1,
'USER_BAN': 1,
'USER_SHADOWBAN': 1,

View File

@ -211,7 +211,7 @@ def get_posts(pids:Iterable[int], v:Optional[User]=None, eager:bool=False, extra
selectinload(User.sub_mods),
selectinload(User.sub_exiles),
),
selectinload(Post.flags),
selectinload(Post.reports),
selectinload(Post.awards),
selectinload(Post.options),
)

View File

@ -327,7 +327,7 @@ def reported_posts(v):
is_approved=None,
is_banned=False,
deleted_utc=0
).join(Post.flags)
).join(Post.reports)
total = listing.count()
@ -350,7 +350,7 @@ def reported_comments(v):
is_approved=None,
is_banned=False,
deleted_utc=0
).join(Comment.flags)
).join(Comment.reports)
total = listing.count()

View File

@ -1,6 +1,6 @@
from flask import g
from files.classes.flags import Flag, CommentFlag
from files.classes.reports import Report, CommentReport
from files.classes.mod_logs import ModAction
from files.classes.sub_logs import SubAction
from files.helpers.actions import *
@ -17,7 +17,7 @@ from files.__main__ import app, limiter, cache
@limiter.limit(DEFAULT_RATELIMIT)
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@auth_required
def flag_post(pid, v):
def report_post(pid, v):
if v.is_muted: abort(403, "You are forbidden from making reports!")
post = get_post(pid)
@ -62,10 +62,10 @@ def flag_post(pid, v):
moved = move_post(post, v, reason)
if moved: return {"message": moved}
existing = g.db.query(Flag.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none()
existing = g.db.query(Report.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none()
if existing: abort(409, "You already reported this post!")
flag = Flag(post_id=post.id, user_id=v.id, reason=reason_html)
g.db.add(flag)
report = Report(post_id=post.id, user_id=v.id, reason=reason_html)
g.db.add(report)
if v.id != post.author_id and not v.shadowbanned and not post.author.has_blocked(v):
message = f'@{v.username} reported [{post.title}]({post.shortlink})\n\n> {reason}'
@ -80,12 +80,12 @@ def flag_post(pid, v):
@limiter.limit(DEFAULT_RATELIMIT)
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@auth_required
def flag_comment(cid, v):
def report_comment(cid, v):
if v.is_muted: abort(403, "You are forbidden from making reports!")
comment = get_comment(cid)
existing = g.db.query(CommentFlag.comment_id).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
existing = g.db.query(CommentReport.comment_id).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
if existing: abort(409, "You already reported this comment!")
reason = request.values.get("reason", "").strip()
@ -96,8 +96,8 @@ def flag_comment(cid, v):
if len(reason_html) > 350: abort(400, "Too long!")
flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason_html)
g.db.add(flag)
report = CommentReport(comment_id=comment.id, user_id=v.id, reason=reason_html)
g.db.add(report)
if v.id != comment.author_id and not v.shadowbanned and not comment.author.has_blocked(v):
message = f'@{v.username} reported your [comment]({comment.shortlink})\n\n> {reason}'
@ -111,13 +111,13 @@ def flag_comment(cid, v):
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit("100/minute;300/hour;2000/day")
@limiter.limit("100/minute;300/hour;2000/day", key_func=get_ID)
@admin_level_required(PERMS['FLAGS_REMOVE'])
@admin_level_required(PERMS['REPORTS_REMOVE'])
def remove_report_post(v, pid, uid):
try:
pid = int(pid)
uid = int(uid)
except: abort(404)
report = g.db.query(Flag).filter_by(post_id=pid, user_id=uid).one_or_none()
report = g.db.query(Report).filter_by(post_id=pid, user_id=uid).one_or_none()
if report:
g.db.delete(report)
@ -137,13 +137,13 @@ def remove_report_post(v, pid, uid):
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit("100/minute;300/hour;2000/day")
@limiter.limit("100/minute;300/hour;2000/day", key_func=get_ID)
@admin_level_required(PERMS['FLAGS_REMOVE'])
@admin_level_required(PERMS['REPORTS_REMOVE'])
def remove_report_comment(v, cid, uid):
try:
cid = int(cid)
uid = int(uid)
except: abort(404)
report = g.db.query(CommentFlag).filter_by(comment_id=cid, user_id=uid).one_or_none()
report = g.db.query(CommentReport).filter_by(comment_id=cid, user_id=uid).one_or_none()
if report:
g.db.delete(report)

View File

@ -143,7 +143,7 @@
<i class="fas fa-face-sleeping text-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="User was chudded for this comment {{c.chuddedfor}}"></i>
{% endif %}
{% if c.active_flags(v) %}<button type="button" class="btn btn-primary" style="padding:1px 5px; font-size:10px" data-toggleelement="#flaggers-{{c.id}}" data-toggleattr="d-none">{{c.active_flags(v)}} Report{{macros.plural(c.active_flags(v))}}</button>{% endif %}
{% if c.active_reports(v) %}<button type="button" class="btn btn-primary" style="padding:1px 5px; font-size:10px" data-toggleelement="#reports-{{c.id}}" data-toggleattr="d-none">{{c.active_reports(v)}} Report{{macros.plural(c.active_reports(v))}}</button>{% endif %}
{% if c.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %}
{% if v and v.admin_level >= PERMS['USER_SHADOWBAN'] 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.shadowbanner}} for "{{c.author.ban_reason}}"'></i>{% endif %}
{% if c.stickied %}
@ -235,7 +235,7 @@
{% endif %}
</div>
{{macros.flags(c, 'comment')}}
{{macros.reports(c, 'comment')}}
{% if c.is_banned and c.ban_reason %}
<div id="comment-banned-warning" class="comment-text text-removed mb-0">removed by @{{c.ban_reason}} (Admin)</div>

View File

@ -77,7 +77,7 @@
{{macros.post_meta(p)}}
</div>
{{macros.flags(p, 'post')}}
{{macros.reports(p, 'post')}}
{% if p.realurl(v) and not v_forbid_deleted %}
<h1 id="post-title" class="card-title post-title text-left mb-md-3 {% if p.chudded %}text-uppercase{% endif %}">

View File

@ -26,7 +26,7 @@
{% set v_forbid_deleted = (p.deleted_utc != 0 or p.is_banned) and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == p.author_id) %}
{{macros.flags(p, 'post')}}
{{macros.reports(p, 'post')}}
<div id="post-{{p.id}}" class="actual-post {% if p.ghost %}ghost-post{% endif %} {% if p.unread %}unread{% else %}card{% endif %} {% if p.is_banned %} banned{% endif %}{% if p.deleted_utc %} deleted{% endif %}{% if p.stickied %} stickied{% endif %}{% if voted==1 %} upvoted{% elif voted==-1 %} downvoted{% endif %}{% if p.over_18 %} nsfw{% endif %}">

View File

@ -54,7 +54,7 @@
{% if p.is_blocking and not p.ghost %}<i class="fas fa-user-minus text-warning" data-bs-toggle="tooltip" data-bs-placement="bottom" title="You're blocking this user."></i>{% endif %}
{% if p.is_blocked and not p.ghost %}<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="mr-2 badge border-warning border-1 text-small-extra">Draft</span>{% endif %}
{% if p.active_flags(v) %}<button type="button" class="btn btn-primary" style="padding:1px 5px; font-size:10px" data-nonce="{{g.nonce}}" data-toggleelement="#flaggers-{{p.id}}" data-toggleattr="d-none">{{p.active_flags(v)}} Report{{plural(p.active_flags(v))}}</button>{% endif %}
{% if p.active_reports(v) %}<button type="button" class="btn btn-primary" style="padding:1px 5px; font-size:10px" data-nonce="{{g.nonce}}" data-toggleelement="#reports-{{p.id}}" data-toggleattr="d-none">{{p.active_reports(v)}} Report{{plural(p.active_reports(v))}}</button>{% endif %}
{% if p.ghost %}
<span {% if p.distinguish_level %}class="mod {% if SITE_NAME == 'rDrama' %}mod-rdrama{% endif %}"{% endif %}>👻</span>
@ -197,20 +197,20 @@
{% endif %}
{% endmacro %}
{% macro flags(i, kind) %}
{% if i.active_flags(v) %}
<div id="flaggers-{{i.id}}" class="flaggers d-none">
{% macro reports(i, kind) %}
{% if i.active_reports(v) %}
<div id="reports-{{i.id}}" class="reports d-none">
<strong><i class="far fa-fw fa-flag"></i> Reported by:</strong>
<ul class="mt-1 mb-0" style="padding-left:20px;word-wrap:break-word">
{% for f in i.filtered_flags(v) %}
{% for r in i.filtered_reports(v) %}
<li>
{% if v and v.admin_level and f.user.shadowbanned %}
<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title='Shadowbanned by @{{f.user.shadowbanner}} for "{{f.user.ban_reason}}"'></i>
{% if v and v.admin_level and r.user.shadowbanned %}
<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title='Shadowbanned by @{{r.user.shadowbanner}} for "{{r.user.ban_reason}}"'></i>
{% endif %}
<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 >= PERMS['FLAGS_REMOVE'] %}
<button type="button" data-nonce="{{g.nonce}}" data-onclick="delReport(this,'/del_report/{{kind}}/{{f.parent_id}}/{{f.user_id}}')">[remove]</button>
<a style="font-weight:bold" href="{{r.user.url}}">{{r.user.username}}</a>
{% if r.reason %}: {{r.realreason(v) | safe}}{% endif %}
{% if v and v.admin_level >= PERMS['REPORTS_REMOVE'] %}
<button type="button" data-nonce="{{g.nonce}}" data-onclick="delReport(this,'/del_report/{{kind}}/{{r.parent_id}}/{{r.user_id}}')">[remove]</button>
{% endif %}
</li>
{% endfor %}

View File

@ -0,0 +1,12 @@
alter table commentflags rename to commentreports;
alter table flags rename to reports;
alter table commentreports rename constraint commentflags_pkey to commentreports_pkey;
alter table commentreports rename constraint commentflags_comment_id_fkey to commentreports_comment_id_fkey;
alter table commentreports rename constraint commentflags_user_id_fkey to commentreports_user_id_fkey;
alter table reports rename constraint flags_pkey to reports_pkey;
alter table reports rename constraint flags_post_id_fkey to reports_post_id_fkey;
alter table reports rename constraint flags_user_id_fkey to reports_user_id_fkey;
alter index cflag_user_idx rename to creport_user_idx;
alter index flag_user_idx rename to report_user_idx;