Get last visited block id as user staus with version v1 (#25498)
Get last visited block id as user staus with version v1 VAN-85
This commit is contained in:
@@ -8,6 +8,7 @@ import datetime
|
||||
import ddt
|
||||
import pytz
|
||||
import six
|
||||
from completion.test_utils import CompletionWaffleTestMixin, submit_completions_for_testing
|
||||
from django.conf import settings
|
||||
from django.template import defaultfilters
|
||||
from django.test import RequestFactory, override_settings
|
||||
@@ -449,14 +450,14 @@ class CourseStatusAPITestCase(MobileAPITestCase):
|
||||
|
||||
|
||||
class TestCourseStatusGET(CourseStatusAPITestCase, MobileAuthUserTestMixin,
|
||||
MobileCourseAccessTestMixin, MilestonesTestCaseMixin):
|
||||
MobileCourseAccessTestMixin, MilestonesTestCaseMixin, CompletionWaffleTestMixin):
|
||||
"""
|
||||
Tests for GET of /api/mobile/v0.5/users/<user_name>/course_status_info/{course_id}
|
||||
Tests for GET of /api/mobile/v<version_number>/users/<user_name>/course_status_info/{course_id}
|
||||
"""
|
||||
def test_success(self):
|
||||
def test_success_v0(self):
|
||||
self.login_and_enroll()
|
||||
|
||||
response = self.api_response()
|
||||
response = self.api_response(api_version=API_V05)
|
||||
self.assertEqual(
|
||||
response.data["last_visited_module_id"],
|
||||
six.text_type(self.sub_section.location)
|
||||
@@ -466,6 +467,16 @@ class TestCourseStatusGET(CourseStatusAPITestCase, MobileAuthUserTestMixin,
|
||||
[six.text_type(module.location) for module in [self.sub_section, self.section, self.course]]
|
||||
)
|
||||
|
||||
def test_success_v1(self):
|
||||
self.override_waffle_switch(True)
|
||||
self.login_and_enroll()
|
||||
submit_completions_for_testing(self.user, [self.unit.location])
|
||||
response = self.api_response(api_version=API_V1)
|
||||
self.assertEqual(
|
||||
response.data["last_visited_block_id"],
|
||||
six.text_type(self.unit.location)
|
||||
)
|
||||
|
||||
|
||||
class TestCourseStatusPATCH(CourseStatusAPITestCase, MobileAuthUserTestMixin,
|
||||
MobileCourseAccessTestMixin, MilestonesTestCaseMixin):
|
||||
|
||||
@@ -4,6 +4,8 @@ Views for user API
|
||||
|
||||
|
||||
import six
|
||||
from completion.utilities import get_key_to_last_completed_block
|
||||
from completion.exceptions import UnavailableCompletionData
|
||||
from django.contrib.auth.signals import user_logged_in
|
||||
from django.shortcuts import redirect
|
||||
from django.utils import dateparse
|
||||
@@ -22,7 +24,7 @@ from lms.djangoapps.courseware.model_data import FieldDataCache
|
||||
from lms.djangoapps.courseware.module_render import get_module_for_descriptor
|
||||
from lms.djangoapps.courseware.views.index import save_positions_recursively_up
|
||||
from lms.djangoapps.courseware.access_utils import ACCESS_GRANTED
|
||||
from lms.djangoapps.mobile_api.utils import API_V05
|
||||
from lms.djangoapps.mobile_api.utils import API_V05, API_V1
|
||||
from openedx.features.course_duration_limits.access import check_course_expired
|
||||
from student.models import CourseEnrollment, User
|
||||
from xmodule.modulestore.django import modulestore
|
||||
@@ -83,6 +85,8 @@ class UserCourseStatus(views.APIView):
|
||||
Get or update the ID of the module that the specified user last
|
||||
visited in the specified course.
|
||||
|
||||
Get ID of the last completed block in case of version v1
|
||||
|
||||
**Example Requests**
|
||||
|
||||
GET /api/mobile/{version}/users/{username}/course_status_info/{course_id}
|
||||
@@ -110,6 +114,11 @@ class UserCourseStatus(views.APIView):
|
||||
visited in the course.
|
||||
* last_visited_module_path: The ID of the modules in the path from the
|
||||
last visited module to the course module.
|
||||
|
||||
For version v1 GET request response includes the following values.
|
||||
|
||||
* last_visited_block_id: ID of the last completed block.
|
||||
|
||||
"""
|
||||
|
||||
http_method_names = ["get", "patch"]
|
||||
@@ -183,8 +192,19 @@ class UserCourseStatus(views.APIView):
|
||||
"""
|
||||
Get the ID of the module that the specified user last visited in the specified course.
|
||||
"""
|
||||
user_course_status = self._get_course_info(request, course)
|
||||
|
||||
return self._get_course_info(request, course)
|
||||
api_version = self.kwargs.get("api_version")
|
||||
if api_version == API_V1:
|
||||
# Get ID of the block that the specified user last visited in the specified course.
|
||||
try:
|
||||
block_id = str(get_key_to_last_completed_block(request.user, course.id))
|
||||
except UnavailableCompletionData:
|
||||
block_id = ""
|
||||
|
||||
user_course_status.data["last_visited_block_id"] = block_id
|
||||
|
||||
return user_course_status
|
||||
|
||||
@mobile_course_access(depth=2)
|
||||
def patch(self, request, course, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user