summaryrefslogtreecommitdiff
path: root/Biz
diff options
context:
space:
mode:
Diffstat (limited to 'Biz')
-rw-r--r--Biz/PodcastItLater/Admin.py23
-rw-r--r--Biz/PodcastItLater/Web.py25
2 files changed, 40 insertions, 8 deletions
diff --git a/Biz/PodcastItLater/Admin.py b/Biz/PodcastItLater/Admin.py
index 6892234..d7a0a4e 100644
--- a/Biz/PodcastItLater/Admin.py
+++ b/Biz/PodcastItLater/Admin.py
@@ -625,7 +625,7 @@ def retry_queue_item(request: Request, job_id: int) -> Response:
def delete_queue_item(request: Request, job_id: int) -> Response:
"""Delete a queue item."""
try:
- # Check if user owns this job
+ # Check if user owns this job or is admin
user_id = request.session.get("user_id")
if not user_id:
return Response("Unauthorized", status_code=401)
@@ -633,15 +633,30 @@ def delete_queue_item(request: Request, job_id: int) -> Response:
job = Core.Database.get_job_by_id(
job_id,
)
- if job is None or job.get("user_id") != user_id:
+ if job is None:
+ return Response("Job not found", status_code=404)
+
+ # Check ownership or admin status
+ user = Core.Database.get_user_by_id(user_id)
+ if job.get("user_id") != user_id and not Core.is_admin(user):
return Response("Forbidden", status_code=403)
Core.Database.delete_job(job_id)
- # Redirect back to admin view
+
+ # Check if request is from admin page via referer header
+ is_from_admin = "/admin" in request.headers.get("referer", "")
+
+ # Redirect to admin if from admin page, trigger update otherwise
+ if is_from_admin:
+ return Response(
+ "",
+ status_code=200,
+ headers={"HX-Redirect": "/admin"},
+ )
return Response(
"",
status_code=200,
- headers={"HX-Redirect": "/admin"},
+ headers={"HX-Trigger": "queue-updated"},
)
except (ValueError, KeyError) as e:
return Response(
diff --git a/Biz/PodcastItLater/Web.py b/Biz/PodcastItLater/Web.py
index 71970cd..f4c65b1 100644
--- a/Biz/PodcastItLater/Web.py
+++ b/Biz/PodcastItLater/Web.py
@@ -433,7 +433,7 @@ class QueueStatus(Component[AnyChildren, QueueStatusAttrs]):
if item["error_message"]
else []
),
- # Add cancel button for pending jobs
+ # Add cancel button for pending jobs, remove for others
html.div(
html.button(
html.i(classes=["bi", "bi-x-lg", "me-1"]),
@@ -451,11 +451,28 @@ class QueueStatus(Component[AnyChildren, QueueStatusAttrs]):
"btn-outline-danger",
"mt-2",
],
+ )
+ if item["status"] == "pending"
+ else html.button(
+ html.i(classes=["bi", "bi-trash", "me-1"]),
+ "Remove",
+ hx_delete=f"/queue/{item['id']}",
+ hx_trigger="click",
+ hx_confirm="Remove this item from the queue?",
+ hx_on=(
+ "htmx:afterRequest: "
+ "if(event.detail.successful) "
+ "htmx.trigger('body', 'queue-updated')"
+ ),
+ classes=[
+ "btn",
+ "btn-sm",
+ "btn-outline-secondary",
+ "mt-2",
+ ],
),
classes=["mt-2"],
- )
- if item["status"] == "pending"
- else html.div(),
+ ),
classes=["card-body"],
),
classes=["card", "mb-2"],