Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: roster endpoint POC #208

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions edx_exams/apps/lti/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@ def test_lti_launch(self, mock_create_launch_url):
resource_link_id=self.exam.resource_id,
external_user_id=str(self.course_staff_user.anonymous_user_id),
context_id=self.exam.course_id,
custom_parameters={
'roster_url': 'http://test.exams:18740/lti/exam/1/instructor_tool/roster',
}
)
)
self.assertEqual(response.status_code, 302)
Expand Down
1 change: 1 addition & 0 deletions edx_exams/apps/lti/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
path('end_assessment/<int:attempt_id>', views.end_assessment, name='end_assessment'),
path('start_proctoring/<int:attempt_id>', views.start_proctoring, name='start_proctoring'),
path('exam/<int:exam_id>/instructor_tool', views.launch_instructor_tool, name='instructor_tool'),
path('exam/<int:exam_id>/instructor_tool/roster', views.exam_roster, name='exam_roster'),
]
36 changes: 36 additions & 0 deletions edx_exams/apps/lti/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
from decimal import Decimal
from urllib.parse import urljoin

from django.conf import settings
from django.contrib.auth import login
from django.http import JsonResponse
from django.shortcuts import redirect
from django.urls import reverse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from lti_consumer.api import get_end_assessment_return, get_lti_1p3_launch_start_url
Expand All @@ -25,6 +28,7 @@
from edx_exams.apps.core.api import (
get_attempt_by_id,
get_attempt_for_user_with_attempt_number_and_resource_id,
get_exam_attempts,
get_exam_by_id,
get_exam_url_path,
update_attempt_status
Expand Down Expand Up @@ -360,6 +364,38 @@
resource_link_id=exam.resource_id,
external_user_id=str(user.anonymous_user_id),
context_id=exam.course_id,
custom_parameters={
'roster_url': settings.LTI_API_BASE + reverse('lti:exam_roster', kwargs={'exam_id': exam.id}),
}
)

# user is authenticated via JWT so use that to create a
# session with this service's authentication backend
request.user.backend = EDX_OAUTH_BACKEND
login(request, user)

return redirect(get_lti_1p3_launch_start_url(launch_data))


@csrf_exempt
@require_http_methods(['GET'])
def exam_roster(request, exam_id):
# pragma: no cover
"""
Temporary endpoint to prove we can authenticate this request properly
"""
user = request.user
exam = get_exam_by_id(exam_id)

Check warning on line 388 in edx_exams/apps/lti/views.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/lti/views.py#L387-L388

Added lines #L387 - L388 were not covered by tests
if not user.is_staff and not user.has_course_staff_permission(exam.course_id):
return Response(status=status.HTTP_403_FORBIDDEN)

Check warning on line 390 in edx_exams/apps/lti/views.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/lti/views.py#L390

Added line #L390 was not covered by tests

attempts = get_exam_attempts(exam_id)
attempts.select_related('user')

Check warning on line 393 in edx_exams/apps/lti/views.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/lti/views.py#L392-L393

Added lines #L392 - L393 were not covered by tests

users = set(attempt.user for attempt in attempts)
roster = [
(user.anonymous_user_id, user.username)
for user in users
]

return JsonResponse(roster, safe=False)

Check warning on line 401 in edx_exams/apps/lti/views.py

View check run for this annotation

Codecov / codecov/patch

edx_exams/apps/lti/views.py#L401

Added line #L401 was not covered by tests
1 change: 1 addition & 0 deletions edx_exams/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
SESSION_COOKIE_DOMAIN = 'localhost'

ROOT_URL = 'http://localhost:18740'
LTI_API_BASE = 'http://localhost:18740'
LMS_ROOT_URL = 'http://localhost:18000'
LEARNING_MICROFRONTEND_URL = 'http://localhost:2000'
EXAMS_DASHBOARD_MFE_URL = 'http://localhost:2020'
Expand Down
1 change: 1 addition & 0 deletions edx_exams/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)

ROOT_URL = 'http://test.exams:18740'
LTI_API_BASE = 'http://test.exams:18740'
LMS_ROOT_URL = 'http://test.lms:18000'
LEARNING_MICROFRONTEND_URL = 'http://test.learning:2000'

Expand Down
Loading