kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Move the FacilityUser viewset family into kolibri/core/auth/viewsets/

Open rtibbles opened this issue 5 months ago • 4 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Move FacilityUserViewSet, DeletedFacilityUserViewSet, and PublicFacilityUserViewSet — already migrated to the serializer-derived pattern in #14327 — from kolibri/core/auth/api.py into kolibri/core/auth/viewsets/facility_user.py, with their serializers inline. This is the first move under the File Organization convention in #14036 and pilots the move workflow for the rest of the migration sub-issues.

Complexity: Low Target branch: develop

Context

PublicFacilityUserViewSet, FacilityUserViewSet, and DeletedFacilityUserViewSet live in kolibri/core/auth/api.py; their serializers — FacilityUserSerializer (which nests FacilityUserRoleSerializer for roles), DeletedFacilityUserSerializer, and PublicFacilityUserSerializer — live in kolibri/core/auth/serializers.py. These were migrated to the serializer-derived pattern in #14327, so this is a pure relocation with no serialization changes.

BaseSignUpViewSet in api.py also uses FacilityUserSerializer; it imports from the new module until its own move.

The Change

Create the kolibri/core/auth/viewsets/ package (empty __init__.py) and move the three viewsets and their serializers into kolibri/core/auth/viewsets/facility_user.py, serializers above the viewsets that use them, as a pure-move commit. Update imports in api.py, api_urls.py, and anywhere else that references the moved classes.

Moving code breaks GitHub blame (local git blame -C -C still works), so digest the history the move obscures:

  1. Run blame over the code being moved; flag hunks whose purpose isn't evident from the code or tests (odd guards, magic orderings, special cases).
  2. Chase each flagged hunk to its originating PR/issue; where the rationale is non-obvious and load-bearing, carry it forward as a code comment citing the reference.
  3. Where the rationale turns out to be obsolete, flag the code for removal — but as a pure move, this PR should not remove it; raise it for follow-up instead.

How to Get There

The moved endpoints are exercised at /api/auth/facilityuser/, /api/auth/deletedfacilityuser/, and /api/public/facilityuser/ (the latter routed via kolibri/core/public/api_urls.py).

Out of Scope

  • Any change to serialization behavior or API response shape — this is a pure move
  • Moving other auth viewsets or serializers — they follow in their own sub-issues
  • Deleting api.py or serializers.py — that happens in the final issue touching these files (#14303)
  • Removing obsolete code found during blame digestion — flag for follow-up instead

Acceptance Criteria

  • [ ] kolibri/core/auth/viewsets/facility_user.py contains FacilityUserViewSet, DeletedFacilityUserViewSet, and PublicFacilityUserViewSet plus their serializers (FacilityUserSerializer, FacilityUserRoleSerializer, DeletedFacilityUserSerializer, PublicFacilityUserSerializer), serializers above the viewsets
  • [ ] Moved classes removed from api.py/serializers.py, with all references updated (auth/api_urls.py, public/api_urls.py, BaseSignUpViewSet, tests)
  • [ ] The relocation lands as a pure-move commit, separate from import updates
  • [ ] Existing API tests pass unchanged
  • [ ] Benchmark comparison passes for all three viewsets (data hash match + no performance regression)
  • [ ] Comments citing the originating PR/issue added where blame digestion found non-obvious, load-bearing rationale

Testing

  • Run the benchmark for each of the three viewsets, baseline with the old dotted path, comparison with the new one:
    python integration_testing/scripts/viewset_serialization_benchmark.py \
        kolibri.core.auth.api.FacilityUserViewSet \
        --inherit-kolibri-home -o facility_user_baseline.json
    
    # ... move ...
    
    python integration_testing/scripts/viewset_serialization_benchmark.py \
        kolibri.core.auth.viewsets.facility_user.FacilityUserViewSet \
        --inherit-kolibri-home --compare facility_user_baseline.json
    
    Likewise for DeletedFacilityUserViewSet and PublicFacilityUserViewSet.
  • All three comparisons must pass (identical output hash, no regression); include the before/after output in the PR description.
  • Benchmark data setup: populate a facility with users via kolibri manage generateuserdata.

AI usage

Drafted with AI assistance (Claude Code) from an interactive design discussion, section by section, with review and final edits by @rtibbles. File locations, serializer relationships, routes, and benchmark comparison behavior were verified against the codebase during drafting.

rtibbles avatar Jun 06 '26 18:06 rtibbles

Plan: Move FacilityUserViewSet, DeletedFacilityUserViewSet, PublicFacilityUserViewSet, their four serializers, and their filter into a new kolibri/core/auth/viewsets/facility_user.py module with no behavior changes.

  • [ ] Run git blame and annotate non-obvious hunks
  • [ ] Create the viewsets package
  • [ ] Create viewsets/facility_user.py (the full moved file)
  • [ ] Lint the new file
  • [ ] Remove moved classes from api.py
  • [ ] Remove moved serializers from serializers.py
  • [ ] Lint modified files and make the pure-move commit
  • [ ] Update api.py — add late import for BaseSignUpViewSet
  • [ ] Update api_urls.py
  • [ ] Update public/api_urls.py
  • [ ] Update management/commands/user_info.py
  • [ ] Lint all changed files and make the import-updates commit
  • [ ] Run existing API tests
  • [ ] Run benchmark comparisons

status


@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?
  • Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
  • Ran the project's full test suite and linter before committing
  • For UI changes: captured live screenshots to verify rendering
  • For backend changes: verified with example API/CLI output

rtibblesbot avatar Jun 06 '26 18:06 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jun 06 '26 22:06 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jun 08 '26 23:06 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jun 09 '26 02:06 rtibblesbot