Tag a company All roles to read its big boards with the agents' wide reach; favourite scores only
Migration 21 adds companies.all_roles, tags every favourite of any agent and each company whose board had params {"reach": "all"} (logged per board, the param removed). reach.plan reads a tagged company's boards with the union of the enabled agents' require reach and the base reach; favourite no longer widens the fetch. POST /api/companies/{key}/all-roles sets it and queues a pull when on. The Companies list, the reader and the company strip draw the toggle beside the affinity buttons, the list filters on it, and the board's reach editor drops its All roles option.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8d9a059e24
commit
5d5b7e7d3f
20 files changed
+422
-124
No files matched your search
+50
-46
@@ -10,21 +10,23 @@ on. Computed once per pull (`plan`) and handed to each board's batch as the
|
||||
function, a remote value other than `remote`, a place the gazetteer does
|
||||
not know), can take a role from anywhere, so the base reach is then
|
||||
everywhere.
|
||||
- **Favourite companies** (affinity 2, which skips the `any` gates in
|
||||
scoring) are read with the `require` reach of the agent that starred them:
|
||||
the intersection of its `require` gates on country and place, Europe
|
||||
today, expanded to its countries through the gazetteer. A company is
|
||||
starred per agent, so its reach is the union over the enabled agents of
|
||||
the `require` reach where it is a favourite and the `any` reach where not.
|
||||
- **Wide reach, for the companies tagged All roles** (`companies.all_roles`,
|
||||
global): the union over the enabled agents of their `require` reach, the
|
||||
intersection of each one's `require` gates on country and place, Europe
|
||||
today, expanded to its countries through the gazetteer, and the base
|
||||
reach, so a tag never reads less than the board would untagged. An agent
|
||||
with no `require` gate on place makes it everywhere. A role in Freiburg
|
||||
may be open to remote, or worth asking the company about for Denmark.
|
||||
Favourite (affinity 2) is scoring only, where it skips the `any` gates; it
|
||||
does not widen what is fetched.
|
||||
- **Board override**: a board whose subscription `params` name a country, a
|
||||
place, remote or `{"reach": "all"}` gets no reach here; `ask_for` reads the
|
||||
params instead.
|
||||
place or remote gets no reach here; `ask_for` reads the params instead.
|
||||
- **Small boards**: a board that listed under `SMALL` roles when last read
|
||||
whole gets no filter; filtering it saves little and risks closing roles.
|
||||
|
||||
A reach of more countries than a `one`-filter host should be asked one by
|
||||
one (a favourite's Europe on SmartRecruiters) is dropped by `ask_for`, which
|
||||
knows the reader (`MAX_SERIES`).
|
||||
one (the wide reach's Europe on SmartRecruiters) is dropped by `ask_for`,
|
||||
which knows the reader (`MAX_SERIES`), so such a board is read whole.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -48,7 +50,9 @@ SMALL = 300
|
||||
SIZE = "ats:size:"
|
||||
|
||||
#: The params that make a board's own reach (see `_runner._PARAM_DIMENSION`).
|
||||
OVERRIDE_KEYS = frozenset(("countries", "country", "places", "place", "remote", "reach"))
|
||||
OVERRIDE_KEYS = frozenset(("countries", "country", "places", "place", "remote"))
|
||||
|
||||
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -160,16 +164,19 @@ def require_reach(agent: Agent, gaz: places.Gazetteer) -> Reach:
|
||||
|
||||
@dataclass
|
||||
class Plan:
|
||||
"""The reach of one pull: `base` for every board, `favourites` for the
|
||||
companies some agent starred, and each board's size by target."""
|
||||
"""The reach of one pull: `base` for every board, `wide` for the boards
|
||||
of the companies in `tagged` (tagged All roles), and each board's size
|
||||
by target."""
|
||||
|
||||
base: Reach
|
||||
favourites: dict[str, Reach] = field(default_factory=dict)
|
||||
wide: Reach = EVERYWHERE
|
||||
sizes: dict[str, int] = field(default_factory=dict)
|
||||
tagged: frozenset[str] = frozenset()
|
||||
|
||||
def why(self, sub: Subscription) -> tuple[Reach, str]:
|
||||
"""The reach `sub` is read with, and why: `override`, `small`,
|
||||
`unknown` (a board never read whole), `favourite` or `agents`."""
|
||||
`unknown` (a board never read whole), `tag` (its company is tagged
|
||||
All roles) or `agents`."""
|
||||
if OVERRIDE_KEYS & set(sub.params or {}):
|
||||
return EVERYWHERE, "override"
|
||||
size = self.sizes.get(sub.target)
|
||||
@@ -177,9 +184,8 @@ class Plan:
|
||||
return EVERYWHERE, "unknown"
|
||||
if size < SMALL:
|
||||
return EVERYWHERE, "small"
|
||||
key = company_key(sub.company or sub.label)
|
||||
if key in self.favourites:
|
||||
return self.favourites[key], "favourite"
|
||||
if company_key(sub.company or sub.label) in self.tagged:
|
||||
return self.wide, "tag"
|
||||
return self.base, "agents"
|
||||
|
||||
def for_subscription(self, sub: Subscription) -> dict[str, Any] | None:
|
||||
@@ -204,29 +210,22 @@ def sizes(store: Store, subs: Iterable[Subscription]) -> dict[str, int]:
|
||||
|
||||
|
||||
def plan(store: Store, subs: Iterable[Subscription] | None = None) -> Plan:
|
||||
"""The reach of a pull, from the enabled agents and their favourites, and
|
||||
the sizes of `subs` (every `ats` subscription when None)."""
|
||||
"""The reach of a pull, from the enabled agents and the companies tagged
|
||||
All roles, and the sizes of `subs` (every `ats` subscription when
|
||||
None)."""
|
||||
gaz = store.gazetteer()
|
||||
agents = store.agents(enabled_only=True)
|
||||
reaches = {a.id: (any_reach(a, gaz), require_reach(a, gaz)) for a in agents}
|
||||
base = NOWHERE
|
||||
for any_of, _ in reaches.values():
|
||||
base = base | any_of
|
||||
if not agents:
|
||||
base = EVERYWHERE
|
||||
starred: dict[str, set[int]] = {}
|
||||
base = wide = NOWHERE
|
||||
for agent in agents:
|
||||
for company in store.companies(agent.id):
|
||||
if company.affinity == 2:
|
||||
starred.setdefault(company.key, set()).add(agent.id)
|
||||
favourites: dict[str, Reach] = {}
|
||||
for key, by in starred.items():
|
||||
reach = NOWHERE
|
||||
for agent_id, (any_of, required) in reaches.items():
|
||||
reach = reach | (required if agent_id in by else any_of)
|
||||
favourites[key] = reach
|
||||
base = base | any_reach(agent, gaz)
|
||||
wide = wide | require_reach(agent, gaz)
|
||||
if not agents:
|
||||
base = wide = EVERYWHERE
|
||||
subs = list(store.subscriptions(source="ats") if subs is None else subs)
|
||||
return Plan(base, favourites, sizes(store, subs))
|
||||
tagged = frozenset(c.key for c in store.companies() if c.all_roles)
|
||||
# A tag never reads less than the board would untagged: the base's
|
||||
# remote, which a `require` of Europe does not name, is kept.
|
||||
return Plan(base, wide | base, sizes(store, subs), tagged)
|
||||
|
||||
|
||||
def reaches(store: Store, subs: Iterable[Subscription]) -> Mapping[str, dict[str, Any]]:
|
||||
@@ -239,14 +238,18 @@ def reaches(store: Store, subs: Iterable[Subscription]) -> Mapping[str, dict[str
|
||||
|
||||
#: Why a board is read whole, as the Companies list says it.
|
||||
_WHOLE = {"small": f"under {SMALL} roles", "unknown": "not read whole yet",
|
||||
"override": "set here", "favourite": "favourite, too many countries to ask",
|
||||
"override": "set here", "tag": "company tag, too many countries to ask",
|
||||
"agents": "an agent takes any place"}
|
||||
|
||||
#: Why a board is read filtered, as the Companies list says it.
|
||||
_SAID = {"override": "set here", "tag": "company tag"}
|
||||
|
||||
|
||||
def line(found: Plan, sub: Subscription) -> str:
|
||||
"""What a pull asks `sub`'s board for, once its reader has narrowed the
|
||||
reach, in a few words: "DK, SE, remote · agents", "all roles · under 300
|
||||
roles", "all roles · Greenhouse cannot filter"."""
|
||||
reach, in a few words: "DK, SE, remote · agents", "33 countries, remote ·
|
||||
company tag", "all roles · under 300 roles", "all roles · Greenhouse
|
||||
cannot filter"."""
|
||||
module = readers.HOSTS.get(sub.target.partition(":")[0])
|
||||
if module is None:
|
||||
return ""
|
||||
@@ -257,10 +260,11 @@ def line(found: Plan, sub: Subscription) -> str:
|
||||
else [f"{len(ask.countries)} countries"]
|
||||
if ask.remote:
|
||||
words.append("remote")
|
||||
return f"{', '.join(words)} · {'set here' if why == 'override' else why}"
|
||||
if why in ("agents", "favourite") and not given.everywhere:
|
||||
if not module.READS.filters.declared():
|
||||
return f"all roles · {module.LABEL} cannot filter"
|
||||
if why == "agents":
|
||||
return f"all roles · {module.LABEL} cannot ask for these"
|
||||
return f"{', '.join(words)} · {_SAID.get(why, why)}"
|
||||
if why in ("agents", "tag") and given.everywhere:
|
||||
return f"all roles · {'company tag' if why == 'tag' else _WHOLE[why]}"
|
||||
if why in ("agents", "tag") and not module.READS.filters.declared():
|
||||
return f"all roles · {module.LABEL} cannot filter"
|
||||
if why == "agents":
|
||||
return f"all roles · {module.LABEL} cannot ask for these"
|
||||
return f"all roles · {_WHOLE[why]}"
|
||||
@@ -984,6 +984,10 @@ class Company(Model):
|
||||
#: Why the company is read by hand, one of `HAND_REASONS`; "" when it is
|
||||
#: not on that list.
|
||||
hand_reason: str = ""
|
||||
#: 1 when every board of the company is read with the agents' wide reach,
|
||||
#: Europe today, rather than their places (`app/jobs/reach.py`). Global,
|
||||
#: not an agent's: it is about what is fetched, and fetching is shared.
|
||||
all_roles: int = 0
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
|
||||
@@ -1113,6 +1113,11 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
|
||||
.affinity button[data-value="-1"][aria-pressed="true"] {
|
||||
color: var(--accent-fg); background: var(--error); border-color: var(--error);
|
||||
}
|
||||
/* The All roles tag, global and apart from the stances: green, the colour
|
||||
the app gives what widens (`--good`). */
|
||||
.affinity button[data-value="all"][aria-pressed="true"] {
|
||||
color: var(--accent-fg); background: var(--good); border-color: var(--good);
|
||||
}
|
||||
|
||||
/* agents */
|
||||
|
||||
@@ -1302,6 +1307,8 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
|
||||
font-size: .96rem; text-decoration: none; color: inherit;
|
||||
}
|
||||
.crow .name { font-weight: 600; }
|
||||
/* A company row has one control more: the All roles tag after the stances. */
|
||||
#companies-list .crow { grid-template-columns: 1fr auto auto auto; }
|
||||
/* Only a name that is a link: the Watchlist draws one without a page to
|
||||
open as text, which must not look as if it led somewhere. */
|
||||
@media (hover: hover) {
|
||||
|
||||
+50
-1
@@ -16,7 +16,8 @@
|
||||
* Beside `api` on `window`, the few helpers more than one page script uses:
|
||||
* `count`, `cell`, `debounce`, `safeUrl`, and the company list with its
|
||||
* affinity control (`loadCompanies`, `companies`, `affinityControl`,
|
||||
* `setAffinity`). One copy each, since two copies of a helper is one of them
|
||||
* `setAffinity`) and the All roles tag beside it (`allRolesControl`). One
|
||||
* copy each, since two copies of a helper is one of them
|
||||
* being fixed.
|
||||
*
|
||||
* Affinity is per search agent. The three company helpers take the agent's
|
||||
@@ -183,7 +184,55 @@
|
||||
if (onChange) await onChange(updated);
|
||||
}
|
||||
|
||||
/* The All roles tag, one more toggle in the affinity buttons' fragment
|
||||
beside them, in a group of its own since it is global rather than an
|
||||
agent's stance: every board of the company is read with the agents'
|
||||
wide reach, Europe today, rather than their places (app/jobs/reach.py). On queues a pull on the server, as the other
|
||||
reopening switches do; off asks nothing, since no role closes until the
|
||||
next pull reads the board with its filter again. `onChange` runs after
|
||||
the server accepted it, with the company it answered. */
|
||||
function allRolesControl(companyKey, current, onChange) {
|
||||
const span = document.createElement("span");
|
||||
span.className = "affinity";
|
||||
span.setAttribute("role", "group");
|
||||
span.setAttribute("aria-label", "Company tag");
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.dataset.value = "all";
|
||||
button.textContent = "All";
|
||||
button.title = current
|
||||
? "All roles within the agents' wide reach (Europe), not only their places. Turning it "
|
||||
+ "off asks nothing first: no role closes until the next pull reads the board again."
|
||||
: "All roles: read this company's boards for all roles within the agents' wide reach "
|
||||
+ "(Europe), not only their places. Turning it on queues a pull.";
|
||||
button.setAttribute("aria-label", "All roles");
|
||||
button.setAttribute("aria-pressed", String(Boolean(current)));
|
||||
button.addEventListener("click", () => setAllRoles(companyKey, !current, onChange));
|
||||
span.appendChild(button);
|
||||
return span;
|
||||
}
|
||||
|
||||
async function setAllRoles(companyKey, on, onChange) {
|
||||
if (!companyKey) return;
|
||||
let updated;
|
||||
try {
|
||||
updated = await api(`/api/companies/${encodeURIComponent(companyKey)}/all-roles`, {
|
||||
method: "POST", body: { on },
|
||||
});
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
const company = companies.get(companyKey);
|
||||
if (company) company.all_roles = Boolean(updated.all_roles);
|
||||
window.toast.info(on
|
||||
? `${updated.name}: all roles within the agents' wide reach. `
|
||||
+ "Reading now, or with the pull right after."
|
||||
: `${updated.name}: back to its reach from the next pull.`);
|
||||
if (onChange) await onChange(updated);
|
||||
}
|
||||
|
||||
Object.assign(window, {
|
||||
api, count, cell, debounce, safeUrl, companies, loadCompanies, affinityControl, setAffinity,
|
||||
allRolesControl,
|
||||
});
|
||||
})();
|
||||
+26
-10
@@ -4,7 +4,9 @@
|
||||
* The list is app.js's shared company list (`/api/companies`), already
|
||||
* joined with each company's board subscription — its id and whether it is
|
||||
* on — so nothing here fetches `/api/sources` as well. The affinity buttons
|
||||
* are `affinityControl`, the same ones the Roles tab and the read page draw.
|
||||
* are `affinityControl`, the same ones the Roles tab and the read page draw,
|
||||
* and beside them `allRolesControl`, the All roles tag, which is global and
|
||||
* drawn with or without an agent.
|
||||
*
|
||||
* Liked and hidden are per search agent, so the `#c-agent` select above the
|
||||
* list says whose the list shows and whose the buttons set. It opens on the
|
||||
@@ -20,13 +22,17 @@
|
||||
*
|
||||
* A row with a board says what a pull asks it for ("reads DK, SE · agents",
|
||||
* `reach` from app/jobs/reach.py), and its editor has a second line that
|
||||
* sets the board's own reach: the agents', all roles, or its own countries
|
||||
* and remote, posted to `/api/sources/{id}/reach`.
|
||||
* sets the board's own reach: the agents', or its own countries and remote,
|
||||
* posted to `/api/sources/{id}/reach`. All roles within the agents' wide
|
||||
* reach (Europe) is the company's All roles tag instead, which the board's
|
||||
* own countries win over.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const { api, count, debounce, safeUrl, companies, loadCompanies, affinityControl } = window;
|
||||
const {
|
||||
api, count, debounce, safeUrl, companies, loadCompanies, affinityControl, allRolesControl,
|
||||
} = window;
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
|
||||
/** @type {object[]} the search agents, by id */
|
||||
@@ -205,8 +211,9 @@
|
||||
return form;
|
||||
}
|
||||
|
||||
/** The open row's reach editor, for a row with a board: the agents' reach,
|
||||
all roles, or the board's own countries and remote. */
|
||||
/** The open row's reach editor, for a row with a board: the agents' reach
|
||||
or the board's own countries and remote. The wide reach is the
|
||||
company's All roles tag, which the editor points to. */
|
||||
function reachEditor(company, rerender) {
|
||||
if (company.subscription_id == null) return null;
|
||||
const own = company.reach_params || {};
|
||||
@@ -215,11 +222,10 @@
|
||||
form.autocomplete = "off";
|
||||
const mode = document.createElement("select");
|
||||
mode.setAttribute("aria-label", `What ${company.name}'s board is asked for`);
|
||||
for (const [value, label] of [["agents", "Agents' reach"], ["all", "All roles"],
|
||||
["own", "These countries"]]) {
|
||||
for (const [value, label] of [["agents", "Agents' reach"], ["own", "These countries"]]) {
|
||||
mode.appendChild(new Option(label, value));
|
||||
}
|
||||
mode.value = own.reach === "all" ? "all" : (own.countries || own.remote != null ? "own" : "agents");
|
||||
mode.value = own.countries || own.remote != null ? "own" : "agents";
|
||||
const codes = document.createElement("input");
|
||||
codes.type = "text";
|
||||
codes.spellcheck = false;
|
||||
@@ -236,7 +242,12 @@
|
||||
const shown = () => { codes.hidden = remote.hidden = mode.value !== "own"; };
|
||||
mode.addEventListener("change", shown);
|
||||
shown();
|
||||
form.append(mode, codes, remote, save);
|
||||
const note = document.createElement("span");
|
||||
note.className = "muted small";
|
||||
note.textContent = company.all_roles
|
||||
? "The All roles tag is on; a reach set here wins over it."
|
||||
: "All roles within the agents' wide reach (Europe): the All tag beside the stars.";
|
||||
form.append(mode, codes, remote, save, note);
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
save.disabled = true;
|
||||
@@ -298,6 +309,7 @@
|
||||
case "favourite": return company.affinity === 2;
|
||||
case "liked": return company.affinity === 1;
|
||||
case "hidden": return company.affinity === -1;
|
||||
case "all_roles": return company.all_roles === true;
|
||||
case "on": return company.on === true;
|
||||
case "off": return company.on === false;
|
||||
case "unreadable": return company.subscription_id == null && !company.from_search;
|
||||
@@ -331,6 +343,10 @@
|
||||
if (agent != null) {
|
||||
row.appendChild(affinityControl(company.key, company.affinity, async () => render(), agent));
|
||||
}
|
||||
row.appendChild(allRolesControl(company.key, company.all_roles, async () => {
|
||||
await loadCompanies(agentId());
|
||||
render();
|
||||
}));
|
||||
row.appendChild(subLine(company, render));
|
||||
if (editing === company.key) {
|
||||
row.appendChild(boardEditor(company, render));
|
||||
|
||||
+18
-9
@@ -81,8 +81,8 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const { api, esc, debounce, safeUrl, companies, loadCompanies, affinityControl, judgeButtons,
|
||||
loadTracked, chipInput } = window;
|
||||
const { api, esc, debounce, safeUrl, companies, loadCompanies, affinityControl, allRolesControl,
|
||||
judgeButtons, loadTracked, chipInput } = window;
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
|
||||
// Below this the rail is over the feed rather than beside it, and the reader
|
||||
@@ -1071,15 +1071,19 @@
|
||||
el.querySelector(".strip-drop").onclick = dropCompany;
|
||||
}
|
||||
const slot = el.querySelector(".affinity-slot");
|
||||
if (slot.dataset.affinity !== String(affinity)) {
|
||||
slot.dataset.affinity = String(affinity);
|
||||
const drawn = `${affinity}:${company ? company.all_roles : ""}`;
|
||||
if (slot.dataset.affinity !== drawn) {
|
||||
slot.dataset.affinity = drawn;
|
||||
slot.replaceChildren(affinityControl(key, affinity,
|
||||
(updated) => affinityChanged(key, company, updated), state.filter.agent));
|
||||
// The All roles tag needs a company row, which a first stance makes.
|
||||
if (company) slot.append(" ", allRolesControl(key, company.all_roles, renderStrip));
|
||||
// What ★ does, before; what it did, after.
|
||||
el.querySelector(".strip-note").textContent = affinity === 2
|
||||
? "★ Favourite: roles from every place the agent's required gates allow are listed."
|
||||
? "★ Favourite: roles from every place the agent's required gates allow are listed. "
|
||||
+ "All fetches them from a big board."
|
||||
: "★ Favourite also lists this company's roles outside your places, as far as the "
|
||||
+ "agent's required gates allow.";
|
||||
+ "agent's required gates allow. All fetches them from a big board.";
|
||||
}
|
||||
const n = state.total;
|
||||
el.querySelector(".strip-count").textContent = state.loaded
|
||||
@@ -1358,9 +1362,10 @@
|
||||
}
|
||||
|
||||
/* The company's ★ ▲ ⊘, the one place a company is judged outside the
|
||||
Companies page. A company seen only through a search has no row until
|
||||
its first change creates one, so the list is reloaded then. A change
|
||||
dims or undims its rows in the feed. */
|
||||
Companies page, and its All roles tag beside them. A company seen only
|
||||
through a search has no row until its first change creates one, so the
|
||||
list is reloaded then, and the tag, which needs a row, waits for it. A
|
||||
change dims or undims its rows in the feed. */
|
||||
function renderAffinity(slot, r) {
|
||||
const company = companies.get(r.company_key);
|
||||
if (!r.company_key) { slot.replaceChildren(); return; }
|
||||
@@ -1369,6 +1374,10 @@
|
||||
renderAffinity(slot, r);
|
||||
renderFeed();
|
||||
}, state.filter.agent));
|
||||
if (company) {
|
||||
slot.append(" ", allRolesControl(r.company_key, company.all_roles,
|
||||
async () => renderAffinity(slot, r)));
|
||||
}
|
||||
}
|
||||
|
||||
/* The answer, into the role on screen and into its row, whose excerpt is
|
||||
|
||||
+45
-3
@@ -18,7 +18,7 @@ import sqlite3
|
||||
from collections.abc import Callable
|
||||
|
||||
from app import places
|
||||
from app.models import SENIORITIES, company_fold, country_of, posted_at, posted_host
|
||||
from app.models import SENIORITIES, company_fold, company_key, country_of, posted_at, posted_host
|
||||
from app.seniority import from_title
|
||||
from app.storage import gazetteer
|
||||
|
||||
@@ -182,7 +182,9 @@ CREATE TABLE IF NOT EXISTS role_tags (
|
||||
-- worth checking by hand, 0 not; careers_opened_at when its careers page was
|
||||
-- last opened from there, which is also when a person last looked at it.
|
||||
-- hand_reason is why a person reads the careers page (models.HAND_REASONS),
|
||||
-- '' when nobody has to.
|
||||
-- '' when nobody has to. all_roles 1 reads every board of the company with
|
||||
-- the agents' wide reach, Europe today (app/jobs/reach.py); global, since
|
||||
-- fetching is shared.
|
||||
CREATE TABLE IF NOT EXISTS companies (
|
||||
key TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
@@ -206,7 +208,8 @@ CREATE TABLE IF NOT EXISTS companies (
|
||||
last_funding INTEGER,
|
||||
last_funding_currency TEXT NOT NULL DEFAULT '',
|
||||
facts_source TEXT NOT NULL DEFAULT '',
|
||||
facts_at TEXT NOT NULL DEFAULT ''
|
||||
facts_at TEXT NOT NULL DEFAULT '',
|
||||
all_roles INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
-- Every folded spelling of a company (models.company_fold): orsted is Ørsted
|
||||
@@ -559,6 +562,11 @@ ALTER TABLE companies ADD COLUMN hand_reason TEXT NOT NULL DEFAULT '';
|
||||
# A Python step: the seed folds every name.
|
||||
(20, "company_aliases and the empty enrichment columns of companies",
|
||||
lambda conn: _add_company_aliases(conn)),
|
||||
# A Python step: params is JSON, the company is found by company_key and
|
||||
# each board that read everywhere is logged.
|
||||
(21, "companies.all_roles: a company tag that reads its boards with the agents' wide "
|
||||
"reach, given to every favourite and taking over a board's {\"reach\": \"all\"}",
|
||||
lambda conn: _add_all_roles(conn)),
|
||||
)
|
||||
|
||||
#: What a file created from `SCHEMA` today is already at.
|
||||
@@ -791,6 +799,40 @@ def _add_company_aliases(conn: sqlite3.Connection) -> None:
|
||||
log.info("migration 20: %d companies folded, %d folds shared", len(rows), len(clashes))
|
||||
|
||||
|
||||
def _add_all_roles(conn: sqlite3.Connection) -> None:
|
||||
"""Migration 21's step. The column; the tag for every company that is a
|
||||
favourite of any agent, since favourite no longer widens what a pull
|
||||
fetches and the tag does, so nothing read today is lost; and the tag for
|
||||
each company whose board's `params` held `{"reach": "all"}`, which the
|
||||
step removes from them. Such a board read everywhere and reads the wide
|
||||
reach from now on, so each is logged. Runs twice without harm."""
|
||||
columns = {r[1] for r in conn.execute("PRAGMA table_info(companies)")}
|
||||
if "all_roles" not in columns:
|
||||
conn.execute("ALTER TABLE companies ADD COLUMN all_roles INTEGER NOT NULL DEFAULT 0")
|
||||
starred = conn.execute(
|
||||
"UPDATE companies SET all_roles=1 WHERE all_roles=0 AND key IN "
|
||||
"(SELECT company_key FROM agent_companies WHERE affinity=2)").rowcount
|
||||
log.info("migration 21: %d favourite companies tagged All roles", starred)
|
||||
for sub_id, target, company, label, raw in conn.execute(
|
||||
"SELECT id, target, company, label, params FROM subscriptions "
|
||||
"WHERE source = 'ats'").fetchall():
|
||||
try:
|
||||
params = json.loads(raw or "{}")
|
||||
except ValueError:
|
||||
continue
|
||||
if not isinstance(params, dict) or params.get("reach") != "all":
|
||||
continue
|
||||
del params["reach"]
|
||||
conn.execute("UPDATE subscriptions SET params=? WHERE id=?", (json.dumps(params), sub_id))
|
||||
key = company_key(company or label)
|
||||
if conn.execute("UPDATE companies SET all_roles=1 WHERE key=?", (key,)).rowcount:
|
||||
log.warning("migration 21: %s read all roles everywhere; %r is tagged All roles, "
|
||||
"which reads the agents' wide reach", target, key)
|
||||
else:
|
||||
log.warning("migration 21: %s read all roles everywhere, but %r has no company row "
|
||||
"to tag; it reads the agents' reach now", target, key)
|
||||
|
||||
|
||||
def user_version(conn: sqlite3.Connection) -> int:
|
||||
return int(conn.execute("PRAGMA user_version").fetchone()[0])
|
||||
|
||||
|
||||
+13
-3
@@ -116,7 +116,7 @@ _EXCERPT_RAW = 240
|
||||
_COMPANY_FIELDS = ("name", "domain", "status", "careers_url", "notes", "ats", "country", "city",
|
||||
"ats_slug", "watch", "careers_opened_at", "hand_reason", "sector", "stage",
|
||||
"size_band", "founded", "last_funding", "last_funding_currency",
|
||||
"facts_source", "facts_at")
|
||||
"facts_source", "facts_at", "all_roles")
|
||||
|
||||
#: A company as the store serves it: the row and the asked-for agent's affinity.
|
||||
_COMPANY_SELECT = """SELECT c.*, COALESCE(ac.affinity, 0) AS affinity FROM companies c
|
||||
@@ -1835,6 +1835,13 @@ class Store:
|
||||
self._alias(conn, key, fields["name"])
|
||||
return self._company(key)
|
||||
|
||||
def set_all_roles(self, key: str, on: bool) -> Company:
|
||||
"""Tag a company All roles, or untag it: its boards are read with the
|
||||
agents' wide reach, Europe today, from the next pull
|
||||
(`app/jobs/reach.py`). Global, not per agent. Raises KeyError for an
|
||||
unknown company."""
|
||||
return self.update_company(key, all_roles=int(bool(on)))
|
||||
|
||||
def remove_company(self, key: str) -> bool:
|
||||
"""Delete the row and every agent's stance on it, in one transaction:
|
||||
`agent_companies` holds the key with no foreign key to hold it back, so
|
||||
@@ -1891,8 +1898,8 @@ class Store:
|
||||
def merge_companies(self, keep: str, other: str) -> Company:
|
||||
"""Fold company `other` into `keep`, in one transaction: its roles and
|
||||
subscriptions move to `keep`, each agent's stance moves unless the
|
||||
agent has one on `keep` already, its aliases and its name become
|
||||
aliases of `keep`, and its row goes. Copies are not recomputed
|
||||
agent has one on `keep` already, an All roles tag carries over, its
|
||||
aliases and its name become aliases of `keep`, and its row goes. Copies are not recomputed
|
||||
(`rebuild_dupes`). Raises KeyError for an unknown company and
|
||||
ValueError for merging one into itself."""
|
||||
if keep == other:
|
||||
@@ -1915,6 +1922,9 @@ class Store:
|
||||
(keep, other))
|
||||
conn.execute("DELETE FROM company_aliases WHERE company_key=?", (other,))
|
||||
self._alias(conn, keep, rows[other])
|
||||
conn.execute("UPDATE companies SET all_roles = MAX(all_roles, "
|
||||
"(SELECT all_roles FROM companies WHERE key=?)) WHERE key=?",
|
||||
(other, keep))
|
||||
conn.execute("DELETE FROM companies WHERE key=?", (other,))
|
||||
return self._company(keep)
|
||||
|
||||
|
||||
@@ -106,6 +106,7 @@
|
||||
<option value="favourite">Favourite</option>
|
||||
<option value="liked">Liked</option>
|
||||
<option value="hidden">Hidden</option>
|
||||
<option value="all_roles">All roles</option>
|
||||
<option value="on">On</option>
|
||||
<option value="off">Off</option>
|
||||
<option value="unreadable">Not readable yet</option>
|
||||
|
||||
+33
-9
@@ -450,7 +450,8 @@ class CompanyOut(BaseModel):
|
||||
`careers_opened_at` are the Watchlist's (`Company`'s), the latter also
|
||||
when a person last looked at the careers page. `by_hand` marks a company
|
||||
with no board shown that is not `from_search`, and `hand_reason` says why
|
||||
it is read by hand (`app.models.HAND_REASONS`)."""
|
||||
it is read by hand (`app.models.HAND_REASONS`). `all_roles` is the
|
||||
company tag that reads its boards with the agents' wide reach."""
|
||||
|
||||
key: str
|
||||
name: str
|
||||
@@ -473,6 +474,7 @@ class CompanyOut(BaseModel):
|
||||
from_search: bool = False
|
||||
hand_reason: str = ""
|
||||
by_hand: bool = False
|
||||
all_roles: 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] = {}
|
||||
@@ -516,6 +518,7 @@ def _company_outs(store: Store, agent: int | None) -> list[CompanyOut]:
|
||||
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,
|
||||
all_roles=bool(c.all_roles),
|
||||
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 ""))
|
||||
@@ -712,6 +715,27 @@ def set_watch(key: str, body: WatchBody, store: StoreDep) -> Company:
|
||||
raise HTTPException(404, f"no such company: {key}") from None
|
||||
|
||||
|
||||
class AllRolesBody(BaseModel):
|
||||
on: bool
|
||||
|
||||
|
||||
@router.post("/companies/{key}/all-roles")
|
||||
def set_all_roles(key: str, body: AllRolesBody, store: StoreDep, queue: QueueDep) -> Company:
|
||||
"""Tag a company All roles, or untag it: global, apart from affinity.
|
||||
Its big boards are then read with the agents' wide reach, Europe today,
|
||||
rather than their places (`app/jobs/reach.py`).
|
||||
On queues a pull right after, as the other reopening switches do; off
|
||||
queues nothing and asks nothing first, since no role closes until the
|
||||
next pull reads the board with its filter again. 404 for an unknown key."""
|
||||
try:
|
||||
company = store.set_all_roles(key, body.on)
|
||||
except KeyError:
|
||||
raise HTTPException(404, f"no such company: {key}") from None
|
||||
if body.on:
|
||||
queue.enqueue("pull")
|
||||
return company
|
||||
|
||||
|
||||
class CareersBody(BaseModel):
|
||||
careers_url: str
|
||||
|
||||
@@ -814,9 +838,10 @@ def switch_source(sub_id: int, body: SwitchBody, store: StoreDep,
|
||||
|
||||
|
||||
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"]
|
||||
#: `agents`: the enabled agents' reach; `own`: the `countries` (ISO
|
||||
#: codes) and remote given here. Every role is the company's All roles
|
||||
#: tag (`/api/companies/{key}/all-roles`), not a board's reach.
|
||||
mode: Literal["agents", "own"]
|
||||
countries: list[str] = []
|
||||
remote: bool = False
|
||||
|
||||
@@ -826,7 +851,8 @@ 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."""
|
||||
vote or an application. A company tagged All roles reads every role
|
||||
whatever its board's reach says."""
|
||||
sub = store.subscription(sub_id)
|
||||
if sub is None or sub.source != "ats":
|
||||
raise HTTPException(404, f"no such board: {sub_id}")
|
||||
@@ -834,11 +860,9 @@ def set_reach(sub_id: int, body: ReachBody, store: StoreDep) -> dict[str, Any]:
|
||||
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.")
|
||||
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}
|
||||
if body.mode == "all":
|
||||
params["reach"] = "all"
|
||||
elif body.mode == "own":
|
||||
if body.mode == "own":
|
||||
params |= {"countries": codes, "remote": body.remote}
|
||||
sub = store.update_subscription(sub_id, params=params)
|
||||
return {"source": _one_source(store, sub_id),
|
||||
|
||||
Reference in new issue
Block a user