Skip to content

Commit 986d3e2

Browse files
authored
Merge pull request #170 from eduNEXT/mfmz/docs-in-enrollment-force-flag
docs: add enrollment force doc and change serializer for response doc
2 parents a6d976a + 90e2d5d commit 986d3e2

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ Change Log
1212
Unreleased
1313
----------
1414

15+
[4.15.1] - 2021-08-13
16+
---------------------
17+
18+
Changed
19+
~~~~~~~
20+
* Add force flag to post method of enrollments api
21+
* Update serializers used by enrollments api
22+
1523
[4.15.0] - 2021-08-06
1624
---------------------
1725

eox_core/api/v1/serializers.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,15 @@ class EdxappCourseEnrollmentSerializer(serializers.Serializer):
318318
enrollment_attributes = EdxappEnrollmentAttributeSerializer(many=True, required=False)
319319
course_id = EdxappValidatedCourseIDField()
320320

321+
def validate(self, attrs):
322+
"""
323+
Check that there are no issues with enrollment
324+
"""
325+
errors = check_edxapp_enrollment_is_valid(**attrs)
326+
if errors:
327+
raise serializers.ValidationError(", ".join(errors))
328+
return attrs
329+
321330
class Meta:
322331
"""
323332
Add extra details for swagger
@@ -329,20 +338,11 @@ class Meta:
329338
("is_active", True),
330339
("mode", "audit"),
331340
("enrollment_attributes", []),
332-
("course_id", "course-v1:edX+DemoX+Demo_Course")
333-
]
341+
("course_id", "course-v1:edX+DemoX+Demo_Course"),
342+
],
334343
),
335344
}
336345

337-
def validate(self, attrs):
338-
"""
339-
Check that there are no issues with enrollment
340-
"""
341-
errors = check_edxapp_enrollment_is_valid(**attrs)
342-
if errors:
343-
raise serializers.ValidationError(", ".join(errors))
344-
return attrs
345-
346346

347347
class EdxappCourseEnrollmentQuerySerializer(EdxappCourseEnrollmentSerializer):
348348
"""
@@ -355,6 +355,19 @@ class EdxappCourseEnrollmentQuerySerializer(EdxappCourseEnrollmentSerializer):
355355
course_id = EdxappValidatedCourseIDField(default=None)
356356
bundle_id = serializers.CharField(max_length=255, default=None)
357357

358+
class Meta(EdxappCourseEnrollmentSerializer.Meta):
359+
"""
360+
Add extra details for swagger
361+
"""
362+
swagger_schema_fields = {
363+
"example": OrderedDict(
364+
{
365+
"force": False,
366+
**EdxappCourseEnrollmentSerializer.Meta.swagger_schema_fields.get("example")
367+
},
368+
),
369+
}
370+
358371

359372
class EdxappCoursePreEnrollmentSerializer(EdxappWithWarningSerializer):
360373
"""Serialize CourseEnrollmentAllowed

eox_core/api/v1/views.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,9 @@ class EdxappEnrollment(UserQueryMixin, APIView):
534534
renderer_classes = (JSONRenderer, BrowsableAPIRenderer)
535535

536536
@apidocs.schema(
537-
body=EdxappCourseEnrollmentSerializer,
537+
body=EdxappCourseEnrollmentQuerySerializer,
538538
responses={
539-
200: EdxappCourseEnrollmentSerializer,
539+
200: EdxappCourseEnrollmentQuerySerializer,
540540
202: "User doesn't belong to site.",
541541
400: "Bad request, invalid course_id or missing either email or username.",
542542
},
@@ -554,6 +554,7 @@ def post(self, request, *args, **kwargs):
554554
"username": "johndoe",
555555
"course_id": "course-v1:edX+DemoX+Demo_Course",
556556
"mode": "audit",
557+
"force": "False",
557558
"is_active": "False",
558559
"enrollment_attributes": [
559560
{
@@ -581,6 +582,11 @@ def post(self, request, *args, **kwargs):
581582
- `is_active` (boolean, _body_):
582583
Flag indicating whether the enrollment is active.
583584
585+
- `force` (boolean, _body_):
586+
Flag indicating whether the platform business rules for enrollment must be skipped. When it is true, the enrollment
587+
is created without looking at the enrollment dates, if the course is full, if the enrollment mode is part of the modes
588+
allowed by that course and other course settings.
589+
584590
- `enrollment_attributes` (list, _body_):
585591
List of enrollment attributes. An enrollment attribute can be used to add extra parameters for a specific course mode.
586592
It must be a dictionary containing the following:
@@ -597,6 +603,7 @@ def post(self, request, *args, **kwargs):
597603
"course_id": "course-v1:edX+DemoX+Demo_Course",
598604
"mode": "audit",
599605
"is_active": "False",
606+
"force": "False",
600607
"enrollment_attributes": [
601608
{
602609
"namespace": "credit",
@@ -610,6 +617,7 @@ def post(self, request, *args, **kwargs):
610617
"course_id": "course-v1:edX+DemoX+Demo_Course",
611618
"mode": "audit",
612619
"is_active": "True",
620+
"force": "False",
613621
"enrollment_attributes": []
614622
},
615623
]
@@ -626,9 +634,9 @@ def post(self, request, *args, **kwargs):
626634
)
627635

628636
@apidocs.schema(
629-
body=EdxappCourseEnrollmentSerializer,
637+
body=EdxappCourseEnrollmentQuerySerializer,
630638
responses={
631-
200: EdxappCourseEnrollmentSerializer,
639+
200: EdxappCourseEnrollmentQuerySerializer,
632640
202: "User or enrollment doesn't belong to site.",
633641
400: "Bad request, invalid course_id or missing either email or username.",
634642
},

0 commit comments

Comments
 (0)