Flagging cleanup

Visible only to Admin
Allow multiple flags per user per post
This commit is contained in:
Julian Rota 2022-05-18 23:54:20 -04:00
parent 6d68993a8d
commit 88fcdabd78
5 changed files with 36 additions and 19 deletions

View file

@ -9,8 +9,9 @@ class Flag(Base):
__tablename__ = "flags"
post_id = Column(Integer, ForeignKey("submissions.id"), primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
id = Column(Integer, primary_key=True)
post_id = Column(Integer, ForeignKey("submissions.id"))
user_id = Column(Integer, ForeignKey("users.id"))
reason = Column(String)
created_utc = Column(Integer)

View file

@ -143,6 +143,9 @@ class User(Base):
super().__init__(**kwargs)
def can_manage_reports(self):
return self.admin_level > 2
@lazy
def mods(self, sub):
return self.admin_level == 3 or bool(g.db.query(Mod.user_id).filter_by(user_id=self.id, sub=sub).one_or_none())

View file

@ -11,23 +11,9 @@ from files.helpers.sanitize import filter_emojis_only
def api_flag_post(pid, v):
post = get_post(pid)
reason = request.values.get("reason", "").strip()
if blackjack and any(i in reason.lower() for i in blackjack.split()):
v.shadowbanned = 'AutoJanny'
send_repeatable_notification(CARP_ID, f"reports on {post.permalink}")
reason = reason[:100]
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
reason = request.values.get("reason", "").strip()[:100]
reason = filter_emojis_only(reason)
if len(reason) > 350: return {"error": "Too long."}
if reason.startswith('!') and v.admin_level > 1:
post.flair = reason[1:]
g.db.add(post)

View file

@ -60,7 +60,7 @@
{% set voted=-2 %}
{% endif %}
{% if p.active_flags(v) %}
{% if v and p.active_flags(v) and v.can_manage_reports() %}
<div id="flaggers-{{p.id}}" class="flaggers d-none">
<strong><i class="far fa-fw fa-flag"></i> Reported by:</strong>
<pre></pre>
@ -175,7 +175,9 @@
{% 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(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 v and p.active_flags(v) and v.can_manage_reports() %}
<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()}}

View file

@ -371,12 +371,31 @@ CREATE TABLE public.exiles (
--
CREATE TABLE public.flags (
id integer NOT NULL,
user_id integer NOT NULL,
post_id integer NOT NULL,
reason character varying(350),
created_utc integer NOT NULL
);
--
-- Name: flags_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.flags_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: flags_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.flags_id_seq OWNED BY public.flags.id;
--
-- Name: follows; Type: TABLE; Schema: public; Owner: -
@ -738,6 +757,12 @@ ALTER TABLE ONLY public.usernotes ALTER COLUMN id SET DEFAULT nextval('public.us
ALTER TABLE ONLY public.comments ALTER COLUMN id SET DEFAULT nextval('public.comments_id_seq'::regclass);
--
-- Name: flags id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.flags ALTER COLUMN id SET DEFAULT nextval('public.flags_id_seq'::regclass);
--
-- Name: modactions id; Type: DEFAULT; Schema: public; Owner: -
--