Update core channel import utilities to handle tokens directly
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Overview
Currently, token resolution happens only in the importchannel management command, and the resolved metadata (version, library status) is discarded — only the channel ID is kept. The core channel import utilities need to handle tokens directly, so that all token-resolved metadata flows through the import process.
Complexity: Medium Target branch: release-v0.19.x
Context
Token resolution currently happens in two places:
kolibri/core/content/management/commands/importchannel.py:resolve_channel_token— CLI import pathkolibri/core/content/api.py:_make_channel_endpoint_request— frontend discovery path via the remote channel API
Both resolve tokens to channel metadata, but downstream consumers only use the channel ID. For tokens that correspond to a single channel (some tokens resolve to collections), this discards token-specific metadata like version and library status.
The core import utilities in kolibri/core/content/utils/resource_import.py separately re-fetch channel info via lookup_channel_listing_status using the channel ID, not the original token, so they don't have access to the token-resolved metadata.
The Change
Update lookup_channel_listing_status in kolibri/core/content/utils/resource_import.py to accept a token or a channel ID, and to return the full token-resolved metadata (version, library) rather than just the public field.
Update RemoteResourceImportManagerBase and its subclasses (RemoteChannelResourceImportManager, RemoteChannelUpdateManager, ContentDownloadRequestResourceImportManager) to accept and pass through the token.
Update the content tasks in kolibri/core/content/tasks.py and their validators to accept and pass through the token from the frontend to the import managers.
Update the importchannel management command to use the consolidated token resolution from lookup_channel_listing_status rather than its own resolve_channel_token implementation.
Add a new library field to ChannelMetadata using the le-utils library constants, and migrate existing public channels to "KOLIBRI" via an upgrade task, not a Django data migration.
Update the le-utils dependency to include the new library constants.
Ensure calls to the token resolution endpoint on Studio include the "channel_versions=true" query parameter.
How to Get There
The token flows through these layers:
lookup_channel_listing_status(resource_import.py) — update to accept a token or channel ID, and return version, library, and public status from the v1 responseRemoteResourceImportManagerBase.__init__(resource_import.py:570) — currently callslookup_channel_listing_statuswith justchannel_id. Update to accept and pass through the token- Content tasks and validators (
tasks.py) —remotechannelimport,remoteimport, and their validators need to accept the token and pass it to the import managers ChannelMetadatamodel (models.py) — addlibraryfield with a Django migration for the schema change. Populate existingpublic=Truechannels to"KOLIBRI"via an upgrade task, not a Django data migration
Acceptance Criteria
- [ ]
lookup_channel_listing_statusaccepts a token or channel ID and returns version, library, and public status - [ ]
RemoteResourceImportManagerBaseand its subclasses accept and pass through the token - [ ] Content tasks and validators accept and pass through the token to import managers
- [ ] The token is optional alongside the required channel ID; when both are provided, the backend validates that the token resolves to the same channel ID
- [ ]
importchannelmanagement command uses the consolidated token resolution fromlookup_channel_listing_status - [ ]
ChannelMetadatamodel has alibraryfield using le-utils library constants - [ ] Existing
public=Truechannels are populated to"KOLIBRI"via an upgrade task - [ ] Draft channel tokens (where Studio returns
version: null) are stored withversion=0as a sentinel value onChannelMetadata - [ ] le-utils dependency updated to include library constants
- [ ] Requests to the v1 API for tokens include the
channel_versions=truequery parameter
Testing
- [ ] Extend existing import manager tests (
ImportContentTestCase,ImportManagerWithChannelDatabaseTestCase) to verify token metadata flows through toChannelMetadata.library - [ ] Extend
ImportChannelTestCaseto verify the consolidated token resolution - [ ] Test upgrade task populates
libraryfor existing public channels
References
- learningequality/studio#5772 — Added channel version token support to Studio's v1 public channel endpoint
AI usage
Used Claude Code to draft this issue interactively. I provided the requirements and Claude explored the Kolibri codebase to understand the token resolution and import flows. All content reflects my decisions and was reviewed section by section.
Watching for resolution on behalf of learningequality/kolibri#14591.
Plan: Thread token-resolved metadata (version, library, public) from Studio's v1 channel lookup endpoint through the full import pipeline, and persist it on ChannelMetadata.
- [ ] Verify le-utils library constants and add
channel_versionsto URL builder - [ ] Update
lookup_channel_listing_statusto accept a token and return full metadata - [ ] Add
libraryfield toChannelMetadata, migration, andset_channel_metadata_fields - [ ] Add
tokentoRemoteResourceImportManagerBaseand store metadata - [ ] Add
tokento validators and tasks; callset_channel_metadata_fieldsafter import - [ ] Replace
resolve_channel_tokenwithlookup_channel_listing_status - [ ] Backfill
library="KOLIBRI"for existing public channels
@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
Fixed in #14598