-
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: course_roles setup #33609
Closed
Closed
feat: course_roles setup #33609
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fa998c5
docs: course_roles readme file
julianpalmerio 00fd5df
feat: course_roles Model Setup (#33229)
julianpalmerio 3615345
docs: adr for data storage in course_roles djangoapp
hsinkoff cc47ebd
docs: adr for course_level roles
lucascalvino 722eb4c
chore: update new table diagram
lucascalvino 0969d0d
feat: course_roles permission check helper function (#33201)
julianpalmerio 5c56213
feat: course_roles add permission checks back end part 1 (#33347)
julianpalmerio 773eb4f
feat: course_roles Create permissions in db table (#33394)
julianpalmerio affa8f9
feat: course_roles permission check back end part 2 (#33432)
julianpalmerio 4ac95de
feat: course_roles mfe-course authoring helper function (#33599)
julianpalmerio 447423f
feat: Waffle Flag for course_roles helper functions
hsinkoff c56064b
feat: add course_roles permisisons checks where roles are currently c…
hsinkoff 7ece66f
feat: remove caching from course_roles
hsinkoff d1a1bdb
chore: prepare branch to PR to master
hsinkoff 4b8e1f3
feat: expose course_roles.use_permission_checks waffle flag for mfe use
hsinkoff 97c568e
docs: update documenation related to course_roles
hsinkoff 9f766af
feat: rename course_roles helper functions
hsinkoff a15b42d
feat: remove course roles namespace for models
julianpalmerio 0098ee4
feat: remove course roles namespace for models
julianpalmerio 372235e
feat: update migrations
julianpalmerio ccebf0d
feat: add unique constraints in many to many relationships
julianpalmerio ec4c505
feat: update migrations
julianpalmerio 8458fb2
test: Add CourseOverview loading to test_helpers.py
julianpalmerio ac71c59
test: Add CourseOverview loading int test_views.py
julianpalmerio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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 |
---|---|---|
|
@@ -25,6 +25,14 @@ | |
OrgLibraryUserRole, | ||
OrgStaffRole | ||
) | ||
from openedx.core.djangoapps.course_roles.helpers import ( | ||
user_has_permission_course_org, | ||
user_has_permission_list_course_org, | ||
user_has_permission_course, | ||
user_has_permission_list_course, | ||
user_has_permission_list_org | ||
) | ||
from openedx.core.djangoapps.course_roles.permissions import CourseRolesPermission | ||
|
||
# Studio permissions: | ||
STUDIO_EDIT_ROLES = 8 | ||
|
@@ -79,6 +87,20 @@ def get_user_permissions(user, course_key, org=None): | |
Can also set course_key=None and pass in an org to get the user's | ||
permissions for that organization as a whole. | ||
""" | ||
COURSE_INSTRUCTOR_ROLE_PERMISSIONS = [ | ||
CourseRolesPermission.MANAGE_CONTENT.value, | ||
CourseRolesPermission.MANAGE_COURSE_SETTINGS.value, | ||
CourseRolesPermission.MANAGE_ADVANCED_SETTINGS.value, | ||
CourseRolesPermission.VIEW_COURSE_SETTINGS.value, | ||
CourseRolesPermission.MANAGE_ALL_USERS.value, | ||
] | ||
STAFF_ROLE_PERMISSIONS = [ | ||
CourseRolesPermission.MANAGE_CONTENT.value, | ||
CourseRolesPermission.MANAGE_COURSE_SETTINGS.value, | ||
CourseRolesPermission.MANAGE_ADVANCED_SETTINGS.value, | ||
CourseRolesPermission.VIEW_COURSE_SETTINGS.value, | ||
CourseRolesPermission.MANAGE_USERS_EXCEPT_ADMIN_AND_STAFF.value, | ||
] | ||
Comment on lines
+90
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we move these constants to the top of the file? |
||
if org is None: | ||
org = course_key.org | ||
course_key = course_key.for_branch(None) | ||
|
@@ -89,9 +111,23 @@ def get_user_permissions(user, course_key, org=None): | |
return STUDIO_NO_PERMISSIONS | ||
all_perms = STUDIO_EDIT_ROLES | STUDIO_VIEW_USERS | STUDIO_EDIT_CONTENT | STUDIO_VIEW_CONTENT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this be replaced later on by these permissions definitions? |
||
# global staff, org instructors, and course instructors have all permissions: | ||
if GlobalStaff().has_user(user) or OrgInstructorRole(org=org).has_user(user): | ||
# TODO: course roles: If the course roles feature flag is disabled the user_has_permission_list_org call | ||
# below will never return true. | ||
# Remove the OrgInstructorRole .has_user call when course_roles Django app are implemented. | ||
if ( | ||
GlobalStaff().has_user(user) | ||
or OrgInstructorRole(org=org).has_user(user) | ||
or user_has_permission_list_org(user, COURSE_INSTRUCTOR_ROLE_PERMISSIONS, org) | ||
): | ||
return all_perms | ||
if course_key and user_has_role(user, CourseInstructorRole(course_key)): | ||
|
||
# TODO: course roles: If the course roles feature flag is disabled the user_has_permission_list_course call | ||
# below will never return true. | ||
# Remove the user_has_role call when course_roles Django app are implemented. | ||
if course_key and ( | ||
user_has_role(user, CourseInstructorRole(course_key)) | ||
or user_has_permission_list_course(user, COURSE_INSTRUCTOR_ROLE_PERMISSIONS, course_key) | ||
): | ||
return all_perms | ||
# HACK: Limited Staff should not have studio read access. However, since many LMS views depend on the | ||
# `has_course_author_access` check and `course_author_access_required` decorator, we have to allow write access | ||
|
@@ -101,14 +137,31 @@ def get_user_permissions(user, course_key, org=None): | |
# The permissions matrix from the RBAC project (https://github.com/openedx/platform-roadmap/issues/246) shows that | ||
# the LMS and Studio permissions will be separated as a part of this project. Once this is done (and this code is | ||
# not removed during its implementation), we can replace the Limited Staff permissions with more granular ones. | ||
|
||
# Limited Course Staff does not have access to Studio. | ||
# TODO: course roles: Remove this validation when course roles app are implemented | ||
if course_key and user_has_role(user, CourseLimitedStaffRole(course_key)): | ||
return STUDIO_EDIT_CONTENT | ||
# Staff have all permissions except EDIT_ROLES: | ||
if OrgStaffRole(org=org).has_user(user) or (course_key and user_has_role(user, CourseStaffRole(course_key))): | ||
# TODO: course roles: If the course roles feature flag is disabled the | ||
# course_or_user_has_permission_list_org call below will never return true. | ||
# Remove the OrgStaffRole has_user call and the user_has_role call | ||
# when course_roles Django app are implemented. | ||
if (OrgStaffRole(org=org).has_user(user) or | ||
(course_key and user_has_role(user, CourseStaffRole(course_key)))) or ( | ||
user_has_permission_list_course_org(user, STAFF_ROLE_PERMISSIONS, course_key, org) | ||
): | ||
return STUDIO_VIEW_USERS | STUDIO_EDIT_CONTENT | STUDIO_VIEW_CONTENT | ||
# Otherwise, for libraries, users can view only: | ||
|
||
if course_key and isinstance(course_key, LibraryLocator): | ||
if OrgLibraryUserRole(org=org).has_user(user) or user_has_role(user, LibraryUserRole(course_key)): | ||
# TODO: course roles: If the course roles feature flag is disabled the user_has_permission_course_org | ||
# call below will never return true. | ||
# Remove the OrgLibraryUserRole has_user call and the user_has_role call | ||
# when course_roles Django app are implemented. | ||
if (OrgLibraryUserRole(org=org).has_user(user) or user_has_role(user, LibraryUserRole(course_key))) or ( | ||
user_has_permission_course_org(user, CourseRolesPermission.MANAGE_LIBRARIES.value, course_key, org) | ||
): | ||
return STUDIO_VIEW_USERS | STUDIO_VIEW_CONTENT | ||
return STUDIO_NO_PERMISSIONS | ||
|
||
|
@@ -230,9 +283,14 @@ def _check_caller_authority(caller, role): | |
# superuser | ||
if GlobalStaff().has_user(caller): | ||
return | ||
|
||
if isinstance(role, (GlobalStaff, CourseCreatorRole, OrgContentCreatorRole)): # lint-amnesty, pylint: disable=no-else-raise | ||
raise PermissionDenied | ||
elif isinstance(role, CourseRole): # instructors can change the roles w/in their course | ||
if not user_has_role(caller, CourseInstructorRole(role.course_key)): | ||
# TODO: course roles: If the course roles feature flag is disabled the user_has_permission_course | ||
# call below will never return true. | ||
# Remove the user_has_role call when course_roles Django app are implemented. | ||
if not ( | ||
user_has_role(caller, CourseInstructorRole(role.course_key)) or | ||
user_has_permission_course(caller, CourseRolesPermission.MANAGE_ALL_USERS.value, role.course_key) | ||
): | ||
raise PermissionDenied |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is this still a TODO? I see the
user_has_permission_course
checks whether the flag is enabled.