From b819fa51d070c74cb8586b52080e1ae0578116a7 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 19 Feb 2023 15:23:08 +0200 Subject: [PATCH] make it possible for jannies to stack chuds and bans --- files/assets/js/ban_modal.js | 4 ---- files/assets/js/core.js | 5 +++-- files/classes/user.py | 5 ++++- files/routes/admin.py | 6 +++++- files/templates/comments.html | 8 ++++---- files/templates/post_actions.html | 4 ++-- files/templates/post_admin_actions_mobile.html | 4 ++-- files/templates/userpage/admintools.html | 4 ++-- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/files/assets/js/ban_modal.js b/files/assets/js/ban_modal.js index df98e695e..47b698e4d 100644 --- a/files/assets/js/ban_modal.js +++ b/files/assets/js/ban_modal.js @@ -13,9 +13,7 @@ function banModal(link, name, fullname, cls) { success = xhr[0].status >= 200 && xhr[0].status < 300; showToast(success, getMessageFromJsonData(success, data)); document.getElementById(`unban-${fullname}`).classList.toggle(cls); - document.getElementById(`ban-${fullname}`).classList.toggle(cls); document.getElementById(`unban2-${fullname}`).classList.toggle(cls); - document.getElementById(`ban2-${fullname}`).classList.toggle(cls); }; xhr[0].send(xhr[1]); @@ -37,9 +35,7 @@ function chudModal(link, name, fullname, cls) { success = xhr[0].status >= 200 && xhr[0].status < 300; showToast(success, getMessageFromJsonData(success, data)); document.getElementById(`unchud-${fullname}`).classList.toggle(cls); - document.getElementById(`chud-${fullname}`).classList.toggle(cls); document.getElementById(`unchud2-${fullname}`).classList.toggle(cls); - document.getElementById(`chud2-${fullname}`).classList.toggle(cls); }; xhr[0].send(xhr[1]); diff --git a/files/assets/js/core.js b/files/assets/js/core.js index 47c750251..ea9b10a3a 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -352,11 +352,12 @@ function sendFormXHR(form, extraActionsOnSuccess) { xhr.send(formData); } -function sendFormXHRSwitch(form) { +function sendFormXHRSwitch(form, donthideself) { sendFormXHR(form, () => { form.previousElementSibling.classList.remove('d-none'); - form.classList.add('d-none'); + if (!donthideself) + form.classList.add('d-none'); } ) } diff --git a/files/classes/user.py b/files/classes/user.py index 9a5ee9d5a..b3f0404d9 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -816,7 +816,10 @@ class User(Base): def ban(self, admin=None, reason=None, days=0.0): if days: - self.unban_utc = int(time.time()) + (days * 86400) + if self.unban_utc: + self.unban_utc += days * 86400 + else: + self.unban_utc = int(time.time()) + (days * 86400) g.db.add(self) self.is_banned = admin.id if admin else AUTOJANNY_ID diff --git a/files/routes/admin.py b/files/routes/admin.py index 7eb8cdc0f..1b0441332 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -720,6 +720,7 @@ def unagendaposter(id, v): abort(403, "Jannies can't undo chud awards anymore!") user.agendaposter = 0 + user.chudded_by = None g.db.add(user) ma = ModAction( @@ -957,7 +958,10 @@ def agendaposter(id, v): duration = "permanently" if days: - user.agendaposter = int(time.time()) + (days * 86400) + if user.agendaposter: + user.agendaposter += days * 86400 + else: + user.agendaposter = int(time.time()) + (days * 86400) days_txt = str(days) if days_txt.endswith('.0'): days_txt = days_txt[:-2] duration = f"for {days_txt} day" diff --git a/files/templates/comments.html b/files/templates/comments.html index 761305c23..9be640a0a 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -473,12 +473,12 @@ {% if v.admin_level >= PERMS['USER_BAN'] and v.id != c.author_id %} - + {% endif %} {% if v.admin_level >= PERMS['USER_AGENDAPOSTER'] and v.id != c.author_id %} - + {% endif %} @@ -674,12 +674,12 @@ {% endif %} {% if v.id != c.author_id and v.admin_level >= PERMS['USER_BAN'] %} - + {% endif %} {% if v.id != c.author_id and v.admin_level >= PERMS['USER_AGENDAPOSTER'] %} - + {% endif %} diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index f48a1c2d9..09bbb61e8 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -86,11 +86,11 @@ {% endif %} {% if v.admin_level >= PERMS['USER_BAN'] and v.id != p.author_id %} - + {% endif %} {% if v.admin_level >= PERMS['USER_AGENDAPOSTER'] and v.id != p.author_id %} - + {% endif %} diff --git a/files/templates/post_admin_actions_mobile.html b/files/templates/post_admin_actions_mobile.html index 4e5d6b3ab..2b41634a2 100644 --- a/files/templates/post_admin_actions_mobile.html +++ b/files/templates/post_admin_actions_mobile.html @@ -40,11 +40,11 @@ {% endif %} {% if v.id != p.author_id and v.admin_level >= PERMS['USER_BAN'] %} - + {% endif %} {% if v.id != p.author_id and v.admin_level >= PERMS['USER_AGENDAPOSTER'] %} - + {% endif %} diff --git a/files/templates/userpage/admintools.html b/files/templates/userpage/admintools.html index 2a4ec414c..b519419cb 100644 --- a/files/templates/userpage/admintools.html +++ b/files/templates/userpage/admintools.html @@ -44,7 +44,7 @@ {% if v.admin_level >= PERMS['USER_BAN'] %} -
+ @@ -67,7 +67,7 @@ {% if v.admin_level >= PERMS['USER_AGENDAPOSTER'] %} - +