From fda1f1e5624514c2c5eadffabd8e8213d4060ce2 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 11 Sep 2022 09:03:34 +0200 Subject: [PATCH] allow asset submitters to remove their pending shit --- files/routes/asset_submissions.py | 26 +++++++++++++------------ files/templates/submit_hats.html | 30 +++++++++++++++++++++++------ files/templates/submit_marseys.html | 30 +++++++++++++++++++++++------ 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/files/routes/asset_submissions.py b/files/routes/asset_submissions.py index 11bfff14c..f0df15108 100644 --- a/files/routes/asset_submissions.py +++ b/files/routes/asset_submissions.py @@ -149,18 +149,19 @@ def approve_marsey(v, name): return {"message": f"'{marsey.name}' approved!"} -@app.post("/admin/reject/marsey/") -@admin_level_required(3) -def reject_marsey(v, name): - if CARP_ID and v.id != CARP_ID: - return {"error": "Only Carp can reject marseys!"}, 403 +@app.post("/remove/marsey/") +@auth_required +def remove_marsey(v, name): name = name.lower().strip() marsey = g.db.query(Marsey).filter_by(name=name).one_or_none() if not marsey: return {"error": f"This marsey '{name}' doesn't exist!"}, 404 + if v.id not in {marsey.submitter_id, CARP_ID}: + return {"error": "Only Carp can remove marseys!"}, 403 + if v.id != marsey.submitter_id: msg = f"@{v.username} has rejected a marsey you submitted: `'{marsey.name}'`" send_repeatable_notification(marsey.submitter_id, msg) @@ -168,7 +169,7 @@ def reject_marsey(v, name): g.db.delete(marsey) os.remove(f"/asset_submissions/marseys/{marsey.name}.webp") - return {"message": f"'{marsey.name}' rejected!"} + return {"message": f"'{marsey.name}' removed!"} @@ -298,18 +299,19 @@ def approve_hat(v, name): return {"message": f"'{hat.name}' approved!"} -@app.post("/admin/reject/hat/") -@admin_level_required(3) -def reject_hat(v, name): - if CARP_ID and v.id != CARP_ID: - return {"error": "Only Carp can reject hats!"}, 403 +@app.post("/remove/hat/") +@auth_required +def remove_hat(v, name): name = name.strip() hat = g.db.query(HatDef).filter_by(name=name).one_or_none() if not hat: return {"error": f"This hat '{name}' doesn't exist!"}, 404 + if v.id not in {hat.submitter_id, CARP_ID}: + return {"error": "Only Carp can remove hats!"}, 403 + if v.id != hat.submitter_id: msg = f"@{v.username} has rejected a hat you submitted: `'{hat.name}'`" send_repeatable_notification(hat.submitter_id, msg) @@ -317,4 +319,4 @@ def reject_hat(v, name): g.db.delete(hat) os.remove(f"/asset_submissions/hats/{hat.name}.webp") - return {"message": f"'{hat.name}' rejected!"} + return {"message": f"'{hat.name}' removed!"} \ No newline at end of file diff --git a/files/templates/submit_hats.html b/files/templates/submit_hats.html index d4131565e..5600c4c1e 100644 --- a/files/templates/submit_hats.html +++ b/files/templates/submit_hats.html @@ -133,6 +133,24 @@ t.classList.remove("disabled"); }, 2000); } + + function remove_hat(t, name) { + t.disabled = true; + t.classList.add("disabled"); + post_toast_callback(`/remove/hat/${name}`, + { + }, + (xhr) => { + if(xhr.status == 200) { + document.getElementById(`${name}-hat`).remove() + } + } + ); + setTimeout(() => { + t.disabled = false; + t.classList.remove("disabled"); + }, 2000); + }

Pending Carp Approval

@@ -164,12 +182,12 @@ - {% if v.admin_level > 2 %} -
- Reject - Approve -
- {% endif %} +
+ Remove + {% if v.admin_level > 2 %} + Approve + {% endif %} +
{% endfor %} diff --git a/files/templates/submit_marseys.html b/files/templates/submit_marseys.html index d1d0e6f1a..fd99d0501 100644 --- a/files/templates/submit_marseys.html +++ b/files/templates/submit_marseys.html @@ -134,6 +134,24 @@ t.classList.remove("disabled"); }, 2000); } + + function remove_marsey(t, name) { + t.disabled = true; + t.classList.add("disabled"); + post_toast_callback(`/remove/marsey/${name}`, + { + }, + (xhr) => { + if(xhr.status == 200) { + document.getElementById(`${name}-marsey`).remove() + } + } + ); + setTimeout(() => { + t.disabled = false; + t.classList.remove("disabled"); + }, 2000); + }

Pending Carp Approval

@@ -162,12 +180,12 @@ - {% if v.admin_level > 2 %} -
- Reject - Approve -
- {% endif %} +
+ Remove + {% if v.admin_level > 2 %} + Approve + {% endif %} +
{% endfor %}