refactor: resolved doc issues and expected response (#30076)
* refactor: resolved doc issues and expected response
This commit is contained in:
@@ -86,13 +86,23 @@ class CourseLiveConfigurationSerializer(serializers.ModelSerializer):
|
||||
Serialize configuration responses
|
||||
"""
|
||||
lti_configuration = LtiSerializer(many=False, read_only=False)
|
||||
pii_sharing_allowed = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = CourseLiveConfiguration
|
||||
|
||||
fields = ['course_key', 'provider_type', 'enabled', 'lti_configuration']
|
||||
fields = ['course_key', 'provider_type', 'enabled', 'lti_configuration', 'pii_sharing_allowed']
|
||||
read_only_fields = ['course_key']
|
||||
|
||||
def get_pii_sharing_allowed(self, instance):
|
||||
return self.context['pii_sharing_allowed']
|
||||
|
||||
def to_representation(self, instance):
|
||||
payload = super().to_representation(instance)
|
||||
if not payload['lti_configuration']:
|
||||
payload['lti_configuration'] = LtiSerializer(LtiConfiguration()).data
|
||||
return payload
|
||||
|
||||
def create(self, validated_data):
|
||||
"""
|
||||
Create a new CourseLiveConfiguration entry in model
|
||||
@@ -128,14 +138,6 @@ class CourseLiveConfigurationSerializer(serializers.ModelSerializer):
|
||||
f'Provider type {data.get("provider_type")} does not exist')
|
||||
return instance
|
||||
|
||||
def to_representation(self, instance: CourseLiveConfiguration) -> dict:
|
||||
"""
|
||||
Serialize data into a dictionary, to be used as a response
|
||||
"""
|
||||
payload = super().to_representation(instance)
|
||||
payload.update({'pii_sharing_allowed': self.context['pii_sharing_allowed']})
|
||||
return payload
|
||||
|
||||
def _update_lti(
|
||||
self,
|
||||
instance: CourseLiveConfiguration,
|
||||
|
||||
@@ -78,13 +78,15 @@ class TestCourseLiveConfigurationView(ModuleStoreTestCase, APITestCase):
|
||||
response = self._get()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
expected_data = {
|
||||
'enabled': False,
|
||||
'enabled': True,
|
||||
'course_key': None,
|
||||
'pii_sharing_allowed': True,
|
||||
'lti_configuration': {
|
||||
'lti_1p1_client_key': '',
|
||||
'lti_1p1_client_secret': '',
|
||||
'lti_1p1_launch_url': '',
|
||||
'lti_config': None,
|
||||
'version': None
|
||||
'lti_config': {},
|
||||
'version': 'lti_1p1'
|
||||
},
|
||||
'provider_type': ''
|
||||
}
|
||||
|
||||
@@ -60,9 +60,10 @@ class CourseLiveConfigurationView(APIView):
|
||||
"message": "PII sharing is not allowed on this course"
|
||||
})
|
||||
|
||||
configuration = CourseLiveConfiguration.get(course_id)
|
||||
configuration = CourseLiveConfiguration.get(course_id) or CourseLiveConfiguration()
|
||||
serializer = CourseLiveConfigurationSerializer(configuration, context={
|
||||
"pii_sharing_allowed": pii_sharing_allowed,
|
||||
"course_id": course_id
|
||||
})
|
||||
|
||||
return Response(serializer.data)
|
||||
@@ -148,27 +149,44 @@ class CourseLiveProvidersView(APIView):
|
||||
)
|
||||
permission_classes = (IsStaffOrInstructor,)
|
||||
|
||||
@apidocs.schema(
|
||||
parameters=[
|
||||
apidocs.string_parameter(
|
||||
'course_id',
|
||||
apidocs.ParameterLocation.PATH,
|
||||
description="The course for which to get provider list",
|
||||
)
|
||||
],
|
||||
responses={
|
||||
200: CourseLiveConfigurationSerializer,
|
||||
401: "The requester is not authenticated.",
|
||||
403: "The requester cannot access the specified course.",
|
||||
404: "The requested course does not exist.",
|
||||
},
|
||||
)
|
||||
@ensure_valid_course_key
|
||||
@verify_course_exists()
|
||||
def get(self, request, course_id: str, **_kwargs) -> Response:
|
||||
"""
|
||||
Handle HTTP/GET requests
|
||||
"""
|
||||
A view for retrieving Program live IFrame .
|
||||
|
||||
Path: ``api/course_live/providers/{course_id}/``
|
||||
|
||||
Accepts: [GET]
|
||||
|
||||
------------------------------------------------------------------------------------
|
||||
GET
|
||||
------------------------------------------------------------------------------------
|
||||
|
||||
**Returns**
|
||||
* 200: Returns list of providers with active provider,
|
||||
* 401: The requester is not authenticated.
|
||||
* 403: The requester cannot access the specified course.
|
||||
* 404: The requested course does not exist.
|
||||
**Response**
|
||||
|
||||
In the case of a 200 response code, the response will be available live providers.
|
||||
|
||||
**Example**
|
||||
|
||||
{
|
||||
"providers": {
|
||||
"active": "zoom",
|
||||
"available": {
|
||||
'zoom': {
|
||||
'name': 'Zoom LTI PRO',
|
||||
'features': []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
data = self.get_provider_data(course_id)
|
||||
return Response(data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user