diff --git a/files/assets/css/main.css b/files/assets/css/main.css index ac8bbe3fb..958f4aa48 100644 --- a/files/assets/css/main.css +++ b/files/assets/css/main.css @@ -6040,6 +6040,7 @@ g { .fa-syringe:before{content:"\f48e"} .fa-spider-web:before{content:"\f719"} .fa-coffin-cross:before{content:"\e051"} +.fa-face-sleeping:before{content:"\e38d"} .pronouns { diff --git a/files/assets/js/ban_modal.js b/files/assets/js/ban_modal.js index 2e4d968c9..300a385ee 100644 --- a/files/assets/js/ban_modal.js +++ b/files/assets/js/ban_modal.js @@ -1,4 +1,4 @@ -function banModal(link, id, name) { +function banModal(link, id, name, fullname, cls) { document.getElementById("banModalTitle").innerHTML = `Ban @${name}`; document.getElementById("ban-modal-link").value = link; document.getElementById("banUserButton").innerHTML = `Ban @${name}`; @@ -12,8 +12,36 @@ function banModal(link, id, name) { catch(e) {console.log(e)} 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]); } -} \ No newline at end of file +} + +function chudModal(link, id, name, fullname, cls) { + document.getElementById("chudModalTitle").innerHTML = `Chud @${name}`; + document.getElementById("chud-modal-link").value = link; + document.getElementById("chudUserButton").innerHTML = `Chud @${name}`; + + document.getElementById("chudUserButton").onclick = function() { + let form = new FormData(document.getElementById("chudModalForm")); + const xhr = createXhrWithFormKey(`/agendaposter/${id}?form`, "POST", form); + xhr[0].onload = function() { + let data + try {data = JSON.parse(xhr[0].response)} + catch(e) {console.log(e)} + 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/classes/comment.py b/files/classes/comment.py index 75e945f1b..feca324f6 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -43,6 +43,7 @@ class Comment(Base): is_banned = Column(Boolean, default=False) ghost = Column(Boolean, default=False) bannedfor = Column(String) + chuddedfor = Column(String) distinguish_level = Column(Integer, default=0) deleted_utc = Column(Integer, default=0) is_approved = Column(Integer, ForeignKey("users.id")) diff --git a/files/classes/submission.py b/files/classes/submission.py index 2458a76bf..f4d8a8117 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -29,6 +29,7 @@ class Submission(Base): thumburl = Column(String) is_banned = Column(Boolean, default=False) bannedfor = Column(String) + chuddedfor = Column(String) ghost = Column(Boolean, default=False) views = Column(Integer, default=0) deleted_utc = Column(Integer, default=0) diff --git a/files/routes/admin.py b/files/routes/admin.py index 6e99303c0..1cb4cf23c 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -806,43 +806,6 @@ def admin_removed_comments(v): next_exists=next_exists ) - -@app.post("/agendaposter/") -@admin_level_required(PERMS['USER_AGENDAPOSTER']) -def agendaposter(user_id, v): - user = get_account(user_id) - - days = request.values.get("days") - - if days: - expiry = int(time.time() + float(days)*60*60*24) - else: expiry = 1 - - user.agendaposter = expiry - g.db.add(user) - - if days: - days_txt = str(days).split('.0')[0] - note = f"for {days_txt} days" - else: note = "permanently" - - ma = ModAction( - kind="agendaposter", - user_id=v.id, - target_user_id=user.id, - _note=note - ) - g.db.add(ma) - - badge_grant(user=user, badge_id=28) - - send_repeatable_notification(user.id, f"@{v.username} (Admin) has marked you as a chud ({note}).") - - - return redirect(user.url) - - - @app.post("/unagendaposter/") @admin_level_required(PERMS['USER_AGENDAPOSTER']) def unagendaposter(user_id, v): @@ -1031,6 +994,67 @@ def ban_user(user_id, v): else: return {"message": f"@{user.username} has been banned!"} +@app.post("/agendaposter/") +@admin_level_required(PERMS['USER_AGENDAPOSTER']) +def agendaposter(user_id, v): + user = get_account(user_id) + + if user.admin_level > v.admin_level: + abort(403) + + days = 0.0 + try: + days = float(request.values.get("days")) + except: + pass + + reason = request.values.get("reason", "").strip() + if reason and reason.startswith("/") and '\\' not in reason: + reason = f'{reason}' + + user.agendaposter = int(time.time()) + (days * 86400) + g.db.add(user) + + duration = "permanently" + if days: + days_txt = str(days).split('.0')[0] + duration = f"for {days_txt} day" + if days != 1: duration += "s" + if reason: text = f"@{v.username} (Admin) has chudded you for **{days_txt}** days for the following reason:\n\n> {reason}" + else: text = f"@{v.username} (Admin) has chudded you for **{days_txt}** days." + else: + if reason: text = f"@{v.username} (Admin) has chudded you permanently for the following reason:\n\n> {reason}" + else: text = f"@{v.username} (Admin) has chudded you permanently." + + send_repeatable_notification(user.id, text) + + note = f'reason: "{reason}", duration: {duration}' + ma=ModAction( + kind="agendaposter", + user_id=v.id, + target_user_id=user.id, + _note=note + ) + g.db.add(ma) + + if 'reason' in request.values: + if request.values["reason"].startswith("/post/"): + try: post = int(request.values["reason"].split("/post/")[1].split(None, 1)[0]) + except: abort(400) + post = get_post(post) + post.chuddedfor = f'{duration} by @{v.username}' + g.db.add(post) + elif request.values["reason"].startswith("/comment/"): + try: comment = int(request.values["reason"].split("/comment/")[1].split(None, 1)[0]) + except: abort(400) + comment = get_comment(comment) + comment.chuddedfor = f'{duration} by @{v.username}' + g.db.add(comment) + + if 'redir' in request.values: return redirect(user.url) + else: return {"message": f"@{user.username} has been chudded!"} + + @app.post("/unban_user/") @limiter.limit("1/second;30/minute;200/hour;1000/day") @admin_level_required(PERMS['USER_BAN']) diff --git a/files/templates/ban_modal.html b/files/templates/ban_modal.html index a5ee7b7b3..3c88b6d6c 100644 --- a/files/templates/ban_modal.html +++ b/files/templates/ban_modal.html @@ -1,4 +1,3 @@ - diff --git a/files/templates/submission.html b/files/templates/submission.html index 098d58200..ae45e3fa6 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -636,6 +636,10 @@ {% endif %} + {% if p.chuddedfor %} + + {% endif %} + {% for a in p.awards %} {% endfor %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 67660fa9b..2812396da 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -129,6 +129,10 @@ {% endif %} + {% if p.chuddedfor %} + + {% endif %} + {% for a in p.awards %} {% endfor %} diff --git a/files/templates/userpage_admintools.html b/files/templates/userpage_admintools.html index 44be725eb..11a141a3e 100644 --- a/files/templates/userpage_admintools.html +++ b/files/templates/userpage_admintools.html @@ -77,10 +77,11 @@ {% if v.admin_level >= PERMS['USER_AGENDAPOSTER'] %}
+ - +
- + {% endif %}