Companies and Searches: follow, hide not mute, prune moved, one row style

Companies gets a Follow-a-company form, a combined affinity/on-off filter,
and one .srow-style row per company (name, board or "from searches", open
roles, on/off switch, affinity). The prune-by-region tool moves here from
Searches, folded under the list in a <details>. The lede states the
difference between switching a board off (stops reading it, closes its
roles) and hiding a company (keeps reading it, keeps its roles out of the
list and unscored).

affinityControl becomes three icon toggles (favourite, like, hidden) instead
of four letter buttons with a neutral one; pressing the pressed icon clears
back to neutral. "Hidden" is the word everywhere the UI names affinity -1;
the code keeps mute/hide_muted. CompanyOut carries each company's board
subscription id and on-state, so the Companies page needs only
/api/companies, not a second fetch of /api/sources. Setting a company's
affinity now enqueues a score job, deduped by the queue to one run.

Searches keeps only the search form and list, in the same row style;
company boards and the prune tool left with it, and "Pull now" left for
Pulls (package B3).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-25 22:02:28 +02:00
1 parent 7d31cca394
commit 55248555e9
8 files changed
+419 -318

No files matched your search

+34 -8
View File
@@ -18,9 +18,11 @@ from pydantic import BaseModel, Field
from app import jobs
from app.models import (
AFFINITY, Agent, Application, Company, Gate, ScoredRole, Status, Subscription, Weights,
company_key,
)
from app.storage import Store
from app.web.deps import ConfigDep, StoreDep
from pipeline.web import QueueDep
router = APIRouter(prefix="/api", tags=["roledesk"])
@@ -57,23 +59,43 @@ def list_roles(
# --------------------------------------------------------------- companies
class CompanyOut(BaseModel):
"""A company row plus the two things only the store can join in: the ats
host it is read from, and how many of its roles are still open."""
"""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
board's subscription, whether it is on, and how many of its roles are
still open."""
key: str
name: str
board: str
subscription_id: int | None = None
on: bool | None = None
affinity: int
open_roles: int
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."""
boards: dict[str, tuple[int, str, bool]] = {}
for sub in store.subscriptions(source="ats"):
boards.setdefault(company_key(sub.company), (sub.id, sub.board,
bool(sub.subscribed and sub.fetch)))
return boards
@router.get("/companies")
def list_companies(store: StoreDep) -> list[CompanyOut]:
boards = store.company_boards()
boards = _company_boards(store)
counts = store.open_role_counts()
return [CompanyOut(key=c.key, name=c.name, board=boards.get(c.key, ""),
affinity=c.affinity, open_roles=counts.get(c.key, 0))
for c in store.companies()]
out = []
for c in store.companies():
sub_id, host, on = boards.get(c.key, (None, "", None))
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)))
return out
class AffinityBody(BaseModel):
@@ -81,13 +103,17 @@ class AffinityBody(BaseModel):
@router.post("/companies/{key}/affinity")
def set_affinity(key: str, body: AffinityBody, store: StoreDep) -> Company:
def set_affinity(key: str, body: AffinityBody, store: StoreDep, queue: QueueDep) -> Company:
"""A change here is not seen in Best match until `score` has run: the
queue dedupes to a live job of that kind, so several clicks are one run."""
if body.affinity not in AFFINITY:
raise HTTPException(422, "affinity is -1, 0, 1 or 2")
try:
return store.update_company(key, affinity=body.affinity)
company = store.update_company(key, affinity=body.affinity)
except KeyError:
raise HTTPException(404, f"no such company: {key}") from None
queue.enqueue("score")
return company
# ----------------------------------------------------------------- sources