Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
3af8fba
1
Parent(s): e4c427f
auth: enforce RBAC for ticket resolution (Assignee, Lead, Admin, Superadmin only)
Browse files- services/ticket_service.py +11 -1
services/ticket_service.py
CHANGED
|
@@ -377,7 +377,17 @@ class TicketService:
|
|
| 377 |
update_data = payload.model_dump(exclude_unset=True)
|
| 378 |
|
| 379 |
if "status" in update_data and update_data["status"] != ticket.status:
|
| 380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
raise HTTPException(status_code=400, detail="Invalid status transition")
|
| 382 |
if update_data["status"] in [TicketStatus.RESOLVED, TicketStatus.CLOSED]:
|
| 383 |
ticket.resolved_at = datetime.utcnow()
|
|
|
|
| 377 |
update_data = payload.model_dump(exclude_unset=True)
|
| 378 |
|
| 379 |
if "status" in update_data and update_data["status"] != ticket.status:
|
| 380 |
+
# RBAC: Only Leads, Admins, Superadmins, or the actual Assignee can transition to RESOLVED/CLOSED
|
| 381 |
+
if update_data["status"] in [TicketStatus.RESOLVED, TicketStatus.CLOSED]:
|
| 382 |
+
is_privileged = current_user.role in [UserRole.SC_LEAD, UserRole.SC_ADMIN, UserRole.SUPERADMIN]
|
| 383 |
+
is_assignee = str(ticket.assigned_to) == str(current_user.id)
|
| 384 |
+
if not (is_privileged or is_assignee):
|
| 385 |
+
raise HTTPException(
|
| 386 |
+
status_code=403,
|
| 387 |
+
detail="Only the assigned agent or a workspace administrator (Lead/Admin/Superadmin) can resolve this incident."
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
if current_user.role not in [UserRole.SC_LEAD, UserRole.SC_ADMIN, UserRole.SUPERADMIN] and update_data["status"] not in ALLOWED_TRANSITIONS.get(ticket.status, []):
|
| 391 |
raise HTTPException(status_code=400, detail="Invalid status transition")
|
| 392 |
if update_data["status"] in [TicketStatus.RESOLVED, TicketStatus.CLOSED]:
|
| 393 |
ticket.resolved_at = datetime.utcnow()
|