feat(tasks): ответственный, пресеты, свимлейны, утренний дайджест на почту
wiki-sync / Publish docs/wiki to Gitea wiki (push) Successful in 28s
wiki-sync / Publish docs/wiki to Gitea wiki (push) Successful in 28s
- radicale: X-RESPONSIBLE/-NAME/-EMAIL, set_responsible; починена правка задач, у которых имя файла ≠ UID (кэш перечитывается при 404, _resource_url помнит href) - board: просрочка после 18:00 МСК, пресеты resp=, группировка по ответственному - tasktracker: правило «вне бэклога только с ответственным», set_responsible - UI доски: бейдж/поповер ответственного, пресеты, переключатель «По ответственным» - контакты: is_employee (звёздочка, пресет «Сотрудники»), 9 сотрудников отмечены, Жигульский/Ферулёв/Чикуров созданы заготовками - scripts/backfill_responsible.py: владелец проставлен 73 задачам - scripts/tasks_digest.py + cron 08:00 daily: письмо с разделами, himalaya -a hermes - tests: test_task_responsible.py (15), test_tasks_digest.py (6) - openspec changes task-responsible и tasks-digest заархивированы
This commit is contained in:
+78
-12
@@ -60,25 +60,47 @@ def _contacts_hint() -> list[str]:
|
||||
|
||||
|
||||
def _board(show_all_done: bool = False, *, q: str = "", status: str = "",
|
||||
done_from: str = "", done_to: str = "") -> dict:
|
||||
"""Доска с фильтрами: текст, колонка (статус), диапазон даты закрытия."""
|
||||
done_from: str = "", done_to: str = "", resp: str = "",
|
||||
view: str = "") -> dict:
|
||||
"""Доска с фильтрами: текст, колонка, дата закрытия, ответственный, вид."""
|
||||
from tasktracker import people
|
||||
|
||||
filters = {
|
||||
"q": (q or "").strip(),
|
||||
"status": status if status in board_mod.COLUMN_KEYS else "",
|
||||
"done_from": done_from if board_mod.parse_iso_date(done_from) else "",
|
||||
"done_to": done_to if board_mod.parse_iso_date(done_to) else "",
|
||||
"resp": resp if resp in dict(board_mod.RESP_PRESETS) else "",
|
||||
"view": "person" if view == "person" else "",
|
||||
}
|
||||
start = board_mod.parse_iso_date(filters["done_from"])
|
||||
end = board_mod.parse_iso_date(filters["done_to"])
|
||||
owner = people.owner_contact() or {}
|
||||
owner_email = people.owner_email()
|
||||
owner_id = (owner.get("id") or "").strip()
|
||||
employees = [{"id": c.get("id"), "name": c.get("full_name")}
|
||||
for c in people.employees()]
|
||||
tasks = board_mod.filter_tasks(_tracker.list(limit=1000), query=filters["q"],
|
||||
column=filters["status"], done_from=start, done_to=end)
|
||||
return board_mod.build_board(tasks, show_all_done=show_all_done, done_from=start,
|
||||
done_to=end, only_column=filters["status"] or None,
|
||||
filters=filters)
|
||||
column=filters["status"], done_from=start, done_to=end,
|
||||
resp=filters["resp"], owner_email=owner_email,
|
||||
owner_id=owner_id)
|
||||
board = board_mod.build_board(tasks, show_all_done=show_all_done, done_from=start,
|
||||
done_to=end, only_column=filters["status"] or None,
|
||||
filters=filters, view=filters["view"],
|
||||
people=employees, owner_email=owner_email,
|
||||
owner_id=owner_id)
|
||||
board["people"] = employees
|
||||
board["owner"] = {"id": owner_id, "email": owner_email,
|
||||
"name": (owner.get("full_name") or people.owner_name())}
|
||||
return board
|
||||
|
||||
|
||||
def _board_response(request: Request, show_all_done: bool = False, error: str = "", status: int = 200):
|
||||
data = _board(show_all_done)
|
||||
def _board_response(request: Request, show_all_done: bool = False, error: str = "",
|
||||
status: int = 200, filters: dict[str, str] | None = None):
|
||||
f = filters or {}
|
||||
data = _board(show_all_done, q=f.get("q", ""), status=f.get("status", ""),
|
||||
done_from=f.get("done_from", ""), done_to=f.get("done_to", ""),
|
||||
resp=f.get("resp", ""), view=f.get("view", ""))
|
||||
if is_htmx(request):
|
||||
return HTMLResponse(fragments.board_html(data, _contacts_hint(), error),
|
||||
status_code=status)
|
||||
@@ -89,9 +111,11 @@ def _board_response(request: Request, show_all_done: bool = False, error: str =
|
||||
|
||||
@router.get("/api/tasks/board")
|
||||
def tasks_board_json(all_done: int = 0, q: str = "", status: str = "",
|
||||
done_from: str = "", done_to: str = ""):
|
||||
"""JSON доски: колонки → задачи (для будущих клиентов)."""
|
||||
return _board(bool(all_done), q=q, status=status, done_from=done_from, done_to=done_to)
|
||||
done_from: str = "", done_to: str = "", resp: str = "",
|
||||
view: str = ""):
|
||||
"""JSON доски: колонки → задачи (+ группы по ответственным при view=person)."""
|
||||
return _board(bool(all_done), q=q, status=status, done_from=done_from,
|
||||
done_to=done_to, resp=resp, view=view)
|
||||
|
||||
|
||||
# --- чтение ---
|
||||
@@ -235,12 +259,54 @@ async def task_status(uid: str, request: Request):
|
||||
return _error(request, f"status must be one of {list(board_mod.COLUMN_KEYS)}")
|
||||
res = _tracker.set_status(uid, status)
|
||||
if res.get("error"):
|
||||
return _error(request, res["error"], status=502 if "conflict" not in res["error"] else 409)
|
||||
reason = res["error"]
|
||||
code = 409 if "conflict" in reason else (400 if reason == "responsible required" else 502)
|
||||
return _error(request, reason, status=code)
|
||||
if is_htmx(request):
|
||||
return _board_response(request)
|
||||
return {"ok": True, "status": status}
|
||||
|
||||
|
||||
@router.post("/api/tasks/{uid}/responsible")
|
||||
async def task_responsible(uid: str, request: Request):
|
||||
"""Назначить/снять ответственного.
|
||||
|
||||
Тело или query: contact_id (id контакта), name, email. Пустой contact_id —
|
||||
снять (разрешено только в бэклоге).
|
||||
"""
|
||||
import json
|
||||
|
||||
from tasktracker import people
|
||||
|
||||
payload: dict = {}
|
||||
ctype = request.headers.get("content-type", "")
|
||||
if "application/json" in ctype:
|
||||
try:
|
||||
payload = json.loads(await request.body() or b"{}") or {}
|
||||
except json.JSONDecodeError:
|
||||
return _error(request, "invalid JSON")
|
||||
else:
|
||||
payload = dict(await request.form())
|
||||
payload.update({k: v for k, v in request.query_params.items()})
|
||||
|
||||
contact_id = str(payload.get("contact_id") or payload.get("responsible") or "").strip()
|
||||
name = str(payload.get("name") or "").strip()
|
||||
email = str(payload.get("email") or "").strip()
|
||||
if contact_id:
|
||||
contact = people.contact_by_id(contact_id)
|
||||
if contact is None:
|
||||
return _error(request, "contact not found")
|
||||
name = (contact.get("full_name") or name).strip()
|
||||
email = (contact.get("email") or email).strip()
|
||||
|
||||
res = _tracker.set_responsible(uid, contact_id, name, email)
|
||||
if res.get("error"):
|
||||
return _error(request, res["error"], status=400)
|
||||
if is_htmx(request):
|
||||
return _board_response(request)
|
||||
return {"ok": True, "responsible": {"id": contact_id, "name": name, "email": email}}
|
||||
|
||||
|
||||
@router.post("/api/tasks/{uid}/tags")
|
||||
async def task_tags(uid: str, request: Request):
|
||||
"""Заменить теги объекта: {"tags": "Винный город,Глория"}."""
|
||||
|
||||
Reference in New Issue
Block a user