Merge branch 'r2-web'
# Conflicts: # app/static/roles.js # app/web/api.py # tests/test_web.py
This commit is contained in:
commit
a629eda8de
13 files changed
+548
-203
No files matched your search
+38
-13
@@ -17,7 +17,7 @@ from pydantic import BaseModel, Field
|
||||
|
||||
from app import jobs
|
||||
from app.models import (
|
||||
AFFINITY, Agent, Application, Company, Gate, Limits, Role, ScoredRole, Status,
|
||||
AFFINITY, Agent, Application, Company, Gate, Limits, Role, RoleRow, Status,
|
||||
Subscription, Weights, company_key,
|
||||
)
|
||||
from app.storage import Store
|
||||
@@ -112,9 +112,14 @@ def unread_role(uid: str, store: StoreDep) -> Role:
|
||||
|
||||
|
||||
class RolesPage(BaseModel):
|
||||
"""One page of roles, and how many the same filters match in all."""
|
||||
"""One page of roles, and how many the same filters match in all. `items`
|
||||
is `RoleRow`, not the full `Role`: the fields a feed row draws, with an
|
||||
excerpt built on the server, never the big columns (`description`,
|
||||
`feed_text`, `raw`, `article_text`) a full role carries — see
|
||||
`Store.roles_page`. The reader fetches the rest by uid when it opens one,
|
||||
`GET /api/roles/{uid}`."""
|
||||
|
||||
items: list[ScoredRole]
|
||||
items: list[RoleRow]
|
||||
total: int
|
||||
|
||||
|
||||
@@ -165,7 +170,7 @@ def list_roles(
|
||||
"hide_muted": not show_muted, "include_read": include_read, "tags": tags,
|
||||
"tag_mode": tag_mode, "agent": agent_id, "by_score": by_score,
|
||||
"gated": gated, "judged": judged or None, "pay": pay or None}
|
||||
return RolesPage(items=store.roles(limit=limit, offset=offset, **filters),
|
||||
return RolesPage(items=store.roles_page(limit=limit, offset=offset, **filters),
|
||||
total=store.count_roles(**filters))
|
||||
|
||||
|
||||
@@ -335,16 +340,21 @@ class CompanyBoardBody(BaseModel):
|
||||
|
||||
|
||||
@router.post("/companies/{key}/board")
|
||||
def set_company_board(key: str, body: CompanyBoardBody, store: StoreDep) -> dict[str, Any]:
|
||||
def set_company_board(key: str, body: CompanyBoardBody, store: StoreDep,
|
||||
queue: QueueDep) -> dict[str, Any]:
|
||||
"""Attach a board to a company, or replace the one it has. The board is
|
||||
fetched first and refused if it does not answer; replacing closes the
|
||||
old board's open roles."""
|
||||
old board's open roles. Queues a pull right after, so the board is read
|
||||
by the one already running or the very next one rather than the
|
||||
schedule, up to six hours later; a refusal because one is already
|
||||
running is not an error, see `app.jobs.pull.claim_run`."""
|
||||
if store.company(key) is None:
|
||||
raise HTTPException(404, f"no such company: {key}")
|
||||
try:
|
||||
sub, found, closed = jobs.sources.set_board(store, key, body.board)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(422, str(exc)) from exc
|
||||
queue.enqueue("pull")
|
||||
return {"source": _one_source(store, sub.id), "found": found, "closed": closed}
|
||||
|
||||
|
||||
@@ -492,12 +502,18 @@ class SwitchBody(BaseModel):
|
||||
|
||||
|
||||
@router.post("/sources/{sub_id}/switch")
|
||||
def switch_source(sub_id: int, body: SwitchBody, store: StoreDep) -> dict[str, Any]:
|
||||
"""On or off for the next pull. Off closes the open roles at once; on
|
||||
reopens the ones the next pull still finds."""
|
||||
def switch_source(sub_id: int, body: SwitchBody, store: StoreDep,
|
||||
queue: QueueDep) -> dict[str, Any]:
|
||||
"""On or off. Off closes the open roles at once; on queues a pull right
|
||||
after, so the ones it still lists reopen once the pull that is already
|
||||
running reads it, or the very next one does, rather than waiting for the
|
||||
schedule, up to six hours later. A refusal because one is already
|
||||
running is not an error, see `app.jobs.pull.claim_run`."""
|
||||
if store.subscription(sub_id) is None:
|
||||
raise HTTPException(404, f"no such board or search: {sub_id}")
|
||||
_, closed = jobs.sources.set_fetch(store, sub_id, body.on)
|
||||
if body.on:
|
||||
queue.enqueue("pull")
|
||||
return {"source": _one_source(store, sub_id), "closed": closed}
|
||||
|
||||
|
||||
@@ -534,14 +550,19 @@ def try_search(body: SearchBody, config: ConfigDep) -> dict[str, Any]:
|
||||
|
||||
|
||||
@router.post("/searches")
|
||||
def save_search(body: SearchBody, store: StoreDep, config: ConfigDep) -> dict[str, Any]:
|
||||
def save_search(body: SearchBody, store: StoreDep, config: ConfigDep,
|
||||
queue: QueueDep) -> dict[str, Any]:
|
||||
"""Save a search, or update the one of that provider and name. It is run
|
||||
once first and refused if it finds nothing."""
|
||||
once first and refused if it finds nothing. Queues a pull right after,
|
||||
so its roles are read by the one already running or the very next one
|
||||
rather than the schedule, up to six hours later; a refusal because one is
|
||||
already running is not an error, see `app.jobs.pull.claim_run`."""
|
||||
try:
|
||||
sub, found, complete = jobs.sources.save_search(config, store, body.provider,
|
||||
body.name, _params(body))
|
||||
except ValueError as exc:
|
||||
raise HTTPException(422, str(exc)) from exc
|
||||
queue.enqueue("pull")
|
||||
return {"source": _one_source(store, sub.id), "found": found, "complete": complete}
|
||||
|
||||
|
||||
@@ -560,14 +581,18 @@ class BoardBody(BaseModel):
|
||||
|
||||
|
||||
@router.post("/boards", status_code=201)
|
||||
def add_board(body: BoardBody, store: StoreDep) -> dict[str, Any]:
|
||||
def add_board(body: BoardBody, store: StoreDep, queue: QueueDep) -> dict[str, Any]:
|
||||
"""Follow a company by its ATS board: `set_board` keyed by the name, so
|
||||
an existing company gets it attached or replaced. The board is fetched
|
||||
first and refused if it does not answer."""
|
||||
first and refused if it does not answer. Queues a pull right after, so
|
||||
its roles are read by the one already running or the very next one
|
||||
rather than the schedule, up to six hours later; a refusal because one is
|
||||
already running is not an error, see `app.jobs.pull.claim_run`."""
|
||||
try:
|
||||
sub, found = jobs.sources.add_board(store, body.board, body.name)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(422, str(exc)) from exc
|
||||
queue.enqueue("pull")
|
||||
return {"source": _one_source(store, sub.id), "found": found}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user