oliver-zehentleitner / maity

hub: claim requests: one confirm path for claim/assign/the request call, one still-valid rule for recheck and sweep, the outside release out of routes

Sign in to report

tsk-wra56ym2syfd Proposed

Audit round 6 (tsk-hgnbapyw7hnh), read at 046a4d3b. Kind: rule built twice / design (domain logic in a route module).

What is wrong

  • The confirmation of a waiting claim request is written three times in routes/tasks.py: claim (:2014-2035), assign (:2552-2577) and _claim_request_call (:2143-2148). Each repeats pending, then is_confirmer / not_a_confirmer / not_the_requester, then begin_nested(), claim_requests.confirm, except Declined: declined.answer(conn). claim_requests.refuse_confirmer (claim_requests.py:740) holds the first step but only one route calls it. hub/context/joins.md:745-746 says the routes hold no rule of their own.
  • claim() runs _require_visible_to_assignee twice with the same arguments on the holder path (routes/tasks.py:2013 and :2042): one redundant read.
  • "Is this request still valid" is decided twice in different orders: claim_requests.recheck (:707-737: taken, gone, instance gone, isolated, not public, not open to outsiders) and sweep (:1221-1240: not public, gone, isolated, instance gone, card unreadable, status not open; no open-to-outsiders check). The same instances.require_active try/except is in both. When two conditions hold at once the decline reason differs by path.
  • release_from_outside (routes/tasks.py:1760-1870) repeats the release route (:2408-2444): the conditional UPDATE values, claim_requests.reset, the task_released event and status_moved. moderation.py:537 imports it from the route module.

Proposal

  • claim_requests.confirm_now(conn, mine, card, waiting, instance, actor) returning the card or the 409 outcome; the three routes call it.
  • One _still_holds(conn, project, member, req) that recheck and sweep both call, in one order.
  • cards.release_claim(...) used by the release route and the outside release; moderation imports it from there.

Effort / risk: M. Medium; savepoint and lock order, and the decline reasons are pinned by test_claim_requests.