Every way a company gets a board is set_board, and an unreadable host keeps its slug

`app.jobs.sources.set_board` attaches a board to an existing company,
replaces the one it has (closing the old board's open roles) or creates
the company, with row and subscription changed in one transaction by
`Store.set_company_board`. A board that lists zero roles is kept. `add`,
`discover --add`, the seed importer (moved out of app/cli.py) and the new
`POST|DELETE /api/companies/{key}/board` all go through it; a seed re-run
attaches a board to a row that never had one. A company's subscription is
rewritten in place, and detaching hides it.

`companies.ats_slug` (migration 9) keeps the slug of a host the app
cannot read yet, and discovery returns such a host before probing slugs.
The Companies rows get Set board / Change, the host select is rendered
from `plugins.ats.HOSTS`, and a row with nothing found reads "board not
found" and is in the "Not readable yet" filter.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-29 14:04:52 +02:00
1 parent 0558ef19ed
commit 3b209d628a
18 files changed
+1038 -178

No files matched your search

+48 -10
View File
@@ -260,11 +260,12 @@ def summarise_role(uid: str, store: StoreDep, config: ConfigDep, queue: QueueDep
class CompanyOut(BaseModel):
"""A company row plus what only the store can join in: the ats host it is
read from (empty for a company known only from a search), the id of that
read from (empty for one with no board), the id of that
board's subscription, whether it is on, and how many of its roles are
still open. `ats` is the host its careers site runs on whether or not the
app reads it, so a followed company with no `board` and an `ats` is one
the app cannot read yet; `careers_url` is where a person can."""
app reads it, and `ats_slug` its name there, so a followed company with
no `board` and an `ats` is one the app cannot read yet; `careers_url` is
where a person can."""
key: str
name: str
@@ -274,6 +275,7 @@ class CompanyOut(BaseModel):
affinity: int
open_roles: int
ats: str = ""
ats_slug: str = ""
careers_url: str = ""
country: str = ""
@@ -282,9 +284,12 @@ def _company_boards(store: Store) -> dict[str, tuple[int, str, bool]]:
"""`company_key -> (subscription id, ats host, on)`, read off each
company's own subscription. Same join as `Store.company_boards`, with the
id and switch state a company row needs to draw its own on/off control
rather than fetching `/api/sources` as well."""
rather than fetching `/api/sources` as well. A detached board (`show`
0) is no board."""
boards: dict[str, tuple[int, str, bool]] = {}
for sub in store.subscriptions(source="ats"):
if not sub.show:
continue
boards.setdefault(company_key(sub.company), (sub.id, sub.board,
bool(sub.subscribed and sub.fetch)))
return boards
@@ -302,10 +307,41 @@ def list_companies(store: StoreDep, agent: int | None = None) -> list[CompanyOut
out.append(CompanyOut(key=c.key, name=c.name, board=host,
subscription_id=sub_id, on=on, affinity=c.affinity,
open_roles=counts.get(c.key, 0), ats=c.ats,
careers_url=c.careers_url, country=c.country))
ats_slug=c.ats_slug, careers_url=c.careers_url,
country=c.country))
return out
class CompanyBoardBody(BaseModel):
board: str
@router.post("/companies/{key}/board")
def set_company_board(key: str, body: CompanyBoardBody, store: StoreDep) -> 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."""
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
return {"source": _one_source(store, sub.id), "found": found, "closed": closed}
@router.delete("/companies/{key}/board")
def detach_company_board(key: str, store: StoreDep) -> dict[str, Any]:
"""Stop reading a company's board: its open roles close, the row stays."""
try:
closed = jobs.sources.detach_board(store, key)
except KeyError:
raise HTTPException(404, f"no such company: {key}") from None
except ValueError as exc:
raise HTTPException(409, str(exc)) from exc
return {"closed": closed}
class AffinityBody(BaseModel):
affinity: int
#: Whose affinity; the default agent when absent.
@@ -370,12 +406,13 @@ def _one_source(store: Store, sub_id: int) -> SourceOut:
@router.get("/sources")
def list_sources(store: StoreDep, config: ConfigDep) -> SourcesOut:
"""Every board, and every search not removed. A board switched off stays
listed, so it can be switched back on."""
"""Every board not detached, and every search not removed. A board
switched off stays listed, so it can be switched back on."""
counts = store.open_countries_by_subscription()
searches = [_source_out(s, counts.get(s.id, {}))
for s in store.subscriptions(source="search") if s.show]
boards = [_source_out(s, counts.get(s.id, {})) for s in store.subscriptions(source="ats")]
boards = [_source_out(s, counts.get(s.id, {}))
for s in store.subscriptions(source="ats") if s.show]
return SourcesOut(searches=searches, boards=boards,
adzuna_key=jobs.sources.has_key(config, "adzuna"))
@@ -454,8 +491,9 @@ class BoardBody(BaseModel):
@router.post("/boards", status_code=201)
def add_board(body: BoardBody, store: StoreDep) -> dict[str, Any]:
"""Follow a company's ATS board. It is fetched first, and refused if it
does not answer or lists nothing."""
"""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."""
try:
sub, found = jobs.sources.add_board(store, body.board, body.name)
except ValueError as exc: