Store a board's reach countries as ISO codes and refuse an empty seniority range
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
4e827665dd
commit
0ebaa852f6
2 files changed
+201
-8
No files matched your search
+30
-8
@@ -98,7 +98,13 @@ def _feed_filters(
|
||||
raise HTTPException(422, f"{name} is one of {', '.join(RUNGS)}, not {rung!r}.")
|
||||
if track and track not in TRACKS:
|
||||
raise HTTPException(422, f"track is one of {', '.join(TRACKS)}, not {track!r}.")
|
||||
levels = levels_between(level_from, level_to, track) if level_from or level_to or track else []
|
||||
levels: tuple[str, ...] = ()
|
||||
if level_from or level_to or track:
|
||||
# The store reads an empty list as "no filter", so a range that holds no
|
||||
# level must be refused here or it would list every role.
|
||||
levels = levels_between(level_from, level_to, track)
|
||||
if not levels:
|
||||
raise HTTPException(422, "That seniority range holds no level.")
|
||||
return {
|
||||
"q": q or None, "company": company or None, "place": place or None,
|
||||
"function": function or None, "remote": remote or None, "days": days,
|
||||
@@ -359,14 +365,21 @@ def _known_role(store: Store, uid: str) -> Role:
|
||||
|
||||
|
||||
@router.post("/roles/{uid}/text")
|
||||
def fetch_text(uid: str, store: StoreDep) -> Role:
|
||||
def fetch_text(uid: str, store: StoreDep, agent: int | None = None) -> ScoredRole:
|
||||
"""Fetch the posting page once and keep it as plain text, for a role whose
|
||||
description is a teaser (`jobs.posting.fetch_posting`); a Jobindex role
|
||||
is read from the page its "Se jobbet" link leads to."""
|
||||
is read from the page its "Se jobbet" link leads to. The role comes back as
|
||||
`agent` sees it, as `GET /api/roles/{uid}` does: the page merges the answer
|
||||
into the open role, and one without the vote would blank the reader's."""
|
||||
agent_id = _agent_id(store, agent)
|
||||
try:
|
||||
return jobs.posting.fetch_posting(store, uid)
|
||||
jobs.posting.fetch_posting(store, uid)
|
||||
except jobs.posting.PostingError as exc:
|
||||
raise HTTPException(exc.status, str(exc)) from exc
|
||||
role = store.role(uid, agent_id)
|
||||
if role is None:
|
||||
raise HTTPException(404, f"no such role: {uid}")
|
||||
return role
|
||||
|
||||
|
||||
@router.post("/roles/{uid}/summarise", status_code=202)
|
||||
@@ -436,12 +449,17 @@ class CompanyOut(BaseModel):
|
||||
with no board shown that is not `from_search`, and `hand_reason` says why
|
||||
it is read by hand (`app.models.HAND_REASONS`). `all_countries` and
|
||||
`all_roles` are the company's two fetch overrides: its big boards read
|
||||
with the agents' wide reach, and with no role-type narrowing."""
|
||||
with the agents' wide reach, and with no role-type narrowing. `target` is
|
||||
the attached board in full, `host:slug`, where `board` is its host alone;
|
||||
the page compares it with the board typed to know whether a replacement
|
||||
closes anything. `ats_slug` cannot stand in for it, since the careers site
|
||||
may run on another host than the board."""
|
||||
|
||||
key: str
|
||||
name: str
|
||||
notes: str = ""
|
||||
board: str
|
||||
target: str = ""
|
||||
subscription_id: int | None = None
|
||||
on: bool | None = None
|
||||
affinity: int
|
||||
@@ -500,6 +518,7 @@ def _company_outs(store: Store, agent: int | None) -> list[CompanyOut]:
|
||||
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,
|
||||
target=target,
|
||||
subscription_id=sub_id, on=on, affinity=c.affinity,
|
||||
open_roles=counts.get(c.key, 0), ats=c.ats,
|
||||
ats_slug=c.ats_slug, careers_url=c.careers_url,
|
||||
@@ -865,9 +884,12 @@ def set_reach(sub_id: int, body: ReachBody, store: StoreDep) -> dict[str, Any]:
|
||||
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)}.")
|
||||
named = sorted({c.strip() for c in body.countries if c.strip()})
|
||||
tokens = {c: places.parse(f"country:{c}") for c in named}
|
||||
if unknown := [c for c, t in tokens.items() if not places.known(str(t)) or t.value == "EU"]:
|
||||
raise HTTPException(422, f"Not a country: {', '.join(unknown)}.")
|
||||
# The ISO code is what the reach compares against, not the name or alias typed.
|
||||
codes = sorted({t.value for t in tokens.values()})
|
||||
if body.mode == "own" and not (codes or body.remote):
|
||||
raise HTTPException(422, "Name a country or remote, or take the agents' reach.")
|
||||
params = {k: v for k, v in sub.params.items() if k not in jobs.reach.OVERRIDE_KEYS}
|
||||
|
||||
Reference in new issue
Block a user