Skip to content

Commit 04547b7

Browse files
feat: Add Content Groups API v2 endpoints for Instructor Dashboard
- Add GET /api/instructor/v2/courses/{course_id}/group_configurations - Add GET /api/instructor/v2/courses/{course_id}/group_configurations/{id} - Create shared constants module for course groups - Add serializers for content group configurations - Add unit tests for new endpoints - Add OpenAPI spec documentation Refactor content groups API from LMS to core.
1 parent e0b2d6b commit 04547b7

10 files changed

Lines changed: 880 additions & 123 deletions

File tree

cms/djangoapps/contentstore/course_group_config.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,20 @@
1212
from cms.djangoapps.contentstore.utils import reverse_usage_url
1313
from common.djangoapps.util.db import MYSQL_MAX_INT, generate_int_id
1414
from lms.lib.utils import get_parent_unit
15+
from openedx.core.djangoapps.course_groups.constants import (
16+
COHORT_SCHEME,
17+
CONTENT_GROUP_CONFIGURATION_DESCRIPTION,
18+
CONTENT_GROUP_CONFIGURATION_NAME,
19+
ENROLLMENT_SCHEME,
20+
RANDOM_SCHEME,
21+
)
1522
from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_user_partition
1623
from xmodule.partitions.partitions import MINIMUM_UNUSED_PARTITION_ID, ReadOnlyUserPartitionError, UserPartition # lint-amnesty, pylint: disable=wrong-import-order
1724
from xmodule.partitions.partitions_service import get_all_partitions_for_course # lint-amnesty, pylint: disable=wrong-import-order
1825
from xmodule.split_test_block import get_split_user_partitions # lint-amnesty, pylint: disable=wrong-import-order
1926

2027
MINIMUM_GROUP_ID = MINIMUM_UNUSED_PARTITION_ID
2128

22-
RANDOM_SCHEME = "random"
23-
COHORT_SCHEME = "cohort"
24-
ENROLLMENT_SCHEME = "enrollment_track"
25-
26-
CONTENT_GROUP_CONFIGURATION_DESCRIPTION = _(
27-
'The groups in this configuration can be mapped to cohorts in the Instructor Dashboard.'
28-
)
29-
30-
CONTENT_GROUP_CONFIGURATION_NAME = _('Content Groups')
31-
3229
log = logging.getLogger(__name__)
3330

3431

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
swagger: '2.0'
2+
info:
3+
title: Instructor Dashboard Content Groups API v2
4+
version: 2.0.0
5+
description: |
6+
REST API for managing content group configurations.
7+
8+
Content groups allow course authors to restrict access to specific
9+
course content based on cohort membership.
10+
11+
host: courses.example.com
12+
basePath: /
13+
schemes:
14+
- https
15+
16+
securityDefinitions:
17+
JWTAuth:
18+
type: apiKey
19+
in: header
20+
name: Authorization
21+
description: JWT token authentication.
22+
23+
security:
24+
- JWTAuth: []
25+
26+
tags:
27+
- name: Content Groups
28+
description: Content group configuration management
29+
30+
parameters:
31+
CourseId:
32+
name: course_id
33+
in: path
34+
required: true
35+
type: string
36+
description: The course key (e.g., course-v1:org+course+run)
37+
ConfigurationId:
38+
name: configuration_id
39+
in: path
40+
required: true
41+
type: integer
42+
description: The ID of the content group configuration
43+
44+
paths:
45+
/api/instructor/v2/courses/{course_id}/group_configurations:
46+
get:
47+
tags:
48+
- Content Groups
49+
summary: List content group configurations
50+
description: |
51+
Returns all content group configurations (scheme='cohort') for a course.
52+
If no content group exists, an empty one is automatically created.
53+
operationId: listGroupConfigurations
54+
produces:
55+
- application/json
56+
parameters:
57+
- $ref: '#/parameters/CourseId'
58+
responses:
59+
200:
60+
description: Content groups retrieved successfully
61+
schema:
62+
$ref: '#/definitions/ContentGroupsListResponse'
63+
400:
64+
description: Invalid course key
65+
401:
66+
description: Authentication required
67+
403:
68+
description: User lacks instructor permission
69+
404:
70+
description: Course not found
71+
72+
/api/instructor/v2/courses/{course_id}/group_configurations/{configuration_id}:
73+
get:
74+
tags:
75+
- Content Groups
76+
summary: Get content group configuration details
77+
description: |
78+
Retrieve a specific content group configuration by ID.
79+
Only returns configurations with scheme='cohort'.
80+
operationId: getGroupConfiguration
81+
produces:
82+
- application/json
83+
parameters:
84+
- $ref: '#/parameters/CourseId'
85+
- $ref: '#/parameters/ConfigurationId'
86+
responses:
87+
200:
88+
description: Configuration retrieved successfully
89+
schema:
90+
$ref: '#/definitions/ContentGroupConfiguration'
91+
400:
92+
description: Invalid course key
93+
401:
94+
description: Authentication required
95+
403:
96+
description: User lacks instructor permission
97+
404:
98+
description: Configuration not found
99+
100+
definitions:
101+
Group:
102+
type: object
103+
properties:
104+
id:
105+
type: integer
106+
description: Unique identifier for the group
107+
name:
108+
type: string
109+
description: Display name of the group
110+
version:
111+
type: integer
112+
description: Version number of the group
113+
usage:
114+
type: array
115+
items:
116+
type: object
117+
description: List of content blocks using this group
118+
119+
ContentGroupConfiguration:
120+
type: object
121+
properties:
122+
id:
123+
type: integer
124+
description: Unique identifier for the configuration
125+
name:
126+
type: string
127+
description: Display name (typically "Content Groups")
128+
scheme:
129+
type: string
130+
enum: [cohort]
131+
description: Partition scheme type
132+
description:
133+
type: string
134+
description: Human-readable description
135+
parameters:
136+
type: object
137+
description: Additional configuration parameters
138+
groups:
139+
type: array
140+
items:
141+
$ref: '#/definitions/Group'
142+
description: List of groups in this configuration
143+
active:
144+
type: boolean
145+
description: Whether this configuration is active
146+
version:
147+
type: integer
148+
description: Version number of the configuration
149+
read_only:
150+
type: boolean
151+
description: Whether this configuration is system-managed
152+
153+
ContentGroupsListResponse:
154+
type: object
155+
properties:
156+
all_group_configurations:
157+
type: array
158+
items:
159+
$ref: '#/definitions/ContentGroupConfiguration'
160+
description: List of content group configurations
161+
should_show_enrollment_track:
162+
type: boolean
163+
description: Whether enrollment track groups should be displayed
164+
should_show_experiment_groups:
165+
type: boolean
166+
description: Whether experiment groups should be displayed
167+
group_configuration_url:
168+
type: string
169+
description: Base URL for accessing individual configurations
170+
course_outline_url:
171+
type: string
172+
description: URL to the course outline

0 commit comments

Comments
 (0)