-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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: converting existing api to drf base api ( 1st api ). get_student_progress_url #35039
Conversation
@@ -231,6 +233,28 @@ def wrapped(*args, **kwargs): | |||
return decorator | |||
|
|||
|
|||
def verify_course_permission(permission): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added new decorator because in existing one they are not passing self
in constructor and its not compatabile with DRF apiview.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making a new decorator, does it make more sense to make a custom permission class instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach mostly seems sound, I think I'd like to see if we can use standard DRF permissions management as much as possible instead of making our own decorators. What do you think?
@@ -1735,21 +1779,21 @@ def get_student_progress_url(request, course_id): | |||
'progress_url': '/../...' | |||
} | |||
""" | |||
course_id = CourseKey.from_string(course_id) | |||
user = get_student_from_identifier(request.POST.get('unique_student_identifier')) | |||
authentication_classes = (JwtAuthentication, BearerAuthentication, SessionAuthentication) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you don't need to define this, since the base authentication classes should be the correct ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I simply matched the other api in this file https://github.com/openedx/edx-platform/blob/master/lms/djangoapps/instructor/views/api.py#L1587
@@ -231,6 +233,28 @@ def wrapped(*args, **kwargs): | |||
return decorator | |||
|
|||
|
|||
def verify_course_permission(permission): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making a new decorator, does it make more sense to make a custom permission class instead?
@@ -1,3 +1,4 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary newline.
@feanil you can review this again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@awais786 that looks great to me!
assert response.status_code == 200 | ||
|
||
expected_headers = { | ||
'Allow': 'POST, OPTIONS', # drf view brings this key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRF returns this extra key Allow
. DRF code reference here.
master branch returns this header response
{
'Content-Type': 'application/json',
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Vary': 'Cookie, Accept-Language, origin',
'X-Frame-Options': 'DENY',
'Content-Language': 'en',
'Content-Length': '130'
}
current branch returns this
{
'Content-Type': 'application/json',
'Allow': 'POST, OPTIONS',
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Vary': 'Cookie, Accept-Language, origin',
'X-Frame-Options': 'DENY',
'Content-Language': 'en',
'Content-Length': '121'
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@feanil I have only found one difference between new vs old api. Old apis are not using any IsAuthenticated
method. So in case of anonymous
user they return 403 which comes from permissions verification but in new API drf will return 401
.
This test on this branch returns 401 which is standard DRF status code.
def test_get_student_progress_url_with_anonymous_user(self):
""" Test that progress_url returns 403 without credentials. """
self.client.logout()
url = reverse('get_student_progress_url', kwargs={'course_id': str(self.course.id)})
data = {'unique_student_identifier': self.students[0].email}
response = self.client.post(url, data)
assert response.status_code == 401
But on master branch its 403
and this test fails on master.
FAILED lms/djangoapps/instructor/tests/test_api.py::TestInstructorAPILevelsDataDump::test_get_student_progress_url_with_anonymous_user - assert 403 == 401
What do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its good to go now.
875605f
to
d7dbdfe
Compare
Adding generic permission class. Added standard authentication classes.
d7dbdfe
to
dd33ae2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@awais786 thanks for verifying with Postman! I think you can merge this at your leisure. Don't forget to mention it in the #cc-edx-platform slack channel.
2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production. |
2U Release Notice: This PR has been deployed to the edX production environment. |
Adding generic permission class. Added standard authentication classes. (cherry picked from commit 39dd3c0)
Issue for tracking.
Updating api code using DRF.
Steps to verify: