oliver-zehentleitner / maity
clean-up: G4 members, projects, joins: one helper each for the owner prelude, namespace-owner check, org-then-project lock, area paths and open joins
tsk-12ar0qkfg95p Open
From the clean-up audit tsk-hgnbapyw7hnh (uncovered files, G4 Members, projects, joins and briefing), read at 9dfd4b65. Line numbers are at that SHA. Paths are under hub/src/maity_hub/.
Rules and preludes written more than once in routes/members.py, routes/projects.py and routes/joins.py.
1. Duplication: the "agent's owner, member of the project or not" prelude
- Kind: duplication.
- Files: routes/members.py
_owner_lifts_line_pause:886-903,_owner_sets_role:930-945,_owner_sets_reports_to:989-1003,_subagents:1136-1151,list_briefings:436-448; routes/briefing_view.pyread_briefing:242-257 with_caller_membership:64-68; routes/projects.py_reader:741-748. Each writesnamespace.resolve,try: member_row ... except ApiError,instances.owns_agent,try: membership(...) except ApiError: None. - Also:
Change(project, line.owner_actor(caller, reader.id if reader else None), caller.principal_id, caller.principal_id, caller.credential_id, caller.via)twice (members.py:906-913, :1020-1027), and thejoin_ruleApiError twice (members.py:939-941, :1131-1133). - Proposal:
instances.owner_target(conn, caller, slug, member_id) -> (project, target, reader | None)andaccess.membership_or_none(conn, caller, slug);Change.of_owner(project, caller, reader);join_rule()next toowner_only(members.py:367). - Effort: S-M. Risk: low (test_member_patch_answer, test_owner_role, test_briefing_view).
2. Duplication: "only the namespace owner, or an owner of the owning organisation" three times
- Kind: duplication.
- Files: project_names.py:168-178 (
authority), routes/projects.py:1443-1449 (confirm_repository), :1541-1552 (_namespace_owner_only). routes/projects.py:500-513 (_create_served) reads the organisation role with its own join instead oforgs.role_of(orgs.py:237). - Proposal: one
project_names.require_namespace_owner(conn, mine, message)for the three;_create_servedusesorgs.role_ofplus the deleted check. - Effort: S. Risk: low.
3. Duplication: "lock the owning organisation, then the project, then check it did not move" five times
- Kind: duplication.
- Files: routes/projects.py:1018-1028 (
patch_project), :1400-1409 (transfer_project), :1435-1442 (confirm_repository); routes/requests.py:1374-1379 (answer), :1747-1753 (withdraw). - Proposal:
orgs.lock_for(conn, mine, also=None) -> Membership: locks the organisation rows in id order, then the project, raisesproject_movedand returnsminewith the locked project. - Effort: S. Risk: low to medium (lock order; run the PostgreSQL and MariaDB race tests).
4. Duplication, two rules: the repository-path check for areas
- Kind: duplication, a rule written twice in different ways.
- Files: routes/members.py:331 and :1106 (the same expression:
AREA.fullmatch,startswith(".."),"/../"); routes/tasks.py:529 importsAREAfrom routes/members.py (:55) and leaves outstartswith(".."). So a card area..xis accepted where a member area or an expert source..xis refused. docs/api.md:8033 and :8150 say "no..segment", which..xis not. - Proposal: one
area_ok(path)in a domain module (not routes/members), used by the three; decide whether..xis allowed and say so in the PR. - Effort: S. Risk: low.
5. Duplication: _is_member twice
- Files: routes/members.py:1213-1218 and routes/projects.py:666-671, identical; projects.py:662-664
_is_guestreads the same row again right after (:618-621). - Proposal:
access.member_row_or_none(conn, project_id, principal); the arbiter check reads the row once. - Effort: S. Risk: none.
6. Duplication: the "open join" condition
- Files: routes/agents.py:324-334, routes/joins.py:494-499, :642-656 (
_spent,_usable), :945-949, :1058-1061, account_deletion.py:357, agent_owners.py:137, project_roles.py:123. Each writesused_at,burned_at,revoked_atIS NULL andexpires_at > now. - Proposal: one clause helper (for example
joins_open(now)in a domain module) used by all of them; the conditional UPDATEs keep their extra terms. - Effort: S. Risk: low.
7. Duplication: the active membership of an agent in a project, four times in joins.py
- Files: routes/joins.py:162-168, :317-323, :1076-1082, :1234-1243 (
_active_member)._consumeruns it twice in a row: :1074 through_active_member, then :1076-1082. - Proposal:
_active_member(conn, project_id, agent_id)used everywhere;_consumereads it once. - Effort: S. Risk: none.
8. Duplication: a third copy of "agent ids owned by the observer"
- Files: routes/members.py:461-470 (
_owned_agents), beside conversation_list.py and routes/conversations.py, which tsk-vt3nbqq1v4rz (A6-18) names. - Proposal: use the helper that card settles on.
- Effort: S. Risk: none.
Order
- Item 3 touches routes/requests.py; tsk-bvw5mk2dbwkp and tsk-dwrtrhdgzezs step 1 move that code. Rebase rather than conflict.
- Item 1 and tsk-0zr2x1qkkq17 item 5 both edit
patch_member's neighbours; rebase.
Open question
- Item 4: may an area or source start with
..when it is no..segment (..x)? Today members say no and cards say yes.
Covered elsewhere
members.chain(the reports_to walk): tsk-vt3nbqq1v4rz A6-13._leaving_tokenskeeps or drops proxies: tsk-hz5nkwyn9sj9 item 8, open question.- Owner lookups at members.py:949, :1155, :1539: tsk-9tj3p6ca30m6.
- Handle checks in
joins._create_for_join(:1347-1357): tsk-hz5nkwyn9sj9 item 9. - Searched: _is_member, project_moved, _namespace_owner_only, AREA, burned_at.
Effort sum: 1 S-M + 7S, about 9 points.