kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Update core channel import utilities to handle tokens directly

Open rtibbles opened this issue 7 months ago • 3 comments

❌ 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 path
  • kolibri/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:

  1. 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 response
  2. RemoteResourceImportManagerBase.__init__ (resource_import.py:570) — currently calls lookup_channel_listing_status with just channel_id. Update to accept and pass through the token
  3. Content tasks and validators (tasks.py) — remotechannelimport, remoteimport, and their validators need to accept the token and pass it to the import managers
  4. ChannelMetadata model (models.py) — add library field with a Django migration for the schema change. Populate existing public=True channels to "KOLIBRI" via an upgrade task, not a Django data migration

Acceptance Criteria

  • [ ] lookup_channel_listing_status accepts a token or channel ID and returns version, library, and public status
  • [ ] RemoteResourceImportManagerBase and 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
  • [ ] importchannel management command uses the consolidated token resolution from lookup_channel_listing_status
  • [ ] ChannelMetadata model has a library field using le-utils library constants
  • [ ] Existing public=True channels are populated to "KOLIBRI" via an upgrade task
  • [ ] Draft channel tokens (where Studio returns version: null) are stored with version=0 as a sentinel value on ChannelMetadata
  • [ ] le-utils dependency updated to include library constants
  • [ ] Requests to the v1 API for tokens include the channel_versions=true query parameter

Testing

  • [ ] Extend existing import manager tests (ImportContentTestCase, ImportManagerWithChannelDatabaseTestCase) to verify token metadata flows through to ChannelMetadata.library
  • [ ] Extend ImportChannelTestCase to verify the consolidated token resolution
  • [ ] Test upgrade task populates library for 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.

rtibbles avatar Apr 12 '26 00:04 rtibbles

Watching for resolution on behalf of learningequality/kolibri#14591.

rtibblesbot avatar Apr 13 '26 19:04 rtibblesbot

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_versions to URL builder
  • [ ] Update lookup_channel_listing_status to accept a token and return full metadata
  • [ ] Add library field to ChannelMetadata, migration, and set_channel_metadata_fields
  • [ ] Add token to RemoteResourceImportManagerBase and store metadata
  • [ ] Add token to validators and tasks; call set_channel_metadata_fields after import
  • [ ] Replace resolve_channel_token with lookup_channel_listing_status
  • [ ] Backfill library="KOLIBRI" for existing public channels

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 Apr 13 '26 23:04 rtibblesbot

Fixed in #14598

rtibbles avatar Apr 14 '26 23:04 rtibbles