Skip to content

Commit

Permalink
refactor: [AXM-549] Refactor UserEnrollmentsStatus API
Browse files Browse the repository at this point in the history
  • Loading branch information
KyryloKireiev committed Jun 21, 2024
1 parent ee862b3 commit a66288f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lms/djangoapps/mobile_api/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ def test_discussion_tab_url(self, discussion_tab_enabled):


@ddt.ddt
class UserEnrollmentsStatus(MobileAPITestCase, MobileAuthUserTestMixin):
class TestUserEnrollmentsStatus(MobileAPITestCase, MobileAuthUserTestMixin):
"""
Tests for /api/mobile/{api_version}/users/<user_name>/enrollments_status/
"""
Expand Down
18 changes: 4 additions & 14 deletions lms/djangoapps/mobile_api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.contrib.auth.signals import user_logged_in
from django.db import transaction
from django.shortcuts import redirect
from django.shortcuts import get_object_or_404, redirect
from django.utils import dateparse
from django.utils.decorators import method_decorator
from opaque_keys import InvalidKeyError
Expand Down Expand Up @@ -416,14 +416,6 @@ def my_user_info(request, api_version):
return redirect("user-detail", api_version=api_version, username=request.user.username)


class UserCourseEnrollmentsV4Pagination(DefaultPagination):
"""
Pagination for `UserCourseEnrollments` API v4.
"""
page_size = 5
max_page_size = 50


@mobile_view(is_user=True)
class UserEnrollmentsStatus(views.APIView):
"""
Expand Down Expand Up @@ -503,13 +495,11 @@ def _build_enrollments_status_dict(
"""
Builds list with dictionaries with user's enrolments statuses.
"""
user_enrollments = CourseEnrollment.objects.filter(
user__username=username,
is_active=True,
)
user = get_object_or_404(User, username=username)
user_enrollments = CourseEnrollment.enrollments_for_user(user).select_related('course')
mobile_available = [
enrollment for enrollment in user_enrollments
if is_mobile_available_for_user(self.request.user, enrollment.course_overview)
if is_mobile_available_for_user(user, enrollment.course_overview)
]
enrollments_status = []
for user_enrollment in mobile_available:
Expand Down

0 comments on commit a66288f

Please sign in to comment.