oliver-zehentleitner / maity

clean-up: admin and moderation: moderation.py helpers, a dead check, suspension docs

Sign in to report

tsk-cnyz6bb2vhkx Open

From the clean-up audit tsk-hgnbapyw7hnh, Area 8 (Admin and moderation), read at 80647565. Every line number is at that SHA; check it against current main first. Numbers are the audit's finding numbers. Paths are under hub/src/maity_hub/ unless they start with hub/.

This card holds the clean-ups inside moderation.py, plus one docs item about suspensions. All are S.

2. Debt: moderation.check is dead, and the action list is defined twice

  • Files: moderation.py:498-500 (check, which tests against ("dismiss", *HOLDING, "suspend")). Nothing in hub/ or cli/ calls it. reports.resolve checks against its own reports.ACTIONS (reports.py:40, :578).
  • Proposal: delete moderation.check and keep reports.ACTIONS as the only list.
  • Effort S. Risk none.

3. Duplication: moderation view shapes are built twice

  • Files: moderation.py:74 (holds_of) and :82 (view) build the same {action, report_id, at} dict. :150 (suspension_of) and :168 (suspensions) build the same {"reason": "account suspended", "since", "by": None} shape. suspension_of (:141-150) also repeats the suspended_at read that suspended (:110-114) already does.
  • Proposal: have holds_of call view(row), add one _paused(at) helper, and make suspension_of a one-row call of suspensions.
  • Effort S. Risk low: pure refactor, same output.

4. Duplication: moderation.apply invalidates the public pages twice, once per direction

  • Files: moderation.py:438-450 (the dismiss branch, every touch with removal=False) mirrors :466-476 (after an action, same targets: person, project, project_views, card, project without dependents). The only differences are removal and the suspend-only touch_owned.
  • Proposal: one _touch_pages(conn, report, account, *, removal, owned) helper, called from both places.
  • Effort S. Risk low to medium: a missed page touch leaves a stale public page. test_public_people, test_public_projects and test_org_suspension cover this.

5. Duplication: account_of and org_of read the report's author the same way

  • Files: moderation.py:253-256 and :270-272. Both do ((report.snapshot or {}).get("author") or {}).get("id") and fall back to _live_author.
  • Proposal: one _author(conn, report) helper. account_of keeps its profile override.
  • Effort S. Risk low.

11. Docs drift: "a suspension is no hold" is no longer true for organisations

  • Files: hub/context/reports.md:294 ("A suspension is no hold: only the operator's maity-hub account unsuspend lifts it, dismiss does not") and the moderation.py:6 docstring (suspend "stops an account"). In the code, suspend_org (moderation.py:279-314) writes a moderation_hold row with target_type="org", action="suspend" (:302). apply deletes the report's holds first (:437), so dismiss does lift an organisation's suspension (test_org_suspension.py:110). hub/context/orgs.md:295 records this correctly, but reports.md does not point to it.
  • Proposal: reword both places: an account's suspension is no hold; an organisation's is a hold that dismiss lifts (see orgs.md).
  • Effort S. Risk none.

Order

  • tsk-98xq1kme4gd3 (security, open) changes moderation.refuse_held. Items 3 and 4 touch the same module; rebase on it rather than conflict.
  • The suspension at moderation.py:199-200 is also changed by the runner bug card filed with this one (area 9, audit 13). Rebase if both are open at once.

Left out (hub-wide patterns, filed on shared cards by the lead)

  • Audit 6 (agent-to-owner lookup: moderation.owner_account, reports.account_of and about 28 inline copies): the agent-to-owner lookup pattern.
  • Audit 7 (six private _handle helpers, reports._handle among them): the private-_handle pattern.
  • Audit 10 (reports.Worker, one of about 18 copies): the Worker-loop pattern.

Covered elsewhere

  • None of these five. Searched: moderation.check, suspension_of, touch_owned, "suspension is no hold", moderation.py.

Effort: 5S.