feat: adopt solution and close ticket
This commit is contained in:
128
docs/superpowers/plans/2026-07-03-adopt-solution-close-ticket.md
Normal file
128
docs/superpowers/plans/2026-07-03-adopt-solution-close-ticket.md
Normal file
@@ -0,0 +1,128 @@
|
||||
# Adopt Solution Close Ticket Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Allow support staff to search published solutions, adopt one, write it into the ticket resolution, and close the ticket in one action.
|
||||
|
||||
**Architecture:** Keep the adoption workflow server-side so ticket status, solution link, solution usage count, resolution fields, and timeline events stay consistent. The frontend remains a shadcn/App-component panel that calls a single action endpoint and refreshes ticket context.
|
||||
|
||||
**Tech Stack:** Django, Django Ninja, PostgreSQL migrations already present, React, TypeScript, Tailwind, shadcn/ui project components.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Backend Adopt-And-Close Endpoint
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/apps/solutions/schemas.py`
|
||||
- Modify: `backend/apps/solutions/api.py`
|
||||
- Test: `backend/apps/solutions/tests/test_solution_api.py`
|
||||
|
||||
- [ ] **Step 1: Write the failing API test**
|
||||
|
||||
Add a test that creates a published solution and pending ticket, posts to `/api/solutions/{solution_id}/adopt-ticket`, and asserts:
|
||||
|
||||
```python
|
||||
assert response.status_code == 200
|
||||
ticket.refresh_from_db()
|
||||
assert ticket.status == "closed"
|
||||
assert ticket.is_resolved is True
|
||||
assert ticket.replied_to_customer is True
|
||||
assert ticket.resolution_summary == solution.solution
|
||||
assert ticket.events.filter(event_type="solution_adopted").exists()
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Implement the schema and endpoint**
|
||||
|
||||
Add a payload with `ticket_id`, `remark`, and `replied_to_customer`. The endpoint should:
|
||||
|
||||
```python
|
||||
link, _ = TicketSolutionLink.objects.get_or_create(
|
||||
ticket=ticket,
|
||||
solution=solution,
|
||||
link_type="adopted",
|
||||
defaults={"created_by": request.user if request.user.is_authenticated else None},
|
||||
)
|
||||
ticket.status = "closed"
|
||||
ticket.resolution_summary = solution.solution
|
||||
ticket.is_resolved = True
|
||||
ticket.replied_to_customer = payload.replied_to_customer
|
||||
ticket.resolved_at = ticket.resolved_at or timezone.now()
|
||||
ticket.closed_at = timezone.now()
|
||||
ticket.save(update_fields=[...])
|
||||
TicketEvent.objects.create(event_type="solution_adopted", ...)
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Verify backend**
|
||||
|
||||
Run:
|
||||
|
||||
```powershell
|
||||
python -m pytest backend\apps\solutions\tests backend\apps\tickets\tests
|
||||
python -m ruff check backend\apps\solutions backend\apps\tickets
|
||||
```
|
||||
|
||||
Expected: all tests pass and ruff reports no issues.
|
||||
|
||||
### Task 2: Frontend Search And Adopt UI
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/src/features/solutions/api.ts`
|
||||
- Modify: `frontend/src/features/solutions/SolutionLinkPanel.tsx`
|
||||
- Modify: `frontend/src/features/tickets/TicketDetailPage.tsx`
|
||||
|
||||
- [ ] **Step 1: Add API client**
|
||||
|
||||
Add:
|
||||
|
||||
```ts
|
||||
export function adoptSolutionAndCloseTicket(solutionId: number, ticketId: number) {
|
||||
return apiRequest(`/solutions/${solutionId}/adopt-ticket`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
ticket_id: ticketId,
|
||||
replied_to_customer: true,
|
||||
remark: '采纳解决方案并关闭工单'
|
||||
})
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Add search and action button**
|
||||
|
||||
In `SolutionLinkPanel`, add a search input filtering by `title`, `problem_signature`, and `solution`. Rename the adoption action to `采纳并关闭`, call the new endpoint, refresh linked solutions, and notify the parent ticket detail page to reload.
|
||||
|
||||
- [ ] **Step 3: Verify frontend**
|
||||
|
||||
Run:
|
||||
|
||||
```powershell
|
||||
npm run typecheck
|
||||
npm run build
|
||||
```
|
||||
|
||||
Expected: TypeScript and Vite build both succeed.
|
||||
|
||||
### Task 3: Commit
|
||||
|
||||
**Files:**
|
||||
- Stage only the backend/frontend files touched by this feature.
|
||||
|
||||
- [ ] **Step 1: Inspect git status**
|
||||
|
||||
Run:
|
||||
|
||||
```powershell
|
||||
git status --short
|
||||
git diff --stat
|
||||
```
|
||||
|
||||
Expected: existing local `.gitignore` and local lock/compose files remain unstaged.
|
||||
|
||||
- [ ] **Step 2: Commit**
|
||||
|
||||
Run:
|
||||
|
||||
```powershell
|
||||
git add backend/apps/solutions frontend/src/features/solutions frontend/src/features/tickets/TicketDetailPage.tsx docs/superpowers/plans/2026-07-03-adopt-solution-close-ticket.md
|
||||
git commit -m "feat: adopt solution and close ticket"
|
||||
```
|
||||
Reference in New Issue
Block a user