Merge branch 'wp-f-reach'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
ca80219bbb
24 files changed
+1657
-124
No files matched your search
+71
-1
@@ -473,6 +473,10 @@ class CompanyOut(BaseModel):
|
||||
from_search: bool = False
|
||||
hand_reason: str = ""
|
||||
by_hand: bool = False
|
||||
#: The board's own reach in its params (`jobs.reach.OVERRIDE_KEYS`), and
|
||||
#: what a pull asks its board for (`jobs.reach.line`).
|
||||
reach_params: dict[str, Any] = {}
|
||||
reach: str = ""
|
||||
|
||||
|
||||
def _company_boards(store: Store) -> dict[str, tuple[int, str, bool, str]]:
|
||||
@@ -495,10 +499,13 @@ def _company_outs(store: Store, agent: int | None) -> list[CompanyOut]:
|
||||
ever_boarded = {company_key(s.company) for s in store.subscriptions(source="ats")}
|
||||
counts = store.open_role_counts()
|
||||
failing = jobs.pull.failing_boards(store)
|
||||
subs = {s.id: s for s in store.subscriptions(source="ats")}
|
||||
plan = jobs.reach.plan(store, subs.values())
|
||||
out = []
|
||||
for c in store.companies(agent):
|
||||
sub_id, host, on, target = boards.get(c.key, (None, "", None, ""))
|
||||
since, reason = failing.get(target, ("", ""))
|
||||
sub = subs.get(sub_id) if sub_id is not None else None
|
||||
from_search = jobs.sources.known_from_search_only(c, ever_boarded)
|
||||
out.append(CompanyOut(key=c.key, name=c.name, notes=c.notes, board=host,
|
||||
subscription_id=sub_id, on=on, affinity=c.affinity,
|
||||
@@ -508,7 +515,10 @@ def _company_outs(store: Store, agent: int | None) -> list[CompanyOut]:
|
||||
watch=c.watch, careers_opened_at=c.careers_opened_at,
|
||||
failing_since=since, failing_reason=reason,
|
||||
from_search=from_search, hand_reason=c.hand_reason,
|
||||
by_hand=c.key not in boards and not from_search))
|
||||
by_hand=c.key not in boards and not from_search,
|
||||
reach_params={k: v for k, v in (sub.params if sub else {}).items()
|
||||
if k in jobs.reach.OVERRIDE_KEYS},
|
||||
reach=jobs.reach.line(plan, sub) if sub else ""))
|
||||
return out
|
||||
|
||||
|
||||
@@ -803,6 +813,66 @@ def switch_source(sub_id: int, body: SwitchBody, store: StoreDep,
|
||||
return {"source": _one_source(store, sub_id), "closed": closed}
|
||||
|
||||
|
||||
class ReachBody(BaseModel):
|
||||
#: `agents`: the enabled agents' reach; `all`: every role; `own`: the
|
||||
#: `countries` (ISO codes) and remote given here.
|
||||
mode: Literal["agents", "all", "own"]
|
||||
countries: list[str] = []
|
||||
remote: bool = False
|
||||
|
||||
|
||||
@router.post("/sources/{sub_id}/reach")
|
||||
def set_reach(sub_id: int, body: ReachBody, store: StoreDep) -> dict[str, Any]:
|
||||
"""A board's own reach, which wins over the agents' (see
|
||||
`app/jobs/reach.py`), or none. The next pull reads the board so; a
|
||||
narrower reach closes the roles outside it then, except those with a
|
||||
vote or an application."""
|
||||
sub = store.subscription(sub_id)
|
||||
if sub is None or sub.source != "ats":
|
||||
raise HTTPException(404, f"no such board: {sub_id}")
|
||||
codes = sorted({c.strip().upper() for c in body.countries if c.strip()})
|
||||
if unknown := [c for c in codes if not places.known(f"country:{c}") or c == "EU"]:
|
||||
raise HTTPException(422, f"Not a country code: {', '.join(unknown)}.")
|
||||
if body.mode == "own" and not (codes or body.remote):
|
||||
raise HTTPException(422, "Name a country or remote, or read all roles.")
|
||||
params = {k: v for k, v in sub.params.items() if k not in jobs.reach.OVERRIDE_KEYS}
|
||||
if body.mode == "all":
|
||||
params["reach"] = "all"
|
||||
elif body.mode == "own":
|
||||
params |= {"countries": codes, "remote": body.remote}
|
||||
sub = store.update_subscription(sub_id, params=params)
|
||||
return {"source": _one_source(store, sub_id),
|
||||
"reach": jobs.reach.line(jobs.reach.plan(store, [sub]), sub)}
|
||||
|
||||
|
||||
class ReaderOut(BaseModel):
|
||||
"""What a reader declares (`plugins/readers/_contract.py`), for the
|
||||
Sources page: `filters` holds only the dimensions it filters."""
|
||||
|
||||
name: str
|
||||
label: str
|
||||
scope: str
|
||||
listing: str
|
||||
text: str
|
||||
filters: dict[str, str]
|
||||
places: str
|
||||
robots: str
|
||||
|
||||
|
||||
@router.get("/readers")
|
||||
def list_readers() -> list[ReaderOut]:
|
||||
"""Every reader that declares `READS`, boards first, by label."""
|
||||
from plugins import readers
|
||||
|
||||
found = [m for m in readers.READERS.values() if isinstance(getattr(m, "READS", None),
|
||||
readers.Reads)]
|
||||
return [ReaderOut(name=m.NAME, label=m.LABEL, scope=m.READS.scope,
|
||||
listing=m.READS.listing, text=m.READS.text,
|
||||
filters=m.READS.filters.declared(), places=m.READS.places,
|
||||
robots=m.READS.robots)
|
||||
for m in sorted(found, key=lambda m: (m.READS.scope != "board", m.LABEL.lower()))]
|
||||
|
||||
|
||||
class SearchBody(BaseModel):
|
||||
provider: str
|
||||
name: str = ""
|
||||
|
||||
Reference in new issue
Block a user