Skip to content

Commit

Permalink
Remove student self-unenrollment
Browse files Browse the repository at this point in the history
The ability for students to unenroll themselves from a course turned out
to be an undesired feature. Therefore this commit disables it. UI
elements have been commented out, the /enroll/ URL has been commented
out, and the DELETE operation on the course students API view is now
only available for course staff.
  • Loading branch information
skulonen authored and markkuriekkinen committed Aug 27, 2021
1 parent 5a9f01f commit 122b287
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
22 changes: 14 additions & 8 deletions course/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ class CourseStudentsViewSet(NestedViewSetMixin,
returns the details of the current user.
`DELETE /courses/<course_id>/students/<user_id>/`:
removes the enrollment.
removes the enrollment. Students cannot unenroll themselves.
- URL parameters:
- `status`: the new status for the enrollment. `REMOVED` and `BANNED`
are currently supported. Students can only remove (not ban)
themselves.
are currently supported.
"""
permission_classes = api_settings.DEFAULT_PERMISSION_CLASSES + [
IsCourseAdminOrUserObjIsSelf,
Expand All @@ -171,6 +170,13 @@ def get_queryset(self):
return self.instance.students

def destroy(self, request, *args, **kwargs):
if not self.is_course_staff:
return Response(
'Student self-unenrollment is not allowed. Contact course '
'staff if you wish to remove your enrollment.',
status=status.HTTP_403_FORBIDDEN
)

status_arg = self.request.GET.get('status')
if status_arg not in Enrollment.ENROLLMENT_STATUS.keys():
return Response(
Expand All @@ -184,11 +190,11 @@ def destroy(self, request, *args, **kwargs):
'Enrollments cannot be activated via this API',
status=status.HTTP_400_BAD_REQUEST
)
if status_code != Enrollment.ENROLLMENT_STATUS.REMOVED and not self.is_course_staff:
return Response(
'Students can only unenroll themselves (status=REMOVED) via this API',
status=status.HTTP_403_FORBIDDEN
)
# if status_code != Enrollment.ENROLLMENT_STATUS.REMOVED and not self.is_course_staff:
# return Response(
# 'Students can only unenroll themselves (status=REMOVED) via this API',
# status=status.HTTP_403_FORBIDDEN
# )

user = self.get_object().user
enrollment = self.instance.get_enrollment_for(user)
Expand Down
6 changes: 3 additions & 3 deletions course/long_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
url(USER_URL_PREFIX + r'enroll/$',
views.Enroll.as_view(),
name='enroll'),
url(USER_URL_PREFIX + r'unenroll/$',
views.Unenroll.as_view(),
name='unenroll'),
# url(USER_URL_PREFIX + r'unenroll/$',
# views.Unenroll.as_view(),
# name='unenroll'),
url(USER_URL_PREFIX + r'setlang',
views.LanguageView.as_view(),
name="set-enrollment-language"),
Expand Down
2 changes: 2 additions & 0 deletions course/templates/course/_course_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ <h4>{{ group.label|parse_localization }}</h4>

{% endif %}

{% comment %}
{% if is_student %}
<li class="header">
<h4>{% trans "ENROLLMENT" %}</h4>
Expand All @@ -222,3 +223,4 @@ <h4>{% trans "ENROLLMENT" %}</h4>
</a>
</li>
{% endif %}
{% endcomment %}
2 changes: 2 additions & 0 deletions course/templates/course/course_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ <h4>{% trans "Calendar" %}</h4>
</div>
</div>

{% comment %}
<div id="unenroll-modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="unenroll-modal-title">
<div class="modal-dialog" role="document">
<div class="modal-content">
Expand Down Expand Up @@ -189,6 +190,7 @@ <h4 class="modal-title" id="unenroll-modal-title">
</div>
</div>
</div>
{% endcomment %}
{% endblock %}

{% block mobilemenu %}
Expand Down

0 comments on commit 122b287

Please sign in to comment.