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
+2
-2
@@ -7,8 +7,8 @@ from __future__ import annotations
|
||||
|
||||
from app.web.api import router as api_router
|
||||
from app.web.pages import (
|
||||
MOVED, SETTINGS, STATIC_DIR, TABS, router as pages_router, templates,
|
||||
SETTINGS, STATIC_DIR, TABS, router as pages_router, templates,
|
||||
)
|
||||
|
||||
__all__ = ["MOVED", "SETTINGS", "STATIC_DIR", "TABS", "api_router", "pages_router",
|
||||
__all__ = ["SETTINGS", "STATIC_DIR", "TABS", "api_router", "pages_router",
|
||||
"templates"]
|
||||
+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}
|
||||
|
||||
|
||||
|
||||
@@ -23,13 +23,6 @@ contains; the others stay in the page, hidden, so each section's script (the
|
||||
ones they had as pages of their own, each guarding on its own root element)
|
||||
keeps working.
|
||||
|
||||
Every path a page has had before (`/agents`, `/companies`, `/sources`,
|
||||
`/jobs`, `/schedules`, `/messages`, `/account`, and the six sub-tabs the
|
||||
settings shell started with) answers 301 to its place now, query string
|
||||
kept, so a bookmark still lands. A merged page's old path lands on its
|
||||
section's anchor; the old Messages paths land on `#messages`, the log's
|
||||
block at the end of Runs.
|
||||
|
||||
`FUNCTIONS` and `HOSTS` are `plugins.ats`'s, not `app`'s: the nine job
|
||||
functions are the classifier's vocabulary and the hosts are what it parses,
|
||||
and this reaches `plugins/` the same way `app.cli` does, since a plugin is
|
||||
@@ -41,7 +34,6 @@ Jobindex areas and Adzuna countries on the Sources page come from
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
@@ -94,24 +86,6 @@ SECTIONS: dict[str, tuple[tuple[str, str], ...]] = {
|
||||
),
|
||||
}
|
||||
|
||||
#: Where each page that used to be a tab or a sub-tab lives now. The fragment
|
||||
#: is the section on the merged page, or an element in one (`#messages`, in
|
||||
#: Runs); a browser keeps it across the 301.
|
||||
MOVED: dict[str, str] = {
|
||||
"/agents": "/settings/agents",
|
||||
"/settings/ranking": "/settings/agents",
|
||||
"/companies": "/settings/sources#company-boards",
|
||||
"/settings/companies": "/settings/sources#company-boards",
|
||||
"/sources": "/settings/sources#job-boards",
|
||||
"/settings/searches": "/settings/sources#job-boards",
|
||||
"/jobs": "/settings/sources#runs",
|
||||
"/schedules": "/settings/sources#runs",
|
||||
"/settings/pulls": "/settings/sources#runs",
|
||||
"/messages": "/settings/sources#messages",
|
||||
"/settings/messages": "/settings/sources#messages",
|
||||
"/account": "/settings/account",
|
||||
}
|
||||
|
||||
#: `value, label` for each select option. `FUNCTIONS` is already the value a
|
||||
#: role's `function` column holds; only the label is dressed up.
|
||||
FUNCTION_OPTIONS = [(f, f.replace("/", " / ").capitalize()) for f in FUNCTIONS]
|
||||
@@ -197,21 +171,3 @@ def sources(request: Request) -> HTMLResponse:
|
||||
@router.get("/settings/account", response_class=HTMLResponse)
|
||||
def account(request: Request) -> HTMLResponse:
|
||||
return page(request, "settings/account.html")
|
||||
|
||||
|
||||
def _moved(to: str) -> Callable[[Request], RedirectResponse]:
|
||||
"""A 301 to `to`, carrying the query string, so `/agents?x=1` keeps it.
|
||||
The query goes before `to`'s fragment, if it has one, or the browser
|
||||
would read `#runs?x=1` as one fragment."""
|
||||
path, _, fragment = to.partition("#")
|
||||
def redirect(request: Request) -> RedirectResponse:
|
||||
query = request.url.query
|
||||
target = f"{path}?{query}" if query else path
|
||||
return RedirectResponse(f"{target}#{fragment}" if fragment else target,
|
||||
status_code=301)
|
||||
return redirect
|
||||
|
||||
|
||||
for _old, _new in MOVED.items():
|
||||
router.add_api_route(_old, _moved(_new), methods=["GET"],
|
||||
response_class=RedirectResponse)
|
||||
Reference in new issue
Block a user