kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Move analytics, tasks, setup_wizard, user_profile, and device plugin API code into viewsets/ packages

Open rtibbles opened this issue 5 months ago • 1 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 the API code of the apps untouched by the serializer-derivation migration — kolibri/core/analytics, kolibri/core/tasks, kolibri/plugins/setup_wizard, kolibri/plugins/user_profile, and kolibri/plugins/device — into per-app viewsets/ packages with serializers inline, deleting the old api.py/viewsets.py/serializers.py modules. None of these viewsets use the ValuesViewset serialization path, so this is pure moves throughout, under the File Organization convention in #14036.

Complexity: Medium Target branch: develop

Context

Per-app surface, all confirmed off the ValuesViewset serialization path:

  • kolibri/core/analytics/api.py: PingbackNotificationViewSet, PingbackNotificationDismissedViewSet, LocalNotificationViewSet (plain DRF viewsets), with three serializers in serializers.py
  • kolibri/core/tasks/api.py: TasksViewSet, with TasksSerializer already defined inline
  • kolibri/plugins/setup_wizard/api.py: SetupWizardResource, FacilityImportViewSet, their permission classes, and _PublicSignupErrorSerializer
  • kolibri/plugins/user_profile/viewsets.py: OnMyOwnSetupViewset, LoginMergedUserViewset (APIViews)
  • kolibri/plugins/device/api.py: DeviceChannelMetadataViewSet with DeviceChannelMetadataSerializer/DeviceChannelMetadataFilter (subclassing imports from kolibri.core.content — only the import lines move, so this is order-independent of the content chain), plus CalculateImportExportSizeView and DeviceChannelOrderView (APIViews)

Each app gets the viewsets/ package shape even where a single module results, for consistency across the codebase. kolibri/core/attendance was considered for this issue but has unmigrated ValuesViewsets, so it gets its own migration sub-issue instead.

The Change

For each of the five apps, create the viewsets/ package, move its viewsets/APIViews with serializers inline into one module per domain, update imports (api_urls.py and any external references), and delete the old api.py/viewsets.py/serializers.py. Land each app's relocation as its own pure-move commit, separate from import updates; the apps are independent, so this can be one PR with per-app commits or split into multiple PRs.

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.

Out of Scope

  • Any change to endpoint behavior or response shape — these are pure moves
  • kolibri/core/attendance — has unmigrated ValuesViewsets, so it gets its own migration sub-issue
  • kolibri/plugins/facility — its api_urls.py routes function-based views, which stay put under the convention
  • Migrating any of these viewsets to the serializer-derived pattern — none use the ValuesViewset serialization path
  • Removing obsolete code found during blame digestion — flag for follow-up instead

Acceptance Criteria

  • [ ] Each of the five apps has a viewsets/ package containing its viewsets/APIViews with serializers inline, one module per domain
  • [ ] The old api.py/viewsets.py/serializers.py modules are deleted in all five apps
  • [ ] All references updated (each app's api_urls.py, tests, any cross-app imports)
  • [ ] Each app's relocation lands as a pure-move commit, separate from import updates
  • [ ] API tests for OnMyOwnSetupViewset and LoginMergedUserViewset written before the move
  • [ ] Existing API tests pass unchanged
  • [ ] Comments citing the originating PR/issue added where blame digestion found non-obvious, load-bearing rationale

Testing

  • Each app's backend suite must pass unchanged: kolibri/core/analytics/test/test_api.py, kolibri/core/tasks/test/test_api.py, kolibri/plugins/setup_wizard/test/test_api.py, kolibri/plugins/device/test/test_api.py.
  • kolibri/plugins/user_profile has no backend API tests. Write API tests covering OnMyOwnSetupViewset and LoginMergedUserViewset before the move, capturing current behavior; they must pass before and after.

AI usage

Drafted with AI assistance (Claude Code) from an interactive design discussion, section by section, with review and final edits by @rtibbles. App surfaces, serialization paths, cross-app imports, and test coverage (including the user_profile gap) were verified against the codebase during drafting.

rtibbles avatar Jun 06 '26 19:06 rtibbles

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

rtibblesbot avatar Jun 11 '26 02:06 rtibblesbot