Files
edx-platform/lms/djangoapps/learner_dashboard/views.py
Ahtisham Shahid 987c641d82 feat: created API to get program discussion iframe (#29205)
fix: py lint issues fixed

feat: added test cases for API

fix: py lint issues fixed and added tests

fix: updated tests and refactored

fix: fixed return type in the function

fix: conflicts resolved and linter issue

refactor: updated code to accommodate backward compatibility

refactor: updated classes for code clean up

feat: added test for ProgramDetailFragment

feat: added a new flag for masters discussion

refactor: updated flag names and other refactors
2021-11-22 11:27:45 +05:00

122 lines
4.1 KiB
Python

"""Learner dashboard views"""
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_GET
from rest_framework import permissions, status
from rest_framework.authentication import SessionAuthentication
from rest_framework.response import Response
from rest_framework.views import APIView
from lms.djangoapps.learner_dashboard.utils import masters_program_tab_view_is_enabled
from common.djangoapps.edxmako.shortcuts import render_to_response
from lms.djangoapps.learner_dashboard.permissions import IsEnrolledInProgram
from lms.djangoapps.learner_dashboard.programs import (
ProgramDetailsFragmentView,
ProgramDiscussionLTI,
ProgramsFragmentView
)
from lms.djangoapps.program_enrollments.rest_api.v1.utils import ProgramSpecificViewMixin
from openedx.core.djangoapps.programs.models import ProgramsApiConfig
from openedx.core.lib.api.authentication import BearerAuthentication
@login_required
@require_GET
def program_listing(request):
"""View a list of programs in which the user is engaged."""
programs_config = ProgramsApiConfig.current()
programs_fragment = ProgramsFragmentView().render_to_fragment(request, programs_config=programs_config)
context = {
'disable_courseware_js': True,
'programs_fragment': programs_fragment,
'nav_hidden': True,
'show_dashboard_tabs': True,
'show_program_listing': programs_config.enabled,
'uses_bootstrap': True,
}
return render_to_response('learner_dashboard/programs.html', context)
@login_required
@require_GET
def program_details(request, program_uuid):
"""View details about a specific program."""
programs_config = ProgramsApiConfig.current()
program_fragment = ProgramDetailsFragmentView().render_to_fragment(
request, program_uuid, programs_config=programs_config
)
context = {
'program_fragment': program_fragment,
'show_program_listing': programs_config.enabled,
'show_dashboard_tabs': True,
'nav_hidden': True,
'disable_courseware_js': True,
'uses_bootstrap': True,
}
return render_to_response('learner_dashboard/program_details.html', context)
class ProgramDiscussionIframeView(APIView, ProgramSpecificViewMixin):
"""
A view for retrieving Program Discussion IFrame .
Path: ``/dashboard/programs/{program_uuid}/discussion/``
Accepts: [GET]
------------------------------------------------------------------------------------
GET
------------------------------------------------------------------------------------
**Returns**
* 200: OK - Contains a program discussion iframe.
* 401: The requesting user is not authenticated.
* 403: The requesting user lacks access to the program.
* 404: The requested program does not exist.
**Response**
In the case of a 200 response code, the response will be iframe HTML and status if discussion is configured
for the program.
**Example**
{
'enabled_for_masters': True,
'discussion': {
"iframe": "
<iframe
id='lti-tab-embed'
style='width: 100%; min-height: 800px; border: none'
srcdoc='{srcdoc}'
>
</iframe>
",
"enabled": false
}
}
"""
authentication_classes = (BearerAuthentication, SessionAuthentication)
permission_classes = (permissions.IsAuthenticated, IsEnrolledInProgram)
def get(self, request, program_uuid):
""" GET handler """
program_discussion_lti = ProgramDiscussionLTI(program_uuid, request)
return Response(
{
'enabled': masters_program_tab_view_is_enabled(),
'discussion': {
'iframe': program_discussion_lti.render_iframe(),
'configured': bool(program_discussion_lti.configuration),
}
},
status=status.HTTP_200_OK
)