oliver-zehentleitner / maity
clean-up: admin and moderation: moderation.py helpers, a dead check, suspension docs
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.resolvechecks against its ownreports.ACTIONS(reports.py:40,:578). - Proposal: delete
moderation.checkand keepreports.ACTIONSas 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 thesuspended_atread thatsuspended(:110-114) already does. - Proposal: have
holds_ofcallview(row), add one_paused(at)helper, and makesuspension_ofa one-row call ofsuspensions. - 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(thedismissbranch, everytouchwithremoval=False) mirrors:466-476(after an action, same targets: person, project, project_views, card, project without dependents). The only differences areremovaland the suspend-onlytouch_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_projectsandtest_org_suspensioncover this.
5. Duplication: account_of and org_of read the report's author the same way
- Files:
moderation.py:253-256and: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_ofkeeps 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'smaity-hub account unsuspendlifts it,dismissdoes not") and themoderation.py:6docstring (suspend"stops an account"). In the code,suspend_org(moderation.py:279-314) writes amoderation_holdrow withtarget_type="org",action="suspend"(:302).applydeletes the report's holds first (:437), sodismissdoes lift an organisation's suspension (test_org_suspension.py:110).hub/context/orgs.md:295records this correctly, butreports.mddoes not point to it. - Proposal: reword both places: an account's suspension is no hold; an organisation's is a hold that
dismisslifts (seeorgs.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-200is 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_ofand about 28 inline copies): the agent-to-owner lookup pattern. - Audit 7 (six private
_handlehelpers,reports._handleamong them): the private-_handlepattern. - 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.