From f37e1dc7022f7eb9d166dfa1557511d2a1f678d0 Mon Sep 17 00:00:00 2001 From: Aevann Date: Mon, 26 Dec 2022 04:38:32 +0200 Subject: [PATCH] disallow jannoids from undoing chud awards --- files/classes/user.py | 3 ++- files/helpers/awards.py | 1 + files/routes/admin.py | 4 ++++ migrations/20221226-add-chudded_by.sql | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 migrations/20221226-add-chudded_by.sql diff --git a/files/classes/user.py b/files/classes/user.py index 8b41a336c..bc006924c 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -77,7 +77,8 @@ class User(Base): lootboxes_bought = Column(Integer, default=0) agendaposter = Column(Integer, default=0) is_activated = Column(Boolean, default=False) - shadowbanned = Column(Integer) + shadowbanned = Column(Integer, ForeignKey("users.id")) + chudded_by = Column(Integer, ForeignKey("users.id")) over_18 = Column(Boolean, default=False) hidevotedon = Column(Boolean, default=False) highlightcomments = Column(Boolean, default=True) diff --git a/files/helpers/awards.py b/files/helpers/awards.py index 3ac85065e..68786b9c8 100644 --- a/files/helpers/awards.py +++ b/files/helpers/awards.py @@ -24,6 +24,7 @@ def award_timers(v, bot=False): notify_if_not_bot("You have been unbanned!") if v.agendaposter and v.agendaposter != 1 and v.agendaposter < now: v.agendaposter = 0 + v.chudded_by = None notify_if_not_bot("Your chud status has expired!") badge = v.has_badge(28) if badge: g.db.delete(badge) diff --git a/files/routes/admin.py b/files/routes/admin.py index 0bd9e35cf..a2284845d 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -873,6 +873,9 @@ def admin_removed_comments(v): def unagendaposter(user_id, v): user = get_account(user_id) + if not user.chudded_by: + abort(403, "Jannies can't undo chud awards anymore!") + user.agendaposter = 0 g.db.add(user) @@ -1080,6 +1083,7 @@ def agendaposter(user_id, v): if reason: text = f"@{v.username} (a site admin) has chudded you permanently for the following reason:\n\n> {reason}" else: text = f"@{v.username} (a site admin) has chudded you permanently." + user.chudded_by = v.id g.db.add(user) send_repeatable_notification(user.id, text) diff --git a/migrations/20221226-add-chudded_by.sql b/migrations/20221226-add-chudded_by.sql new file mode 100644 index 000000000..707766fb2 --- /dev/null +++ b/migrations/20221226-add-chudded_by.sql @@ -0,0 +1,4 @@ +alter table users add column chudded_by int; +alter table users add constraint user_chudded_by_fkey foreign key (chudded_by) references users(id); +create index fki_user_chudded_by_fkey on users using btree (chudded_by); +update users set chudded_by=1 where agendaposter > 0;