-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Summary
The Cohorts API v1 POST and PATCH endpoints do not support saving group_id and user_partition_id fields, even though the GET endpoint returns these values. This creates an inconsistent API where consumers cannot set content group associations when creating or updating cohorts via the REST API.
Current Behavior
GET /api/cohorts/v1/courses/{course_id}/cohorts/{cohort_id} returns:
{
"name": "My Cohort",
"id": 1,
"user_count": 10,
"assignment_type": "manual",
"user_partition_id": 50,
"group_id": 1
}POST /api/cohorts/v1/courses/{course_id}/cohorts/ only accepts:
name(required)assignment_type(required)
PATCH /api/cohorts/v1/courses/{course_id}/cohorts/{cohort_id} only accepts:
name(optional)assignment_type(optional)
Neither POST nor PATCH accept group_id or user_partition_id, so there's no way to associate a cohort with a content group via the v1 API.
Expected Behavior
Both POST and PATCH should accept optional group_id and user_partition_id parameters to allow setting content group associations:
POST request body:
{
"name": "My Cohort",
"assignment_type": "manual",
"user_partition_id": 50,
"group_id": 1
}PATCH request body:
{
"user_partition_id": 50,
"group_id": 2
}Setting group_id to null should remove the content group association.
Technical Details
The logic already exists in the legacy cohort_handler function in openedx/core/djangoapps/course_groups/views.py (lines 218-234):
group_id = request.json.get('group_id')
if group_id is not None:
user_partition_id = request.json.get('user_partition_id')
if user_partition_id is None:
return JsonResponse(
{"error": "If group_id is specified, user_partition_id must also be specified."}, 400
)
existing_group_id, existing_partition_id = cohorts.get_group_info_for_cohort(cohort)
if group_id != existing_group_id or user_partition_id != existing_partition_id:
unlink_cohort_partition_group(cohort)
link_cohort_to_partition_group(cohort, user_partition_id, group_id)
else:
# If group_id was specified as None, unlink the cohort if it previously was associated
existing_group_id, _ = cohorts.get_group_info_for_cohort(cohort)
if existing_group_id is not None:
unlink_cohort_partition_group(cohort)This logic needs to be ported to the CohortHandler class's post() and patch() methods.
Additional Work
- Update OpenAPI schema in docs/lms-openapi.yaml to document the request/response schemas for these endpoints (currently just properties: {})
Files to Modify
- openedx/core/djangoapps/course_groups/views.py - Add group_id/user_partition_id support to CohortHandler.post() and CohortHandler.patch()
- docs/lms-openapi.yaml - Add proper schema definitions for cohort endpoints
Metadata
Metadata
Assignees
Labels
Type
Projects
Status