forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move progress related apis permissions to standard permission f…
…ile so it can be override for data researchers
- Loading branch information
1 parent
3381de6
commit f1ed047
Showing
4 changed files
with
66 additions
and
17 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
lms/djangoapps/course_home_api/course_metadata/permissions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from opaque_keys.edx.keys import CourseKey | ||
|
||
from rest_framework.permissions import BasePermission | ||
|
||
from lms.djangoapps.course_api.api import course_detail | ||
from lms.djangoapps.courseware.access import has_access | ||
from lms.djangoapps.courseware.courses import check_course_access | ||
|
||
|
||
class HasCourseLoadPermission(BasePermission): | ||
""" | ||
Permission to check if the user has load access to the course. | ||
""" | ||
def has_permission(self, request, view): | ||
course_key_string = view.kwargs.get('course_key_string') | ||
course_key = CourseKey.from_string(course_key_string) | ||
course = course_detail(request, request.user.username, course_key) | ||
|
||
# Check course load access | ||
load_access = check_course_access( | ||
course, | ||
request.user, | ||
'load', | ||
check_if_enrolled=True, | ||
check_if_authenticated=True, | ||
apply_enterprise_checks=True, | ||
) | ||
|
||
if not load_access.has_access: | ||
return False | ||
|
||
request.course_load_access = load_access.to_json() | ||
request.user_has_staff_access = has_access(request.user, 'staff', course_key).has_access | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from opaque_keys.edx.keys import CourseKey | ||
|
||
from rest_framework.permissions import BasePermission | ||
from lms.djangoapps.courseware.access import has_access | ||
from lms.djangoapps.course_api.api import course_detail | ||
|
||
|
||
class HasProgressTabAccess(BasePermission): | ||
""" | ||
Permission to check if the user has load access | ||
""" | ||
|
||
def has_permission(self, request, view): | ||
course_key_string = view.kwargs.get('course_key_string') | ||
course_key = CourseKey.from_string(course_key_string) | ||
is_staff = bool(has_access(request.user, 'staff', course_key)) | ||
course = course_detail(request, request.user.username, course_key) | ||
if is_staff or bool(has_access(request.user, 'load', course)): | ||
request.has_progress_tab_staff_access = is_staff | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters