forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: disable unenroll button for paid courses
- Loading branch information
1 parent
05aa67c
commit df4ac66
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
openedx/features/edly/api/v1/views/user_paid_for_course.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from opaque_keys import InvalidKeyError | ||
from opaque_keys.edx.keys import CourseKey | ||
from rest_framework import viewsets | ||
from rest_framework.permissions import IsAuthenticated | ||
|
||
from common.djangoapps.student.models import CourseEnrollment | ||
from common.djangoapps.util.json_request import JsonResponse | ||
|
||
|
||
class UserPaidForCourseViewSet(viewsets.ViewSet): | ||
""" | ||
**Use Case** | ||
Get the status of a user's paid status for a given course. | ||
**Example Request** | ||
GET /api/v1/user_paid_for_course/{course_id} | ||
**GET Parameters** | ||
* pk: The course id of the course to retrieve the user's paid status for. | ||
**Response Values** | ||
If the request is successful, the request returns an HTTP 200 "OK" response. | ||
The HTTP 200 response has the following values. | ||
* has_user_paid: True if the user has paid for the course, False otherwise. | ||
""" | ||
permission_classes = [IsAuthenticated] | ||
|
||
def retrieve(self, request, pk=None): | ||
"""Get the status of a user's paid status for a given course.""" | ||
try: | ||
course_key = CourseKey.from_string(pk) | ||
course_enrollment = CourseEnrollment.get_enrollment(request.user, course_key) | ||
except InvalidKeyError: | ||
return JsonResponse({'has_user_paid': False}, status=406) | ||
|
||
paid_status = course_enrollment.get_order_attribute_value('order_number') | ||
return JsonResponse({'has_user_paid': bool(paid_status)}, status=200) |